buildingmotif.shape_builder.shape#

Functions

AND(*nodes)

add AND property

NOT(node)

add NOT property

OR(*nodes)

add OR property

XONE(*nodes)

add XONE property

Classes

NodeShape([identifier, message])

Class for constructing Node Shapes programatically

PropertyShape([identifier, message])

Shape([identifier, message])

Base class for constructing shapes programatically

class Shape(identifier: Optional[Union[Node, str]] = None, message: Optional[str] = None)[source]#

Base class for constructing shapes programatically

add_property(property: URIRef, object: Node)[source]#

Add property to shape

Parameters:
  • property (URIRef) – ref of property

  • object (Node) – ref of object

add_list_property(property: URIRef, nodes: Union[List[Node], Tuple[Node, ...]])[source]#

Add property which references list to shape

Parameters:
  • property (URIRef) – ref of property

  • nodes (Union[List[Node], Tuple[Node, ...]]) – nodes to include in list

OR(*nodes: Node)[source]#

add OR property

Parameters:

nodes (Union[List[Node], Tuple[Node, ...]]) – list of nodes to OR

AND(*nodes: Node)[source]#

add AND property

Parameters:

nodes (Union[List[Node], Tuple[Node, ...]]) – list of nodes to AND

NOT(node: Node)[source]#

add NOT property

Parameters:

nodes (Union[List[Node], Tuple[Node, ...]]) – list of nodes to NOT

XONE(*nodes: Node)[source]#

add XONE property

Parameters:

nodes (Union[List[Node], Tuple[Node, ...]]) – list of nodes to XONE

add(triple: Tuple[Node, Node, Node])[source]#

Add a triple with self as context

class NodeShape(identifier: Optional[Union[Node, str]] = None, message: Optional[str] = None)[source]#

Class for constructing Node Shapes programatically

of_class(class_: Node, active=False)[source]#

Add constraint that target much be of a certain class

Parameters:
  • class (Node) – class of target

  • active (bool) – should shape actively target the class or not

always_run()[source]#

Add blank node target This target insures that the shape will always be evaluated. If the shape has properties this can cause it to fail.

count(exactly: int = None)[source]#

Add an exact count constraint.

Parameters:

exactly (int) – exact number of instances of class to match

has_property(property: Union[Node, URIRef])[source]#

Add property constraint.

Parameters:

property (Union[Node, URIRef]) – property shape or property to add constraint for

class PropertyShape(identifier: Optional[Union[Node, str]] = None, message: Optional[str] = None)[source]#
has_path(path: Node, zero_or_one: bool = False, zero_or_more: bool = False, one_or_more: bool = False) PropertyShape[source]#

Add path constraint to shape. zero_or_one, zero_or_more, and one_or_more flags are mutually exclusive

Parameters:
  • path (Node) – path to add constraint for

  • zero_or_one (bool) – match zero or one instances of path

  • zero_or_more (bool) – match zero or more instances of path

  • one_or_more (bool) – match one or more instances of path

matches(target: Node, type: URIRef, min: int = None, max: int = None, exactly: int = None, qualified: bool = False)[source]#

Add target matches constraint to property shape

Parameters:
  • target (Node) – target node to specify what should be matched, usually shape or class

  • type (URIRef) – sh:class or sh:node

  • min (int) – min count of matched entities

  • max (int) – max count of matched entities

  • exactly (int) – exact count of matched entities (takes precidence over min/max)

  • qualified (bool) – Is this property qualified or universal

matches_class(class_: URIRef, min: int = None, max: int = None, exactly: int = None, qualified=False)[source]#

Add target matches class constraint to property shape

Parameters:
  • class (Node) – target class what should be matched

  • min (int) – min count of matched entities

  • max (int) – max count of matched entities

  • exactly (int) – exact count of matched entities (takes precidence over min/max)

  • qualified (bool) – Is this property qualified or universal

matches_shape(shape: Node, min: int = None, max: int = None, exactly: int = None, qualified=False)[source]#

Add target matches shape constraint to property shape

Parameters:
  • shape (Node) – target shape what should be matched

  • min (int) – min count of matched entities

  • max (int) – max count of matched entities

  • exactly (int) – exact count of matched entities (takes precidence over min/max)

  • qualified (bool) – Is this property qualified or universal

OR(*nodes: Node) Shape[source]#

add OR property

Parameters:

nodes (Union[List[Node], Tuple[Node, ...]]) – list of nodes to OR

AND(*nodes: Node) Shape[source]#

add AND property

Parameters:

nodes (Union[List[Node], Tuple[Node, ...]]) – list of nodes to AND

NOT(node: Node) Shape[source]#

add NOT property

Parameters:

nodes (Union[List[Node], Tuple[Node, ...]]) – list of nodes to NOT

XONE(*nodes: Node) Shape[source]#

add XONE property

Parameters:

nodes (Union[List[Node], Tuple[Node, ...]]) – list of nodes to XONE