MarkLogic可以使用嵌入式三元组的推理吗?

时间:2015-03-06 17:09:17

标签: rdf marklogic

当使用sem查询三元组时,MarkLogic是否应用推理:sparql针对选定的一组商店?

2 个答案:

答案 0 :(得分:4)

亚历克斯,看看Choosing Rulesets for Queries。您将看到一个示例,其中SPARQL查询应用于三元组存储,这是因为将一组推理规则应用于一组三元组。如果稍微修改该示例,则会显示应用于三元组索引中所有三元组的运行推理的SPARQL查询,其中包括嵌入的三元组。

xquery version "1.0-ml";
import module namespace sem = "http://marklogic.com/semantics" 
  at "/MarkLogic/semantics.xqy";

PREFIX skos: <http://www.w3.org/2004/02/skos/core#Concept/>

sem:sparql("select * { ?c a skos:Concept; rdfs:label ?l }",(),(),
  sem:ruleset-store(
    ("subClassOf.rules", "subPropertyOf.rules"),
    sem:store()
  )
)

答案 1 :(得分:1)

If you have established some relationships among triples and try to fetch results using a ruleset then it will Marklogic definitely apply reasoning while performing search.

For Example i created the following triple

 PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX prod: <http://www.example.com/products/>
 PREFIX ex: <http://www.example.com/>

 INSERT DATA
 {

   prod:1001 rdf:type ex:Apple;

   prod:1002 rdf:type ex:Fruit;

 }

Now if you search for all the subjects which are of type apple it will only give you prod:1002

And now establish a relationship among them as

 PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
 PREFIX ex: <http://www.example.com/>

 INSERT DATA
 {

   ex:Apple rdfs:subClassOf ex:Fruit .

 }

and set the default ruleset of your database to subClassOf.rules and then run the same query

 PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX ex: <http://www.example.com/>

 SELECT ?product
 WHERE
 {
  ?product rdf:type ex:Fruit 
 }

Now it will return you both prod:1001 and prod:1002

also for further details you can visit the marklogic documentation which has a very good description of inferencing. https://developer.marklogic.com/features/semantics/inference-examples