Guest User

Untitled

a guest
Jun 4th, 2018
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.33 KB | None | 0 0
  1. @prefix :<http://expl.at#>.
  2. :JamesCameron :directorOf :Terminator.
  3.  
  4. prefix : <http://expl.at#>
  5. select * where {:directorOf ?y ?z}
  6.  
  7. @prefix :<http://expl.at#>.
  8. @prefix rdfs:<http://www.w3.org/2000/01/rdf-schema#>.
  9. :directorOf rdfs:domain :Director; rdfs:range :Movie.
  10.  
  11. prefix : <http://expl.at#>
  12. select * where {:Terminator a ?z}
  13.  
  14. prefix : <http://expl.at#>
  15. select * where
  16. {
  17. :Terminator a ?z
  18. filter (!strstarts(str(?z),"http://www.w3.org"))
  19. }
  20.  
  21. We can now also ask what is James Cameron:
  22. prefix : <http://expl.at#>
  23. select * where {:JamesCameron a ?z}
  24.  
  25. Several other statements were also generated – for example that Director and Movie are classes, things, resources and also subclasses of owl:Thing (because any director and movie is a thing, not only the classes Director and Movie).
  26.  
  27. Now upload the following:
  28.  
  29. @prefix :<http://expl.at#>.
  30. :TimBurton :directorOf :Batman.
  31. :StevenSpielberg :directorOf :ET.
  32.  
  33. If you ask what is TimBurton or what is ET you will receive the right answers – Director and Movie – although you never uploaded such information explicitly. This is because the axioms remain active (until you delete them) and will keep generating relevant statements for every statement that we upload. You can also retrieve a list of all directors (or movies):
  34. prefix : <http://expl.at#>
  35. select * where {?x a :Director}
  36.  
  37.  
  38. Upload a new axiom:
  39. @prefix rdfs:<http://www.w3.org/2000/01/rdf-schema#>.
  40. @prefix :<http://expl.at#>.
  41. :Director rdfs:subClassOf :Artist.
  42. This axiom declares the inclusion of two classes, which translates to the following rule: "any director is also an artist". Now if we ask what is JamesCameron we get richer answers - not only Director, but also Artist:
  43.  
  44. prefix : <http://expl.at#>
  45. select * where {:JamesCameron a ?z}
  46.  
  47.  
  48. Upload a new axiom:
  49. @prefix rdfs:<http://www.w3.org/2000/01/rdf-schema#>.
  50. @prefix :<http://expl.at#>.
  51. :AmericanDirector rdfs:subClassOf :Director.
  52.  
  53.  
  54. You may think that, based on the same reasoning, JamesCameron now also becomes an AmericanDirector. Check this with the following query:
  55. prefix : <http://expl.at#>
  56. select * where {:JamesCameron a ?z}
  57.  
  58.  
  59. prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
  60. prefix : <http://expl.at#>
  61. select * where {:AmericanDirector rdfs:subClassOf ?x}
  62.  
  63. Upload a new axiom:
  64. @prefix rdfs:<http://www.w3.org/2000/01/rdf-schema#>.
  65. @prefix :<http://expl.at#>.
  66. :directorOf rdfs:subPropertyOf :creatorOf.
  67.  
  68. This axiom generates a similar hierarchy, but for properties. It will be interpreted as a logical implication: "If x is director of y, then x created y". We can check that a new relation was generated between the mentioned directors and their movies:
  69.  
  70. prefix : <http://expl.at#>
  71. select * where {?x :creatorOf ?y}
  72.  
  73. The superproperty is a more general version of its subproperties, manifesting between the same pair of instances. Just as with the classes, the propagation works only upwards in the hierarchy. If we add the following axiom, it will not be generated between he same things:
  74.  
  75. @prefix rdfs:<http://www.w3.org/2000/01/rdf-schema#>.
  76. @prefix : <http://expl.at#>.
  77. :codirectorOf rdfs:subPropertyOf :directorOf.
  78.  
  79. You can check that this axiom did not generate new relations (JamesCameron is directorOf Terminator, but this does not mean he is also codirector – the relation propagates only towards superproperties):
  80.  
  81. prefix : <http://expl.at#>
  82. select * where {?x :codirectorOf ?y}
  83.  
  84. However, some statements were generated – the general description of the newly introduced property codirector:
  85.  
  86. prefix : <http://expl.at#>
  87. select * where {:codirectorOf ?x ?y}
  88.  
  89.  
  90. Delete the axiom that defined the original domain for directOf:
  91. prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
  92. prefix : <http://expl.at#>
  93. delete data {:directorOf rdfs:domain :Director}
  94.  
  95. Now if you ask for information about JamesCameron you will notice that everything that was deduced from the deleted axiom was also deleted:
  96.  
  97. prefix : <http://expl.at#>
  98. select * where {:JamesCameron ?y ?x}
  99.  
  100. Also, the domain of codirectorOf does is not inherited anymore from the (deleted) domain of directorOf:
  101.  
  102. prefix : <http://expl.at#>
  103. select * where {:codirectorOf ?x ?y}
  104.  
  105. The knowledge that JamesCameron, TimBurton, StevenSpielberg are directors also disappeared – we have no more directors:
  106.  
  107. prefix : <http://expl.at#>
  108. select * where {?x a :Director}
  109.  
  110. OWL reasoning in GraphDB
  111.  
  112. Upload the following axioms:
  113.  
  114. @prefix : <http://expl.at#>.
  115. @prefix owl: <http://www.w3.org/2002/07/owl#>.
  116. :hasFriend a owl:SymmetricProperty.
  117. :hasRelative a owl:TransitiveProperty.
  118. :hasHusband owl:inverseOf :hasWife.
  119.  
  120.  
  121. To check the effect of these axioms, upload the following statements using these axioms:
  122.  
  123. @prefix : <http://expl.at#>.
  124. :Jim :hasFriend :George.
  125. :Anna :hasHusband :George.
  126. :Andrew :hasRelative :Jim.
  127. :Jim :hasRelative :Jane.
  128.  
  129. We will check that the following statements are generated:
  130. :George :hasFriend :Jim (because of the symmetry of friendship)
  131. :George :hasWife :Anna (because it is inverse to the husband relationship)
  132. :Andrew :hasRelative :Jane (because being a relative is a transitive relationship)
  133.  
  134. To check, run the following queries:
  135. prefix : <http://expl.at#>
  136. select *
  137. where {?x :hasFriend ?y}
  138. (it will show the friendship relation in both directions)
  139.  
  140. prefix : <http://expl.at#>
  141. select *
  142. where {?x :hasWife ?y}
  143. (it will show George as subject and Anna as object)
  144.  
  145. prefix : <http://expl.at#>
  146. select *
  147. where {?x :hasRelative ?y}
  148. (it will show three hasRelative relationships – two explicit ones and one generated between Andrew and Jane)
  149.  
  150. We can add some RDFS axioms to combine all these relations and to assign them to classes:
  151. @prefix : <http://expl.at#>.
  152. @prefix rdfs:<http://www.w3.org/2000/01/rdf-schema#>.
  153. :hasWife rdfs:subPropertyOf :hasRelative.
  154. :hasHusband rdfs:subPropertyOf :hasRelative.
  155. :hasRelative rdfs:domain :Person; rdfs:range :Person.
  156.  
  157. The generated ones are:
  158. :Anna :hasRelative :George.
  159. :George :hasRelative :Anna.
  160. :George :hasRelative :George. (because of transitivity combined with inverse)
  161. :Anna :hasRelative :Anna. (because of transitivity combined with inverse)
  162. :hasWife rdfs:domain :Person; rdfs:range :Person.
  163. :hasHusband rdfs:domain :Person; rdfs:range :Person.
  164. :Anna a :Person.
  165. :George a :Person.
  166. :Andrew a :Person.
  167. :Jim a :Person.
  168. :Jane a :Person.
  169.  
  170. Queries to check them:
  171.  
  172. prefix : <http://expl.at#>
  173. select *
  174. where {?x a :Person}
  175.  
  176. prefix : <http://expl.at#>
  177. select *
  178. where {?x :hasRelative ?y}
  179.  
  180. prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
  181. prefix : <http://expl.at#>
  182. select *
  183. where {?x rdfs:domain :Person; rdfs:range :Person}
  184.  
  185. Upload the following statements:
  186. @prefix : <http://expl.at#>.
  187. @prefix owl:<http://www.w3.org/2002/07/owl#>.
  188.  
  189. :hasUncle owl:propertyChainAxiom (:hasParent :hasBrother).
  190. :John :hasParent :Richard.
  191. :Richard :hasBrother :Mike.
  192.  
  193. The first statement is an axiom. Its rule is: "IF x hasParent y and y hasBrother z, THEN generate x hasUncle z". The generated statement is:
  194. :John :hasUncle :Mike.
  195.  
  196. You can find it with the query:
  197. prefix : <http://expl.at#>
  198. select *
  199. where
  200. {
  201. :John ?y ?z
  202. }
  203.  
  204. Add the following statements:
  205. @prefix : <http://expl.at#>.
  206. @prefix owl: <http://www.w3.org/2002/07/owl#>.
  207. :SolarSystemBody owl:onProperty :orbits; owl:hasValue :Sun.
  208. :Mars :orbits :Sun.
  209. :Earth a :SolarSystemBody.
  210.  
  211. The axiom has a double interpretation, because the reasoning works in two directions: "IF x orbits the Sun, THEN x is a Solar System Body; IF x is a SolarSystemBody, THEN x orbits the Sun".
  212.  
  213. Based on the facts provided together with the axiom, it will generate:
  214. :Mars a :SolarSystemBody.
  215. (from the fact that Mars orbits the Sun)
  216. :Earth :orbits :Sun.
  217. (from the fact that Earth is a Solar System Body)
  218.  
  219. Queries for checking:
  220. prefix : <http://expl.at#>
  221. select *
  222. where {?x :orbits ?y}
  223.  
  224. prefix : <http://expl.at#>
  225. select *
  226. where {?x a :SolarSystemBody}
  227.  
  228. Some other statements will also be generated (:orbits a rdf:Property, :SolarSystemBody a owl:Restriction ș.a.m.d.). owl:Restriction includes all the classes that are defined by applying a restriction (here owl:hasValue) on a property (here :orbits).
  229.  
  230. Upload the statements:
  231. @prefix : <http://expl.at#>.
  232. @prefix owl: <http://www.w3.org/2002/07/owl#>.
  233. @prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
  234. :Human owl:onProperty :hasFather;
  235. owl:maxCardinality "1"^^xsd:nonNegativeInteger.
  236. :Jack a :Human; :hasFather :Chris, :Christoph.
  237. :Anne :hasEmail <mailto:anne@yahoo.com>.
  238. :Ana77 :hasEmail <mailto:anne@yahoo.com>.
  239. :hasEmail a owl:InverseFunctionalProperty.
  240.  
  241.  
  242.  
  243. The following statements will be generated:
  244. :Chris owl:sameAs :Christoph.
  245. (because both are declared as fathers of Jack, and Jack is declared as Human)
  246. :Anne owl:sameAs :Ana77.
  247. (because both have the same e-mail address)
  248.  
  249. We can check the generated equivalencies with a query (the filter removes statements saying that something is equivalent with itself):
  250. prefix : <http://expl.at#>
  251. select *
  252. where
  253. {
  254. ?x owl:sameAs ?y
  255. filter (?x!=?y)
  256. }
  257. Observe that the equivalence is bidirectional (by default it is a symmetric property) therefore each of them is detected twice, in both directions.
  258.  
  259. The contradiction will only appear if the knowledge base also has some statements that establish a clear distinction between these individuals. Try to upload one or both of the following statements:
  260.  
  261. @prefix : <http://expl.at#>.
  262. @prefix owl: <http://www.w3.org/2002/07/owl#>.
  263. :Chris owl:differentFrom :Christoph.
  264. :Anne owl:differentFrom :Ana77.
  265.  
  266.  
  267. Upload the following statements:
  268. @prefix : <http://expl.at#>.
  269. @prefix owl: <http://www.w3.org/2002/07/owl#>.
  270. :Human owl:unionOf (:Man :Woman).
  271. :AustrianWriter owl:intersectionOf (:Writer :Austrian).
  272. :Johann a :AustrianWriter, :Man.
  273.  
  274. Interpretation as rules:
  275. • For owl:unionOf: "IF x is the union of y and z, THEN y an z are subclasses of x "
  276. • For owl:intersectionOf: "IF x is the intersection of y and z, THEN x is a subclass of both y and z "
  277.  
  278. These are set operations that can be used to extend the class hiearchy, by generating additional subclass relations. The following will be generated:
  279. :Man rdfs:subClassOf :Human.
  280. :Woman rdfs:subClassOf :Human.
  281. :AustrianWriter rdfs:subClassOf :Writer, :Austrian.
  282.  
  283. We can check if we query all subclass relations (we apply a filter to keep only classes created by us and to remove the axioms saying that a class is subclass of itself):
  284. prefix : <http://expl.at#>
  285. prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
  286. select ?x ?y
  287. where
  288. {
  289. ?x rdfs:subClassOf ?y
  290. filter (contains(str(?x),"expl.at")&&contains(str(?y),"expl.at")&&(?x!=?y))
  291. }
  292.  
  293. Since we now have a richer class hierarchy, this will trigger additional deductions about the type of Johann. The following will be generated from the new class hierarchy:
  294. :Johann a :Writer, :Austrian, :Human.
  295.  
  296. Check what is Johann and you will see al these types (both the explicit and the deduced ones):
  297. prefix : <http://expl.at#>
  298. select *
  299. where
  300. {
  301. :Johann a ?x
  302. filter contains(str(?x),"expl.at")
  303. }
  304.  
  305.  
  306.  
  307. Try to upload the following:
  308. @prefix : <http://expl.at#>.
  309. @prefix owl: <http://www.w3.org/2002/07/owl#>.
  310. :Man owl:disjointWith :Woman.
  311. :Anna a :Man, :Woman.
  312. You will get an error because there is a contradiction: Man and Woman are declared as disjoint sets (i.e., with no common elements) but on the other side we declare the Anna as being an instance of both sets.
  313.  
  314. Try to upload the following:
  315. @prefix : <http://expl.at#>.
  316. @prefix owl: <http://www.w3.org/2002/07/owl#>.
  317. :Anna owl:sameAs :Ann.
  318. :Anna owl:differentFrom :Ann.
  319.  
  320.  
  321. @prefix : <http://expl.at#>.
  322. @prefix owl: <http://www.w3.org/2002/07/owl#>.
  323. :J :hasEmail <mailto:j@yahoo.com>.
  324. :John :hasEmail <mailto:j@yahoo.com>.
  325. :hasEmail a owl:InverseFunctionalProperty.
  326. :J owl:differentFrom :John.
  327.  
  328. Try to upload the following:
  329. @prefix : <http://expl.at#>.
  330. @prefix owl: <http://www.w3.org/2002/07/owl#>.
  331. @prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
  332. :Orphan owl:onProperty :hasParent;
  333. owl:maxCardinality "0"^^xsd:nonNegativeInteger.
  334. :John a :Orphan; :hasParent :Ann.
  335.  
  336.  
  337. A more sophisticated version of this is where we enrich the restriction with the class of the objects of the relation. Try to upload the following:
  338. @prefix : <http://expl.at#>.
  339. @prefix owl: <http://www.w3.org/2002/07/owl#>.
  340. @prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
  341. :OrphanOfMother owl:onProperty :hasParent;
  342. owl:maxQualifiedCardinality "0"^^xsd:nonNegativeInteger;
  343. owl:onClass :Woman.
  344. :Andrew a :OrphanOfMother; :hasParent :Mimi.
  345. :Mimi a :Woman.
  346.  
  347.  
  348. @prefix : <http://expl.at#>.
  349. @prefix owl: <http://www.w3.org/2002/07/owl#>.
  350. @prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
  351. :OrphanOfMother owl:onProperty :hasParent;
  352. owl:maxQualifiedCardinality "0"^^xsd:nonNegativeInteger;
  353. owl:onClass :Woman.
  354. :Andrew a :OrphanOfMother; :hasParent :John.
  355.  
  356. Try to upload the following:
  357. @prefix : <http://expl.at#>.
  358. @prefix owl: <http://www.w3.org/2002/07/owl#>.
  359. :isMotherOf a owl:AsymmetricProperty .
  360. :Anna :isMotherOf :Mary .
  361. :Mary :isMotherOf :Anna .
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368. After you create the knowledge base, connect to it and upload the following:
  369.  
  370. @prefix : <http://expl.at#>.
  371. @prefix owl: <http://www.w3.org/2002/07/owl#>.
  372. @prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
  373. :Parent owl:onProperty :hasChild;
  374. owl:minCardinality "1"^^xsd:nonNegativeInteger.
  375. :John :hasChild :Peter.
  376.  
  377. The meaning of the axiom is: "if x has at least one hasChild relation, then x is a parent".
  378.  
  379. Check the list of parents to see that the "John a Parent" statement was generated:
  380. prefix : <http://expl.at#>
  381. select * where {?x a :Parent}
  382. As we already suggested, it has the same effect as rdfs:domain with the advantage that we can set minCardinality at a higher number (e.g., "IF x has minimum 2 wives, x is a Polygamous").
  383.  
  384. Now upload the contradicting statements to check how the contradiction for asymmetric properties is handled:
  385. @prefix : <http://expl.at#>.
  386. @prefix owl: <http://www.w3.org/2002/07/owl#>.
  387. :isMotherOf a owl:AsymmetricProperty .
  388.  
  389.  
  390.  
  391. :Anna :isMotherOf :Mary .
  392. :Mary :isMotherOf :Anna .
  393.  
  394. This time the statements are not rejected at the upload attempt. They are maked up by an anonymous node and can be queried by looking for that node:
  395.  
  396. prefix : <http://expl.at#>
  397. select * where
  398. {
  399. ?prop a x:WrongStatement;
  400. x:PropertyInWrongStatement ?p;
  401. x:ParticipantInWrongStatement ?x.
  402. }
  403.  
  404. You will get two anonymous nodes, one for each of the two contradicting statements.
Add Comment
Please, Sign In to add comment