topologicpy.Ontology module

class topologicpy.Ontology.Ontology

Bases: object

A lightweight ontology helper class for TopologicPy.

The Ontology class provides a dictionary-based semantic layer for TopologicPy topologies and graphs. It does not replace TopologicPy dictionaries. Instead, it standardises semantic keys such as ontology class, category, label, URI, IFC class, IFC GUID, source, and provenance.

The class intentionally avoids mandatory RDF/OWL dependencies. It can export simple RDF Turtle strings/files directly from TopologicPy dictionaries and graph connectivity.

Methods

Annotate(topology[, ontologyClass, ...])

Annotates a topology using canonical ontology dictionary keys.

AnnotateIFC(topology[, ifcClass, ifcGUID, ...])

Annotates a topology using IFC metadata.

AnnotateSubtopologies(topology[, vertices, ...])

Annotates the requested subtopologies with inferred ontology classes.

BOTClassByClass(ontologyClass[, defaultValue])

Returns a BOT class from a TopologicPy ontology class.

Category(topology[, defaultValue])

Returns the category assigned to the input topology.

CategoryByClass(ontologyClass[, defaultValue])

Returns a category for the input ontology class.

Class(topology[, defaultValue])

Returns the ontology class assigned to the input topology.

ClassByIFCClass(ifcClass[, defaultValue])

Returns a TopologicPy ontology class from an IFC class.

ClassByTopology(topology[, defaultValue])

Returns a TopologicPy ontology class inferred from the topology type.

ExpandQName(qname[, defaultValue])

Expands a QName into a full URI.

ExportOntologyTTL(path[, includeBOT, ...])

Exports the TopologicPy ontology specification as a Turtle file.

ExportRDF(topology, path[, format, ...])

Exports a topology or graph to an RDF file using RDFLib.

ExportTTL(topology, path[, includeGraph, ...])

Exports a topology or graph as a Turtle file.

GraphByRDFFile(path[, format, graphSubject, ...])

Reconstructs a TopologicPy graph from an RDF/Turtle file.

GraphByRDFGraph(rdfGraph[, graphSubject, ...])

Reconstructs a TopologicPy graph from an RDFLib graph exported by Ontology.RDFGraph or Ontology.ExportRDF.

GraphByTTL(path[, graphSubject, ...])

Reconstructs a TopologicPy graph from a Turtle file.

GraphByTTLString(ttlString[, graphSubject, ...])

Reconstructs a TopologicPy graph from a Turtle string.

GraphTriples(graph[, includeVertices, ...])

Returns RDF-like triples from a TopologicPy graph.

IsA(topology, ontologyClass[, transitive])

Returns True if the input topology is an instance of the input ontology class.

Label(topology[, defaultValue])

Returns the label assigned to the input topology.

Namespace(prefix[, defaultValue])

Returns the namespace URI associated with the input prefix.

Namespaces()

Returns the default ontology namespace dictionary.

NormalizeDictionary(topology[, labelKeys, ...])

Normalises common dictionary keys into canonical ontology keys.

OntologyTTLString([includeBOT, ...])

Returns the TopologicPy ontology specification as a Turtle string.

OntologyTriples([includeBOT])

Returns triples describing the TopologicPy ontology itself.

PropertyQName(key[, defaultPrefix])

Returns a canonical ontology property QName from a dictionary key.

RDFGraph(topology[, includeGraph, ...])

Returns an RDFLib graph from a topology or graph.

RDFString(topology[, format, includeGraph, ...])

Serializes a topology or graph to an RDF string using RDFLib.

SetCategory(topology, category[, silent])

Sets the category of the input topology.

SetClass(topology, ontologyClass[, ...])

Sets the ontology class of the input topology.

SetLabel(topology, label[, silent])

Sets the label of the input topology.

SetURI(topology, uri[, silent])

Sets the URI of the input topology.

Superclasses(ontologyClass[, transitive])

Returns the superclasses of the input ontology class.

TTLString(topology[, includeGraph, ...])

Returns a Turtle string from a topology or graph.

Triples(topology[, subject, ...])

Returns RDF-like triples from a topology or graph dictionary.

TurtleFromTriples(triples[, namespaces, ...])

Returns a Turtle string from the input triples.

URI(topology[, defaultValue])

Returns the URI assigned to the input topology.

Validate(topology[, requireClass, ...])

Validates the ontology annotation of a topology or graph object.

ValidateGraph(graph[, requireClass, ...])

Validates ontology annotations on a graph, its vertices, and its edges.

ValidateTTLFile(path[, silent])

Validates a Turtle file using RDFLib when available.

ValidateTTLString(ttlString[, silent])

Validates a Turtle string using RDFLib when available.

static Annotate(topology, ontologyClass=None, category=None, label=None, uri=None, source=None, derivedFrom=None, generatedBy=None, inferClass=False, silent=False)

