# Fun-fact - using SPARQL to query the type registry

**URL:** https://forum.solidproject.org/t/fun-fact-using-sparql-to-query-the-type-registry/776
**Category:** Solid App Development FAQs
**Created:** [December 3, 2018, 7:53pm UTC](https://forum.solidproject.org/t/fun-fact-using-sparql-to-query-the-type-registry/776 "2018-12-03T19:53:51Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![JornWildt](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/jornwildt/32/112_2.png) [@JornWildt](https://forum.solidproject.org/u/JornWildt)
#### Post date: [December 3, 2018, 7:53pm UTC](https://forum.solidproject.org/t/fun-fact-using-sparql-to-query-the-type-registry/776/1 "2018-12-03T19:53:51Z")

</div>

I have just managed to use SPARQL for querying your POD’s personal “type registry” which is a registry that informs web-apps about your preferred data location for various data types (like for instance contacts or photos) - and since Google is incapable of locating any documentation for it, I thought it might useful for others.

You can see the discovery spec. here: [https://github.com/solid/solid/blob/master/proposals/data-discovery.md](https://github.com/solid/solid/blob/master/proposals/data-discovery.md)

The basic technique goes like this:

- Use rdflib.js and it’s built-in “fetcher” to fetch data into a data-store as explained here: [https://solid.inrupt.com/docs/manipulating-ld-with-rdflib](https://solid.inrupt.com/docs/manipulating-ld-with-rdflib)

- First fetch the user profile document. Here you find this little reference to the type registry;

- Use rdflib to find those triples above in the profile document using “match” or “any” and extract the URLs.

- Use the fetcher again to load the type index resources. My private index tells apps that I want data about my radio controlled hobby stored in `/rc-data`:

- Now the discovery spec says “Find statement pairs of `solid:forClass` and `solid:instanceContainer` to get class reference and data location”. In SPARQL we can express this as:

- We have read all the necessary resources (turtle documents) in to the local store and now we only need to run the query:

- The query engine calls the `result` callback for each pair found.

- The “gotcha!” part here is that you need to index the result by `"?cl"` and `"?loc"` - and you won’t be able to detect that by JSON-dumping `result` as it comes out as an empty array!

It seems like the SPARQL library can fetch data too, but I haven’t tried that (yet).

---

<div class="post-metadata">

### Author: ![kidehen](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.solidproject.org/kidehen/32/42_2.png) [@kidehen](https://forum.solidproject.org/u/kidehen)
#### Post date: [April 8, 2019, 8:25pm UTC](https://forum.solidproject.org/t/fun-fact-using-sparql-to-query-the-type-registry/776/3 "2019-04-08T20:25:26Z")

</div>

Great!

On a related note, you can use any SPARQL Query implementation that supports URI-variable and URI-constant dereference in the body of a query to crawl any Solid Pod, subject to ACLs in place.

Here is a SPARQL Query example using our [URIBurner Service](https://linkeddata.uriburner.com) (a live Virtuoso Instance)

```auto
## Remove comments to sponge-afresh

# DEFINE input:grab-all "yes"

SELECT DISTINCT ?o
WHERE {
		 { <https://kidehen3.solid.openlinksw.com:8444/public/CoolStuff/> ldp:contains ?o.
	         OPTIONAL { ?o owl:sameAs ?o2 }
		 }
	         
  } 

```

**Examples:**

1. [Live Query Results Page for one of my Folders](https://tinyurl.com/y55h9e3s)

**Related**

- [Github Issues Thread](https://github.com/solid/node-solid-server/issues/962)
- [What is the Virtuoso Sponger Middleware about, and why is it important?](https://medium.com/virtuoso-blog/what-is-the-virtuoso-sponger-middleware-about-and-why-is-it-important-293546b32a32)
