I have the following 2 documents. 1 document has this data:
<Content>
<sem:triples xmlns:sem="http://marklogic.com/semantics">
<sem:triple>
<sem:subject>http://sector#Basic_Materials</sem:subject>
<sem:predicate>http://relationship#isTRBCEconomicSectorOf</sem:predicate>
<sem:object>http://company#CST_Mining_Group_Limited</sem:object>
</sem:triple>
</sem:triples>
<AnalystName>Henrik Christiansson</AnalystName>
<DocumentFormat>pdf</DocumentFormat>
</Content>
And another document that has the following data:
<Content>
<sem:triples xmlns:sem="http://marklogic.com/semantics">
<sem:triple>
<sem:triple>
<sem:subject>http://sector#Energy_-_Fossil_Fuels</sem:subject>
<sem:predicate>http://relationship#isTRBCEconomicSectorOf</sem:predicate>
<sem:object>http://company#Bodycote_PLC</sem:object>
</sem:triple>
</sem:triple>
</sem:triples>
<AnalystName>Pawel Dziedzic</AnalystName>
<DocumentFormat>pdf</DocumentFormat>
</Content>
I have made a relationship between these two embedded triples as
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
INSERT DATA
{
<http://company#CST_Mining_Group_Limited> rdfs:subClassOf <http://company#Bodycote_PLC> .
}
When I query to get all the results that are economicSector of Bodycote Plc, I get both of the triples, which is correct, but when I use a combined query it does not give me the required results.
For example, when the query has an economic sector of BodyCote and also the Analyst Name is Henrik Christiansson, I want it to return the first triple but it does not.
I used the following query:
xquery version "1.0-ml";
import module namespace sem = "http://marklogic.com/semantics"
at "/MarkLogic/semantics.xqy";
sem:sparql(
'SELECT ?subject
WHERE {
?subject <http://relationship#isTRBCEconomicSectorOf> <http://company#Bodycote_PLC>
}',
(),
(),
cts:and-query( (
cts:element-value-query( xs:QName("AnalystName"), "Henrik Christiansson" )
) )
)
I wanted to know if there is a way through which i can apply inferencing in combined queries also.
答案 0 :(得分:1)
您的方法的问题是cts:query仅选择相关文档,而不是指定子类的托管三元组。你没有在这里使用真正的推理,但实际上通过字面添加三元组来外化推理规则。相反,使用规则集,更灵活,也可以更好地工作。有关详细信息,请参阅Semantics guide。
准备好规则集文件后,需要将查询包装在sem:store中,然后将规则集应用于sem:ruleset-store:
sem:sparql(
'
SELECT ?subject
WHERE {
?subject <http://relationship#isTRBCEconomicSectorOf <http://company#Bodycote_PLC>
}
',
(),
(),
sem:ruleset-store(
"myrules",
sem:store(
(),
cts:and-query((
cts:element-value-query( xs:QName("AnalystName"), "Henrik Christiansson" )
))
)
)
)
HTH!