Annotates a topology using canonical ontology dictionary keys.

Parameters
topologytopologic_core.Topology or topologic_core.Graph

The input topology or graph.

ontologyClassstr , optional

The ontology class. Default is None.

categorystr , optional

The category. Default is None.

labelstr , optional

The label. Default is None.

uristr , optional

The URI. Default is None.

sourcestr , optional

The source identifier. Default is None.

derivedFromstr , optional

The source entity from which this topology was derived. Default is None.

generatedBystr , optional

The process or method that generated this topology. Default is None.

inferClassbool , optional

If True and ontologyClass is None, the ontology class is inferred from the Topologic type. Default is False.

silentbool , optional

If True, error and warning messages are suppressed. Default is False.

Returns
topologic_core.Topology or topologic_core.Graph

The annotated topology or graph.

static AnnotateIFC(topology, ifcClass=None, ifcGUID=None, ifcName=None, source=None, silent=False)

Annotates a topology using IFC metadata.

Parameters
topologytopologic_core.Topology or topologic_core.Graph

The input topology or graph.

ifcClassstr , optional

The IFC class. Default is None.

ifcGUIDstr , optional

The IFC GlobalId. Default is None.

ifcNamestr , optional

The IFC name. If specified, it is stored as the label. Default is None.

sourcestr , optional

The source file or source identifier. Default is None.

silentbool , optional

If True, error and warning messages are suppressed. Default is False.

Returns
topologic_core.Topology or topologic_core.Graph

The annotated topology or graph.

static AnnotateSubtopologies(topology, vertices=True, edges=True, wires=True, faces=True, shells=True, cells=True, cellComplexes=True, inferClass=True, silent=False)

Annotates the requested subtopologies with inferred ontology classes.

Parameters
topologytopologic_core.Topology

The input topology.

verticesbool , optional

If True, annotate vertices. Default is True.

edgesbool , optional

If True, annotate edges. Default is True.

wiresbool , optional

If True, annotate wires. Default is True.

facesbool , optional

If True, annotate faces. Default is True.

shellsbool , optional

If True, annotate shells. Default is True.

cellsbool , optional

If True, annotate cells. Default is True.

cellComplexesbool , optional

If True, annotate cell complexes. Default is True.

inferClassbool , optional

If True, infer ontology classes from Topologic types. Default is True.

silentbool , optional

If True, error and warning messages are suppressed. Default is False.

Returns
topologic_core.Topology

The input topology.

static BOTClassByClass(ontologyClass, defaultValue=None)

Returns a BOT class from a TopologicPy ontology class.

Parameters
ontologyClassstr

The TopologicPy ontology class.

defaultValueany , optional

The value to return if the class is not mapped. Default is None.

Returns
str

The BOT class.

CATEGORY_KEY = 'category'
CLASS_COMMENTS = {'top:Aperture': 'An opening or aperture associated with a topology.', 'top:Cell': 'A volumetric element bounded by faces.', 'top:CellComplex': 'A collection of cells that share faces.', 'top:Cluster': 'A heterogeneous collection of related topologies.', 'top:Context': 'The environment or settings in which topologies are interpreted.', 'top:Dictionary': 'A key-value store for semantic, analytical, and provenance metadata.', 'top:Edge': 'A line segment connecting two vertices.', 'top:Face': 'A bounded two-dimensional surface, optionally with internal boundaries.', 'top:Graph': 'A collection of nodes and relationships represented by vertices and edges.', 'top:Grid': 'A spatial structure dividing space into regular intervals.', 'top:Matrix': 'A rectangular array of numbers used for transformations.', 'top:Project': 'A project-level container for a model or dataset.', 'top:Shell': 'A collection of faces that share edges and form a segmented surface.', 'top:Topology': 'A superclass of Vertex, Edge, Wire, Face, Shell, Cell, CellComplex, and Cluster.', 'top:Vector': 'A mathematical entity with magnitude and direction.', 'top:Vertex': 'A point in 3D space defined by X, Y, Z coordinates.', 'top:Wire': 'A sequence of connected edges.'}
static Category(topology, defaultValue=None)

Returns the category assigned to the input topology.

Parameters
topologytopologic_core.Topology or topologic_core.Graph

The input topology or graph.

defaultValueany , optional

The value to return if no category is found. Default is None.

Returns
str

The category.

static CategoryByClass(ontologyClass, defaultValue=None)

Returns a category for the input ontology class.

Parameters
ontologyClassstr

The ontology class.

defaultValueany , optional

The value to return if no category is found. Default is None.

Returns
str

The category.

static Class(topology, defaultValue=None)

Returns the ontology class assigned to the input topology.

Parameters
topologytopologic_core.Topology or topologic_core.Graph

The input topology or graph.

defaultValueany , optional

The value to return if no ontology class is found. Default is None.

Returns
str

The ontology class.

