SPARQL

Run SPARQL against different data sources, importing the results into Roam!

Installation

You could use the Copy Extension button below to individually install this extension. To install, just paste anywhere in your Roam graph and click "Yes, I Know What I'm Doing".

Manual Installation

If the extension doesn't work after using the copy extension button above, try installing manually using the instructions below.

First create a block with the text {{[[roam/js]]}} on any page in your Roam DB. Then, create a single child of this block type three back ticks. A code block should appear. Copy this code and paste it into the child code block in your graph:

var existing = document.getElementById("roamjs-sparql");
if (!existing) {
  var extension = document.createElement("script");
  extension.src = "https://roamjs.com/sparql.js";
  extension.id = "roamjs-sparql";
  extension.async = true;
  extension.type = "text/javascript";
  document.getElementsByTagName("head")[0].appendChild(extension);
}

Finally, click "Yes, I Know What I'm Doing".


Usage

Usage

To run a SPARQL query, open the Roam command palette with CMD+p (CTRL+p on Windows) and search for "Run SPARQL Query". This will open a dialog where you could run one of two types of SPARQL queries>

Current Page

This will run a query to search all the properties of an entity based on the current page name and will bring the specified number of values. They will be created as pairs of blocks in your graph in the following way: properties as Roam attributes and their values as child blocks. All attributes will show the matching Wikidata property in their page, linked with same as:: attribute. All property values, which are entities (people, places, and things as opposed to numbers and dates ) will be created (or reused if existing) as page references and their matching Wikidata item URI will be inserted as value of same as:: attribute, the same way as the property.

Current Block

This will run a query to search all of the properties of an entity based on the current block text. If the current block text is empty, it will use the parent block. All properties and entities imported will automatically tagged with a reference to their link on their respective pages.

Custom Query

You could write your own query in the code box in the dialog. The code block supports SPARQL query syntax. The results of the query will output with entity values being chilren of select variable names.

Label

You could define a custom global default label on the roam/js/sparql page. Each query could also use its own label, accessible by expanding the additional options. The {date} placeholder can be used to record the datetime of the import.

Resources

Check out this video from Ivo Velitchkov on importing data from Wikdata into your Roam database!

Demo


Contributors

This extension is brought to you by RoamJS! If you are facing any issues reach out to support@roamjs.com or click on the chat button on the bottom right.

If you get value from using this extension, consider sponsoring RoamJS by clicking on the button below!

A special thanks to those who's contributions also helped make this extension possible:

Other Extensions