Semantics: BY … SOME …
Contents
Semantics: BY … SOME …#
import sys
sys.path.append('../py/')
from gd06 import GenDifS_Map
mindmap = "semantics_bysome" # filename without .mm extension
o = GenDifS_Map(f"../mm/{mindmap}.mm",
pattern = [ "owl", "owl-test", "owl-classify", "docu" ],
# use_rdflib = False, # default: true
# remove_attributes= False, # default: true
verbose = 1)
__init__: GenDifS 0.63 (2023-08-01, 2023-09-08)
o.compile()
lexer: Lexer: found #1 start nodes: ['TAXONOMY']
codegen: codegen: generated 4 entries in `ttl_records`
get_code: Collected 19 code lines, pattern: ['owl', 'owl-test', 'owl-classify', 'docu', 'ALL']
rdflib_parse: rdflib: 39 triples.
# write back ttl in order to highlight source nodes
# o.mindmap.write(f"../mm/{mindmap}.mm", pretty_print=True)
Graph without inferencing#
o.pattern
['owl', 'owl-test', 'owl-classify', 'docu', 'ALL']
len(o.rdflib_graph.serialize(destination=f"../ttl/{mindmap}_gd06.ttl"))
39
Code directly generated by our script:
print(o.ttl_code)
# __init__
# ALL:
@prefix ex: <http://example.net/namespace/ex#> .
@prefix cpt: <http://example.net/namespace/cpt#> .
@prefix sheet: <http://example.net/namespace/sheet#> .
@prefix : <http://example.net/namespace/default#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix gendifs: <http://jbusse.de/gendifs#> .
# __init__
# owl-test:
ex:classifyLike a owl:ObjectProperty .
# __init__
# ALL:
[ rdf:type owl:Ontology ] .
# SUBTAXON.TAXONOMY.a.01 ----
# docu:
# TAXONOMY
# Milk
# SUBTAXON.TAXONOMY.a
# owl: declare class *Milk* being a subclass of topConcept
:Milk
a owl:Class ;
rdfs:subClassOf :topConcept .
# SUBTAXON.TAXONOMY.b
# owl-test: allocate an example instance
ex:Milk_12_563_091
a :Milk .
# BY.0
# docu: --------------------
# Milk
# BY None SOME Animal
# BY.a
# owl: declare *None* as a object property.
:None
rdf:type owl:ObjectProperty .
# BY.b
# owl: declare *Animal* as a owl:Class .
:Animal
a owl:Class .
# BY.c
# owl-test: allocate a test instance of *Animal* .
ex:Animal_1_612_661_532
a :Animal .
# SUBTAXON.BY.a.03 ----
# docu:
# Milk
# BY ... SOME ...
# Goatmilk
# SUBTAXON.BY.a
# owl: declare class *Goatmilk* being a subclass of Milk
:Goatmilk
a owl:Class ;
rdfs:subClassOf :Milk .
# SUBTAXON.BY.b
# owl-test: allocate an example instance
ex:Goatmilk_1_208_031_273
a :Goatmilk .
# SOME.0 ----
# docu:
# Milk
# BY has_source SOME Animal
# Goatmilk
# SOME Goat
# SOME.b
# owl: declare *Goat* as a owl:Class
:Goat
a owl:Class ;
rdfs:subClassOf :Animal .
# SOME.c
# owl-test: allocate an example instance of *Goat*
ex:Goat_1_017_958_217
a :Goat .
# SOME.g
# owl-classify:
:SOME_1_017_958_217_restriction
a owl:Class ;
rdfs:label "BY has_source SOME Goat" ;
rdfs:subClassOf :gendifs_restrictions ;
owl:equivalentClass [ a owl:Restriction ;
owl:onProperty :has_source ;
owl:someValuesFrom :Goat ] .
# SOME.h
# owl-classify: intersection of the superiors
:SOME_1_017_958_217_intersection
a owl:Class ;
rdfs:label "(BY has_source SOME Goat) INTERSECT Milk" ;
rdfs:subClassOf :Goatmilk , :gendifs_intersections ;
owl:equivalentClass [ a owl:Class ;
owl:intersectionOf (
:SOME_1_017_958_217_restriction
:Milk ) ] .
# SOME.i
# owl-test:
# Milk has_source Goat -> Goatmilk
ex:Milk_1_017_958_217_GAP1
a :Milk , :GAP1 .
ex:Milk_1_017_958_217_GAP2
a :Milk , :GAP2 ;
:has_source ex:Goat_1_017_958_217 ;
ex:classifyLike ex:Goatmilk_1_017_958_217_target .
ex:Goat_1_017_958_217
a :Goat .
ex:Goatmilk_1_017_958_217_target
a :Goatmilk .
Our ttl imported into and serialized by rdflib:
len(o.rdflib_graph.serialize(destination=f"../ttl/{mindmap}_rdflib.ttl"))
39
print(o.rdflib_graph.serialize())
@prefix : <http://example.net/namespace/default#> .
@prefix ex: <http://example.net/namespace/ex#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
:None a owl:ObjectProperty .
:SOME_1_017_958_217_intersection a owl:Class ;
rdfs:label "(BY has_source SOME Goat) INTERSECT Milk" ;
rdfs:subClassOf :Goatmilk,
:gendifs_intersections ;
owl:equivalentClass [ a owl:Class ;
owl:intersectionOf ( :SOME_1_017_958_217_restriction :Milk ) ] .
ex:Animal_1_612_661_532 a :Animal .
ex:Goatmilk_1_208_031_273 a :Goatmilk .
ex:Milk_12_563_091 a :Milk .
ex:Milk_1_017_958_217_GAP1 a :GAP1,
:Milk .
ex:Milk_1_017_958_217_GAP2 a :GAP2,
:Milk ;
:has_source ex:Goat_1_017_958_217 ;
ex:classifyLike ex:Goatmilk_1_017_958_217_target .
ex:classifyLike a owl:ObjectProperty .
:SOME_1_017_958_217_restriction a owl:Class ;
rdfs:label "BY has_source SOME Goat" ;
rdfs:subClassOf :gendifs_restrictions ;
owl:equivalentClass [ a owl:Restriction ;
owl:onProperty :has_source ;
owl:someValuesFrom :Goat ] .
ex:Goat_1_017_958_217 a :Goat .
ex:Goatmilk_1_017_958_217_target a :Goatmilk .
:Animal a owl:Class .
:Goat a owl:Class ;
rdfs:subClassOf :Animal .
:Goatmilk a owl:Class ;
rdfs:subClassOf :Milk .
:Milk a owl:Class ;
rdfs:subClassOf :topConcept .
[] a owl:Ontology .
Graph after inferencing#
o.owlrl()
owlrl: owlrl: 265 triples.
len(o.owlrl_graph.serialize(destination=f"../ttl/{mindmap}_owlrl.ttl"))
265
print(o.owlrl_graph.serialize())
@prefix : <http://example.net/namespace/default#> .
@prefix ex: <http://example.net/namespace/ex#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
ex:Animal_1_612_661_532 a :Animal,
owl:Thing ;
owl:sameAs ex:Animal_1_612_661_532 .
ex:Goatmilk_1_208_031_273 a :Goatmilk,
:Milk,
:topConcept,
owl:Thing ;
owl:sameAs ex:Goatmilk_1_208_031_273 .
ex:Milk_12_563_091 a :Milk,
:topConcept,
owl:Thing ;
owl:sameAs ex:Milk_12_563_091 .
ex:Milk_1_017_958_217_GAP1 a :GAP1,
:Milk,
:topConcept,
owl:Thing ;
owl:sameAs ex:Milk_1_017_958_217_GAP1 .
ex:Milk_1_017_958_217_GAP2 a _:n184c5530163e4a159a6d8957dada7a65b2,
_:n184c5530163e4a159a6d8957dada7a65b3,
:GAP2,
:Goatmilk,
:Milk,
:SOME_1_017_958_217_intersection,
:SOME_1_017_958_217_restriction,
:gendifs_intersections,
:gendifs_restrictions,
:topConcept,
owl:Thing ;
:has_source ex:Goat_1_017_958_217 ;
ex:classifyLike ex:Goatmilk_1_017_958_217_target ;
owl:sameAs ex:Milk_1_017_958_217_GAP2 .
rdf:HTML a rdfs:Datatype ;
owl:sameAs rdf:HTML .
rdf:PlainLiteral a rdfs:Datatype ;
owl:sameAs rdf:PlainLiteral .
rdf:XMLLiteral a rdfs:Datatype ;
owl:sameAs rdf:XMLLiteral .
rdf:first owl:sameAs rdf:first .
rdf:langString a rdfs:Datatype ;
owl:sameAs rdf:langString .
rdf:rest owl:sameAs rdf:rest .
rdf:type owl:sameAs rdf:type .
rdfs:Literal a rdfs:Datatype ;
owl:sameAs rdfs:Literal .
rdfs:comment a owl:AnnotationProperty ;
owl:sameAs rdfs:comment .
rdfs:isDefinedBy a owl:AnnotationProperty ;
owl:sameAs rdfs:isDefinedBy .
rdfs:label a owl:AnnotationProperty ;
owl:sameAs rdfs:label .
rdfs:seeAlso a owl:AnnotationProperty ;
owl:sameAs rdfs:seeAlso .
rdfs:subClassOf owl:sameAs rdfs:subClassOf .
rdfs:subPropertyOf owl:sameAs rdfs:subPropertyOf .
xsd:NCName a rdfs:Datatype ;
owl:sameAs xsd:NCName .
xsd:NMTOKEN a rdfs:Datatype ;
owl:sameAs xsd:NMTOKEN .
xsd:Name a rdfs:Datatype ;
owl:sameAs xsd:Name .
xsd:anyURI a rdfs:Datatype ;
owl:sameAs xsd:anyURI .
xsd:base64Binary a rdfs:Datatype ;
owl:sameAs xsd:base64Binary .
xsd:boolean a rdfs:Datatype ;
owl:sameAs xsd:boolean .
xsd:byte a rdfs:Datatype ;
owl:sameAs xsd:byte .
xsd:date a rdfs:Datatype ;
owl:sameAs xsd:date .
xsd:dateTime a rdfs:Datatype ;
owl:sameAs xsd:dateTime .
xsd:dateTimeStamp a rdfs:Datatype ;
owl:sameAs xsd:dateTimeStamp .
xsd:decimal a rdfs:Datatype ;
owl:sameAs xsd:decimal .
xsd:double a rdfs:Datatype ;
owl:sameAs xsd:double .
xsd:float a rdfs:Datatype ;
owl:sameAs xsd:float .
xsd:hexBinary a rdfs:Datatype ;
owl:sameAs xsd:hexBinary .
xsd:int a rdfs:Datatype ;
owl:sameAs xsd:int .
xsd:integer a rdfs:Datatype ;
owl:sameAs xsd:integer .
xsd:language a rdfs:Datatype ;
owl:sameAs xsd:language .
xsd:long a rdfs:Datatype ;
owl:sameAs xsd:long .
xsd:negativeInteger a rdfs:Datatype ;
owl:sameAs xsd:negativeInteger .
xsd:nonNegativeInteger a rdfs:Datatype ;
owl:sameAs xsd:nonNegativeInteger .
xsd:nonPositiveInteger a rdfs:Datatype ;
owl:sameAs xsd:nonPositiveInteger .
xsd:normalizedString a rdfs:Datatype ;
owl:sameAs xsd:normalizedString .
xsd:positiveInteger a rdfs:Datatype ;
owl:sameAs xsd:positiveInteger .
xsd:short a rdfs:Datatype ;
owl:sameAs xsd:short .
xsd:string a rdfs:Datatype ;
owl:sameAs xsd:string .
xsd:time a rdfs:Datatype ;
owl:sameAs xsd:time .
xsd:token a rdfs:Datatype ;
owl:sameAs xsd:token .
xsd:unsignedByte a rdfs:Datatype ;
owl:sameAs xsd:unsignedByte .
xsd:unsignedInt a rdfs:Datatype ;
owl:sameAs xsd:unsignedInt .
xsd:unsignedLong a rdfs:Datatype ;
owl:sameAs xsd:unsignedLong .
xsd:unsignedShort a rdfs:Datatype ;
owl:sameAs xsd:unsignedShort .
owl:backwardCompatibleWith a owl:AnnotationProperty ;
owl:sameAs owl:backwardCompatibleWith .
owl:deprecated a owl:AnnotationProperty ;
owl:sameAs owl:deprecated .
owl:equivalentClass owl:sameAs owl:equivalentClass .
owl:equivalentProperty owl:sameAs owl:equivalentProperty .
owl:incompatibleWith a owl:AnnotationProperty ;
owl:sameAs owl:incompatibleWith .
owl:intersectionOf owl:sameAs owl:intersectionOf .
owl:onProperty owl:sameAs owl:onProperty .
owl:priorVersion a owl:AnnotationProperty ;
owl:sameAs owl:priorVersion .
owl:sameAs owl:sameAs owl:sameAs .
owl:someValuesFrom owl:sameAs owl:someValuesFrom .
owl:versionInfo a owl:AnnotationProperty ;
owl:sameAs owl:versionInfo .
:GAP1 owl:sameAs :GAP1 .
:GAP2 owl:sameAs :GAP2 .
:has_source owl:sameAs :has_source .
ex:Goat_1_017_958_217 a :Animal,
:Goat,
owl:Thing ;
owl:sameAs ex:Goat_1_017_958_217 .
ex:Goatmilk_1_017_958_217_target a :Goatmilk,
:Milk,
:topConcept,
owl:Thing ;
owl:sameAs ex:Goatmilk_1_017_958_217_target .
() owl:sameAs () .
owl:Ontology owl:sameAs owl:Ontology .
owl:Restriction owl:sameAs owl:Restriction .
"(BY has_source SOME Goat) INTERSECT Milk" owl:sameAs "(BY has_source SOME Goat) INTERSECT Milk" .
"BY has_source SOME Goat" owl:sameAs "BY has_source SOME Goat" .
:None a owl:ObjectProperty ;
rdfs:subPropertyOf :None ;
owl:equivalentProperty :None ;
owl:sameAs :None .
ex:classifyLike a owl:ObjectProperty ;
rdfs:subPropertyOf ex:classifyLike ;
owl:equivalentProperty ex:classifyLike ;
owl:sameAs ex:classifyLike .
owl:Nothing a owl:Class ;
rdfs:subClassOf _:n184c5530163e4a159a6d8957dada7a65b2,
_:n184c5530163e4a159a6d8957dada7a65b3,
:Animal,
:Goat,
:Goatmilk,
:Milk,
:SOME_1_017_958_217_intersection,
:SOME_1_017_958_217_restriction,
:gendifs_intersections,
:gendifs_restrictions,
:topConcept,
owl:Nothing,
owl:Thing ;
owl:equivalentClass owl:Nothing ;
owl:sameAs owl:Nothing .
owl:ObjectProperty owl:sameAs owl:ObjectProperty .
:gendifs_intersections owl:sameAs :gendifs_intersections .
:Goat a owl:Class ;
rdfs:subClassOf :Animal,
:Goat,
owl:Thing ;
owl:equivalentClass :Goat ;
owl:sameAs :Goat .
:Animal a owl:Class ;
rdfs:subClassOf :Animal,
owl:Thing ;
owl:equivalentClass :Animal ;
owl:sameAs :Animal .
:SOME_1_017_958_217_intersection a owl:Class ;
rdfs:label "(BY has_source SOME Goat) INTERSECT Milk" ;
rdfs:subClassOf _:n184c5530163e4a159a6d8957dada7a65b2,
_:n184c5530163e4a159a6d8957dada7a65b3,
:Goatmilk,
:Milk,
:SOME_1_017_958_217_intersection,
:SOME_1_017_958_217_restriction,
:gendifs_intersections,
:gendifs_restrictions,
:topConcept,
owl:Thing ;
owl:equivalentClass _:n184c5530163e4a159a6d8957dada7a65b3,
:SOME_1_017_958_217_intersection ;
owl:sameAs :SOME_1_017_958_217_intersection .
:gendifs_restrictions owl:sameAs :gendifs_restrictions .
:Goatmilk a owl:Class ;
rdfs:subClassOf :Goatmilk,
:Milk,
:topConcept,
owl:Thing ;
owl:equivalentClass :Goatmilk ;
owl:sameAs :Goatmilk .
:SOME_1_017_958_217_restriction a owl:Class ;
rdfs:label "BY has_source SOME Goat" ;
rdfs:subClassOf _:n184c5530163e4a159a6d8957dada7a65b2,
:SOME_1_017_958_217_restriction,
:gendifs_restrictions,
owl:Thing ;
owl:equivalentClass _:n184c5530163e4a159a6d8957dada7a65b2,
:SOME_1_017_958_217_restriction ;
owl:sameAs :SOME_1_017_958_217_restriction .
owl:AnnotationProperty owl:sameAs owl:AnnotationProperty .
owl:Class owl:sameAs owl:Class .
:topConcept owl:sameAs :topConcept .
:Milk a owl:Class ;
rdfs:subClassOf :Milk,
:topConcept,
owl:Thing ;
owl:equivalentClass :Milk ;
owl:sameAs :Milk .
owl:Thing a owl:Class ;
rdfs:subClassOf owl:Thing ;
owl:equivalentClass owl:Thing ;
owl:sameAs owl:Thing .
rdfs:Datatype owl:sameAs rdfs:Datatype .
_:n184c5530163e4a159a6d8957dada7a65b1 a owl:Ontology ;
owl:sameAs _:n184c5530163e4a159a6d8957dada7a65b1 .
_:n184c5530163e4a159a6d8957dada7a65b4 rdf:first :SOME_1_017_958_217_restriction ;
rdf:rest _:n184c5530163e4a159a6d8957dada7a65b5 ;
owl:sameAs _:n184c5530163e4a159a6d8957dada7a65b4 .
_:n184c5530163e4a159a6d8957dada7a65b5 rdf:first :Milk ;
rdf:rest () ;
owl:sameAs _:n184c5530163e4a159a6d8957dada7a65b5 .
_:n184c5530163e4a159a6d8957dada7a65b3 a owl:Class ;
rdfs:subClassOf _:n184c5530163e4a159a6d8957dada7a65b2,
_:n184c5530163e4a159a6d8957dada7a65b3,
:Goatmilk,
:Milk,
:SOME_1_017_958_217_intersection,
:SOME_1_017_958_217_restriction,
:gendifs_intersections,
:gendifs_restrictions,
:topConcept,
owl:Thing ;
owl:equivalentClass _:n184c5530163e4a159a6d8957dada7a65b3,
:SOME_1_017_958_217_intersection ;
owl:intersectionOf _:n184c5530163e4a159a6d8957dada7a65b4 ;
owl:sameAs _:n184c5530163e4a159a6d8957dada7a65b3 .
_:n184c5530163e4a159a6d8957dada7a65b2 a owl:Restriction ;
rdfs:subClassOf _:n184c5530163e4a159a6d8957dada7a65b2,
:SOME_1_017_958_217_restriction,
:gendifs_restrictions,
owl:Thing ;
owl:equivalentClass _:n184c5530163e4a159a6d8957dada7a65b2,
:SOME_1_017_958_217_restriction ;
owl:onProperty :has_source ;
owl:sameAs _:n184c5530163e4a159a6d8957dada7a65b2 ;
owl:someValuesFrom :Goat .
ask graph with SPARQL#
q = """
SELECT ?a ?A
WHERE {
?a rdf:type ?A .
?a ex:classifyLike ?b .
}
"""
def show_rows(g, q):
for row in g.query(q):
print([item.n3(g.namespace_manager) for item in row])
show_rows(o.rdflib_graph, q)
['ex:Milk_1_017_958_217_GAP2', ':Milk']
['ex:Milk_1_017_958_217_GAP2', ':GAP2']
show_rows(o.owlrl_graph, q)
['ex:Milk_1_017_958_217_GAP2', ':Milk']
['ex:Milk_1_017_958_217_GAP2', ':GAP2']
['ex:Milk_1_017_958_217_GAP2', ':topConcept']
['ex:Milk_1_017_958_217_GAP2', '_:n184c5530163e4a159a6d8957dada7a65b2']
['ex:Milk_1_017_958_217_GAP2', ':SOME_1_017_958_217_restriction']
['ex:Milk_1_017_958_217_GAP2', 'owl:Thing']
['ex:Milk_1_017_958_217_GAP2', '_:n184c5530163e4a159a6d8957dada7a65b3']
['ex:Milk_1_017_958_217_GAP2', ':gendifs_restrictions']
['ex:Milk_1_017_958_217_GAP2', ':gendifs_intersections']
['ex:Milk_1_017_958_217_GAP2', ':SOME_1_017_958_217_intersection']
['ex:Milk_1_017_958_217_GAP2', ':Goatmilk']