MUO Services Mashup Demo
From Morfeo Wiki
This is the demo CTIC presented at the SWIG F2F meeting during the W3C Technical Plenary meeting (21/Oct/2008).
Contents |
Introduction
The MUO Reasoner Service implements a HTTP (GET) interface. Therefore, requesting a certain URI it is possible to get the result of reasoning with the triples retrieved from another URI. The syntax is as follows:
http://uri.of.the.reasoner/?source=<URI-to-be-reasoned-with>
The reasoner returns just the "new" triples, i.e., only the ones which have been created by the reasoning process. It doesn't return the triples that were already in the original source. (NOTE: this feature may change in the future).
SPARQL endpoints also have a HTTP interface as defined in the SPARQL protocol. In some implementations, SPARQL endpoints can gather data from external sources before executing a query. The way to do this is to use multiple 'FROM' clauses.
Therefore, both the MUO Reasoner and public SPARQL endpoints can be used to create "mash-ups" by piping their results as input for the other one, as this demo demonstrates.
Public resources to be used
- At http://dbpedia.org/sparql there is a public SPARQL endpoint powered by the Virtuoso RDF store. We'll use this endpoint for the demo because it is a well-known public endpoint, but we won't use the data exposed by the endpoint. Therefore, any other public endpoint may be used instead.
- The reference implementation of the MUO Services is deployed at http://idi.fundacionctic.org/muo-services-ri/.
Example 1 (sample data)
- http://idi.fundacionctic.org/muo/example1.rdf contains some RDF triples. They described a person (resource #Tom). Among other data, there is information about Tom's height (property #height), measured in feet.
- We want a list of all the people taller than 1.80 meters. Using the MUO framework, we write the following SPARQL query:
SELECT ?person ?heightNumValue
WHERE {
?person ex:height ?height .
?height muo:measuredIn ucum:meter .
?height muo:numericalValue ?heightNumValue .
FILTER (?heightNumValue > 1.80) .
}
- However, executing this query won't get us any result, because we don't have any information about Tom's height in meters. In order to make it work, we need to use the MUO Reasoner to translate Tom's height from feet to meters. Using the syntax described above, we use the HTTP binding of the reasoner to build a request that returns the "inferred" triples: http://idi.fundacionctic.org/muo-services-ri/reasoner?source=http%3A%2F%2Fidi.fundacionctic.org%2Fmuo%2Fexample1.rdf.
- By default, the public SPARQL endpoint of Virtuoso only queries the data hosted by the Virtuoso instance. However, we aren't interested in these data. We want to use data from external sources (URIs). In order to use them, we must pick "Retrieve remote RDF data for all missing source graphs" in the HTTP form of the Virtuoso endpoint. It is also very important to clean the value of the "Default Graph" field, because it takes precedence over the sources in our query. Then, we can execute this query:
PREFIX ex: <http://example.org/> PREFIX muo: <http://purl.oclc.org/NET/muo/muo#> PREFIX ucum: <http://purl.oclc.org/NET/muo/ucum/unit/length/> SELECT ?person ?heightNumValue FROM <http://idi.fundacionctic.org/muo/example1.rdf> FROM <http://idi.fundacionctic.org/muo-services-ri/reasoner?source=http%3A%2F%2Fidi.fundacionctic.org%2Fmuo%2Fexample1.rdf> WHERE { ?person ex:height ?height . ?height muo:measuredIn ucum:meter . ?height muo:numericalValue ?heightNumValue . FILTER (?heightNumValue > 1.80) . }
Example 2 (leveraging CIA FactBook data)
In this example, we use "real" RDF triples from a data repository included in the Linking Open Data initiative and graphically depicted in the LOD cloud. The purpose of this example is to demonstrate how existing RDF triples can be leveraged to benefit from the MUO framework.
Quick and easy: just one country
- The CIA World FactBook is a comprehensive source of data that has been converted and published as RDF. For instance, http://www4.wiwiss.fu-berlin.de/factbook/resource/Spain is the URI that represents Spain. By clicking on that URI, you'll get some data in HTML. However, when a semantic web client requests that URI, it gets RDF triples (due to content-negotiation). Anyway, you can also take a look at the RDF triples using your web browser using this link.
- This dataset includes some measurable properties, such as the length of all the railways in a country (property #railways_total). This datatype property links to a literal value. It is implicit that this literal value contains the length of the railways measured in kilometers.
- Unfortunately, if we use the MUO reasoner with these data, we get no results. There isn't enough information to extract any conclusion, i.e., nothing can be inferred.
- At http://idi.fundacionctic.org/muo/examples/cia-factbook.rdf there are a few RDF triples which define the property #railways_total. It is defined as a sub-property of muo:qualityLiteralValue, and it is linked to a new, equivalent ObjectProperty, #railways_total_qualityValue. Finally, we declare ucum:foot as the preferred unit of this second property.
- In UCUM, we lack a definition for kilometers. Therefore, we shall define this unit now. At http://idi.fundacionctic.org/muo/examples/additional-units.rdf we have such definition.
- At this point, we can invoke the reasoner with the data about Spain and our definition of the properties. Check the results. Note that we don't have to explicitly include our definition of "kilometer", because the reasoner can automatically retrieve the definition from its URI.
- Let's query the data using SPARQL. For instance, the following query generates a report with the length of the railways in all the available units. Check the results:
SELECT ?country ?value ?unit FROM <http://www4.wiwiss.fu-berlin.de/factbook/resource/Spain> FROM <http://idi.fundacionctic.org/muo-services-ri/reasoner?source=http%3A%2F%2Fwww4.wiwiss.fu-berlin.de%2Ffactbook%2Fresource%2FSpain&source=http%3A%2F%2Fidi.fundacionctic.org%2Fmuo%2Fexamples%2Fcia-factbook.rdf> WHERE { ?country a <http://www4.wiwiss.fu-berlin.de/factbook/ns#Country> . ?country <http://www4.wiwiss.fu-berlin.de/factbook/ns#railways_total_qualityValue> ?qv . ?qv <http://purl.oclc.org/NET/muo/muo#numericalValue> ?value . ?qv <http://purl.oclc.org/NET/muo/muo#measuredIn> ?unit }
Complex and slow: many countries
- So far, we have used data from just one country. How can we get data about many countries? We need to extract the relevant triples from the CIA FactBook. The following SPARQL construct can be used:
CONSTRUCT {
?country <http://www4.wiwiss.fu-berlin.de/factbook/ns#railways_total> ?railways_total
}
WHERE {
?country <http://www4.wiwiss.fu-berlin.de/factbook/ns#railways_total> ?railways_total
}
- In order to execute the query above, we have to build a request to the public SPARQL endpoint of the CIA FactBook. The SPARQL query will be a parameter of the request, therefore we need to URL-encode the string. We can use the form at http://www.vermiip.es/url_encode/ for this task. Then, we concat the URL of the public SPARQL endpoint of the CIA FactBook with the string "?query=" and the URL-encoded query. The result is this ugly URL: http://www4.wiwiss.fu-berlin.de/factbook/sparql?query=CONSTRUCT+{+++%3Fcountry+%3Chttp%3A%2F%2Fwww4.wiwiss.fu-berlin.de%2Ffactbook%2Fns%23railways_total%3E+%3Frailways_total+}+WHERE+{+++%3Fcountry+%3Chttp%3A%2F%2Fwww4.wiwiss.fu-berlin.de%2Ffactbook%2Fns%23railways_total%3E+%3Frailways_total+}. Sending a HTTP GET request to this URI will return the triples we need for this example.
- Now, we use the MUO Reasoner with these triples and the definitions of the properties. These are the inferred triples. Note that we replaced the URI of Spain with the ugly URI. For practical reasons, we added "LIMIT 5" to the SPARQL CONSTRUCT query (otherwise, it takes some time to do the reasoning).
- Finally, using a public SPARQL endpoint, we can execute any SPARQL query against the data. For instance, the very same SPARQL SELECT query we used before to get a list of the countries and the length of their railways.
Future work
- ...