It’s often very useful when creating custom SPARQL queries against the IMM Metadata Store using the sw_Sparql stored procedure to pull in some “inferred” metadata from the ontologies that you have imported. For example, you may have ingested a bunch of metadata into the IMM data table that stores the “facts” but you want to query back for information that is generated dynamically based on you ontology definitions.
One simple example of this is you may have saved a VideoItem in the database with it’s rdf:type set to imm:VideoItem, but you never provided the metadata to explain that this item is also derived from imm:MediaItem. That information is provided in the IMM core ontology. To write a query for that directly against the sw_sparql stored procedure in the database, you need to know two well known graph URI’s.
The first one is the URI to the IMM data graph which stores all of the known “facts". Note that the “IMM” in this URI is case sensitive! http://schemas.microsoft.com/IMM/data
The next URI you will need is the one for the inferred metadata generated from your imported ontology.
If I execute the following query in SQL Server Management Studio against the IMMMetadata database, it will select all the VideoItems from the “facts” table as you can see in the FROM clause. If you have the Litware sample data installed, you should get some results back. If you look at the Litware rdf data, you will notice that we have set the type of these objects to VideoItem already, so the “facts” table contains their types.
exec sw_Sparql '
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dii: <urn:mpeg:mpeg21:2002:01-DII-NS#>
PREFIX did: <urn:mpeg:mpeg21:2002:02-DIDMODEL-NS#>
PREFIX imm: <http://schemas.microsoft.com/imm/2.0/core/>
SELECT ?s
FROM <http://schemas.microsoft.com/IMM/data>
WHERE {
?s rdf:type imm:VideoItem.
}',
1
?s rdf:type imm:MediaItem.
exec sw_sparql '
SELECT ?s ?o
FROM <http://schemas.microsoft.com/IMM/ontology>
WHERE { graph ?g { ?s <http://schemas.microsoft.com/imm/2.0/core/InferenceIndex> ?o. }}
order by ?o',
Now, we can rewrite the script above to add a extra FROM clause that uses this inference index to point to the correct inference graph. Look at the results of the above query and locate the Ontology that you are interested in using. Append the InferenceIndex that is returned in column 2 of the results to the following URI “http://schemas.microsoft.com/IMM/inference_” and you will get the URI for that inference graph. For example the results from my database contains the index number “8” for the IMM Core ontology, so my resulting graph URI would be “http://schemas.microsoft.com/IMM/inference_8”.
My new query with ontology inferencing enabled would then look like this:
FROM <http://schemas.microsoft.com/IMM/inference_8>
If you execute this against the Litware sample metadata you will now get back the same (or more if you have other items that are derived from MediaItem) number of results as in the first query.
John Deutscher Group Program Manager Microsoft johndeu@microsoft.com