Overview

I had an opportunity to count co-occurrence frequencies for RDF triples, so this is a memo of the process. Following the article below, I will again use the Japan Search RDF store as an example.

Example 1

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

s}el??FeeeIcnnLtttTiiE(ttRcyy(o12?uenaantt(tstsi*ycyct)phphyeeee1a:m:msaa!::=?;c;ccrr?oeeeuaannttttooi)rrtyw??2hvveaa&rll&euuee?{e..ntity1<?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.

s}el??FeeeIcnnLtttTiiE?ttReyy(n12?teiaanttytstsi1ycyctphphy?eeee1e:m:mnaa!t::=i;c;ctrr?yeee2aanttt?ooivrrtayl??2uvveaa&ll&wuuhee?eer..neti{ty1<?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 you to retrieve a list of sword-type instances that share common values.

Summary

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