x in A or x in B (or in both)#
somebody says: “x is in A or B (or in both)”.
“in” … “is Element of”
We do have two interpretations:
(1) x is in A, in B, or in both A and B
(2) x is in the union of A and B
import rdflib
import owlrl
ttl = """
@prefix : <http://example.org/ns#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix dct: <http://purl.org/dc/terms/> .
@prefix openwemi: <https://dcmi.github.io/openwemi/ns#> .
"""
ttl += """
#:Work rdfs:subClassOf :WEMI .
#:Expression rdfs:subClassOf :WEMI .
#:Manifestation rdfs:subClassOf :WEMI .
#:Item rdfs:subClassOf :WEMI .
:WEMI a owl:Class;
owl:unionOf (
:Work
:Expression
:Manifestation
:Item ) .
:inst :instantiates :unknown1 .
:man :manifests :unknown2 .
:instantiates
a rdf:Property ;
rdfs:domain :Item ;
rdfs:range :WEM .
:WEM a owl:Class;
owl:unionOf (
:Work
:Expression
:Manifestation) .
:manifests
a rdf:Property ;
rdfs:domain :Manifestation ;
rdfs:range :WE .
:WE a owl:Class;
owl:unionOf (
:Work
:Expression ) .
"""
g = rdflib.Graph().parse(data= ttl)
print(f"Initially g has {len(g)} triples")
Initially g has 32 triples
def focus(focus_curie_list, ttl): # ll ... 'RDF_RDFtest_OWL_OWLtest'
result = "\n\n".join( [ paragraph for paragraph in ttl.split("\n\n") \
if any( [ focus_curie in paragraph for focus_curie in focus_curie_list ] ) ] )
return result
interesting = [ "inst", "man", "unknown", "WEM", "WE" ]
print(focus(interesting, g.serialize()))
:WEMI a owl:Class ;
owl:unionOf ( :Work :Expression :Manifestation :Item ) .
:inst :instantiates :unknown1 .
:instantiates a rdf:Property ;
rdfs:domain :Item ;
rdfs:range :WEM .
:man :manifests :unknown2 .
:manifests a rdf:Property ;
rdfs:domain :Manifestation ;
rdfs:range :WE .
:WE a owl:Class ;
owl:unionOf ( :Work :Expression ) .
:WEM a owl:Class ;
owl:unionOf ( :Work :Expression :Manifestation ) .
owlrl.DeductiveClosure(owlrl.OWLRL_Semantics,
axiomatic_triples = False).expand(g)
print(f"After inferencing g has {len(g)} triples")
After inferencing g has 216 triples
print(focus(interesting, g.serialize()))
:inst a :Item,
:WEMI,
owl:Thing ;
:instantiates :unknown1 ;
owl:sameAs :inst .
:man a :Manifestation,
:WEM,
:WEMI,
owl:Thing ;
:manifests :unknown2 ;
owl:sameAs :man .
:unknown1 a :WEM,
owl:Thing ;
owl:sameAs :unknown1 .
:unknown2 a :WE,
owl:Thing ;
owl:sameAs :unknown2 .
:instantiates a rdf:Property ;
rdfs:domain :Item,
:WEMI,
owl:Thing ;
rdfs:range :WEM,
owl:Thing ;
rdfs:subPropertyOf :instantiates ;
owl:equivalentProperty :instantiates ;
owl:sameAs :instantiates .
:manifests a rdf:Property ;
rdfs:domain :Manifestation,
:WEM,
:WEMI,
owl:Thing ;
rdfs:range :WE,
owl:Thing ;
rdfs:subPropertyOf :manifests ;
owl:equivalentProperty :manifests ;
owl:sameAs :manifests .
owl:Nothing a owl:Class ;
rdfs:subClassOf :WE,
:WEM,
:WEMI,
owl:Nothing,
owl:Thing ;
owl:equivalentClass owl:Nothing ;
owl:sameAs owl:Nothing .
:Expression rdfs:subClassOf :WE,
:WEM,
:WEMI,
owl:Thing ;
owl:sameAs :Expression .
:Item rdfs:subClassOf :WEMI,
owl:Thing ;
owl:sameAs :Item .
:Work rdfs:subClassOf :WE,
:WEM,
:WEMI,
owl:Thing ;
owl:sameAs :Work .
:Manifestation rdfs:subClassOf :WEM,
:WEMI,
owl:Thing ;
owl:sameAs :Manifestation .
:WE a owl:Class ;
rdfs:subClassOf :WE,
owl:Thing ;
owl:equivalentClass :WE ;
owl:sameAs :WE ;
owl:unionOf _:nd1a95268118e4b8daf66939791f86bacb8 .
:WEM a owl:Class ;
rdfs:subClassOf :WEM,
owl:Thing ;
owl:equivalentClass :WEM ;
owl:sameAs :WEM ;
owl:unionOf _:nd1a95268118e4b8daf66939791f86bacb5 .
:WEMI a owl:Class ;
rdfs:subClassOf :WEMI,
owl:Thing ;
owl:equivalentClass :WEMI ;
owl:sameAs :WEMI ;
owl:unionOf _:nd1a95268118e4b8daf66939791f86bacb1 .