MarkLogic SPARQL使用属性路径未按预期返回数据

时间:2015-12-15 23:41:41

标签: sparql marklogic marklogic-8

使用以下示例三元组:

@prefix : <http://www.me.org/me_schema#> .
@prefix dc: <http://purl.org/dc#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://www.me.org/content/me_schema>
  rdf:type owl:Ontology ;
  owl:imports <http://www.w3.org/2004/02/skos/core> ;
.
:a
  rdf:type owl:ObjectProperty ;
  rdfs:label "A" ;
  rdfs:subPropertyOf :b ;
.
:b
  rdf:type owl:ObjectProperty ;
  rdfs:label "B" ;
  rdfs:subPropertyOf :c ;
.
:c
  rdfs:label "C"^^xsd:string ;
.

此查询按预期返回两行(列和?中的b和c):

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

select * 
from <test>
where
{
  ?s rdfs:label 'A' .
  ?s rdfs:subPropertyOf+ ?o
}

但是,我希望以下内容返回1行但返回空结果。在查询控制台中测试:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

select * 
from <test>
where
{
  ?s rdfs:label 'A' .
  ?s rdfs:subPropertyOf+ <http://www.me.org/me_schema#c>
}

我希望它为&#34; a&#34;返回一行。这是一个错误还是我错过了一些明显的东西?

我尝试使用DBPedia进行类似的查询,它似乎按照我的预期返回数据。例如,以下查询返回&#34; star&#34;的两行。虽然两者都不是直接的subClassOf owl:Thing。

select *
where 
{
 ?s rdfs:label  "star"@en .
 ?s rdfs:subClassOf+ owl:Thing
} LIMIT 100

如果有人遇到同样的问题,我想出了以下工作:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

select * 
from <test>
where
{
  ?s rdfs:label 'A' .
  ?s rdfs:subPropertyOf ?s2 .
  ?s2 rdfs:subPropertyOf* <http://www.me.org/me_schema#c>
}

1 个答案:

答案 0 :(得分:7)

(我会在评论中加以说明,但我没有这样的声誉。)

我刚刚在MarkLogic 8.0-3上尝试过你的null结果示例,我确实得到[{"s":"<http://www.me.org/me_schema#a>"}],正如你所期望的那样。您使用的是早期版本的MarkLogic(您可以在localhost:8001的左上角看到该版本)吗?

为了验证这一点,我转到localhost:8000/qconsole/ PREFIX : <http://www.me.org/me_schema#> prefix dc: <http://purl.org/dc#> prefix owl: <http://www.w3.org/2002/07/owl#> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix skos: <http://www.w3.org/2004/02/skos/core#> prefix xsd: <http://www.w3.org/2001/XMLSchema#> INSERT DATA { GRAPH <test> { <http://www.me.org/content/me_schema> rdf:type owl:Ontology . <http://www.me.org/content/me_schema> owl:imports <http://www.w3.org/2004/02/skos/core> . :a rdf:type owl:ObjectProperty . :a rdfs:label "A" . :a rdfs:subPropertyOf :b . :b rdf:type owl:ObjectProperty . :b rdfs:label "B" . :b rdfs:subPropertyOf :c . :c rdfs:label "C"^^xsd:string . }} ,设置了内容来源&#39;到我的数据库(打开三重索引)将查询类型更改为&#39; SPARQL更新&#39;,并输入此SPARQL插入代码:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

select * 
from <test>
where
{
  ?s rdfs:label 'A' .
  ?s rdfs:subPropertyOf+ <http://www.me.org/me_schema#c>
}

然后我在查询控制台中打开了一个新选项卡,将查询类型设置为&#34; SPARQL查询&#34;,并运行您的确切查询:

#hideme{display:none;}

.menu  ul {
    padding:0;
    margin:0;
	color:white;
	text-decoration:none;
}

.menu  li {
    box-sizing:border-box;
    padding:0;
    margin:0;
    list-style:none;
	color:white;
	text-decoration: none;
	text-align: bottom; vertical-align: bottom;
}


.menu > li ul li{
    box-sizing:border-box;
    margin-left:20px;
	margin-top:5px;
    list-style:none;
	text-decoration: none;
    text-align: bottom; vertical-align: bottom;
}

ul.menu > li {
    overflow:hidden;
    width:90px;
	min-height:90px;
    max-height:90px;
    padding:10px;
    margin-bottom:10px;
    background:#5DB26E;
    color:#5DB26E;
    cursor:pointer;
    transition:all 0s ease;
	
}


ul.menu > li:hover {
    width:180px;
	min-height:180px;
	color: white;
    border: 3px solid white;
	box-shadow: 0px 0px 0px 3px #5DB26E;
	 position: relative;
}

ul.menu> li:hover #hideme{display:block;  position: absolute;
    bottom: 10;}
ul.menu> li:hover .fa-arrow-right{content: "\f023";}

.hoverme:hover .fa-arrow-right,
.hoverme .fa-check {
    display: none;
}
.hoverme:hover .fa-check {
    display: inline;
}

	
.menu a {
    margin:0;
	text-decoration:none;
	color:white;
}

如果您使用的是早期版本的MarkLogic,请尝试更新MarkLogic query console上的最新版本。