ccobra.spatial

Spatial reasoning submodule that contains utility functionality to facilitate modeling and analyses in the domain of spatial reasoning.

Constants

Note

Since the built-in lists and dictionaries are intended to be constants, avoid altering them to avoid unwanted behavior.

ccobra.spatial.CARDINAL_DIRECTIONS = ['north', 'east', 'south', 'west']

List with the four cardinal directions.

ccobra.spatial.ORDINAL_DIRECTIONS = ['north-east', 'north-west', 'south-east', 'south-west']

List with the four ordinal directions.

ccobra.spatial.OPPOSITES: dict(str, str)

Dictionary mapping a spatial relation to its opposite.

ccobra.spatial.CARDINAL_COMBINATIONS: dict(str, set(set))

Dictionary mapping an ordinal relation to a set of the cardinal direction it is composed of.

Functions

ccobra.spatial.invert(statement)[source]

Inverts a given spatial statement (in list form). Thereby, the statement preserves its meaning, but uses the opposite relation. For example: [“left”, “A”, “B”] becomes [“right”, “B”, “A”]. This can be useful to bring a set of statements in a unified form.

Parameters:

statement (list(str)) – The spatial statement in list form.

Returns:

The inverted statement.

Return type:

list(str)

ccobra.spatial.combine_cardinal_relations(card1, card2)[source]

Combines two cardinal relations. If the cardinal directions do oppose each other, ‘None’ is returned. If they are the same, the same relation will be returned. Otherwise, they will be combined into an ordinal direction. For example: combine_cardinal_relations(“north”, “south”) –> None combine_cardinal_relations(“north”, “north”) –> “north” combine_cardinal_relations(“north”, “west”) –> “north-west”

Parameters:
  • card1 (str) – The first cardinal direction

  • card2 (str) – The second cardinal direction

Returns:

The combined relation (or None)

Return type:

str

ccobra.spatial.combine_ordinal_relations(ord1, ord2)[source]

Combines two ordinal relations. If the ordinal directions do oppose each other, ‘None’ is returned. If they are the same, the same relation will be returned. Otherwise, they will be combined into an cardinal direction. For example: combine_ordinal_relations(“north-west”, “south-east”) –> None combine_ordinal_relations(“north-west”, “north-west”) –> “north-west” combine_ordinal_relations(“north-west”, “south-west”) –> “west”

Parameters:
  • ord1 (str) – The first ordinal direction

  • ord2 (str) – The second ordinal direction

Returns:

The combined relation (or None)

Return type:

str

ccobra.spatial.is_partially_equal(relation1, relation2)[source]

Tests if two relations are sharing a same component. For example, “south-east” and “south-west” share the partitial direction “south”, and would therefore be partially equal.

Parameters:
  • relation1 (str) – The first relation

  • relation2 (str) – The second relation

Returns:

True, if both relations have a shared component

Return type:

bool