static ClassByIFCClass(ifcClass, defaultValue='top:Element')

Returns a TopologicPy ontology class from an IFC class.

Parameters
ifcClassstr

The IFC class, for example “IfcSpace”.

defaultValueany , optional

The value to return if the IFC class is not mapped. Default is “top:Element”.

Returns
str

The TopologicPy ontology class.

static ClassByTopology(topology, defaultValue='top:Topology')

Returns a TopologicPy ontology class inferred from the topology type.

Parameters
topologytopologic_core.Topology or topologic_core.Graph

The input topology or graph.

defaultValueany , optional

The value to return if the topology type cannot be inferred. Default is “top:Topology”.

Returns
str

The inferred ontology class.

DATA_PROPERTIES = {'top:category': ('top:Topology', 'xsd:string', 'The broad category of a topology or graph.'), 'top:createdAt': ('top:Topology', 'xsd:dateTime', 'The creation timestamp.'), 'top:hasArea': ('top:Topology', 'xsd:double', 'The area of a face, shell, cell, or cell complex.'), 'top:hasLength': ('top:Topology', 'xsd:double', 'The length of an edge or wire.'), 'top:hasMantissa': ('top:Topology', 'xsd:integer', 'The number of decimal places used to report values.'), 'top:hasUnit': ('top:Topology', 'xsd:string', 'The unit of measurement.'), 'top:hasVolume': ('top:Topology', 'xsd:double', 'The volume of a cell or cell complex.'), 'top:hasX': ('top:Vertex', 'xsd:double', 'The X coordinate of a vertex.'), 'top:hasY': ('top:Vertex', 'xsd:double', 'The Y coordinate of a vertex.'), 'top:hasZ': ('top:Vertex', 'xsd:double', 'The Z coordinate of a vertex.'), 'top:updatedAt': ('top:Topology', 'xsd:dateTime', 'The last update timestamp.')}
DERIVED_FROM_KEY = 'derived_from'
static ExpandQName(qname, defaultValue=None)

Expands a QName into a full URI.

Parameters
qnamestr

The QName, for example “top:Room”.

defaultValueany , optional

The value to return if the QName cannot be expanded. Default is None.

Returns
str

The expanded URI.

static ExportOntologyTTL(path, includeBOT=True, instanceNamespace='http://w3id.org/topologicpy/instance#', silent=False)

Exports the TopologicPy ontology specification as a Turtle file.

Parameters
pathstr

The output Turtle file path.

includeBOTbool , optional

If True, BOT alignment triples are included. Default is True.

instanceNamespacestr , optional

The instance namespace URI. Default is “http://w3id.org/topologicpy/instance#”.

silentbool , optional

If True, error and warning messages are suppressed. Default is False.

Returns
str

The input path if successful. Otherwise None.

static ExportRDF(topology, path, format=None, includeGraph=True, includeDictionaries=True, includeBOT=True, namespacePrefix='inst', instanceNamespace='http://w3id.org/topologicpy/instance#', silent=False)

Exports a topology or graph to an RDF file using RDFLib.

Parameters
topologytopologic_core.Topology or topologic_core.Graph

The input topology or graph.

pathstr

The output file path.

formatstr , optional

RDFLib serialization format. If None, it is inferred from the extension. Default is None.

includeGraphbool , optional

If True and the input is a graph, vertices and edges are exported. Default is True.

includeDictionariesbool , optional

If True, dictionary keys are exported. Default is True.

includeBOTbool , optional

If True, BOT type triples are included where mapped. Default is True.

namespacePrefixstr , optional

The instance namespace prefix. Default is “inst”.

instanceNamespacestr , optional

The instance namespace URI. Default is “http://w3id.org/topologicpy/instance#”.

silentbool , optional

If True, warnings are suppressed. Default is False.

Returns
str

The output path, or None on failure.

static ExportTTL(topology, path, includeGraph=True, includeDictionaries=True, includeBOT=True, namespacePrefix='inst', instanceNamespace='http://w3id.org/topologicpy/instance#', silent=False)

Exports a topology or graph as a Turtle file.

Parameters
topologytopologic_core.Topology or topologic_core.Graph

The input topology or graph.

pathstr

The output Turtle file path.

includeGraphbool , optional

If True and the input is a graph, graph vertices and edges are exported. Default is True.

includeDictionariesbool , optional

If True, dictionary entries are exported as top properties. Default is True.

includeBOTbool , optional

If True, BOT rdf:type triples are added when mappings exist. Default is True.

namespacePrefixstr , optional

The instance namespace prefix. Default is “inst”.

instanceNamespacestr , optional

The instance namespace URI. Default is “http://w3id.org/topologicpy/instance#”.

silentbool , optional

If True, error and warning messages are suppressed. Default is False.

Returns
str

The input path if successful. Otherwise None.

