2016-11-02 6 views
0

다음과 같은 질문에 사용자가 대답해야하는 퀴즈 게임이 있습니다. 독일 수도 이름은 무엇입니까? 옵션은 다음과 같습니다 : Berlin Madrid London 데이터가 올빼미 파일에 있습니다.Java 변수를 사용하여 SPARQL 쿼리를 필터링하는 방법

저는 rdfs : rdfs와 같은 리소스 (퀴즈 질문 옵션)에 대한 의견을 가지고 있습니다. 베를린, 런던 등의 의견을 말합니다. 사용자가 잘못된 옵션 인 런던, rdfs : right 이 경우 베를린 사용자에게 옵션이 표시되어야합니다.

The right (correct) option I have is in java variable 'correct' and if user click wrong option, I want to show the rdfs:comment of correct option as: 

     "SELECT * " + 
        " WHERE { ?x rdfs:comment ?y " + "FILTER regex(?x ,'"+correct+"') " + 

       "}"; 
     System.out.println(queryString); 
        Query query = QueryFactory.create(queryString); 
      QueryExecution qexec = QueryExecutionFactory.create(query, model) ; 
      ResultSet results = qexec.execSelect() ; 
       while (results.hasNext()) 
      { 
       QuerySolution binding = results.nextSolution(); 

         Literal l=binding.getLiteral("y"); 
         String s=l.toString(); 

     The problem is that it does not show me the filtered value rdfs:comment. When I remove Filter, it shows all rdfs:comment of resources but with Filter value, it simply does not work. 

     When I print the query, it shows the options values but does not display the rdfs:comment of that resources. 

     PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> prefix dbr: <http://dbpedia.org/page/>PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT * WHERE { ?x rdfs:comment ?y FILTER regex(?x ,"Berlin") } 

     PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> prefix dbr: <http://dbpedia.org/page/>PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT * WHERE { ?x rdfs:comment ?y FILTER regex(?x ,"Rome") } 

    My owl for rdfs:comment is like: Berlin--> rdfs:comment 
    Rome--> rdfs:comment etc 
+0

같은 운동/프로젝트를 수행하는 대학의 학생 수는 몇 명입니까? 나는 당신이 이미 당신의 반의 누군가에 의해 예나 메일 링리스트에 물었다는 것을 확신합니다. – AKSW

답변

2
당신의 자료 구조에 대해 확실하지

하지만 난은 X의 필터를 들어

는이처럼해야 할 일을하는 URI에 있다고 가정 :

필터 정규식 (STR (x)는 , "Berlin")

+0

다음 번 사용자가 다음 버튼을 클릭 할 때 변수에 로마, 마드리드 등이 포함될 것이고 항상 베를린이 포함되지 않기 때문에 상수 베를린 대신 변수 이름을 사용해야합니다. 여기에 str 키워드를 사용하지 않았습니다. 필수입니까? –

+1

@ s.shah 'STR'은 IRI를 문자열로 변환하고 REGEX가 문자열에서 작동하는 SPARQL 함수입니다. 항상 SPARQLl 사양을 사용하십시오. https://www.w3.org/TR/sparql11-query/#func -str – AKSW

+0

물론 FILTER regex (str (? x), ' "+ correct +"')를 사용할 수도 있습니다. – ChristophE

관련 문제