security_subclasses, safety_subclasses, ) from bricksrc.substances import substances from bricksrc.quantities import quantity_definitions, get_units from bricksrc.properties import properties from bricksrc.tags import tags logging.basicConfig( format="%(asctime)s,%(msecs)d %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s", datefmt="%Y-%m-%d:%H:%M:%S", level=logging.INFO, ) G = Graph() bind_prefixes(G) A = RDF.type tag_lookup = defaultdict(set) intersection_classes = {} def add_restriction(klass, definition): """ Defines OWL.Restrictions linked to Brick classes through OWL.equivalentClass. This populates the property-object pairs (OWL.onProperty, 'property'), (OWL.hasValue, 'value'). The intersection of these properties is made to be equivalent to the given class.
) from bricksrc.substances import substances from bricksrc.quantities import quantity_definitions, get_units from bricksrc.properties import properties from bricksrc.entity_properties import shape_properties, entity_properties from bricksrc.timeseries import define_timeseries_model logging.basicConfig( format= "%(asctime)s,%(msecs)d %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s", datefmt="%Y-%m-%d:%H:%M:%S", level=logging.INFO, ) G = Graph() bind_prefixes(G) A = RDF.type shaclGraph = Graph() bind_prefixes(shaclGraph) intersection_classes = {} has_tag_restriction_class = {} shacl_tag_property_shapes = {} has_exactly_n_tags_shapes = {} def add_properties(item, propdefs): for propname, propval in propdefs.items(): if isinstance(propval, list): for pv in propdefs: G.add((item, propname, pv))
import sys import brickschema from bricksrc.namespaces import A, OWL, RDFS, SKOS, BRICK, SH, BSH, bind_prefixes from .util import make_readable sys.path.append("..") from bricksrc.properties import properties # noqa: E402 g = brickschema.Graph() g.load_file("shacl/BrickShape.ttl") bind_prefixes(g) def test_domainProperties(): for (name, props) in properties.items(): if RDFS.domain in props: q = f"""SELECT ?shape WHERE {{ ?shape a sh:NodeShape . ?shape sh:targetSubjectsOf brick:{name} . ?shape sh:class <{props[RDFS.domain]}> . }} """ res = make_readable(g.query(q)) assert len(res) == 1, "unexpected # of query results" return def test_rangeProperties(): for (name, props) in properties.items(): if RDFS.range in props: q = f"""SELECT ?shape WHERE {{ ?shape a sh:NodeShape .
import sys from bricksrc.namespaces import A, OWL, RDFS, SKOS, BRICK, SH, BSH, bind_prefixes import brickschema schema_g = brickschema.Graph().load_file('shacl/BrickShape.ttl') bind_prefixes(schema_g) prefixes = """ @prefix brick: <https://brickschema.org/schema/Brick#> . @prefix : <http://example.com#> . """ base_data = prefixes + """ :equip a brick:Equipment. :point a brick:Point. :loc a brick:Location. """ def test_no_relations(): data = base_data data_g = brickschema.Graph().parse(data=data, format='turtle') conforms, r1, r2 = data_g.validate([schema_g]) assert conforms def test_equip(): valid_data = base_data + """ :equip brick:hasLocation :loc. """ valid_g = brickschema.Graph().parse(data=valid_data, format='turtle') conforms, _, _ = valid_g.validate([schema_g]) assert conforms