Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
def test_rangeProperties():
    for (name, props) in properties.items():
        if RDFS.range in props:
            q = f"""SELECT ?shape WHERE {{
            ?shape a sh:NodeShape .
            ?shape sh:property [
            sh:class <{props[RDFS.range]}> ;
            sh:path brick:{name} ;
            ] }}
            """
            res = make_readable(g.query(q))
            assert len(res) == 1, "unexpected # of query results"
    return
Ejemplo n.º 3
0
    shapename = f"{propertyName}RangeShape"
    G.add((BSH[shapename], SH["property"], sh_prop))
    G.add((BSH[shapename], A, SH.NodeShape))
    G.add((sh_prop, SH["path"], BRICK[propertyName]))
    G.add((sh_prop, SH["class"], expectedType))
    G.add((BSH[shapename], SH.targetSubjectsOf, BRICK[propertyName]))
    G.add(
        (
            sh_prop,
            SH["message"],
            Literal(f"Property {propertyName} has object with incorrect type"),
        )
    )


for name, properties in property_definitions.items():
    for pred, obj in properties.items():
        # We are only concerned with properties that have RDFS.domain or .range
        # predicate.  The temporary replacements for those predicates are
        # brick:expectedDomain and :expectedRange.  See properties.py for
        # explanation.

        if pred == RDFS.domain:
            addDomainShape(name, obj)

        if pred == RDFS.range:
            addRangeShape(name, obj)

        # subproperties are considered after "domain" and "range" are counted for
        if pred == "subproperties":
            for subprop, desc in obj.items():
Ejemplo n.º 4
0
        Literal(f"Property {propertyName} has object with incorrect type"),
    ))


def addPropertyShapes(propertyName, defn):
    for pred, obj in defn.items():
        # We are only concerned with properties that have RDFS.domain or .range
        # predicate.  The temporary replacements for those predicates are
        # brick:expectedDomain and :expectedRange.  See properties.py for
        # explanation.

        if pred == RDFS.domain:
            addDomainShape(propertyName, obj)

        if pred == RDFS.range:
            addRangeShape(propertyName, obj)

        # subproperties are considered after "domain" and "range" are counted for
        if pred == "subproperties":
            for subprop, desc in obj.items():
                addPropertyShapes(subprop, desc)


for name, defn in property_definitions.items():
    addPropertyShapes(name, defn)

# serialize to output
with open("BrickShape.ttl", "wb") as fp:
    fp.write(G.serialize(format="turtle").rstrip())
    fp.write(b"\n")