GENERATED_BY_KEY = 'generated_by'
static GraphByRDFFile(path, format=None, graphSubject=None, namespacePrefix='inst', tolerance=0.0001, silent=False)

Reconstructs a TopologicPy graph from an RDF/Turtle file.

Parameters
pathstr

The RDF file path.

formatstr , optional

RDFLib parser format. If None, inferred from the extension. Default is None.

graphSubjectstr , optional

The graph subject URI or QName. Default is None.

namespacePrefixstr , optional

The instance namespace prefix. Default is “inst”.

tolerancefloat , optional

Graph creation tolerance. Default is 0.0001.

silentbool , optional

If True, warnings are suppressed. Default is False.

Returns
topologic_core.Graph

The reconstructed graph, or None on failure.

static GraphByRDFGraph(rdfGraph, graphSubject=None, namespacePrefix='inst', tolerance=0.0001, silent=False)

Reconstructs a TopologicPy graph from an RDFLib graph exported by Ontology.RDFGraph or Ontology.ExportRDF.

Parameters
rdfGraphrdflib.Graph

The input RDFLib graph.

graphSubjectstr , optional

The graph subject URI or QName. If None, the first subject with top:hasNode is used. Default is None.

namespacePrefixstr , optional

The preferred instance namespace prefix for stored uri values. Default is “inst”.

tolerancefloat , optional

The graph creation tolerance. Default is 0.0001.

silentbool , optional

If True, warnings are suppressed. Default is False.

Returns
topologic_core.Graph

The reconstructed graph, or None on failure.

static GraphByTTL(path, graphSubject=None, namespacePrefix='inst', tolerance=0.0001, silent=False)

Reconstructs a TopologicPy graph from a Turtle file.

static GraphByTTLString(ttlString, graphSubject=None, namespacePrefix='inst', tolerance=0.0001, silent=False)

Reconstructs a TopologicPy graph from a Turtle string.

static GraphTriples(graph, includeVertices=True, includeEdges=True, includeDictionaries=True, includeBOT=True, namespacePrefix='inst', silent=False)

Returns RDF-like triples from a TopologicPy graph.

Parameters
graphtopologic_core.Graph

The input graph.

includeVerticesbool , optional

If True, vertex triples are exported. Default is True.

includeEdgesbool , optional

If True, edge triples are exported. Default is True.

includeDictionariesbool , optional

If True, dictionary entries are exported. Default is True.

includeBOTbool , optional

If True, BOT rdf:type triples are added when mappings exist. Default is True.

namespacePrefixstr , optional

The instance namespace prefix. Default is “inst”.

silentbool , optional

If True, error and warning messages are suppressed. Default is False.

Returns
list

A list of triples.

IFC_CLASS_KEY = 'ifc_class'
IFC_GUID_KEY = 'ifc_guid'
IFC_TO_TOP = {'IfcBeam': 'top:Beam', 'IfcBuilding': 'top:Building', 'IfcBuildingElementProxy': 'top:Element', 'IfcBuildingStorey': 'top:Storey', 'IfcColumn': 'top:Column', 'IfcCurtainWall': 'top:Wall', 'IfcDistributionElement': 'top:Equipment', 'IfcDoor': 'top:Door', 'IfcFlowTerminal': 'top:Equipment', 'IfcFurnishingElement': 'top:Furniture', 'IfcFurniture': 'top:Furniture', 'IfcOpeningElement': 'top:Opening', 'IfcProject': 'top:Project', 'IfcRailing': 'top:Railing', 'IfcRelSpaceBoundary': 'top:Interface', 'IfcRoof': 'top:Roof', 'IfcSite': 'top:Site', 'IfcSlab': 'top:Slab', 'IfcSpace': 'top:Space', 'IfcStair': 'top:Stair', 'IfcStairFlight': 'top:Stair', 'IfcVirtualElement': 'top:Element', 'IfcWall': 'top:Wall', 'IfcWallStandardCase': 'top:Wall', 'IfcWindow': 'top:Window', 'IfcZone': 'top:Zone'}
static IsA(topology, ontologyClass, transitive=True)

Returns True if the input topology is an instance of the input ontology class.

Parameters
topologytopologic_core.Topology or topologic_core.Graph

The input topology or graph.

ontologyClassstr

The ontology class to test against.

transitivebool , optional

If True, superclass inheritance is considered. Default is True.

Returns
bool

True if the topology is an instance of ontologyClass. Otherwise False.

LABEL_KEY = 'label'
static Label(topology, defaultValue=None)

Returns the label assigned to the input topology.

Parameters
topologytopologic_core.Topology or topologic_core.Graph

The input topology or graph.

defaultValueany , optional

The value to return if no label is found. Default is None.

Returns
str

The label.

