向SPARQL查询添加文本搜索where子句 [英] Add text search where clause to SPARQL query

查看:102
本文介绍了向SPARQL查询添加文本搜索where子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经得到了我认为很简单的任务-进行一个现有的SPARQL查询并修改WHERE子句以将结果限制为特定文本字段包含特定搜索词的实体.

I have been given what I thought would be a simple task - take an existing SPARQL query and adapt the WHERE clause to restrict results to entities where a specific text field contains a specific search term.

但是,我对SPARQL语言是完全陌生的,我尝试过的任何方法都没有用.看来我需要使用text:query (rdfs:label 'word' 10)语法,但是我还没有设法将其成功集成到下面的查询中.

However, I am entirely new to the SPARQL language and nothing I've tried is working. It seems I need to use the text:query (rdfs:label 'word' 10) syntax, but I haven't managed to successfully integrate this into the query below.

我需要进一步过滤以下查询的结果,其中rdfs:label三元组的值包含搜索词.如果您能提供有关如何更改查询的指导,我将不胜感激.

What I need is to further filter the results of the below query where the rdfs:label triple has a value containing the search term. If any of you could provide guidance about how I need to change the query I'd be very grateful.

SELECT DISTINCT * WHERE 
{
  { SELECT  ?object ?label ?accessionNumber ?image  WHERE {
      ?object a my:Object .
      ?object my:accessionNumber ?accessionNumber .
      ?object  rdfs:label ?label .
      ?object my:maker <http://id.my.org.uk/agent/1234> .  
  }}  

  OPTIONAL  { 
    ?object my:preferredAsset ?asset .
    ?asset a my:Asset .
    ?asset dcterms:hasVersion ?image .
    ?image my:role 'thumbnail' .  
  }  
} 

谢谢.

推荐答案

近似匹配

字符串匹配

String Matching

Joshua Taylor 的评论指出了一种出色且优雅的解决方案,可以完全满足您的要求:

Joshua Taylor's comment points out an excellent and elegant solution to do exactly what you asked for:

filter contains( lcase(?label), "word").

您还可以通过 REGEX过滤器功能.您只需在查询中添加一个附加过滤器,例如:

You can also use regular expressions via the REGEX Filter Function. You would simply add an additional filter to your query such as:

FILTER regex(?label, "*word*", "i") .

这将允许您检索包含word(不区分大小写)的所有标签.

This would allow you to retrieve all labels that contain word (case-insensitive).

Jena Text

Jena Text

您提到的语法text:query (rdfs:label 'word' 10)jena-text项目的一部分.请注意,您必须配置jena-text 才能正常工作.您要使用的主要时间是要执行近似文本匹配,即:是否可以搜索word并取回wordswordpress等内容.

The syntax text:query (rdfs:label 'word' 10) you mentioned is part of the jena-text project. Note that you must configure jena-text for it to work. The primary time that you want to use that is if you want to perform approximate text matching ie: if it's acceptable to search for word and get back things like words or wordpress etc.

完全匹配

另一种选择是精确匹配.您可以通过指定初始绑定或直接修改查询来完成此操作.

Another alternative is exact matching. You can do this by specifying an initial binding, or by modifying your query directly.

查询修改

Query Modification

修改查询将产生以下几种变化之一.并非所有这些变体都被认为是相等的(普通文字/语言文字/类型文字),因此在搜索时必须小心以确保数据匹配.

Modifying your query would produce one of several variations. Not all of these variations are considered equal (Plain Literals / Language Literals / Typed Literals), so you need to be careful when searching to know that your data will match.

 ?object  rdfs:label "word" .
 ?object  rdfs:label '''word''' .
 ?object  rdfs:label "word"@en .
 ?object  rdfs:label "word"^^xsd:string .

绑定规范

Binding Specification

构造初始绑定通常看起来像这样(伪代码):

Constructing an initial binding usually looks something like this (psuedocode):

final QuerySolutionMap initialBinding = new QuerySolutionMap(){{
     this.add("?label", model.createTypedLiteral(someString));
}};
final QueryExecution e = 
         QueryExecutionFactory.create(query,model,initialBinding);

请注意,add的第二个参数与查询修改具有相同的选择.您可以创建语言文字或普通文字,而不是类型文字.同样,它需要匹配您的基础数据.

Note that the second argument to add has the same choices as the query modification. You can create a language literal or a plain literal rather than a typed literal. Again, it needs to match your underlying data.

这篇关于向SPARQL查询添加文本搜索where子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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