Skip to main content
Version: 0.0.6

OWL and RDFS Turtle import

load_owl(source) reads a local Turtle file and returns an ImportResult. loads_owl(text) reads Turtle text. Each result contains a GraphSchema and an ordered list of FormatWarning values. Both functions accept optional name and version arguments.

load_schema("ontology.ttl") also reads Turtle and returns a GraphSchema. It logs each import warning at warning level. A .ttl file can also be used as the extends source.

Install the optional schema-formats extra to use these functions:

pip install "agentic-graphrag[schema-formats]"

Supported RDF terms​

Turtle termSchema field
owl:Class, rdfs:ClassEntity type
rdfs:subClassOf between declared classesEntity parents
owl:DatatypeProperty with a declared class domainEntity property
owl:ObjectProperty with declared class domains and rangesRelation patterns
owl:FunctionalPropertyRelation max_per_source: 1
owl:InverseFunctionalPropertyRelation max_per_target: 1
owl:SymmetricPropertyRelation patterns in both directions, with the same source and target limit
rdfs:commentNot used as a description. When present, a warning reports that it was ignored. Classes use the class name as their description. Relations and properties use their local name when a comment is present.
rdfs:labelIgnored for classes. For relations and properties without a comment, the first sorted label is the description; without a label, the local name is used.
XSD string, integer, decimal, float, double, boolean, dateProperty type
owl:unionOf in domains or rangesDeclared endpoint types
owl:oneOf with literal valuesProperty enum
Unqualified owl:maxCardinality, owl:cardinalityRelation source limit
Positive datatype owl:minCardinality, owl:cardinalityRequired property

For an object property, one domain and one range can each be a class or an owl:unionOf. The importer expands union members into all source and target pairs. Multiple separate domain or range statements are conjunctive, so the importer drops that relation. Class-specific relation limits use the loosest limit across source classes. A source class without a limit prevents a global limit. The importer reports loss of class-specific constraints, relation minimums, and datatype maximums above one.

The importer does not infer triples or follow owl:imports. Unsupported restrictions, equivalence, property chains, alternative labels, and individuals produce warnings. Unknown parents and endpoint classes are ignored with warnings. Invalid or colliding local class names fail the import. The schema validator rejects reserved labels, cycles, and invalid relation patterns.

SchemaFormatError reports Turtle that cannot be read. SchemaLoadError reports schema data that fails validation. SchemaFormatMissingExtraError names the extra when rdflib is not installed.