1111from rdflib .namespace import XSD
1212from rdflib .collection import Collection
1313
14- from bricksrc .ontology import define_ontology , ontology_imports , define_extension , BRICK_IRI_VERSION
14+ from bricksrc .ontology import (
15+ define_ontology ,
16+ ontology_imports ,
17+ define_extension ,
18+ BRICK_IRI_VERSION ,
19+ )
1520
1621
1722from bricksrc .namespaces import (
@@ -321,7 +326,9 @@ def define_classes(definitions, parent, pun_classes=False, graph=G):
321326 graph .add ((alias , OWL .equivalentClass , classname ))
322327 graph .add ((alias , BRICK .aliasOf , classname ))
323328 if not has_label (alias , graph = graph ):
324- graph .add ((alias , RDFS .label , Literal (alias .split ("#" )[- 1 ].replace ("_" , " " ))))
329+ graph .add (
330+ (alias , RDFS .label , Literal (alias .split ("#" )[- 1 ].replace ("_" , " " )))
331+ )
325332
326333 # all other key-value pairs in the definition are
327334 # property-object pairs
@@ -383,8 +390,8 @@ def define_entity_properties(definitions, superprop=None, graph=G):
383390 assert (
384391 "property_of" in defn
385392 ), f"{ entprop } missing a 'property_of' annotation so Brick doesn't know where this property can be used"
386- assert (
387- _allowed_annotations . intersection ( defn .keys () )
393+ assert _allowed_annotations . intersection (
394+ defn .keys ()
388395 ), f"{ entprop } missing at least one of { _allowed_annotations } so Brick doesn't know what the values of this property can be"
389396 assert RDFS .label in defn , f"{ entprop } missing a RDFS.label annotation"
390397 graph .add ((entprop , A , BRICK .EntityProperty ))
@@ -530,7 +537,9 @@ def define_shape_properties(definitions, graph=G):
530537 vals = defn .pop ("values" )
531538 if isinstance (vals [0 ], str ):
532539 Collection (
533- graph , enumeration , map (lambda x : Literal (x , datatype = XSD .string ), vals )
540+ graph ,
541+ enumeration ,
542+ map (lambda x : Literal (x , datatype = XSD .string ), vals ),
534543 )
535544 elif isinstance (vals [0 ], int ):
536545 Collection (
@@ -945,7 +954,10 @@ def handle_deprecations():
945954
946955G .remove ((BRICK .value , A , OWL .ObjectProperty ))
947956
957+ # handle class deprecations
948958handle_deprecations ()
959+ # handle non-class deprecations
960+ G .parse ("bricksrc/deprecations.ttl" )
949961
950962logging .info ("Adding class definitions" )
951963add_definitions ()
@@ -974,9 +986,7 @@ def handle_deprecations():
974986 G .add ((rule , SH .prefixes , BRICK_IRI_VERSION ))
975987
976988# remove ontology declarations
977- for ontology in G .subjects (
978- predicate = RDF .type , object = OWL .Ontology
979- ):
989+ for ontology in G .subjects (predicate = RDF .type , object = OWL .Ontology ):
980990 if ontology != BRICK_IRI_VERSION :
981991 G .remove ((ontology , RDF .type , OWL .Ontology ))
982992 G .remove ((ontology , OWL .imports , None ))
@@ -989,17 +999,17 @@ def handle_deprecations():
989999 # TODO: add ontology definition
9901000 print (f"Reading in entity properties and/or class definitions from { filename } " )
9911001 mod = importlib .import_module (filename )
992- if hasattr (mod , ' entity_properties' ):
1002+ if hasattr (mod , " entity_properties" ):
9931003 define_entity_properties (mod .entity_properties , graph = extension_graph )
994- if hasattr (mod , ' classes' ):
1004+ if hasattr (mod , " classes" ):
9951005 for parent , tree in mod .classes .items ():
9961006 define_classes (tree , parent , graph = extension_graph )
997- if hasattr (mod , ' property_value_shapes' ):
1007+ if hasattr (mod , " property_value_shapes" ):
9981008 define_shape_properties (mod .property_value_shapes , graph = extension_graph )
999- if hasattr (mod , ' ontology_definition' ):
1009+ if hasattr (mod , " ontology_definition" ):
10001010 define_extension (extension_graph , mod .ontology_definition )
10011011
1002- parts = Path ('/' .join (filename .split ('.' )))
1012+ parts = Path ("/" .join (filename .split ("." )))
10031013 dest = Path ("extensions" ) / parts .with_suffix (".ttl" )
10041014 os .makedirs (dest .parent , exist_ok = True )
10051015 print (f"Writing extension graph to { dest } " )
0 commit comments