如何使用SPARQL给予一个排名?

huangapple 未分类评论46阅读模式
英文:

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.

如何使用SPARQL给予一个排名?

Query that i have done but it didn't meet my needs:

String queryString =
				&quot;PREFIX rdfs: &lt;http://www.w3.org/2000/01/rdf-schema#&gt; &quot;
				+ &quot;PREFIX rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt; &quot;
				+ &quot;PREFIX owl: &lt;http://www.w3.org/2002/07/owl#&gt; &quot;
				+ &quot;SELECT ?e (COUNT (?e) AS ?countKonsentrasi) &quot;
				+ &quot; (COUNT (*) AS ?ranking) &quot;
	  			+ &quot; WHERE { ?x rdfs:label  ?a;&quot;
				+ &quot; rdfs:subClassOf ?b .&quot;
				+ &quot; ?b rdfs:subClassOf owl:Thing .&quot;
				+ &quot; ?b rdfs:label ?e .&quot;
			   	+ &quot; FILTER (regex(str(?a), &#39;%s&#39;,&#39;i&#39;)) .&quot;
	  			+ &quot;}&quot;
			   	+ &quot;GROUP BY ?e &quot;
	  			+ &quot;ORDER BY DESC (?countKonsentrasi) &quot;;

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 =
				&quot;PREFIX rdfs: &lt;http://www.w3.org/2000/01/rdf-schema#&gt; &quot;
				+ &quot;PREFIX rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt; &quot;
				+ &quot;PREFIX owl: &lt;http://www.w3.org/2002/07/owl#&gt; &quot;
				+ &quot;SELECT ?e (COUNT (?e) AS ?countKonsentrasi) &quot;
				+ &quot;(COUNT (?countKonsentrasi) AS ?ranking) &quot;
	  			+ &quot; WHERE { ?x rdfs:label  ?a;&quot;
				+ &quot; rdfs:subClassOf ?b .&quot;
				+ &quot; ?b rdfs:subClassOf owl:Thing .&quot;
				+ &quot; ?b rdfs:label ?e .&quot;
			   	+ &quot; FILTER (regex(str(?a), &#39;%s&#39;,&#39;i&#39;)) .&quot;
	  			+ &quot;}&quot;
			   	+ &quot;GROUP BY ?e &quot;
	  			+ &quot;ORDER BY DESC (?countKonsentrasi) LIMIT 5 &quot;;

please help me. all helps i appreciate. thank you

huangapple
  • 本文由 发表于 2020年4月7日 11:45:00
  • 转载请务必保留本文链接:https://java.coder-hub.com/61072500.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定