diff --git a/Graql/.gitignore b/Graql/.gitignore new file mode 100644 index 0000000..1f75a70 --- /dev/null +++ b/Graql/.gitignore @@ -0,0 +1,2 @@ +/animals.ttl +/queries.txt diff --git a/Graql/RdfImporter.jar b/Graql/RdfImporter.jar index 1f5d0db..1dc8a8b 100644 Binary files a/Graql/RdfImporter.jar and b/Graql/RdfImporter.jar differ diff --git a/Graql/rdf.gql b/Graql/rdf.gql index 933e511..2889795 100644 --- a/Graql/rdf.gql +++ b/Graql/rdf.gql @@ -66,7 +66,16 @@ when { ## subClassOf is reflexive (each class is a subclass of itself) -## TODO +rule rdf-reflexive-subclassof: +when { + $class "http://www.w3.org/2000/01/rdf-schema#Class" isa rdf-IRI; + $subclass "http://www.w3.org/2000/01/rdf-schema#subClassOf" isa rdf-IRI; + $type "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" isa rdf-IRI; + (rdf-subject: $c, rdf-predicate: $type, rdf-object: $class) isa rdf-triple; +} then { + (rdf-subject: $c, rdf-predicate: $subclass, rdf-object: $c) isa rdf-triple; +}; + ## subClassOf is transitive rule rdf-transitive-subclassof: @@ -78,6 +87,7 @@ when { (rdf-subject: $x, rdf-predicate: $subclass, rdf-object: $y) isa rdf-triple; }; + ## If a property P is a subproperty of property P', ## then all pairs of resources which are related by P are also related by P'. rule rdf-sub-property: @@ -86,7 +96,6 @@ when { (rdf-subject: $p, rdf-predicate: $subprop, rdf-object: $p1) isa rdf-triple; $p1 isa rdf-IRI; (rdf-subject: $s, rdf-predicate: $p, rdf-object: $o) isa rdf-triple; - $p != $p1; } then { (rdf-subject: $s, rdf-predicate: $p1, rdf-object: $o) isa rdf-triple; }; diff --git a/Graql/test_data.ttl b/Graql/test_data.ttl new file mode 100644 index 0000000..01a2d43 --- /dev/null +++ b/Graql/test_data.ttl @@ -0,0 +1,44 @@ +@prefix rdf: . +@prefix rdfs: . +@prefix owl: . +@prefix dc: . +@prefix maxi: . + +maxi:Animal a rdfs:Class ; + rdfs:label "Animal" . + +maxi:Dog a rdfs:Class ; + rdfs:label "Dog" ; + rdfs:subClassOf maxi:Animal . + +maxi:Husky a rdfs:Class ; + rdfs:label "Husky" ; + rdfs:subClassOf maxi:Dog . + +maxi:RedHusky a rdfs:Class ; + rdfs:label "Red Husky" ; + rdfs:subClassOf maxi:Husky . + +maxi:Cat a rdfs:Class ; + rdfs:label "Cat" ; + rdfs:subClassOf maxi:Animal . + +maxi:Milo a maxi:RedHusky . + +maxi:hates a rdf:Property . + +maxi:reallyHates rdfs:subPropertyOf maxi:hates . + +maxi:reallyReallyHates rdfs:subPropertyOf maxi:reallyHates . + +maxi:Grebo a maxi:Cat . + +maxi:Grebo maxi:reallyReallyHates maxi:Milo . + +maxi:hasColor rdfs:range maxi:Color . + +maxi:pen maxi:hasColor maxi:red . + +maxi:isPoisonous rdfs:domain maxi:Mushroom . + +maxi:Amanita maxi:isPoisonous false . \ No newline at end of file diff --git a/Graql/test_queries.txt b/Graql/test_queries.txt new file mode 100644 index 0000000..92091d2 --- /dev/null +++ b/Graql/test_queries.txt @@ -0,0 +1,43 @@ +## rule rdf-instancesOf-subclassof: +## Milo as RedHusky > Husky > Dog > Animal +match $t (rdf-subject:$s, rdf-predicate:$p, rdf-object:$o) isa rdf-triple; $s "http://mz.name/#Milo"; get $s, $p, $o; + +## rule rdf-reflexive-subclassof: +## Animal is a subclas of itself +match $t (rdf-subject:$s, rdf-predicate:$p, rdf-object:$o) isa rdf-triple; $s "http://mz.name/#Animal"; get $s, $p, $o; + +## rule rdf-transitive-subclassof: +## RedHusky > Husky > Dog > Animal +match $t (rdf-subject:$s, rdf-predicate:$p, rdf-object:$o) isa rdf-triple; $s "http://mz.name/#RedHusky"; get $s, $p, $o; + +## rule rdf-sub-property: +## reallyReallyHates > reallyHates > hates > Property +match $t (rdf-subject:$s, rdf-predicate:$p, rdf-object:$o) isa rdf-triple; $s "http://mz.name/#Grebo"; get $s, $p, $o; + +##rule rdf-transitive-subpropertyof: +## reallyReallyHates > reallyHates > hates > Property +match $t (rdf-subject:$s, rdf-predicate:$p, rdf-object:$o) isa rdf-triple; $s "http://mz.name/#reallyReallyHates"; get $s, $p, $o; + +## rule rdf-properties-have-range: +## hasColor is a Property +match $t (rdf-subject:$s, rdf-predicate:$p, rdf-object:$o) isa rdf-triple; $s "http://mz.name/#hasColor"; get $s, $p, $o; + +## rule rdf-classes-are-range: +## Color is a class +match $t (rdf-subject:$s, rdf-predicate:$p, rdf-object:$o) isa rdf-triple; $s "http://mz.name/#Color"; get $s, $p, $o; + +## rule rdf-instances-in-range: +## red is a Color +match $t (rdf-subject:$s, rdf-predicate:$p, rdf-object:$o) isa rdf-triple; $s "http://mz.name/#red"; get $s, $p, $o; + +## rule rdf-properties-have-domain: +## isPoisonous is a Property +match $t (rdf-subject:$s, rdf-predicate:$p, rdf-object:$o) isa rdf-triple; $s "http://mz.name/#isPoisonous"; get $s, $p, $o; + +## rule rdf-classes-are-domain: +## Mushroom is a class +match $t (rdf-subject:$s, rdf-predicate:$p, rdf-object:$o) isa rdf-triple; $s "http://mz.name/#Mushroom"; get $s, $p, $o; + +## rule rdf-instances-in-domain: +## Amanita is a Mushroom +match $t (rdf-subject:$s, rdf-predicate:$p, rdf-object:$o) isa rdf-triple; $s "http://mz.name/#Amanita"; get $s, $p, $o; diff --git a/Notepad++/graql.xml b/Notepad++/graql.xml index 3d2ed1a..ede63a2 100644 --- a/Notepad++/graql.xml +++ b/Notepad++/graql.xml @@ -25,9 +25,9 @@ thing entity attribute relation role rule - define undefine match get insert delete compute offset limit group sort asc desc centrality using abstract as id type isa isa! sub sub! key has plays relates value regex when then or not like + define undefine match get insert delete compute offset limit group sort asc desc centrality using abstract as id type isa isa! sub sub! key owns plays relates value regex when then or not like long double string boolean datetime true false - + TODO @@ -35,30 +35,30 @@ 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 - - - + + + - - - - + + + + - + - - + + - - - - - + + + + + - - + + diff --git a/eclipse/kraal/src/main/java/io/github/mzattera/semanticweb/kraal/RdfImporter.java b/eclipse/kraal/src/main/java/io/github/mzattera/semanticweb/kraal/RdfImporter.java index 2dc100d..978e7f3 100644 --- a/eclipse/kraal/src/main/java/io/github/mzattera/semanticweb/kraal/RdfImporter.java +++ b/eclipse/kraal/src/main/java/io/github/mzattera/semanticweb/kraal/RdfImporter.java @@ -86,7 +86,7 @@ public RdfImporter(String db) { public RdfImporter(String host, String db) { client = Grakn.coreClient(host); session = client.session(db, GraknSession.Type.DATA); - logger.info("Connected to fatabase " + db + " on " + host); + logger.info("Connected to database " + db + " on " + host); } /** @@ -99,7 +99,7 @@ public RdfImporter(String host, String db) { public RdfImporter(String host, String db, GraknOptions options) { client = Grakn.coreClient(host); session = client.session(db, GraknSession.Type.DATA, options); - logger.info("Connected to fatabase " + db + " on " + host); + logger.info("Connected to database " + db + " on " + host); } /**