Making Topic Maps
Sparql
Agenda
• Rationale
• SPARQL
• Theory
• Some examples
TMSparql
• A set of conventions and a small pseudo-
ontology to enable a topic map to present
itself as a SPARQL end-point
Rationale
• Integration
• A Simple Query Language
SPARQL
• A query language based on graph pattern
matching with support for value testing.
• The result of a SPARQL query is a list of
the different combination of variable-to-
term mappings that match against the
queried graph
Basic Matching
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name ?mbox WHERE
{
?x foaf:name ?name .
?x foaf:mbox ?mbox
}
Filtering
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX ns: <http://example.org/ns#>
SELECT ?title ?price WHERE
{
?x ns:price ?price .
FILTER (?price < 30.5)
?x dc:title ?title .
}
Optional Pattern Matching
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name ?mbox WHERE
{
?x foaf:name ?name .
OPTIONAL { ?x foaf:mbox ?mbox }
}
Alternative Patterns
PREFIX dc10: <http://purl.org/dc/elements/1.0/>
PREFIX dc11: <http://purl.org/dc/elements/1.1/>
SELECT ?title WHERE
{
{ ?book dc10:title ?title } UNION { ?book
dc11:title ?title }
}
Goals
• Don’t get caught up in RDF <-> Topic Maps
conversion
• Make the result as intuitive and interoperable as
possible
– No extensions to the SPARQL syntax
– Limited use of “magic” identifiers
• Linked Data Query Interop
– Make it possible to fire the same queries at RDF-
based and Topic Maps-based SPARQL endpoints and
get equivalent results.
Resource Identifiers
• In RDF, every resource has a single URI
identifier.
• In Topic Maps topics in particular have
multiple identifiers.
• Solution:
– Any subject identifier can be used to refer to a
topic item.
– Any item identifier can be used to refer to a
topic map item
Basic Triple Patterns
• To make TMSparql intuitive and to make
SPARQL queries to Topic Maps equivalent
to RDF we introduce a number of basic
triple matching patterns.
• The intuitive nature of TMSparql comes
from being selective and restrictive about
how these patterns are defined.
Type-Instance Triple
• ?instance a ?type
• ?instance rdf:type ?type
– ?type identifies a topic item
– ?instance identifies a topic, association,
occurrence or role item that is an instance of
the topic identified by ?type
Examples
SELECT ?person {
?person a ont:person
}
Finds all instances of ont:person
SELECT ?type {
http://www.networkedplanet.com/ a ?type
}
Returns the topics that define the type(s) of the topic
with the subject or item identifier
http://www.networkedplanet.com.
Topic Property Triple
• ?topic ?type ?value
– ?topic bound to a topic item
– ?type bound to a topic item
– ?value bound to the value of an occurrence or
name of ?topic where the occurrence type is
defined by ?type
Examples
SELECT ?person, ?age {
?person a ont:person .
?person ont:age ?age
}
Finds all instances of ont:person that have
an ont:age occurrence and returns the
each matching person/age pair.
Examples
• The object part of the triple binds to a literal
value, so we can also make use of SPARQL
FILTER
SELECT ?person , ?age {
?person a ont:person .
?person ont:age ?age .
FILTER ( ?age >= 18 )
}
Find all people we can serve beer to
Related Topics Triple
• ?topic ?roleType ?relatedTopic
– Binds ?topic to any topic that plays a role of a type
other than the type bound to ?roleType in an
association
– Binds ?roleType to the type of role played by the
topic bound to ?relatedTopic
– Binds ?relatedTopic to any topic that plays a role
of the type bound to ?roleType
• Allows us to traverse an association using the
target role type as the predicate.
Example
SELECT ?person, ?company {
?person ont:employer ?company
}
Binds ?company to any topic that plays a
role of type ont:employer in an association
and binds ?person to the topic(s) that play
any other type of role in that association.
Aside: Mapping RDF Vocabularies
• Map RDF predicates that have a literal range to occurrence types.
• Map RDF predicates that have a resource range to role types (and
generate the association type and inverse role type).
E.g. If we have:
– foaf:name mapped to a name type and
– foaf:member mapped to a role type
Then the following query works against an RDF-based or TM-based
endpoint:
SELECT ?memberName, ?groupName {
?g foaf:member ?m .
?m foaf:name ?memberName .
?g foaf:name ?groupName
}
TMSparql Predicates
• The basic triple patterns introduced above provide
the ability to traverse from topic to topic and to
retrieve and filter on the properties of topics.
• For the occasions when a topic map practitioner
needs to get into more detail, we introduce a
number of predicates that perform different model
traversals.
• All TMSparql predicates use the namespace
http://www.networkedplanet.com/tmsparql
(mapped to tms: in the following examples)
TMSparql Predicates
• tms:reifier
– Traversal from a topic map item to its reifier.
• tms:topicProperty
– Traversal from a topic item to its name and occurrence items
• tms:value
– Traversal from a name or occurrence item to its value
• tms:role
– Traversal from an association item to its role items
• tms:player
– Traversal from a role item to the role player topic item
• tms:scope
– Traversal from a scoped topic map item to the topic items in its
scope.
Example
SELECT ?employmentAssoc, ?person, ?company,
?position {
?employmentAssoc a ont:worksFor .
?employmentAssoc tms:role ?r1 .
?r1 a ont:employee .
?r1 tms:player ?person .
?r2 a ont:employer .
?r2 tms:player ?company .
}
Finds all associations of type ont:worksFor with at least one role
of type ont:employee and one of type ont:employer and binds
the role players to ?person and ?company respectively.
Conclusion
• TMSparql is an implementation of the
SPARQL query language on top of the
TMDM.
• With careful mapping of ontologies, it is
possible to create a TMDM repository for
RDF data that responds to SPARQL queries
in the same way as a “native” RDF repository
would
• TMSparql makes it possible for TMDM
repositories to participate more fully in the
Linked Data web

