像使用Spark查询获取rdfs:label的Condition

时间:2022-10-19 23:08:44

I am using this query to get specific class in an ontology using jena and spark.

我正在使用此查询来使用jena和spark获取本体中的特定类。

 final String queryString = "" +
            "prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" +
            "\n" +
            "select ?class where {\n" +
            "  ?class rdfs:label \""+ word +"\"\n" +
            "}\n" +
            "";
ResultSet results = QueryExecutionFactory.create( queryString, model).execSelect();

how should I change the query to get classes that word is part of their labels? actually I need something like "sql Like statement" in spark. thanks for helping me!

我应该如何更改查询以获取单词是其标签的一部分的类?实际上我需要像火花中的“sql Like statement”之类的东西。谢谢你的帮助!

2 个解决方案

#1


0  

It is not Spark it is Sparql, for apache spark head here. What you are looking for is the String functions. You might be looking for the regex() function. But anything else than the most trivial queries will take a lot of time, in fact it is advisable to not use like in any DB system. Your SPARQL string should be like :

它不是Spark它是Sparql,对于这里的apache spark head。您正在寻找的是String函数。您可能正在寻找regex()函数。但是除了最简单的查询之外的任何事情都需要花费很多时间,事实上,建议不要在任何数据库系统中使用。您的SPARQL字符串应该是这样的:

final String queryString =
        "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " +
        "SELECT ?s ?label ?contains" 
        "WHERE {" +
        "   ?s rdfs:label ?label ." +
        "   BIND(CONTAINS(?label,\""+ variableToFind +"\") AS ?contains)"
        "}";

Also you are not searching for a class you are looking for a subject and that can be a URI, BN, literal.

此外,您不是在搜索正在寻找主题的类,它可以是URI,BN,文字。

#2


0  

after more search I Found right query

经过多次搜索后我找到了正确的查询

String Quert ="PREFIX  rdfs: <http://www.w3.org/2000/01/rdf-schema#>"
            + " SELECT ?x WHERE { ?x rdfs:label ?v ." +
            "FILTER regex(?v, \"word\", \"i\")}" ;

#1


0  

It is not Spark it is Sparql, for apache spark head here. What you are looking for is the String functions. You might be looking for the regex() function. But anything else than the most trivial queries will take a lot of time, in fact it is advisable to not use like in any DB system. Your SPARQL string should be like :

它不是Spark它是Sparql,对于这里的apache spark head。您正在寻找的是String函数。您可能正在寻找regex()函数。但是除了最简单的查询之外的任何事情都需要花费很多时间,事实上,建议不要在任何数据库系统中使用。您的SPARQL字符串应该是这样的:

final String queryString =
        "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " +
        "SELECT ?s ?label ?contains" 
        "WHERE {" +
        "   ?s rdfs:label ?label ." +
        "   BIND(CONTAINS(?label,\""+ variableToFind +"\") AS ?contains)"
        "}";

Also you are not searching for a class you are looking for a subject and that can be a URI, BN, literal.

此外,您不是在搜索正在寻找主题的类,它可以是URI,BN,文字。

#2


0  

after more search I Found right query

经过多次搜索后我找到了正确的查询

String Quert ="PREFIX  rdfs: <http://www.w3.org/2000/01/rdf-schema#>"
            + " SELECT ?x WHERE { ?x rdfs:label ?v ." +
            "FILTER regex(?v, \"word\", \"i\")}" ;