Expanding Topics in SPARQL Query Results

Top  Previous  Next

In some cases it is desirable to retrieve more than just the URI address of a topic - for example labels and type are useful for display purposes and in some cases other topic properties can be useful too. In most cases it is advisable to add extra columns to the query to return just the specific properties, labels or identifiers of interest. However there are some cases where what the developer really needs is the one of the three Web3 topic representation structures in place of the topic URI. This is now supported through the SPARQL query interface as an in-place expansion of all URIs that refer to a topic into a representation of the referenced topic.

Procedure

To specify that expansion of topics references should take place, specify an additional query parameter with the name expandTopic and one of the following values:

expandTopic Query Parameter Value

Topic URIs are replaced with:

ref

TopicRef - Provides topic labels, identifiers and types (types only as a web address)

rep

TopicRepr - Provides topic labels, identifiers, types and properties (types serialized as a TopicRef)

ful

FullTopicRepr - Provides a TopicRepr plus a list of AssociationRepr for all associations the topic is in.

 

The resulting SPARQL results set structure will contain the specified topic serialization as the value for any binding that is recognized as a Web3 topic web address instead of the normal URI binding.

 

For example, a query that returns the following SPARQL results XML with no expandTopic query parameter:

<sparql xmlns="http://www.w3.org/2005/sparql-results#">

  <head>

    <variable name="t"/>

  </head>

  <results>

    <result>

      <binding name="t">

        <uri>http://localhost/web3/topicmaps/eab7e7e8-6fe9-402d-97c8-3a571b476189/topics/4d213ce8-7ef6-4dec-a286-d6b1f4cc306d</uri>

      </binding>

    </result>

  </results>

</sparql>

 

Would return something like the following when expandTopic is set to ref:

 

<sparql xmlns="http://www.w3.org/2005/sparql-results#">

  <head>

    <variable name="t"/>

  </head>

  <results>

    <result>

      <binding name="t">

        <TopicRef Address="http://localhost/web3/topicmaps/eab7e7e8-6fe9-402d-97c8-3a571b476189/topics/4d213ce8-7ef6-4dec-a286-d6b1f4cc306d"

                  xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 

                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

          <Labels>

            <Label Lang="en">Sample Topic</Label>

          </Labels>

          <Identifiers/>

          <Types>

            <Type Address="http://localhost/web3/topicmaps/eab7e7e8-6fe9-402d-97c8-3a571b476189/topics/e81a795e-6e49-4bea-be7f-4f282aba5da4"/>

          </Types>

        </TopicRef>

      </binding>

    </result>

  </results>

</sparql>

 

Limitation and Cautions

1.The expandTopic option is a NetworkedPlanet-specific extension to the SPARQL Protocol Recommendation and so is not likely to be supported on other systems.
2.The expandTopic option is only available when the requested results format is either XML or JSON. It is not available in the HTML representation of the results set.
3.The option should be used with caution when the query results set could potentially be very large as the results set will not be returned until all topic references on the requested results set page have been expanded. If a query could potentially return a large number of results we recommend either retrieving the required properties into separate columns or using the OFFSET and LIMIT modifiers to page through the results as the expansion applies only to the page (as specified by OFFSET and LIMIT).
4.Expansion applies to all columns of the result set - it is not possible to ask for only a specific column to be expanded.
5.Expansion limits the performance benefits of caching as the cache contains only the unexpanded results set and expansion must be performed each time the query is made, even if the results set itself has not changed.