Making Topicmaps SPARQL

  • 1.
  • 2.
    Agenda • Rationale • SPARQL •Theory • Some examples
  • 3.
    TMSparql • A setof conventions and a small pseudo- ontology to enable a topic map to present itself as a SPARQL end-point
  • 4.
    Rationale • Integration • ASimple Query Language
  • 5.
    SPARQL • A querylanguage based on graph pattern matching with support for value testing. • The result of a SPARQL query is a list of the different combination of variable-to- term mappings that match against the queried graph
  • 6.
    Basic Matching PREFIX foaf:<http://xmlns.com/foaf/0.1/> SELECT ?name ?mbox WHERE { ?x foaf:name ?name . ?x foaf:mbox ?mbox }
  • 7.
    Filtering PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIXns: <http://example.org/ns#> SELECT ?title ?price WHERE { ?x ns:price ?price . FILTER (?price < 30.5) ?x dc:title ?title . }
  • 8.
    Optional Pattern Matching PREFIXfoaf: <http://xmlns.com/foaf/0.1/> SELECT ?name ?mbox WHERE { ?x foaf:name ?name . OPTIONAL { ?x foaf:mbox ?mbox } }
  • 9.
    Alternative Patterns PREFIX dc10:<http://purl.org/dc/elements/1.0/> PREFIX dc11: <http://purl.org/dc/elements/1.1/> SELECT ?title WHERE { { ?book dc10:title ?title } UNION { ?book dc11:title ?title } }
  • 10.
    Goals • Don’t getcaught up in RDF <-> Topic Maps conversion • Make the result as intuitive and interoperable as possible – No extensions to the SPARQL syntax – Limited use of “magic” identifiers • Linked Data Query Interop – Make it possible to fire the same queries at RDF- based and Topic Maps-based SPARQL endpoints and get equivalent results.
  • 11.
    Resource Identifiers • InRDF, every resource has a single URI identifier. • In Topic Maps topics in particular have multiple identifiers. • Solution: – Any subject identifier can be used to refer to a topic item. – Any item identifier can be used to refer to a topic map item
  • 12.
    Basic Triple Patterns •To make TMSparql intuitive and to make SPARQL queries to Topic Maps equivalent to RDF we introduce a number of basic triple matching patterns. • The intuitive nature of TMSparql comes from being selective and restrictive about how these patterns are defined.
  • 13.
    Type-Instance Triple • ?instancea ?type • ?instance rdf:type ?type – ?type identifies a topic item – ?instance identifies a topic, association, occurrence or role item that is an instance of the topic identified by ?type
  • 14.
    Examples SELECT ?person { ?persona ont:person } Finds all instances of ont:person SELECT ?type { http://www.networkedplanet.com/ a ?type } Returns the topics that define the type(s) of the topic with the subject or item identifier http://www.networkedplanet.com.
  • 15.
    Topic Property Triple •?topic ?type ?value – ?topic bound to a topic item – ?type bound to a topic item – ?value bound to the value of an occurrence or name of ?topic where the occurrence type is defined by ?type
  • 16.
    Examples SELECT ?person, ?age{ ?person a ont:person . ?person ont:age ?age } Finds all instances of ont:person that have an ont:age occurrence and returns the each matching person/age pair.
  • 17.
    Examples • The objectpart of the triple binds to a literal value, so we can also make use of SPARQL FILTER SELECT ?person , ?age { ?person a ont:person . ?person ont:age ?age . FILTER ( ?age >= 18 ) } Find all people we can serve beer to
  • 18.
    Related Topics Triple •?topic ?roleType ?relatedTopic – Binds ?topic to any topic that plays a role of a type other than the type bound to ?roleType in an association – Binds ?roleType to the type of role played by the topic bound to ?relatedTopic – Binds ?relatedTopic to any topic that plays a role of the type bound to ?roleType • Allows us to traverse an association using the target role type as the predicate.
  • 19.
    Example SELECT ?person, ?company{ ?person ont:employer ?company } Binds ?company to any topic that plays a role of type ont:employer in an association and binds ?person to the topic(s) that play any other type of role in that association.
  • 20.
    Aside: Mapping RDFVocabularies • Map RDF predicates that have a literal range to occurrence types. • Map RDF predicates that have a resource range to role types (and generate the association type and inverse role type). E.g. If we have: – foaf:name mapped to a name type and – foaf:member mapped to a role type Then the following query works against an RDF-based or TM-based endpoint: SELECT ?memberName, ?groupName { ?g foaf:member ?m . ?m foaf:name ?memberName . ?g foaf:name ?groupName }
  • 21.
    TMSparql Predicates • Thebasic triple patterns introduced above provide the ability to traverse from topic to topic and to retrieve and filter on the properties of topics. • For the occasions when a topic map practitioner needs to get into more detail, we introduce a number of predicates that perform different model traversals. • All TMSparql predicates use the namespace http://www.networkedplanet.com/tmsparql (mapped to tms: in the following examples)
  • 22.
    TMSparql Predicates • tms:reifier –Traversal from a topic map item to its reifier. • tms:topicProperty – Traversal from a topic item to its name and occurrence items • tms:value – Traversal from a name or occurrence item to its value • tms:role – Traversal from an association item to its role items • tms:player – Traversal from a role item to the role player topic item • tms:scope – Traversal from a scoped topic map item to the topic items in its scope.
  • 23.
    Example SELECT ?employmentAssoc, ?person,?company, ?position { ?employmentAssoc a ont:worksFor . ?employmentAssoc tms:role ?r1 . ?r1 a ont:employee . ?r1 tms:player ?person . ?r2 a ont:employer . ?r2 tms:player ?company . } Finds all associations of type ont:worksFor with at least one role of type ont:employee and one of type ont:employer and binds the role players to ?person and ?company respectively.
  • 24.
    Conclusion • TMSparql isan implementation of the SPARQL query language on top of the TMDM. • With careful mapping of ontologies, it is possible to create a TMDM repository for RDF data that responds to SPARQL queries in the same way as a “native” RDF repository would • TMSparql makes it possible for TMDM repositories to participate more fully in the Linked Data web

Editor's Notes

  • #2 Oxford-based software technology company developing products focussed on helping organisations to better manage the complex relationships between conceptual models such as business processes and domain knowledge and documents, data and other information that people use on a day-to-day basis. Developed out of working on the ISO standard for structured information exchange – Topic Maps.
  • #20 For the (typical) binary association case, or for associations that have only two distinct role types, this produces an intuitive result.