Overview

I had the opportunity to count co-occurrence frequencies for RDF triples, so here are my notes. Following the previous article, I will again use the Japan Search RDF store as an example.

Example 1

The following query counts the number of triples among sword-type instances that share a common creator (schema:creator). The filter avoids counting identical instances and prevents duplicate counting.

select (count(*) as ?count) where {
  ?entity1 a type:刀剣;
             schema:creator ?value .
  ?entity2 a type:刀剣;
             schema:creator ?value .
  FILTER(?entity1 != ?entity2 && ?entity1 < ?entity2)
}

https://jpsearch.go.jp/rdf/sparql/easy/?query=select+(count(*)+as+%3Fcount)+where+{ ++%3Fentity1+a+type%3A刀剣%3B +++++++++++++schema%3Acreator+%3Fvalue+. ++%3Fentity2+a+type%3A刀剣%3B +++++++++++++schema%3Acreator+%3Fvalue+. ++FILTER(%3Fentity1+!%3D+%3Fentity2+%26%26+%3Fentity1+<+%3Fentity2) }

Example 2

Let’s display the specific triples.

select ?entity1 ?entity2 ?value where {
  ?entity1 a type:刀剣;
             schema:creator ?value .
  ?entity2 a type:刀剣;
             schema:creator ?value .
  FILTER(?entity1 != ?entity2 && ?entity1 < ?entity2)
}

https://jpsearch.go.jp/rdf/sparql/easy/?query=select+%3Fentity1+%3Fentity2+%3Fvalue+where+{ ++%3Fentity1+a+type%3A刀剣%3B +++++++++++++schema%3Acreator+%3Fvalue+. ++%3Fentity2+a+type%3A刀剣%3B +++++++++++++schema%3Acreator+%3Fvalue+. ++FILTER(%3Fentity1+!%3D+%3Fentity2+%26%26+%3Fentity1+<+%3Fentity2) }

This allows us to retrieve a list of sword-type instances that share common values.

Summary

There may be some inaccuracies, but I hope this serves as a useful reference.