简体   繁体   English

SPARQL 最常用谓词

[英]SPARQL Most Frequent Predicates

I want to find the top k frequent predicates in a graph.我想在图中找到前 k 个频繁谓词。 That is the predicates that occur in more triples.那就是出现在更多三元组中的谓词。 How can this be done using SPARQL?如何使用 SPARQL 做到这一点?

You can do this using the group and aggregation features of the query language.您可以使用查询语言的组和聚合功能来执行此操作。 You want to group by the predicate and count all the triples that use the predicate eg您想按谓词分组并计算使用谓词的所有三元组,例如

SELECT ?p (COUNT(*) AS ?usages)
WHERE
{
  GRAPH <http://your-graph.com> { ?s ?p ?o } 
}
GROUP BY ?p
ORDER BY DESC(?usages)
LIMIT 5

You can then sort by descending number of usages and limit the results to obtain just the top K然后,您可以按使用次数降序排序并限制结果以仅获得前 K 个

See the spec for more examples - https://www.w3.org/TR/sparql11-query/#aggregates有关更多示例,请参阅规范 - https://www.w3.org/TR/sparql11-query/#aggregates

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM