过滤注释 - SPARQL [英] Filter on annotation - SPARQL

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

问题描述

我想根据数据类型为浮点数和字符串的注释查询我的本体.例如,我有一个人有一个 float 类型的注释EBC_value"和一个 String 类型的注释Label".

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.

我该怎么做?我已经尝试过像这样使用 REGEX,但它不起作用.我没有收到任何错误,只是没有结果.

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.

首先,您的查询引用的 ont:title 属性似乎不存在于您的数据中.

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

其次,您的命名空间似乎没有对齐,我假设查询中的 ont 命名空间应该与 RDF/中的 beer 命名空间相同XML,但您没有显示名称空间,所以我只能猜测.尽管命名空间主要是一种便利机制,但最好与前缀的使用保持一致,因为这样可以减少混淆.

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.

第三,绝对不需要使用 REGEX() 你只需要使用适当的图形模式:

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" .
}

由于 beer:Label 是一个属性,您可以在查询中直接访问它.这将找到 beer:Label 属性值为 Sack 的所有个人,如果您想对搜索字符串进行部分匹配,您可以始终使用 CONTAINS() 函数将比REGEX():

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"))
}

这将找到所有有 beer:Label 并且包含值 Sack

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

要回答您的评论,匹配键入的值需要您知道值的类型,假设您使用的是 xsd:float 那么您将查询如下:

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天全站免登陆