ns tax=<http://example.com/taxonomy/>
ns r=<http://example.com/resource/>
ns bm=<http://www.w3.org/2002/01/bookmark#>
@../test/bookmarkRules.alg
@../test/rdfs.alg
slurp ../test/subCategoryExample.rdf ()
ask (
?sub bm:subCategoryOf ?super .
?bmark bm:hasCategory ?super .
!?bmark bm:foo ?super
)
collect (?bmark ?sub ?super)
ns bm=<http://www.w3.org/2002/01/bookmark#>
# fwrule (head '((bm::hasCategory ?a ?b)(! (|| (bm::subCategoryOf ?b ?c) (bm::subDategoryOf ?b ?c) (bm::subFategoryOf ?b ?c))))
fwrule ask (?a bm:hasCategory ?b . ?b bm:subCategoryOf ?c)
assert (?a bm:hasCategory ?c)
@../test/owl.alg
assert (bm:subCategoryOf rdf:type owl:TransitiveProperty)
ns rdf=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
ns rdfs=<http://www.w3.org/2000/01/rdf-schema#>
ns owl=<http://www.w3.org/2002/07/owl#>
@../test/owl.alg
# rdfs subPropertyOf
fwrule ask (?a rdfs:subPropertyOf ?b . ?c ?a ?d)
assert (?c ?b ?d)
# rdfs subPropertyOf transitivity
# fwrule ask (?a rdfs:subPropertyOf ?b)(?b rdfs:subPropertyOf ?c)
# assert (?A rdfs:subPropertyOf ?c)
assert (rdfs:subPropertyOf rdf:type owl:TransitiveProperty)
# rdfs subClassOf and rdf type
fwrule ask (?a rdf:type ?b . ?b rdfs:subClassOf ?c)
assert (?a rdf:type ?c)
# rdfs subClassOf transitivity
# fwrule ask (?a rdfs:subClassOf ?b . ?b rdfs:subClassOf ?c)
# assert (?a rdfs:subClassOf ?c)
# rdfs domain
assert (rdfs:subClassOf rdf:type owl:TransitiveProperty)
fwrule ask (?a rdfs:domain ?b . ?c ?a ?d)
assert (?c rdf:type ?b)
# rdfs range
fwrule ask (?a rdfs:range ?b . ?c ?a ?d)
assert (?d rdf:type ?b)
ns owl=<http://www.w3.org/2002/07/owl#>
ns rdf=<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
# owl TransitiveProperty
fwrule ask (?p rdf:type owl:TransitiveProperty . ?x ?p ?y . ?y ?p ?z)
assert (?x ?p ?z)
<rdf:RDF
xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
xmlns:b='http://www.w3.org/2002/01/bookmark#'
xmlns:bar='http://example.com/bar#'
xmlns:a='http://www.w3.org/annotate#'
xmlns:dc='http://www.w3.org/dc#'
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<rdf:Description rdf:about="http://www.w3.org/2002/01/bookmark#hasCategory">
<rdfs:range rdf:resource="http://www.w3.org/2002/01/bookmark#Category"/>
</rdf:Description>
<rdf:Description rdf:about='http://example.com/resource/one'>
<b:foo rdf:resource='http://example.com/taxonomy/blue-whales'/>
</rdf:Description>
<rdf:Description rdf:about='http://www.w3.org/2002/01/bookmark#foo'>
<rdfs:subPropertyOf rdf:resource='http://www.w3.org/2002/01/bookmark#hasCategory'/>
</rdf:Description>
<rdf:Description rdf:about='http://example.com/taxonomy/blue-whales'>
<b:subCategoryOf rdf:resource='http://example.com/taxonomy/opaque-whales'/>
</rdf:Description>
<rdf:Description rdf:about='http://example.com/taxonomy/bright-blue-whales'>
<b:subCategoryOf rdf:resource='http://example.com/taxonomy/blue-whales'/>
</rdf:Description>
</rdf:RDF>
yields:
+---------------------------------+------------------------------------------------+-------------------------------------------+ | bmark| sub| super| |---------------------------------|------------------------------------------------|-------------------------------------------| |<http://example.com/resource/one>| <http://example.com/taxonomy/blue-whales>|<http://example.com/taxonomy/opaque-whales>| |<http://example.com/resource/one>|<http://example.com/taxonomy/bright-blue-whales>|<http://example.com/taxonomy/opaque-whales>| +---------------------------------+------------------------------------------------+-------------------------------------------+
( xmlns:b="http://www.w3.org/2002/01/bookmark#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:r="http://example.com/resource/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:tax="http://example.com/taxonomy/" )
r:one b:hasCategory tax:opaque-whales .
-->{[fwrule ask(?a b:hasCategory ?b &&
?b b:subCategoryOf ?c)
assert(?a b:hasCategory ?c)
-->{<file:run.sh>}
- r:one b:hasCategory tax:blue-whales .
-->{[fwrule ask(?a rdfs:subPropertyOf ?b &&
?c ?a ?d)
assert(?c ?b ?d)
-->{<file:run.sh>}
- b:foo rdfs:subPropertyOf b:hasCategory .
-->{<file:../test/subCategoryExample.rdf>}
- r:one b:foo tax:blue-whales .
-->{<file:../test/subCategoryExample.rdf>}
| a: b:foo
| b: b:hasCategory
| bmark: NULL
| c: r:one
| d: tax:blue-whales
| p: NULL
| sub: NULL
| super: NULL
| x: NULL
| y: NULL
| z: NULL]}
- tax:blue-whales b:subCategoryOf tax:opaque-whales .
-->{<file:../test/subCategoryExample.rdf>}
| a: r:one
| b: tax:blue-whales
| bmark: NULL
| c: tax:opaque-whales
| d: NULL
| p: NULL
| sub: NULL
| super: NULL
| x: NULL
| y: NULL
| z: NULL]},
tax:blue-whales b:subCategoryOf tax:opaque-whales .
-->{<file:../test/subCategoryExample.rdf>},
tax:bright-blue-whales b:subCategoryOf tax:opaque-whales .
-->{[fwrule ask(?p rdf:type owl:TransitiveProperty &&
?x ?p ?y &&
?y ?p ?z)
assert(?x ?p ?z)
-->{<file:run.sh>}
- b:subCategoryOf rdf:type owl:TransitiveProperty .
-->{<file:run.sh>}
- tax:bright-blue-whales b:subCategoryOf tax:blue-whales .
-->{<file:../test/subCategoryExample.rdf>}
- tax:blue-whales b:subCategoryOf tax:opaque-whales .
-->{<file:../test/subCategoryExample.rdf>}
| a: NULL
| b: NULL
| bmark: NULL
| c: NULL
| d: NULL
| p: b:subCategoryOf
| sub: NULL
| super: NULL
| x: tax:bright-blue-whales
| y: tax:blue-whales
| z: tax:opaque-whales]}
This approach puts the bindings into a sepparate context to keep from making assertions about them in the outer (evaluation) context. Dunno how people feel about this technique.
@prefix b=<http://www.w3.org/2002/01/bookmark#> .
@prefix owl=<http://www.w3.org/2002/07/owl#> .
@prefix r=<http://example.com/resource/> .
@prefix rdf=<http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs=<http://www.w3.org/2000/01/rdf-schema#> .
@prefix tax=<http://example.com/taxonomy/> .
([ a :Statement ;
:repr {r:one b:hasCategory tax:opaque-whales .} ;
:accordingTo ([ a :InferenceAttribution ;
:rule [ a :FwRule ;
:repr {{ ?a b:hasCategory ?b .
?b b:subCategoryOf ?c }
=>
{ ?a b:hasCategory ?c }} ;
:accordingTo ( [ a :GroundFact ;
:from <file:run.sh> ])] ;
:appliedTo ( [ a :Statement ;
:repr {r:one b:hasCategory tax:blue-whales .} ;
:accordingTo ([ a :InferenceAttribution ;
:rule [ a :FwRule ;
:repr {{ ?a rdfs:subPropertyOf ?b .
?c ?a ?d }
=>
{ ?c ?b ?d }} ;
:accordingTo ( [ a :GroundFact ;
:from <file:run.sh> ])] ;
:appliedTo ( [ a :Statement ;
:repr {b:foo rdfs:subPropertyOf b:hasCategory .} ;
:accordingTo ( [ a :GroundFact ;
:from <file:../test/subCategoryExample.rdf> ])],
[ a :Statement ;
:repr {r:one b:foo tax:blue-whales .} ;
:accordingTo ( [ a :GroundFact ;
:from <file:../test/subCategoryExample.rdf> ])]) ;
:bindings { ?a :boundTo b:foo.
?b :boundTo b:hasCategory.
?bmark :boundTo :NULL.
?c :boundTo r:one.
?d :boundTo tax:blue-whales.
?p :boundTo :NULL.
?sub :boundTo :NULL.
?super :boundTo :NULL.
?x :boundTo :NULL.
?y :boundTo :NULL.
?z :boundTo :NULL. }])],
[ a :Statement ;
:repr {tax:blue-whales b:subCategoryOf tax:opaque-whales .} ;
:accordingTo ( [ a :GroundFact ;
:from <file:../test/subCategoryExample.rdf> ])]) ;
:bindings { ?a :boundTo r:one.
?b :boundTo tax:blue-whales.
?bmark :boundTo :NULL.
?c :boundTo tax:opaque-whales.
?d :boundTo :NULL.
?p :boundTo :NULL.
?sub :boundTo :NULL.
?super :boundTo :NULL.
?x :boundTo :NULL.
?y :boundTo :NULL.
?z :boundTo :NULL. }])],
[ a :Statement ;
:repr {tax:blue-whales b:subCategoryOf tax:opaque-whales .} ;
:accordingTo ( [ a :GroundFact ;
:from <file:../test/subCategoryExample.rdf> ])],
[ a :Statement ;
:repr {tax:bright-blue-whales b:subCategoryOf tax:opaque-whales .} ;
:accordingTo ([ a :InferenceAttribution ;
:rule [ a :FwRule ;
:repr {{ ?p rdf:type owl:TransitiveProperty .
?x ?p ?y .
?y ?p ?z }
=>
{ ?x ?p ?z }} ;
:accordingTo ( [ a :GroundFact ;
:from <file:run.sh> ])] ;
:appliedTo ( [ a :Statement ;
:repr {b:subCategoryOf rdf:type owl:TransitiveProperty .} ;
:accordingTo ( [ a :GroundFact ;
:from <file:run.sh> ])],
[ a :Statement ;
:repr {tax:bright-blue-whales b:subCategoryOf tax:blue-whales .} ;
:accordingTo ( [ a :GroundFact ;
:from <file:../test/subCategoryExample.rdf> ])],
[ a :Statement ;
:repr {tax:blue-whales b:subCategoryOf tax:opaque-whales .} ;
:accordingTo ( [ a :GroundFact ;
:from <file:../test/subCategoryExample.rdf> ])]) ;
:bindings { ?a :boundTo :NULL.
?b :boundTo :NULL.
?bmark :boundTo :NULL.
?c :boundTo :NULL.
?d :boundTo :NULL.
?p :boundTo b:subCategoryOf.
?sub :boundTo :NULL.
?super :boundTo :NULL.
?x :boundTo tax:bright-blue-whales.
?y :boundTo tax:blue-whales.
?z :boundTo tax:opaque-whales. }])]) .