Overview

This is a memo on how to count the number of triples in an RDF store.

This time, we will use the Japan Search RDF store as an example.

https://jpsearch.go.jp/rdf/sparql/easy/

Number of Triples

You can count the number of triples with the following query.

SW}EHLE?ERsCET?{p(C?OoUNT(*)AS?NumberOfTriples)

The result is as follows.

https://jpsearch.go.jp/rdf/sparql/easy/?query=SELECT+(COUNT(*)+AS+%3FNumberOfTriples) WHERE+{ ++%3Fs+%3Fp+%3Fo+. }

As of the time of writing this article (May 6, 2024), there were 1,280,645,565 triples.

NumberOfTriples

1280645565

How Many Triples Are Connected by a Specific Property

Next, let’s count how many triples are connected by a specific property. Here is an example query.

SW}GOEHRRLE?ODERsUECEPRT?{pBB?YYp?o?D(pECSOCU(N?Tc(o*u)ntA)S?count)

The result is as follows.

https://jpsearch.go.jp/rdf/sparql/easy/?query=SELECT+%3Fp+(COUNT(*)+AS+%3Fcount) WHERE+{ ++%3Fs+%3Fp+%3Fo+. } GROUP+BY+%3Fp ORDER+BY+DESC(%3Fcount)

We can see that there are 399,447,925 triples, approximately 400 million, connected by schema:description.

pcount
schema:description399447925
rdf:type84363276
jps:relationType72908233
jps:value72214780
schema:name57377225
schema:provider52481873

Counting Combinations of Specific Subject and Object Types Using a Specified Property

To understand the overview of the above connections, we count the combinations of subject types and object types where ?subject and ?object are linked by the schema:description property.

SW}GOEHRRLE??oODERsspUECEuutPRTbbi{jjoBB?eenYYsccauttl?DbsEjsr{uSecd?bCchfoj(te:be?Tmtjccyayetop:pcTuedetynept?s?re)ocsdbruf?jib:oepjtbcteyjticpeTotecynTtpy?Te?poyoebp(bjeCj.eOecUctNtTTy(.p*e).AS}?count)

The result is as follows.

https://jpsearch.go.jp/rdf/sparql/easy/?query=SELECT+%3FsubjectType+%3FobjectType+(COUNT(*)+AS+%3Fcount) WHERE+{ ++%3Fsubject+schema%3Adescription+%3Fobject+. ++%3Fsubject+rdf%3Atype+%3FsubjectType+.+ ++optional+{%3Fobject+rdf%3Atype+%3FobjectType+.+} } GROUP+BY+%3FsubjectType+%3FobjectType ORDER+BY+DESC(%3Fcount)

There were approximately 9,000 triples with instances of the type:図書 (Book) class as subjects.

subjectTypeobjectTypecount
type:図書87593194
type:動物標本47068657
type:植物標本46548944
type:アクセス情報33291083
type:雑誌21643930
type:行政文書11780814

Counting Instances

With the following query, we count the combinations of triples that have instances of the type:図書 (Book) class as subjects and schema:description as the property.

SW}GOEHRRLE??ODERssUECEuuPRTbb{jjBB?eeYYsccutt?dbsejsrusecdbcchfj(te:e?mtcc(aytoC:puOdenUetNst)Tcy(rp*ie)p:tAiSon.?c?ooubnjte)ct.

The result is as follows.

https://jpsearch.go.jp/rdf/sparql/easy/?query=SELECT+%3Fsubject+(COUNT(*)+AS+%3Fcount) WHERE+{ ++%3Fsubject+schema%3Adescription+%3Fobject+. ++%3Fsubject+rdf%3Atype+type%3A図書+. } GROUP+BY+%3Fsubject ORDER+BY+desc(%3Fcount)

We can see that a single instance has many triples connected by schema:description.

subjectcount
https://jpsearch.go.jp/data/bibnl-20601759251
https://jpsearch.go.jp/data/bibnl-23328672213
https://jpsearch.go.jp/data/bibnl-22858450211
https://jpsearch.go.jp/data/bibnl-20579860186
https://jpsearch.go.jp/data/bibnl-20919858171
https://jpsearch.go.jp/data/bibnl-21013375170
https://jpsearch.go.jp/data/bibnl-20787748168
https://jpsearch.go.jp/data/bibnl-22866452165

By actually accessing the following URL, it was confirmed that there are indeed 251 triples.

https://jpsearch.go.jp/data/bibnl-20601759

Summary

I hope this is helpful for analyzing the number of triples in an RDF store.