[英]How can I get a max values in a query sparql
我想知道在另一个SELECT中应用计数后如何在sparql查询中获得MAX值。 我的代码是:
#PREFIX nobel: <http://data.nobelprize.org/terms/>
#PREFIX cat: <http://data.nobelprize.org/resource/category/>
#PREFIX foaf: <http://xmlns.com/foaf/0.1/>
#PREFIX dbo: <http://dbpedia.org/ontology/>
#PREFIX dbp: <http://dbpedia.org/property/>
#PREFIX dbr: <http://dbpedia.org/resource/>
#PREFIX owl: <http://www.w3.org/2002/07/owl#>
#PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#>
#PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
Select ?advisorName (max (?c) as ?m ) {#the answer is empty.. )
SELECT ?advisorName (count (distinct (?category)) as ?c) (max (?c) as ?m) {
?student a nobel:Laureate ;
owl:sameAs ?dbpStudent ;
foaf:name ?studentName ;
nobel:nobelPrize ?pStudent .
?pStudent nobel:category ?category .
FILTER (afn:namespace(?dbpStudent) = str(dbr:))
SERVICE <http://dbpedia.org/sparql> {
{ ?dbpStudent dbo:doctoralAdvisor ?dbpAdvisor .}
union
{?dbpAdvisor dbo:doctoralStudent ?dbpStudent. }
?dbpAdvisor rdfs:label ?advisorName .
Filter (lang(?advisorName)= "en") }}
group by ?dbpStudent ?advisorName
order by desc (?c) }
非常感谢!
在开始调试之前,您的查询应该使用标准的SPARQL语法:
SELECT ?advisorName (MAX(?c) AS ?m)
WHERE
{ { SELECT ?advisorName (COUNT(DISTINCT ?category) AS ?c)
WHERE
{ ?student rdf:type nobel:Laureate ;
owl:sameAs ?dbpStudent ;
foaf:name ?studentName ;
nobel:nobelPrize ?pStudent .
?pStudent nobel:category ?category
FILTER ( afn:namespace(?dbpStudent) = str(dbr:) )
SERVICE <http://dbpedia.org/sparql>
{ { ?dbpStudent dbo:doctoralAdvisor ?dbpAdvisor }
UNION
{ ?dbpAdvisor dbo:doctoralStudent ?dbpStudent }
?dbpAdvisor rdfs:label ?advisorName
FILTER ( lang(?advisorName) = "en" )
}
}
GROUP BY ?advisorName
}
}
GROUP BY ?advisorName
ORDER BY DESC(?c)
我不明白的东西:
?dbpStudent
上有一个group by
,因为没有这样的绑定,因为内部SELECT查询未返回它 所以我的问题是,查询的总体目标是什么?
一旦确定了您的查询应该做什么,我们就可以通过检查中间结果开始调试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.