Skip to content

Instantly share code, notes, and snippets.

@shad
Last active October 16, 2024 17:30
Show Gist options
  • Save shad/21d21998602f81f976df44bfa8688523 to your computer and use it in GitHub Desktop.
Save shad/21d21998602f81f976df44bfa8688523 to your computer and use it in GitHub Desktop.

NOTE: This document outlines a feature that was never fully tested in the platform, but appears to work (at least for simple cases). Use at your own risk, and test your usages as you do.

Uploading data with BASE

BASE is a very useful thing to know about in data.world. It is set to the dataset where the file was uploaded be default. It can be used in prefixes, or directly in triples using the <..> syntax.

NOTE: Does not currently work for .r2rml files.

PREFIX : <> # required if you want to use `:` in your statements
PREFIX foo: <../different-dataset/> # reletive prefix IRI

# SUBJECT: https://{org}.linked.data.world/d/{datatset}/thing1
<thing1> a <Thing> .   

# SUBJECT: https://{org}.linked.data.world/d/thing2
<../thing2> a <Thing> . 

# SUBJECT: https://{org}.linked.data.world/d/different-dataset/foo/thing3
foo:thing3 a :Thing .


:shad <hasThing> <../thing2> .
<shad> :hasThing foo:thing3 .

Quering data with BASE

You can query this data. The following are exactly the same semantically.

BASE <local://>
SELECT *
WHERE {
  ?aThing <hasThing> ?anotherThing.
}
image

And...

PREFIX : <local://>
SELECT *
WHERE {
  ?aThing :hasThing ?anotherThing.
}
image

NOTE: that prefixes don't get shortened in this version, but that is not important to the overall functionality. Just a by-product of how do the prefix replacement.

BASE in SPARQL

You can also set BASE in SPARQL. This includes setting it to the special local:// IRI, which always points to the target dataset. This has the benefit of very readable FROM statements.

BASE <local://>
PREFIX aice: <https://data.world/aice/1.0/>

SELECT *
FROM <file/ontology.ttl>
WHERE {
    ?s ?p ?o
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment