Skip to content

Commit

Permalink
RDFS tested with test data and test queries
Browse files Browse the repository at this point in the history
  • Loading branch information
mzattera committed May 3, 2021
1 parent c178648 commit 3411c10
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 23 deletions.
2 changes: 2 additions & 0 deletions Graql/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/animals.ttl
/queries.txt
Binary file modified Graql/RdfImporter.jar
Binary file not shown.
13 changes: 11 additions & 2 deletions Graql/rdf.gql
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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;
};
Expand Down
44 changes: 44 additions & 0 deletions Graql/test_data.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
@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 dc: <http://purl.org/dc/elements/1.1/> .
@prefix maxi: <http://mz.name/#> .

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 .
43 changes: 43 additions & 0 deletions Graql/test_queries.txt
Original file line number Diff line number Diff line change
@@ -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;
38 changes: 19 additions & 19 deletions Notepad++/graql.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,40 +25,40 @@
<Keywords name="Folders in comment, middle"></Keywords>
<Keywords name="Folders in comment, close"></Keywords>
<Keywords name="Keywords1">thing&#x000D;&#x000A;entity&#x000D;&#x000A;attribute&#x000D;&#x000A;relation&#x000D;&#x000A;role&#x000D;&#x000A;rule&#x000D;&#x000A;</Keywords>
<Keywords name="Keywords2">define&#x000D;&#x000A;undefine&#x000D;&#x000A;match&#x000D;&#x000A;get&#x000D;&#x000A;insert&#x000D;&#x000A;delete&#x000D;&#x000A;compute&#x000D;&#x000A;offset&#x000D;&#x000A;limit&#x000D;&#x000A;group&#x000D;&#x000A;sort&#x000D;&#x000A;asc&#x000D;&#x000A;desc&#x000D;&#x000A;centrality&#x000D;&#x000A;using&#x000D;&#x000A;abstract&#x000D;&#x000A;as&#x000D;&#x000A;id&#x000D;&#x000A;type&#x000D;&#x000A;isa&#x000D;&#x000A;isa!&#x000D;&#x000A;sub&#x000D;&#x000A;sub!&#x000D;&#x000A;key&#x000D;&#x000A;has&#x000D;&#x000A;plays&#x000D;&#x000A;relates&#x000D;&#x000A;value&#x000D;&#x000A;regex&#x000D;&#x000A;when&#x000D;&#x000A;then&#x000D;&#x000A;or&#x000D;&#x000A;not&#x000D;&#x000A;like</Keywords>
<Keywords name="Keywords2">define&#x000D;&#x000A;undefine&#x000D;&#x000A;match&#x000D;&#x000A;get&#x000D;&#x000A;insert&#x000D;&#x000A;delete&#x000D;&#x000A;compute&#x000D;&#x000A;offset&#x000D;&#x000A;limit&#x000D;&#x000A;group&#x000D;&#x000A;sort&#x000D;&#x000A;asc&#x000D;&#x000A;desc&#x000D;&#x000A;centrality&#x000D;&#x000A;using&#x000D;&#x000A;abstract&#x000D;&#x000A;as&#x000D;&#x000A;id&#x000D;&#x000A;type&#x000D;&#x000A;isa&#x000D;&#x000A;isa!&#x000D;&#x000A;sub&#x000D;&#x000A;sub!&#x000D;&#x000A;key&#x000D;&#x000A;owns&#x000D;&#x000A;plays&#x000D;&#x000A;relates&#x000D;&#x000A;value&#x000D;&#x000A;regex&#x000D;&#x000A;when&#x000D;&#x000A;then&#x000D;&#x000A;or&#x000D;&#x000A;not&#x000D;&#x000A;like</Keywords>
<Keywords name="Keywords3">long&#x000D;&#x000A;double&#x000D;&#x000A;string&#x000D;&#x000A;boolean&#x000D;&#x000A;datetime&#x000D;&#x000A;true&#x000D;&#x000A;false</Keywords>
<Keywords name="Keywords4"></Keywords>
<Keywords name="Keywords4">TODO</Keywords>
<Keywords name="Keywords5"></Keywords>
<Keywords name="Keywords6"></Keywords>
<Keywords name="Keywords7"></Keywords>
<Keywords name="Keywords8"></Keywords>
<Keywords name="Delimiters">00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23</Keywords>
</KeywordLists>
<Styles>
<WordsStyle name="DEFAULT" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="COMMENTS" fgColor="808040" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
<WordsStyle name="LINE COMMENTS" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DEFAULT" fgColor="000000" bgColor="FFFFFF" fontName="tt\Projects\Git - KRAAL\Notepad++" fontStyle="0" nesting="0" />
<WordsStyle name="COMMENTS" fgColor="808040" bgColor="FFFFFF" fontName="er" fontStyle="1" nesting="0" />
<WordsStyle name="LINE COMMENTS" fgColor="000000" bgColor="FFFFFF" fontName="&#xFFFF;&#xFFFF;&#xFFFF;&#xFFFF;" fontStyle="0" nesting="0" />
<WordsStyle name="NUMBERS" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS1" fgColor="0080FF" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
<WordsStyle name="KEYWORDS2" fgColor="800080" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
<WordsStyle name="KEYWORDS3" fgColor="FF8000" bgColor="FFFFFF" fontName="" fontStyle="1" nesting="0" />
<WordsStyle name="KEYWORDS4" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS1" fgColor="0080FF" bgColor="FFFFFF" fontName="&#x0001;e&#x0004;" fontStyle="1" nesting="0" />
<WordsStyle name="KEYWORDS2" fgColor="800080" bgColor="FFFFFF" fontName="&#x0C98;&#x06FA;" fontStyle="1" nesting="0" />
<WordsStyle name="KEYWORDS3" fgColor="FF8000" bgColor="FFFFFF" fontName="&#xABB0;&#x0A96;&#x2064;&#x514E;" fontStyle="1" nesting="0" />
<WordsStyle name="KEYWORDS4" fgColor="FF0000" bgColor="FFFFFF" fontName="&#xA658;&#x0A96;&#xAAD8;&#x0A96;&#x9478;&#x035D;&#x0001;&#x656A;&#xA400;&#x0709; " fontStyle="1" nesting="0" />
<WordsStyle name="KEYWORDS5" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS6" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS6" fgColor="000000" bgColor="FFFFFF" fontName="&#x106F;&#x6D00;&#x617A;&#x7474;&#x3C00;&#x0900;&#x0400;&#xEF00;&#xBEBE;&#x3C4C;&#xA323;R&#x2E44;" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS7" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="KEYWORDS8" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="OPERATORS" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="FOLDER IN CODE1" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="OPERATORS" fgColor="000000" bgColor="FFFFFF" fontName="&#xE720;&#x06F5;&#xE700;&#x06F5;" fontStyle="0" nesting="0" />
<WordsStyle name="FOLDER IN CODE1" fgColor="000000" bgColor="FFFFFF" fontName="&#x5048;&#x75E3;&#x1500;&#x8000;&#xDBE4;&#x75E3;&#x2218;&#x0010;" fontStyle="0" nesting="0" />
<WordsStyle name="FOLDER IN CODE2" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="FOLDER IN COMMENT" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS1" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS2" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS3" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS4" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS5" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS1" fgColor="000000" bgColor="FFFFFF" fontName="oleacc.dll" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS2" fgColor="000000" bgColor="FFFFFF" fontName="&#x91F8;&#x4638;&#x0408;&#x8000;:&#x421F;&#xA727;&#xE31E;&#x12ED;&#x4702;&#x0C82;&#x644B;&#xF245;&#x1A8E;&amp;&#x0001;&amp;&#xBEEF;&#x0011;" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS3" fgColor="000000" bgColor="FFFFFF" fontName="&#x3F72;&#x44A7;&#xC589;&#x9555;&#x6BFE;&#xEE30;&amp;&#x0001;&amp;&#xBEEF;&#x0010;" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS4" fgColor="000000" bgColor="FFFFFF" fontName="&#x0007;" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS5" fgColor="000000" bgColor="FFFFFF" fontName="&#x4D4C;&#x4D45;x" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS6" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS7" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS8" fgColor="000000" bgColor="FFFFFF" fontName="" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS7" fgColor="000000" bgColor="FFFFFF" fontName="&#x8000;&#x4395;" fontStyle="0" nesting="0" />
<WordsStyle name="DELIMITERS8" fgColor="000000" bgColor="FFFFFF" fontName="5/07/Computer" fontStyle="0" nesting="0" />
</Styles>
</UserLang>
</NotepadPlus>
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit 3411c10

Please sign in to comment.