英文:
Fetch snap SPARQL query using OWL API in java web
问题
oke,我有这个使用Protege的SPARQL查询
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 : <http://www.semanticweb.org/astrid/ontologies/2019/5/mpasiv2#>
SELECT ?resep_makanan
WHERE {
?resep_makanan rdf:type :resep_makanan.
?resep_makanan :resep_untuk :6-7_bulan.
}
ORDER BY ?resep_makanan
它可以正常工作,我获得了我的'resep_makanan'实例,它们是食物名称,具有对象属性'resep_untuk'(用于)6-7个月大的婴儿。
然后在我的Java Web代码中,我写了
PREFIX : <http://www.semanticweb.org/astrid/ontologies/2019/5/mpasiv2#>
SELECT DISTINCT ?resep_makanan
WHERE {
Type(?resep_makanan, :resep_makanan),
PropertyValue(?resep_makanan, :resep_untuk, :6-7_bulan)
}
ORDER BY ?resep_makanan
但是我得到了0个查询结果。
我正在使用OWL API。
我应该如何正确编写它?
英文:
oke, I have this snap SPARQL query using protege
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 :<http://www.semanticweb.org/astrid/ontologies/2019/5/mpasiv2#>
SELECT ?resep_makanan
WHERE {
?resep_makanan rdf:type :resep_makanan.
?resep_makanan :resep_untuk :6-7_bulan.
}
ORDER BY ?resep_makanan
and it works, i get instance for my resep_makanan
which are food name, with object property resep_untuk
(recipe_for) baby who is 6-7_bulan (6-7_month old).
then in my java web code, i write
PREFIX :<http://www.semanticweb.org/astrid/ontologies/2019/5/mpasiv2#>
SELECT DISTINCT ?resep_makanan
WHERE {
Type (?resep_makanan, :resep_makanan),
PropertyValue(?resep_makanan, :resep_untuk, :6-7_bulan)
}
order by ?resep_makanan
But i get 0 query result.
Im using OWL API.
How should i write it correctly?
答案1
得分: 0
查询'snap SPARQL'会跳转到https://github.com/protegeproject/snap-sparql-query
项目,我相信这是您实际上用来运行查询的项目(因为在Protege中使用它)。
如果是这样的话,您在代码的SPARQL部分不是在使用OWL API,因为OWL API本身不支持SPARQL;我不了解snap sparql项目,但由于它与基于OWL API的Protege集成,我假设OWL API用于在Protege中与基于SPARQL的API进行交互。根据项目的依赖关系,我认为是de-derivo-sparqldlapi
。
回答您的问题,如果在Protege之外相同的查询没有产生结果,这可能取决于它未被发送到相同的SPARQL端点,或者端点的设置不同(例如,您的查询是否依赖推理来获取结果?)
这些信息中的一部分可能在您运行的代码中,并且这里没有显示,但如果没有看到代码,我们将无法确定。
英文:
Looking up 'snap SPARQL' brings the https://github.com/protegeproject/snap-sparql-query
project, which I believe is what you're actually using to run your queries (as it's used in Protege).
If that's the case, you're not using OWL API for the SPARQL part of your code, as OWL API does not support SPARQL itself; I don't know the snap sparql project but, as it integrates with Protege, which is OWL API based, I assume OWL API is used for interfacing a SPARQL based API with Protege. From the project dependencies, I think that's de-derivo-sparqldlapi
.
To answer your question, if the same query does not produce a result outside of Protege this must depend on it not being sent to the same SPARQL endpoint or to a different set up of the endpoint (e.g., does your query depend on reasoning for its results?)
Some of this information might be in the code that you're running and have not shown here, but we won't be able to tell without seeing it.
专注分享java语言的经验与见解,让所有开发者获益!
评论