Referring to Topics and Schema Types

Top  Previous  Next

SPARQL queries are built from a number of triple patterns. Each triple pattern defines a subject, predicate and object that the query must match where any of those three items could be a variable. When querying the Web3 Platform, topics, associations and topic properties are normally used as the subject (or occasionally the object) of SPARQL triple patterns. Schema types are normally used as the predicate in a SPARQL triple pattern.

 

To Refer to an Item in a Topic Map

A specific topic, association or topic property can be referenced directly by their address in the Web3 Platform's REST interface. For example the following query finds the labels of a specific topic referenced by its address (for brevity the GUIDs in the URL have been shortened:

SELECT ?l WHERE {
  <http://localhost/web3/topicmaps/123.../topics/456...> tms:label ?l
}

A topic can also be referenced by using one of its subject identifiers rather than its address.

 

NOTE: When a topic is returned as part of a results set, the URLs returned in the results are always the Web3 Platform address of the topic.

 

To Refer to a Schema Type

Schema types can be referenced by using on of the subject identifiers of the type. This facility allows the creation of SPARQL queries that will work on any topic map that uses a particular set of schema types. For example, the following query finds all topics of a particular type:

SELECT ?t WHERE {
  ?t a <http://psi.networkedplanet.com/types/person>
}

Shortening References

To make complex SPARQL queries a little more compact and easier to read, SPARQL supports shortening URIs using predefined prefixes. Prefixes must be declared at the start of the query like this:

PREFIX ont: <http://psi.networkedplanet.com/types/>

The prefix can then be used inside the query followed by the remainder of the URL. So the previous SPARQL query can be rewritten with a prefix like this:

PREFIX ont: <http://psi.networkedplanet.com/types/>
SELECT ?t WHERE { 
  ?t a ont:person 
}

Note that when a prefix is used inside a query, the value should not be surrounded by < > brackets.