英文:
How to give a rank using SPARQL?
问题
以下是翻译的内容:
我有一个问题,我们如何使用SPARQL给出一个排名号码?假设我在下面的图片中有一个示例。所以,如果countKonsentrasi有最高的数字,排名就是1,依此类推。
查询我已经完成的,但不符合我的需求:
String queryString =
    "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "
    + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "
    + "PREFIX owl: <http://www.w3.org/2002/07/owl#> "
    + "SELECT ?e (COUNT (?e) AS ?countKonsentrasi) "
    + "(COUNT (*) AS ?ranking) "
    + "WHERE { ?x rdfs:label  ?a;"
    + " rdfs:subClassOf ?b ."
    + " ?b rdfs:subClassOf owl:Thing ."
    + " ?b rdfs:label ?e ."
    + " FILTER (regex(str(?a), '%s','i')) ."
    + "}"
    + "GROUP BY ?e "
    + "ORDER BY DESC (?countKonsentrasi)";
在SPARQL中是否有类似于RANK的排名函数?
更新
我已经尝试了这些新的语法。列ranking显示为0值。
String queryString =
    "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "
    + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "
    + "PREFIX owl: <http://www.w3.org/2002/07/owl#> "
    + "SELECT ?e (COUNT (?e) AS ?countKonsentrasi) "
    + "(COUNT (?countKonsentrasi) AS ?ranking) "
    + "WHERE { ?x rdfs:label  ?a;"
    + " rdfs:subClassOf ?b ."
    + " ?b rdfs:subClassOf owl:Thing ."
    + " ?b rdfs:label ?e ."
    + " FILTER (regex(str(?a), '%s','i')) ."
    + "}"
    + "GROUP BY ?e "
    + "ORDER BY DESC (?countKonsentrasi) LIMIT 5";
请帮助我。我非常感谢所有的帮助。谢谢。
英文:
I have a question, how can we give a rank number using SPARQL? let's say, i have the example in the picture below. So, if countKonsentrasi has the highest number, the rank is 1, and so on.
Query that i have done but it didn't meet my needs:
String queryString =
				"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "
				+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "
				+ "PREFIX owl: <http://www.w3.org/2002/07/owl#> "
				+ "SELECT ?e (COUNT (?e) AS ?countKonsentrasi) "
				+ " (COUNT (*) AS ?ranking) "
	  			+ " WHERE { ?x rdfs:label  ?a;"
				+ " rdfs:subClassOf ?b ."
				+ " ?b rdfs:subClassOf owl:Thing ."
				+ " ?b rdfs:label ?e ."
			   	+ " FILTER (regex(str(?a), '%s','i')) ."
	  			+ "}"
			   	+ "GROUP BY ?e "
	  			+ "ORDER BY DESC (?countKonsentrasi) ";
is there a function for ranking like RANK in SPARQL?
UPDATE
I have tried with these new syntaxes. The column ranking shows 0 values.
String queryString =
				"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "
				+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "
				+ "PREFIX owl: <http://www.w3.org/2002/07/owl#> "
				+ "SELECT ?e (COUNT (?e) AS ?countKonsentrasi) "
				+ "(COUNT (?countKonsentrasi) AS ?ranking) "
	  			+ " WHERE { ?x rdfs:label  ?a;"
				+ " rdfs:subClassOf ?b ."
				+ " ?b rdfs:subClassOf owl:Thing ."
				+ " ?b rdfs:label ?e ."
			   	+ " FILTER (regex(str(?a), '%s','i')) ."
	  			+ "}"
			   	+ "GROUP BY ?e "
	  			+ "ORDER BY DESC (?countKonsentrasi) LIMIT 5 ";
please help me. all helps i appreciate. thank you
专注分享java语言的经验与见解,让所有开发者获益!


评论