我想避免使用子字符串来消除我的示例 本体:抽象或本体:标签,它与sparql资源管理器一起使用但是当我在jena中使用http查询时它不会给出任何结果...我在jena库(androjena)的android项目中尝试了这个查询
SELECT ?type (STR(?l) AS ?label) {
?type a owl:Class;
rdfs:label ?l .
FILTER (LANG(?l) = "en")
}
一旦我把它放在我的Jena httpquery (STR(?l) AS ?label)
中,它就不再给出任何结果了。有人可以帮助我吗?
这是我试图改变以避免使用子串的代码部分:
private String entityQuery(String entity, String keyWord, String language) {
return addPrefix("rdfs: <http://www.w3.org/2000/01/rdf-schema#>") +
addPrefix("ontology: <http://dbpedia.org/ontology/>") +
addQuery("SELECT ?name ?desc ?thumb WHERE {\n"
+"?author a ontology:" + entity + ";\n"
+"rdfs:label ?name;\n"
+"ontology:abstract ?desc.\n"
+"FILTER(<bif:contains>(?desc,\"'"+keyWord+"'\") && langMatches(lang(?desc), \""+language+"\") " +
"&& langMatches( lang(?name), \""+language+"\"))\n"
+"OPTIONAL { ?author ontology:thumbnail ?thumb }.\n"
+"}ORDER BY ?name\n");
}
private LinkedList<Entity> collectEntities(ResultSet results) {
LinkedList<Entity> temp = new LinkedList<>();
/* do stuff with the results */
while (results.hasNext()) {
Entity a = new Entity();
QuerySolution row = results.next();
if (row.getResource("thumb") != null)
a.setPictureURL(row.get("thumb").toString());
a.setTitle(row.get("name").toString().substring(0, row.get("name").toString().indexOf("@")));
a.setSummary(row.get("desc").toString().substring(0, row.get("desc").toString().indexOf("@")));
temp.add(a);
}
return temp;
}
private String addPrefix(String prefix) {
return "PREFIX " + prefix + "\n";
}
private String addQuery(String query) {
return query;
}
我在这里使用substring:
a.setTitle(row.get("name").toString().substring(0, row.get("name").toString().indexOf("@")));
a.setSummary(row.get("desc").toString().substring(0, row.get("desc").toString().indexOf("@")));