2016-08-09 20 views
0

私は、has_answerとhas_choiceというプロパティを含む個人を2回持っています。私が何をしたいかsparqlを使用して複数のプロパティを持つ個人を表示

<!-- http://www.semanticweb.org/myontology#Which_of_the_following_planet_has_the_average_speed_of_about_30Km/Seconds --> 

<owl:NamedIndividual rdf:about="&myontology;Which_of_the_following_planet_has_the_average_speed_of_about_30Km/Seconds"> 
    <rdf:type rdf:resource="&myontology;Question"/> 
    <rdfs:label>Which of the following planet has the average speed of about 30Km/Seconds ?</rdfs:label> 
    <myontology:QuestionNumber>1</myontology:QuestionNumber> 
    <myontology:has_answer rdf:resource="http://dbpedia.org/resource/Earth"/> 
    <myontology:has_choice rdf:resource="http://dbpedia.org/resource/Mars"/> 
    <myontology:has_choice rdf:resource="http://dbpedia.org/resource/Moon"/> 
    <myontology:has_score rdf:resource="&myontology;4_points"/> 
    <myontology:has_Level rdf:resource="&myontology;Expert"/> 
</owl:NamedIndividual> 

は、私は次のようになる与える個々

+ "SELECT distinct ?Qs ?CorrAns ?Choice " 
     + "WHERE {?Question rdf:type owl:NamedIndividual." 
     + "?Question rdfs:label ?Qs. " 
     + "?Question myontology:has_answer ?CorrAns." 
     + "?Question myontology:has_choice ?Choice." 
    // 
     + "}" 
     // + "GROUP BY ?Qs" 
     + ""; 
... 
    while (rs.hasNext()) { 
      QuerySolution soln = rs.nextSolution(); 
      String Qs = soln.getLiteral("Qs").getString(); 
      RDFNode choice = soln.get("Choice"); 
      String ans = choice.asNode().getLocalName(); 
      RDFNode Canswer = soln.get("CorrAns"); 
      String cans = Canswer.asNode().getLocalName(); 
.... 

からプロパティリストを取得することです:

Which of the following planet has the average speed of about 30Km/Seconds ? Choice : Mars CorrectAns: Earth 
Which of the following planet has the average speed of about 30Km/Seconds ? Choice : Moon CorrectAns: Earth 

私の質問は、私が行うことができる方法であります次のように結果を1行にします。

Which of the following planet has the average speed of about 30Km/Seconds ? || choice 1 : Mars || choice 2 : Moon || CorrecAns : Earth 

これはSparqlで可能ですか?

+2

はい、 '?Question' – AKSW

+0

によってグループ化しながら、SPARQL 1.1集約関数' GROUP_CONCAT'と私はどのようにあなたが表示されませんあなたが '' select ...?choice "+" WHERE {... "' '' choiceWHERE'という名前の変数になるときに期待している結果を得ます。 –

+0

@JoshuaTaylorリプレイありがとう、はいそれはちょうどエスケープされていません。私のコードでは '?choice" + "WHERE ..."のようなものです... –

答えて

0

私はOWLファイルに@AKSW答えに従うことによって、私の質問を解決し、いくつかの問題を修正

関連する問題