我的个人包含属性has_answer和has_choice两次。
<!-- 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
我的问题是如何将结果放在一行中,如下所示:
Which of the following planet has the average speed of about 30Km/Seconds ? || choice 1 : Mars || choice 2 : Moon || CorrecAns : Earth
是否可以使用Sparql来做到这一点?
答案 0 :(得分:0)
我按照@AKSW答案解决了我的问题,并修复了我的OWL文件中的一些问题