上标注过滤器 - SPARQL [英] Filter on annotation - SPARQL

查看:312
本文介绍了上标注过滤器 - SPARQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想基于与float和string的数据类型的注解来查询我的本体
比如我有一个具有float类型的标注EBC_value和一个String类型的注释标签的个人。

我如何做到这一点?我曾尝试与正则表达式,像这样的,但它doesn't工作。我不得到任何错误,只是没有结果。

  preFIX ONT:其中,HTTP://vestbrygg.no/ontologies/beer.owl#>
preFIX RDF:其中,HTTP://www.w3.org/1999/02/22-rdf-syntax-ns#>
preFIX猫头鹰:其中,HTTP://www.w3.org/2002/07/owl#>
preFIX的xsd:其中,HTTP://www.w3.org/2001/XMLSchema#>
preFIX RDFS:其中,HTTP://www.w3.org/2000/01/rdf-schema#>SELECT?标题
WHERE {X ONT:??冠军称号
          FILTER正则表达式(?称号,炒鱿鱼)
        }

希望你们能有所帮助。 Thanks.And是啊,除非你想看到和测试整个本体,
在code的注解是这样的:

 < NamedIndividual的rdf:about =&放大器;啤酒; Base_malt _-_ Best_Malz>
    < RDF:RDF类型:资源=&放大器;啤酒;光/>
    <啤酒:EBC_value RDF:数据类型=&放大器; XSD;浮动>< /啤酒:EBC_value>
    <啤酒:标签RDF:数据类型=&放大器; XSD;字符串>&袋LT; /啤酒:标签>
< / NamedIndividual>


解决方案

您查询毫无关系到你的数据这就是为什么你得到任何结果。

首先在 ONT:你的查询引用不出现标题属性,在您的数据中存在

其次您的命名空间不出现调整,我相信在您的查询的 ONT 命名空间应该是相同的命名空间啤酒命名空间在RDF / XML,但你没有显示的命名空间,所以我可以在这个只能猜测。尽管命名空间大多是一种方便的机制,最好是与您使用prefixes一致的,因为它会让事情少了很多混乱。

第三应该是完全没有必要使用 REGEX()你只需要使用适当的图形模式:

  preFIX啤酒:其中,HTTP://vestbrygg.no/ontologies/beer.owl#>选择·X
哪里
{
  ·X啤酒:标签炒鱿鱼。
}

由于啤酒:标签是一个属性您可以直接在您的查询访问​​它。这会找到你所在的啤酒每一个人:标签属性的值为,如果你想要做的部分匹配的搜索字符串可以随时使用 包含( ) 功能,这将是快于 REGEX()

  preFIX啤酒:其中,HTTP://vestbrygg.no/ontologies/beer.owl#>选择·X
哪里
{
  ·X啤酒:标签标签?
  FILTER(CONTAINS(?标签,炒鱿鱼))
}

这会发现所有个人,其中有一个啤酒:标签,它包含值

修改

要回答你的评论,匹配类型的值需要你知道值的类型是,假设你使用的xsd:浮法,那么你会像查询的以下内容:

  preFIX啤酒:其中,HTTP://vestbrygg.no/ontologies/beer.owl#>
preFIX的xsd:其中,HTTP://www.w3.org/2001/XMLSchema#>选择·X
哪里
{
  ·X啤酒:EBC_value4.8^^的xsd:浮动。
}

I want to query my ontology based on annotations with datatype of float and string. For instance I have an individual that has an annotation "EBC_value" of type float and an annotation "Label" of type String.

How do I do this? I have tried with REGEX, like this, but it doesn´t work. I don´t get any errors, just no results.

PREFIX ont: <http://vestbrygg.no/ontologies/beer.owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT  ?title
WHERE   { ?x ont:title ?title
          FILTER regex(?title, "Sack") 
        }

Hope you guys can help. Thanks.And yeah, unless you want to see and test the entire ontology, the code for the annotations are like this:

<NamedIndividual rdf:about="&beer;Base_malt_-_Best_Malz">
    <rdf:type rdf:resource="&beer;Light"/>
    <beer:EBC_value rdf:datatype="&xsd;float"></beer:EBC_value>
    <beer:Label rdf:datatype="&xsd;string">Sack</beer:Label>
</NamedIndividual>

解决方案

Your query bears no relation to your data which is why you get no results.

Firstly the ont:title property that your query references does not appear to exist in your data.

Secondly your namespaces don't appear to align, I assume the ont namespace in your query is supposed to be the same namespace as the beer namespace in your RDF/XML but you haven't shown the namespaces so I can only guess at this. Even though namespaces are mostly a convenience mechanism it's best to be consistent with your use of prefixes because it'll make things a lot less confusing.

Thirdly there should be absolutely no need to use REGEX() you simply need to use an appropriate graph pattern:

PREFIX beer: <http://vestbrygg.no/ontologies/beer.owl#>

SELECT ?x
WHERE
{
  ?x beer:Label "Sack" .
}

Since beer:Label is a property you can access it directly in your query. This will find you all individuals where the beer:Label property has the value Sack, if you want to do a partial match on the search string you can always use the CONTAINS() function which will be faster than REGEX():

PREFIX beer: <http://vestbrygg.no/ontologies/beer.owl#>

SELECT ?x
WHERE
{
  ?x beer:Label ?label .
  FILTER(CONTAINS(?label, "Sack"))
}

This will find all individuals where there is a beer:Label and it contains the value Sack

Edit

To answer your comment, matching typed values requires you to know what the type of the values are, assuming you are using xsd:float then you'd query like the following:

PREFIX beer: <http://vestbrygg.no/ontologies/beer.owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT ?x
WHERE
{
  ?x beer:EBC_value "4.8"^^xsd:float .
}

这篇关于上标注过滤器 - SPARQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