问题描述
我是SPARQL和Jena的新手.在这里,我使用的是Jena 2.13版.我想从Java Web应用程序使用REGEX边界(\b)
执行SPARQL查询.我正在使用REGEX边界来匹配并找到确切的单词.
i'm new in SPARQL and Jena. Here i'm using Jena version 2.13. I would like to perform a SPARQL query from java web application with REGEX boundary (\b)
. I'm using REGEX boundary to match and find exact word.
我也在protege上运行相同的SPARQL查询.
I'm running the same SPARQL query on protege too.
这是我在Java中的SPARQL查询:
Here my SPARQL query in java :
"PREFIX foaf: <http://xmlns.com/foaf/0.1/> "
+ "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#> "
+ "PREFIX : <" + CROSS_NS + "> "
+ "SELECT ((?FoodAndBeveragesRecipes) AS ?Resep)((?FoodAndBeverages) AS ?a) "
+ "WHERE{ ?FoodAndBeveragesRecipes :IngR ?_IngR."
+ " ?_IngR :HasIngredients ?FoodAndBeverages;"
+ ":UnitValue ?Value;"
+ " :MeasurementUnit ?Measurements;"
+ " :Ing_Type ?IngType."
+ "FILTER regex(str(?FoodAndBeverages), \"\\b" + recipe + "\\b\")}"
+ " ORDER BY ?FoodAndBeveragesRecipes";
recipe
是用于存储用户输入的String variabel,它作为参数接收.
recipe
is String variabel to store user input, it's received as a parameter.
当我执行查询时,Jena返回一个空集(甚至没有null指针异常),而Protégé返回/查找正确的结果.我不知道问题出在REGEX代码还是什么.
When i perform the query, Jena returns an empty set (not even null pointer exception) while Protégé return/find the correct results.I don't know if the problem is with the REGEX code or what.
我想知道为什么我的REGEX无法正常工作?有人可以帮我吗?
I was wondering why my REGEX is not working correctly ? could anyone help me?
谢谢.
推荐答案
您需要\\\\W
-是,4. Java进入一个级别将\\W
放入SPARQL,下一级别是将SPARQL字符串精确保留为\W
.
You need \\\\W
- yes, 4 . One level goes for Java to get \\W
into SPARQL, the next level is the SPARQL string to leave exactly \W
.
这篇关于Java中的SPARQL查询REGEX边界返回空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!