NAMESPACES = {'bot': 'https://w3id.org/bot#', 'brick': 'https://brickschema.org/schema/Brick#', 'owl': 'http://www.w3.org/2002/07/owl#', 'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'rdfs': 'http://www.w3.org/2000/01/rdf-schema#', 'top': 'http://w3id.org/topologicpy#', 'xsd': 'http://www.w3.org/2001/XMLSchema#'}
static Namespace(prefix, defaultValue=None)

Returns the namespace URI associated with the input prefix.

Parameters
prefixstr

The namespace prefix.

defaultValueany , optional

The value to return if the prefix is not found. Default is None.

Returns
str

The namespace URI.

static Namespaces()

Returns the default ontology namespace dictionary.

Returns
dict

The namespace dictionary.

static NormalizeDictionary(topology, labelKeys=None, categoryKeys=None, ifcClassKeys=None, ifcGUIDKeys=None, silent=False)

Normalises common dictionary keys into canonical ontology keys.

Parameters
topologytopologic_core.Topology or topologic_core.Graph

The input topology or graph.

labelKeyslist , optional

Candidate keys for the label. Default is [“name”, “Name”, “LongName”, “ifc_name”, “label”].

categoryKeyslist , optional

Candidate keys for the category. Default is [“category”, “type”, “ObjectType”].

ifcClassKeyslist , optional

Candidate keys for the IFC class. Default is [“ifc_class”, “IfcClass”, “class”, “type”].

ifcGUIDKeyslist , optional

Candidate keys for the IFC GUID. Default is [“ifc_guid”, “GlobalId”, “global_id”, “guid”].

silentbool , optional

If True, error and warning messages are suppressed. Default is False.

Returns
topologic_core.Topology or topologic_core.Graph

The input topology or graph.

OBJECT_PROPERTIES = {'top:adjacentTo': ('top:Topology', 'top:Topology', 'The topologies adjacent to a topology.'), 'top:connectsTo': ('top:Topology', 'top:Topology', 'Alias of top:connectsTo.'), 'top:containsElement': ('top:Topology', 'top:Topology', 'A topology contained by this topology.'), 'top:hasCellComplexes': ('top:Cluster', 'top:CellComplex', 'The cell complexes that belong to a cluster.'), 'top:hasCells': ('top:Topology', 'top:Cell', 'The cells that belong to a topology.'), 'top:hasDictionary': ('top:Topology', 'top:Dictionary', 'The dictionary of a topology or graph.'), 'top:hasDirection': ('top:Topology', 'top:Vector', 'The direction vector of a topology.'), 'top:hasEdges': ('top:Topology', 'top:Edge', 'The edges that belong to a topology or graph.'), 'top:hasEndVertex': ('top:Edge', 'top:Vertex', 'The ending vertex of an edge.'), 'top:hasExternalBoundary': ('top:Topology', 'top:Topology', 'The external boundary of a topology.'), 'top:hasFaces': ('top:Topology', 'top:Face', 'The faces that belong to a topology.'), 'top:hasFreeCells': ('top:Cluster', 'top:Cell', 'Free cells in a cluster.'), 'top:hasFreeEdges': ('top:Cluster', 'top:Edge', 'Free edges in a cluster.'), 'top:hasFreeFaces': ('top:Cluster', 'top:Face', 'Free faces in a cluster.'), 'top:hasFreeShells': ('top:Cluster', 'top:Shell', 'Free shells in a cluster.'), 'top:hasFreeVertices': ('top:Cluster', 'top:Vertex', 'Free vertices in a cluster.'), 'top:hasFreeWires': ('top:Cluster', 'top:Wire', 'Free wires in a cluster.'), 'top:hasInternalBoundaries': ('top:Topology', 'top:Topology', 'The internal boundaries of a topology.'), 'top:hasNode': ('top:Graph', 'top:Vertex', 'A node that belongs to a graph.'), 'top:hasRelationship': ('top:Graph', 'top:Edge', 'A relationship that belongs to a graph.'), 'top:hasShells': ('top:Topology', 'top:Shell', 'The shells that belong to a topology.'), 'top:hasStartVertex': ('top:Edge', 'top:Vertex', 'The starting vertex of an edge.'), 'top:hasVertices': ('top:Topology', 'top:Vertex', 'The vertices that belong to a topology or graph.'), 'top:hasWires': ('top:Topology', 'top:Wire', 'The wires that belong to a topology.'), 'top:interfaceOf': ('top:Topology', 'top:Topology', 'The topologies connected or separated by an interface.'), 'top:isPartOf': ('top:Topology', 'top:Topology', 'The topology that contains this topology.')}
ONTOLOGY_CLASS_KEY = 'ontology_class'
ONTOLOGY_URI_KEY = 'ontology_uri'
static OntologyTTLString(includeBOT=True, instanceNamespace='http://w3id.org/topologicpy/instance#')

Returns the TopologicPy ontology specification as a Turtle string.

Parameters
includeBOTbool , optional

If True, BOT alignment triples are included. Default is True.

instanceNamespacestr , optional

The instance namespace URI. Default is “http://w3id.org/topologicpy/instance#”.

Returns
str

The ontology Turtle string.

static OntologyTriples(includeBOT=True)

Returns triples describing the TopologicPy ontology itself.

Parameters
includeBOTbool , optional

If True, BOT alignment triples are included where appropriate. Default is True.

Returns
list

A list of triples describing classes, properties, subclass relations, and comments.

PROPERTY_ALIASES = {'area': 'hasArea', 'connectedTo': 'connectsTo', 'endsAt': 'hasEndVertex', 'length': 'hasLength', 'mantissa': 'hasMantissa', 'startsAt': 'hasStartVertex', 'unit': 'hasUnit', 'volume': 'hasVolume', 'x': 'hasX', 'y': 'hasY', 'z': 'hasZ'}
static PropertyQName(key, defaultPrefix='top')

Returns a canonical ontology property QName from a dictionary key.

Parameters
keystr

The dictionary key or property name.

defaultPrefixstr , optional

The default namespace prefix to use if the key is not already a QName. Default is “top”.

Returns
str

The canonical property QName.

static RDFGraph(topology, includeGraph=True, includeDictionaries=True, includeBOT=True, namespacePrefix='inst', instanceNamespace='http://w3id.org/topologicpy/instance#', silent=False)

Returns an RDFLib graph from a topology or graph.

Parameters
topologytopologic_core.Topology or topologic_core.Graph

The input topology or graph.

includeGraphbool , optional

If True and the input is a graph, vertices and edges are exported. Default is True.

includeDictionariesbool , optional

If True, dictionary keys are exported as data properties. Default is True.

includeBOTbool , optional

If True, BOT type triples are included where mapped. Default is True.

namespacePrefixstr , optional

The instance namespace prefix. Default is “inst”.

instanceNamespacestr , optional

The instance namespace URI. Default is “http://w3id.org/topologicpy/instance#”.

silentbool , optional

If True, warnings are suppressed. Default is False.

Returns
rdflib.Graph

The RDFLib graph, or None if RDFLib is unavailable.

static RDFString(topology, format='turtle', includeGraph=True, includeDictionaries=True, includeBOT=True, namespacePrefix='inst', instanceNamespace='http://w3id.org/topologicpy/instance#', silent=False)

Serializes a topology or graph to an RDF string using RDFLib.

Parameters
topologytopologic_core.Topology or topologic_core.Graph

The input topology or graph.

formatstr , optional

RDFLib serialization format, e.g. “turtle”, “xml”, “json-ld”, “nt”. Default is “turtle”.

includeGraphbool , optional

If True and the input is a graph, vertices and edges are exported. Default is True.

includeDictionariesbool , optional

If True, dictionary keys are exported. Default is True.

includeBOTbool , optional

If True, BOT type triples are included where mapped. Default is True.

namespacePrefixstr , optional

The instance namespace prefix. Default is “inst”.

instanceNamespacestr , optional

The instance namespace URI. Default is “http://w3id.org/topologicpy/instance#”.

silentbool , optional

If True, warnings are suppressed. Default is False.

Returns
str

The serialized RDF string, or None on failure.

SOURCE_KEY = 'source'
static SetCategory(topology, category, silent=False)

Sets the category of the input topology.

Parameters
topologytopologic_core.Topology or topologic_core.Graph

The input topology or graph.

categorystr

The category.

silentbool , optional

If True, error and warning messages are suppressed. Default is False.

Returns
topologic_core.Topology or topologic_core.Graph

The input topology or graph.

static SetClass(topology, ontologyClass, setCategory=True, setURI=True, silent=False)

Sets the ontology class of the input topology.

Parameters
topologytopologic_core.Topology or topologic_core.Graph

The input topology or graph.

ontologyClassstr

The ontology class, for example “top:Room”.

setCategorybool , optional

If True, the category is also set if it can be inferred. Default is True.

setURIbool , optional

If True, ontology_uri is also set if the class can be expanded. Default is True.

silentbool , optional

If True, error and warning messages are suppressed. Default is False.

Returns
topologic_core.Topology or topologic_core.Graph

The input topology or graph.

static SetLabel(topology, label, silent=False)

Sets the label of the input topology.

Parameters
topologytopologic_core.Topology or topologic_core.Graph

The input topology or graph.

labelstr

The label.

silentbool , optional

If True, error and warning messages are suppressed. Default is False.

Returns
topologic_core.Topology or topologic_core.Graph

The input topology or graph.

static SetURI(topology, uri, silent=False)

Sets the URI of the input topology.

Parameters
topologytopologic_core.Topology or topologic_core.Graph

The input topology or graph.

uristr

The URI.

silentbool , optional

If True, error and warning messages are suppressed. Default is False.

Returns
topologic_core.Topology or topologic_core.Graph

The input topology or graph.

static Superclasses(ontologyClass, transitive=True)

Returns the superclasses of the input ontology class.

Parameters
ontologyClassstr

The ontology class.

transitivebool , optional

If True, all transitive superclasses are returned. If False, only direct superclasses are returned. Default is True.

Returns
list

The list of superclasses.

TOP_CATEGORIES = {'top:AdjacencyGraph': 'graph', 'top:Aperture': 'element', 'top:Beam': 'element', 'top:Building': 'building', 'top:Cell': 'topology', 'top:CellComplex': 'topology', 'top:CirculationGraph': 'graph', 'top:Cluster': 'topology', 'top:Column': 'element', 'top:ConnectivityGraph': 'graph', 'top:Context': 'context', 'top:Dictionary': 'metadata', 'top:Door': 'element', 'top:Edge': 'topology', 'top:Element': 'element', 'top:Face': 'topology', 'top:Graph': 'graph', 'top:Grid': 'utility', 'top:Interface': 'interface', 'top:KnowledgeGraph': 'graph', 'top:Matrix': 'mathematics', 'top:Opening': 'element', 'top:Project': 'project', 'top:Roof': 'element', 'top:Room': 'space', 'top:Shell': 'topology', 'top:Site': 'site', 'top:Slab': 'element', 'top:Space': 'space', 'top:SpatialGraph': 'graph', 'top:Storey': 'storey', 'top:ThermalZone': 'space', 'top:Vector': 'mathematics', 'top:Vertex': 'topology', 'top:VisibilityGraph': 'graph', 'top:Wall': 'element', 'top:Window': 'element', 'top:Wire': 'topology', 'top:Zone': 'space'}
TOP_SUPERCLASSES = {'top:AdjacencyGraph': ['top:SpatialGraph'], 'top:Aperture': ['top:Face', 'top:Element'], 'top:Beam': ['top:Element'], 'top:Building': ['top:Zone'], 'top:Cell': ['top:Topology'], 'top:CellComplex': ['top:Topology'], 'top:CirculationGraph': ['top:SpatialGraph'], 'top:Cluster': ['top:Topology'], 'top:Column': ['top:Element'], 'top:ConnectivityGraph': ['top:SpatialGraph'], 'top:Context': [], 'top:Dictionary': [], 'top:Door': ['top:Element'], 'top:Edge': ['top:Topology'], 'top:Element': ['top:Topology'], 'top:Equipment': ['top:Element'], 'top:Face': ['top:Topology'], 'top:Furniture': ['top:Element'], 'top:Graph': [], 'top:Grid': [], 'top:Interface': ['top:Face'], 'top:KnowledgeGraph': ['top:Graph'], 'top:Matrix': [], 'top:Node': ['top:Vertex'], 'top:Opening': ['top:Element'], 'top:Point': ['top:Vertex'], 'top:Project': [], 'top:Railing': ['top:Element'], 'top:Relationship': ['top:Edge'], 'top:Roof': ['top:Element'], 'top:Room': ['top:Space'], 'top:Shell': ['top:Topology'], 'top:Site': ['top:Zone'], 'top:Slab': ['top:Element'], 'top:Space': ['top:Zone'], 'top:SpatialGraph': ['top:Graph'], 'top:Stair': ['top:Element'], 'top:Storey': ['top:Zone'], 'top:Surface': ['top:Face'], 'top:ThermalZone': ['top:Space'], 'top:Topology': [], 'top:Vector': [], 'top:Vertex': ['top:Topology'], 'top:VisibilityGraph': ['top:SpatialGraph'], 'top:Wall': ['top:Element'], 'top:Window': ['top:Element'], 'top:Wire': ['top:Topology'], 'top:Zone': ['top:Cell']}
TOP_TO_BOT = {'top:Beam': 'bot:Element', 'top:Building': 'bot:Building', 'top:Column': 'bot:Element', 'top:Door': 'bot:Element', 'top:Element': 'bot:Element', 'top:Interface': 'bot:Interface', 'top:Roof': 'bot:Element', 'top:Room': 'bot:Space', 'top:Site': 'bot:Site', 'top:Slab': 'bot:Element', 'top:Space': 'bot:Space', 'top:Storey': 'bot:Storey', 'top:Wall': 'bot:Element', 'top:Window': 'bot:Element', 'top:Zone': 'bot:Zone'}
static TTLString(topology, includeGraph=True, includeDictionaries=True, includeBOT=True, namespacePrefix='inst', instanceNamespace='http://w3id.org/topologicpy/instance#', silent=False)

Returns a Turtle string from a topology or graph.

Parameters
topologytopologic_core.Topology or topologic_core.Graph

The input topology or graph.

includeGraphbool , optional

If True and the input is a graph, graph vertices and edges are exported. Default is True.

includeDictionariesbool , optional

If True, dictionary entries are exported as top properties. Default is True.

includeBOTbool , optional

If True, BOT rdf:type triples are added when mappings exist. Default is True.

namespacePrefixstr , optional

The instance namespace prefix. Default is “inst”.

instanceNamespacestr , optional

The instance namespace URI. Default is “http://w3id.org/topologicpy/instance#”.

silentbool , optional

If True, error and warning messages are suppressed. Default is False.

Returns
str

The Turtle string.

static Triples(topology, subject=None, includeDictionaries=True, includeBOT=True, includeType=True, includeLabel=True, includeCategory=True, namespacePrefix='inst', silent=False)

Returns RDF-like triples from a topology or graph dictionary.

Parameters
topologytopologic_core.Topology or topologic_core.Graph

The input topology or graph.

subjectstr , optional

The subject QName. If None, one is inferred. Default is None.

includeDictionariesbool , optional

If True, dictionary entries are exported as top properties. Default is True.

includeBOTbool , optional

If True, a BOT rdf:type triple is added when a mapping exists. Default is True.

includeTypebool , optional

If True, rdf:type triples are exported. Default is True.

includeLabelbool , optional

If True, rdfs:label is exported when a label exists. Default is True.

includeCategorybool , optional

If True, top:category is exported when a category exists. Default is True.

namespacePrefixstr , optional

The instance namespace prefix. Default is “inst”.

silentbool , optional

If True, error and warning messages are suppressed. Default is False.

Returns
list

A list of triples. Each triple is a tuple of the form (subject, predicate, object).

static TurtleFromTriples(triples, namespaces=None, instanceNamespace='http://w3id.org/topologicpy/instance#', includeHeader=True)

Returns a Turtle string from the input triples.

Parameters
tripleslist

A list of triples. Each triple must be a tuple of the form (subject, predicate, object).

namespacesdict , optional

Namespace dictionary. Default is None.

instanceNamespacestr , optional

The URI for the “inst” namespace. Default is “http://w3id.org/topologicpy/instance#”.

includeHeaderbool , optional

If True, namespace prefixes are included. Default is True.

Returns
str

The Turtle string.

static URI(topology, defaultValue=None)

Returns the URI assigned to the input topology.

Parameters
topologytopologic_core.Topology or topologic_core.Graph

The input topology or graph.

defaultValueany , optional

The value to return if no URI is found. Default is None.

Returns
str

The URI.

URI_KEY = 'uri'
static Validate(topology, requireClass=True, requireCategory=False, requireLabel=False, requireURI=False, checkClassKnown=True, checkCategory=True, checkQName=True, silent=False)

Validates the ontology annotation of a topology or graph object.

Parameters
topologytopologic_core.Topology or topologic_core.Graph

The input topology or graph.

requireClassbool , optional

If True, ontology_class must be present. Default is True.

requireCategorybool , optional

If True, category must be present. Default is False.

requireLabelbool , optional

If True, label must be present. Default is False.

requireURIbool , optional

If True, uri or ontology_uri must be present. Default is False.

checkClassKnownbool , optional

If True, ontology_class must be in the built-in ontology class map or be expandable as a QName. Default is True.

checkCategorybool , optional

If True, validates category against the inferred category where possible. Default is True.

checkQNamebool , optional

If True, validates QName prefixes against Ontology.NAMESPACES. Default is True.

silentbool , optional

If True, warnings are suppressed. Default is False.

Returns
dict

A validation report with keys ok, errors, warnings, and dictionary.

static ValidateGraph(graph, requireClass=True, requireVertexClasses=True, requireEdgeClasses=True, requireLabels=False, checkConnectivity=True, silent=False)

Validates ontology annotations on a graph, its vertices, and its edges.

Parameters
graphtopologic_core.Graph

The input graph.

requireClassbool , optional

If True, the graph itself must have ontology_class. Default is True.

requireVertexClassesbool , optional

If True, every vertex must have ontology_class. Default is True.

requireEdgeClassesbool , optional

If True, every edge must have ontology_class. Default is True.

requireLabelsbool , optional

If True, graph elements must have labels. Default is False.

checkConnectivitybool , optional

If True, validates that edge endpoints can be resolved. Default is True.

silentbool , optional

If True, warnings are suppressed. Default is False.

Returns
dict

A validation report with aggregate status and per-element reports.

static ValidateTTLFile(path, silent=False)

Validates a Turtle file using RDFLib when available.

Parameters
pathstr

The Turtle file path.

silentbool , optional

If True, errors are suppressed. Default is False.

Returns
dict

A validation report.

static ValidateTTLString(ttlString, silent=False)

Validates a Turtle string using RDFLib when available.

Parameters
ttlStringstr

The Turtle string.

silentbool , optional

If True, errors are suppressed. Default is False.

Returns
dict

A validation report with keys ok, errors, warnings, and triple_count.