<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Interactive Media Manager Blog : OWL</title><link>http://blogs.msdn.com/imm/archive/tags/OWL/default.aspx</link><description>Tags: OWL</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>How to use inferencing with the sw_Sparql stored procedure and how to get the InferenceIndex for a specific ontology in the database</title><link>http://blogs.msdn.com/imm/archive/2008/12/08/how-to-use-inferencing-with-the-sw-sparql-stored-procedure-and-how-to-get-the-inferenceindex-for-a-specific-ontology-in-the-database.aspx</link><pubDate>Mon, 08 Dec 2008 23:22:48 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9185389</guid><dc:creator>johndeu</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/imm/comments/9185389.aspx</comments><wfw:commentRss>http://blogs.msdn.com/imm/commentrss.aspx?PostID=9185389</wfw:commentRss><description>&lt;p&gt;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.&amp;#160; 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. &lt;/p&gt;  &lt;p&gt;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.&amp;#160; 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.&amp;#160; &lt;/p&gt;  &lt;p&gt;The first one is the URI to the IMM data graph which stores all of the known “facts&amp;quot;.&amp;#160; Note that the “IMM” in this URI is case sensitive!    &lt;br /&gt;    &lt;br /&gt;&lt;a href="http://schemas.microsoft.com/IMM/data"&gt;http://schemas.microsoft.com/IMM/data&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The next URI you will need is the one for the inferred metadata generated from your imported ontology.&lt;/p&gt;  &lt;p&gt;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.&lt;/p&gt;  &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;   &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;     &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;exec&lt;/span&gt; sw_Sparql &lt;span style="color: #006080"&gt;'&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;PREFIX rdf: &amp;lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;PREFIX dii: &amp;lt;urn:mpeg:mpeg21:2002:01-DII-NS#&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;PREFIX did: &amp;lt;urn:mpeg:mpeg21:2002:02-DIDMODEL-NS#&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;PREFIX imm: &amp;lt;http://schemas.microsoft.com/imm/2.0/core/&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;SELECT ?s &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;FROM &amp;lt;http://schemas.microsoft.com/IMM/data&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;WHERE {  &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    ?s rdf:type imm:VideoItem.&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;}'&lt;/span&gt;,&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;1&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;If I execute&amp;#160; this query, which is the same as above except now this time I am asking for a type that is in the IMM core Ontology, but not declared in the facts that I imported – it will return no results. Notice that the only change I made is the name of the type.&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;
  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;exec&lt;/span&gt; sw_Sparql &lt;span style="color: #006080"&gt;'&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;PREFIX rdf: &amp;lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;PREFIX dii: &amp;lt;urn:mpeg:mpeg21:2002:01-DII-NS#&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;PREFIX did: &amp;lt;urn:mpeg:mpeg21:2002:02-DIDMODEL-NS#&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;PREFIX imm: &amp;lt;http://schemas.microsoft.com/imm/2.0/core/&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;SELECT ?s &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;FROM &amp;lt;http://schemas.microsoft.com/IMM/data&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;WHERE {  &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;    ?s rdf:type imm:MediaItem.&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;}'&lt;/span&gt;,&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;1&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;So, how do I get back these “inferred” types in a query. First we need to know the graph name that was generated for us when we imported our Ontology.&amp;#160; IMM automatically creates an inference graph when you import the core and any custom ontology.&amp;#160; We automatically add those inference graphs if you pass in the URI to to your ontology in the GetResource or Query methods on the web service.&amp;#160; &lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div&gt;In order to get back this information from the database you can execute the following SQL script which will return back a list of the known ontologies that are imported into IMM, as well as an ID that is used to identify their inference graph name. &lt;/div&gt;

&lt;div&gt;&amp;#160;&lt;/div&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;
  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;exec&lt;/span&gt; sw_sparql &lt;span style="color: #006080"&gt;'&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;SELECT ?s ?o &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;FROM &amp;lt;http://schemas.microsoft.com/IMM/ontology&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;WHERE { graph ?g { ?s &amp;lt;http://schemas.microsoft.com/imm/2.0/core/InferenceIndex&amp;gt; ?o. }}&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;order by ?o'&lt;/span&gt;,&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;1&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;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. 
  &lt;br /&gt;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&amp;#160; “http://schemas.microsoft.com/IMM/inference_”&amp;#160; and you will get the URI for that inference graph.&amp;#160;&amp;#160; &lt;br /&gt;

  &lt;br /&gt;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”.&lt;/p&gt;

&lt;p&gt;My new query with ontology inferencing enabled would then look like this:&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; background-color: #f4f4f4"&gt;
  &lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;
    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;exec&lt;/span&gt; sw_Sparql &lt;span style="color: #006080"&gt;'&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;PREFIX rdf: &amp;lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;PREFIX dii: &amp;lt;urn:mpeg:mpeg21:2002:01-DII-NS#&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;PREFIX did: &amp;lt;urn:mpeg:mpeg21:2002:02-DIDMODEL-NS#&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;PREFIX imm: &amp;lt;http://schemas.microsoft.com/imm/2.0/core/&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;#160;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;SELECT ?s &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;FROM &amp;lt;http://schemas.microsoft.com/IMM/data&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;FROM &amp;lt;http://schemas.microsoft.com/IMM/inference_8&amp;gt;&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;WHERE {  &lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;    ?s rdf:type imm:MediaItem.&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;}'&lt;/span&gt;,&lt;/pre&gt;

    &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &amp;#39;Courier New&amp;#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"&gt;1&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;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.&amp;#160;&amp;#160; &lt;/p&gt;

&lt;table cellspacing="0" cellpadding="0" width="550" border="0"&gt;&lt;tbody&gt;
    &lt;tr&gt;
      &lt;td valign="top" width="92"&gt;
        &lt;p&gt;&lt;img height="150" src="http://avatar.xboxlive.com/avatar/deutscherj/avatar-body.png" width="75" /&gt; &lt;/p&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="456"&gt;
        &lt;p&gt;&lt;b&gt;
            &lt;br /&gt;

            &lt;br /&gt;

            &lt;br /&gt;

            &lt;br /&gt;

            &lt;br /&gt;John Deutscher 

            &lt;br /&gt;&lt;/b&gt;Group Program Manager 

          &lt;br /&gt;Microsoft 

          &lt;br /&gt;&lt;a href="mailto:johndeu@microsoft.com"&gt;johndeu@microsoft.com&lt;/a&gt;&lt;/p&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9185389" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/imm/archive/tags/IMM/default.aspx">IMM</category><category domain="http://blogs.msdn.com/imm/archive/tags/SPARQL/default.aspx">SPARQL</category><category domain="http://blogs.msdn.com/imm/archive/tags/OWL/default.aspx">OWL</category><category domain="http://blogs.msdn.com/imm/archive/tags/RDF/default.aspx">RDF</category><category domain="http://blogs.msdn.com/imm/archive/tags/model/default.aspx">model</category><category domain="http://blogs.msdn.com/imm/archive/tags/metadata/default.aspx">metadata</category><category domain="http://blogs.msdn.com/imm/archive/tags/sw_5F00_Sparql/default.aspx">sw_Sparql</category><category domain="http://blogs.msdn.com/imm/archive/tags/Inference/default.aspx">Inference</category><category domain="http://blogs.msdn.com/imm/archive/tags/Graphs/default.aspx">Graphs</category></item><item><title>Advanced SPARQL in IMM</title><link>http://blogs.msdn.com/imm/archive/2008/10/28/advanced-sparql-in-imm.aspx</link><pubDate>Tue, 28 Oct 2008 15:02:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9020887</guid><dc:creator>derbaron</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/imm/comments/9020887.aspx</comments><wfw:commentRss>http://blogs.msdn.com/imm/commentrss.aspx?PostID=9020887</wfw:commentRss><description>&lt;p&gt;Today I would like to profile an advanced &lt;a href="http://www.w3.org/TR/rdf-sparql-query/"&gt;SPARQL&lt;/a&gt; query, break it down, and explain how each part works.&lt;/p&gt;  &lt;h5&gt;The Query:&lt;/h5&gt;  &lt;blockquote&gt;   &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;with&lt;/span&gt; (
      &lt;span class="kwrd"&gt;select&lt;/span&gt; &lt;font color="#ff0000"&gt;?entityIdIn ?highestTypeOut&lt;/font&gt;
      {
            { &lt;font color="#ff0000"&gt;?entityIdIn &lt;font color="#400000"&gt;rdf:type&lt;/font&gt; ?highestTypeOut&lt;/font&gt;.  }
            &lt;span class="kwrd"&gt;&lt;font color="#408080"&gt;not&lt;/font&gt;&lt;/span&gt;() {
               &lt;font color="#ff0000"&gt;?entityIdIn&lt;/font&gt; rdf:type &lt;font color="#ff0000"&gt;?hType&lt;/font&gt;.
               &lt;font color="#ff0000"&gt;?hType&lt;/font&gt; rdfs:subClassOf &lt;font color="#ff0000"&gt;?highestTypeOut&lt;/font&gt;.
            }
      } &lt;span class="kwrd"&gt;as&lt;/span&gt; :getMostSpecificType
)

&lt;span class="kwrd"&gt;SELECT&lt;/span&gt; &lt;font color="#ff0000"&gt;?title ?rdfType&lt;/font&gt;
&lt;span class="kwrd"&gt;WHERE&lt;/span&gt;
{     
      &lt;font color="#ff0000"&gt;?entityId ?predicate ?title&lt;/font&gt;.    
      { :getMostSpecificType(&lt;font color="#ff0000"&gt;?entityId&lt;/font&gt;, &lt;font color="#ff0000"&gt;?rdfType&lt;/font&gt;) }
      &lt;font color="#0000ff"&gt;FILTER&lt;/font&gt;(:&lt;span class="kwrd"&gt;&lt;font color="#408080"&gt;contains&lt;/font&gt;&lt;/span&gt;(&lt;font color="#ff0000"&gt;?title&lt;/font&gt;, &lt;span class="str"&gt;'Superman'&lt;/span&gt;))
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;




.csharpcode {
	background-color: #ffffff; font-family: consolas, "Courier New", courier, monospace; color: black; font-size: small
}
.csharpcode pre {
	background-color: #ffffff; font-family: consolas, "Courier New", courier, monospace; color: black; font-size: small
}
.csharpcode pre {
	margin: 0em
}
.csharpcode .rem {
	color: #008000
}
.csharpcode .kwrd {
	color: #0000ff
}
.csharpcode .str {
	color: #006080
}
.csharpcode .op {
	color: #0000c0
}
.csharpcode .preproc {
	color: #cc6633
}
.csharpcode .asp {
	background-color: #ffff00
}
.csharpcode .html {
	color: #800000
}
.csharpcode .attr {
	color: #ff0000
}
.csharpcode .alt {
	background-color: #f4f4f4; margin: 0em; width: 100%
}
.csharpcode .lnum {
	color: #606060
}&lt;/style&gt;

&lt;h5&gt;Overview&lt;/h5&gt;

&lt;p&gt;In essence, this query is searching every entity in the store and returns those entities where a property contains the word “Superman.” It also finds and returns the &lt;em&gt;most specific type &lt;/em&gt;of each result. The purpose of this query is simple: to allow a user to search for a single term and find any resultant entities, regardless of their type or their schema. &lt;/p&gt;

&lt;p&gt;In the results below, a number of different entities are returned: videos, clips, containers, and even resources.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/imm/WindowsLiveWriter/AdvancedSPARQLFunctionsandNegation_AB02/image_2.png"&gt;&lt;img style="display: inline" title="SPARQL results" border="0" alt="SPARQL results" src="http://blogs.msdn.com/blogfiles/imm/WindowsLiveWriter/AdvancedSPARQLFunctionsandNegation_AB02/image_thumb.png" width="486" height="183" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;h5&gt;Inference Rules&lt;/h5&gt;

&lt;p&gt;The “&lt;font color="#0000ff" face="Consolas"&gt;with&lt;/font&gt;” clause provides the ability to specify custom inference rules within a SPARQL query. In this case, we have a named rule that returns the most derivative (specific) type of the supplied entity. Since &lt;a href="http://www.w3.org/TR/rdf-sparql-query/#defn_QueryVariable"&gt;SPARQL variables&lt;/a&gt; either act as constraints or as variables depending on whether they are bound or unbound, I have suffixed “in” and “out” to make it clear how each is expected to be used. Calling the rule is simple. It is important to note that the results of this rule are not optional. Therefore, all returned entities must have at least one &lt;a href="http://www.w3.org/TR/rdf-sparql-query/#abbrevRdfType"&gt;rdf:type&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;{ :getMostSpecificType(&lt;font color="#ff0000"&gt;?entityId&lt;/font&gt;, &lt;font color="#ff0000"&gt;?rdfType&lt;/font&gt;) } &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h5&gt;Negation&lt;/h5&gt;

&lt;p&gt;The idea of negation is simple. The solution is the result of a graph pattern which is negatively constrained against the results of another graph pattern.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;{&amp;#160; &lt;font color="#ff0000"&gt;?entityIdIn &lt;font color="#400000"&gt;rdf:type&lt;/font&gt; ?highestTypeOut&lt;/font&gt;.&amp;#160; } 

    &lt;br /&gt;&lt;span class="kwrd"&gt;&lt;font color="#408080"&gt;not&lt;/font&gt;&lt;/span&gt;()&amp;#160; { 

    &lt;br /&gt;&lt;font color="#ff0000"&gt;&amp;#160;&amp;#160; ?entityIdIn&lt;/font&gt; rdf:type &lt;font color="#ff0000"&gt;?hType&lt;/font&gt;. 

    &lt;br /&gt;&lt;font color="#ff0000"&gt;&amp;#160;&amp;#160; ?hType&lt;/font&gt; rdfs:subClassOf &lt;font color="#ff0000"&gt;?highestTypeOut&lt;/font&gt;. 

    &lt;br /&gt;} &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Expressed in English: “Any triple where the subject is ?entityIdIn and the predicate is rdf:type &lt;strong&gt;EXCEPT&lt;/strong&gt; where the same triple exists in the following graph pattern: any triple where the subject is ?entityIdIn and the predicate is rdf:type &lt;strong&gt;AND&lt;/strong&gt; the resultant type is a subclass of another resultant type.” Whew. Put more simply: “Bind ?highestTypeOut to the rdf:type which &lt;strong&gt;has no derivative types&lt;/strong&gt;.” This is an example of using &lt;em&gt;negation&lt;/em&gt; to constrain the results of a &lt;a href="http://www.w3.org/TR/rdf-sparql-query/#GroupPatterns"&gt;graph pattern&lt;/a&gt;.&lt;/p&gt;

&lt;h5&gt;Full Text Search&lt;/h5&gt;

&lt;p&gt;The :contains function provides support for &lt;a href="http://msdn.microsoft.com/en-us/library/ms142571.aspx"&gt;SQL full-text queries&lt;/a&gt; in a SPARQL filter. This is the most performant method of querying for specific text. In addition to simple word matching seen in the query above, advanced features of full-text can be used. For example, we can search for different inflections of the word “ship” by using the following:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;font size="2"&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;FILTER&lt;/font&gt;(:&lt;font color="#408080"&gt;contains&lt;/font&gt;(&lt;font color="#ff0000"&gt;?title&lt;/font&gt;, 'FORMSOF(INFLECTIONAL, \&amp;quot;ship\&amp;quot;)')) &lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;font size="2" face="Tah"&gt;This will return results with values such as “ships,” “shipped,” and “shipping.”&lt;/font&gt;&lt;/p&gt;

&lt;h5&gt;Other Thoughts&lt;/h5&gt;

&lt;p&gt;&lt;font size="2"&gt;As mentioned in &lt;a href="http://blogs.msdn.com/imm/archive/2008/10/23/migrating-code-to-imm-2-0.aspx"&gt;my previous post&lt;/a&gt;, the “rdf” and “rdfs” prefixes used in this query are handled automatically by IMM. Additionally, this query uses the ontology graph to determine class derivation. An enterprising developer could utilize more facts from the ontology to enhance the results of the query. For example, he/she could return the friendly name (rdfs:label) for a type instead of the type’s URI.&lt;/font&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9020887" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/imm/archive/tags/SPARQL/default.aspx">SPARQL</category><category domain="http://blogs.msdn.com/imm/archive/tags/OWL/default.aspx">OWL</category><category domain="http://blogs.msdn.com/imm/archive/tags/RDF/default.aspx">RDF</category><category domain="http://blogs.msdn.com/imm/archive/tags/metadata/default.aspx">metadata</category></item><item><title>IMM's Metadata Model: a 2min. 18sec. vidcast</title><link>http://blogs.msdn.com/imm/archive/2008/08/20/imm-s-metadata-model-a-2min-18sec-vidcast.aspx</link><pubDate>Wed, 20 Aug 2008 22:28:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8882090</guid><dc:creator>mkashman</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/imm/comments/8882090.aspx</comments><wfw:commentRss>http://blogs.msdn.com/imm/commentrss.aspx?PostID=8882090</wfw:commentRss><description>&lt;SPAN style="LAYOUT-GRID-MODE: line; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: Arial; mso-ansi-language: EN-US; mso-fareast-language: EN-GB"&gt;&lt;FONT size=3&gt;
&lt;P style="MARGIN: 0in 0in 6pt; LINE-HEIGHT: normal" class=MsoNormal&gt;&lt;SPAN style="LAYOUT-GRID-MODE: line; FONT-FAMILY: 'Arial','sans-serif'; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-GB"&gt;IMM is designed to enable users who work with rich media to ingest, manage, edit, and distribute content. While IMM is based on Office SharePoint Server 2007 and offers collaborative, enterprise content management, and search capabilities, IMM is designed specifically to work with media files, and has been modified to integrate with the wider media industry. Key to this is the addition of the IMM Semantic Metadata Store. IMM uses Semantic Web technologies to express, interchange, store and search media asset metadata. This is because RDF and OWL enable developers and users to add business specific and technical information to media assets. In the below vidcast, &lt;STRONG&gt;John Deutscher&lt;/STRONG&gt; - Group Program Manager, spends a few minutes drilling into the IMM metadata model and reasons behind the decision to use the &lt;A class="" title="RDF primer from W3C website" href="http://www.w3.org/2001/09/rdfprimer/rdf-primer-20030119.html" mce_href="http://www.w3.org/2001/09/rdfprimer/rdf-primer-20030119.html"&gt;RDF standard&lt;/A&gt;:&lt;/SPAN&gt;&lt;/P&gt;&lt;IFRAME style="WIDTH: 500px; HEIGHT: 340px" src="http://silverlight.services.live.com/invoke/67617/The%20Interactive%20Media%20Manager%20metadata%20model%20(Aug%202008)/iframe.html" frameBorder=0 scrolling=no&gt;&lt;/IFRAME&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8882090" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/imm/archive/tags/IMM/default.aspx">IMM</category><category domain="http://blogs.msdn.com/imm/archive/tags/OWL/default.aspx">OWL</category><category domain="http://blogs.msdn.com/imm/archive/tags/RDF/default.aspx">RDF</category><category domain="http://blogs.msdn.com/imm/archive/tags/interactive+media+manager/default.aspx">interactive media manager</category><category domain="http://blogs.msdn.com/imm/archive/tags/model/default.aspx">model</category><category domain="http://blogs.msdn.com/imm/archive/tags/metadata/default.aspx">metadata</category></item><item><title>Putting the SPARQL Back in Your Eye</title><link>http://blogs.msdn.com/imm/archive/2007/10/16/putting-the-sparql-back-in-your-eye.aspx</link><pubDate>Tue, 16 Oct 2007 15:45:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5464125</guid><dc:creator>aweiker</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/imm/comments/5464125.aspx</comments><wfw:commentRss>http://blogs.msdn.com/imm/commentrss.aspx?PostID=5464125</wfw:commentRss><description>&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/imm/IMMSharepoint_20_2D_20Video_20Accent.png" mce_href="http://blogs.msdn.com/blogfiles/imm/IMMSharepoint_20_2D_20Video_20Accent.png"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/imm/IMMSharepoint_20_2D_20Video_20Accent_thumb.jpg" alt="IMMSharepoint - Video Accent" mce_src="http://blogs.msdn.com/blogfiles/imm/IMMSharepoint_20_2D_20Video_20Accent_thumb.jpg" border="0"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;How long should it take you to build out an IMM site like this?&lt;/p&gt;
&lt;p&gt;What about if you need to extend our ontology because it doesn’t meet all of your needs?&lt;/p&gt;
&lt;p&gt;Just last week we had to do this very thing for one of our internal customers here at Microsoft. In the process a few things really hit us. First: We knew our documentation was poor, but when all of the custimizations we did are undocumented that is just a sad thing. Secondly: It only took us about 4 days. This is how long we want it to take when we deploy to customers; however it is nowhere near this timeframe. This is primarily related to my first point.&lt;/p&gt;
&lt;p&gt;So what is to follow is a primer on the Media Library web part. In case you are wondering, the Media Library web part is that thing highlighted in red in the screen shot above.&lt;/p&gt;
&lt;h3&gt;What do you mean that's not a list, I thought everything was a list in SharePoint?&lt;/h3&gt;
&lt;p&gt;As some of you may have already thought about&amp;nbsp;or experienced, SharePoint can be pretty unforgiving when working with hundreds of large files. So how then, with IMM being built on SharePoint, do we provide you the ability to manage, dare I say “millions”, of video files through a single SharePoint site? Does IMM use the external storage API identified in KB938499?&lt;/p&gt;
&lt;p&gt;While you are pondering that, let us also take a look at what metadata is required to work with these media files. After all, what good is a 4 GB movie if you don't know if it's &lt;i&gt;The Matrix&lt;/i&gt;, &lt;i&gt;Jaws&lt;/i&gt;, or my high school prom video? While we can all agree on the title, how do we decide how to capture the rest of the metadata? There are already two very popular websites that solve this problem, &lt;i&gt;&lt;a href="http://www.imdb.com/" target="_blank" mce_href="http://www.imdb.com/"&gt;The Internet Movie Database&lt;/a&gt;&lt;/i&gt; (IMDb) and &lt;i&gt;&lt;a href="http://www.wikipedia.com/" target="_blank" mce_href="http://www.wikipedia.com/"&gt;Wikipedia&lt;/a&gt;&lt;/i&gt;. Both websites take two very different approaches. Now being built using SharePoint the obvious choice would have been to go with storing all data in a SharePoint list and using our own content types. While this approach would have given us the ability to inherit content types and allow our customers to add their own metadata onto each list, we still come back to a fundmental problem: performance. &lt;a href="http://technet2.microsoft.com/Office/en-us/library/6a13cd9f-4b44-40d6-85aa-c70a8e5c34fe1033.mspx?mfr=true" title="TechNet Article  - Plan for software boundaries" target="_blank" mce_href="http://technet2.microsoft.com/Office/en-us/library/6a13cd9f-4b44-40d6-85aa-c70a8e5c34fe1033.mspx?mfr=true"&gt;As we all know&lt;/a&gt; this would have slowed down SharePoint to the point where it was a very poor experience.&lt;/p&gt;
&lt;p&gt;So as you already guessed, we aren’t using a list to store our data.&amp;nbsp;Instead what we decided to do with IMM is to store all of our metadata&amp;nbsp;in Resource Description Framework (RDF). RDF is a specification outlined by the W3C at &lt;a href="http://www.w3.org/RDF/" mce_href="http://www.w3.org/RDF/"&gt;http://www.w3.org/RDF/&lt;/a&gt;. Since RDF by itself can be a very unstructured way of describing things a Web Ontology Language (OWL) (&lt;a href="http://www.w3.org/2004/OWL/" mce_href="http://www.w3.org/2004/OWL/"&gt;http://www.w3.org/2004/OWL/&lt;/a&gt;) was created by the W3C to create a vocabulary so that things could be described consistently and related to each other. In this article I don't want to go into all of the details on why we chose RDF over using a SharePoint list or something else. This is saved for another day.&lt;/p&gt;
&lt;p&gt;Do I still have your attention? Are you wondering how we store RDF metadata in SharePoint?&amp;nbsp;We dont’ store our RDF metadata in SharePoint, we&amp;nbsp;use our own proprietory RDF store. Where then do we store our large essence files? The typical scenario for this&amp;nbsp;is a large SAN; however, this could be another Digital Asset Management (DAM) system or even a tape. So here you have it, we do not use any lists in SharePoint to store our data!&lt;/p&gt;
&lt;h3&gt;Getting the data about the data&lt;/h3&gt;
&lt;p&gt;The media library provides you a glimpse into the metadata repository. It's not meant to show you the whole thing, but just that thing that you need to know in order to do your job. Its meant to help you see the forest from the trees, or however that saying goes. The media library consists of views. A view is simply two things: 1) the query on how to get the data, and 2) the way that the grid should look. This allows us to have multiple ways of looking at the same set of data. This view here is the default view that we use for our demos.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://blogs.msdn.com/blogfiles/imm/IMM_2DSharePoint_20Media_20Library_20_2D_20Default_small.jpg" alt="Media Library - Default View" mce_src="http://blogs.msdn.com/blogfiles/imm/IMM_2DSharePoint_20Media_20Library_20_2D_20Default_small.jpg" border="0"&gt;&lt;/p&gt;
&lt;p&gt;While this is the same media library in a different view.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://blogs.msdn.com/blogfiles/imm/IMM_2DSharePoint_20Media_20Library_20_2D_20Additional_20Details_small.jpg" alt="Media Library - Additional Details View" mce_src="http://blogs.msdn.com/blogfiles/imm/IMM_2DSharePoint_20Media_20Library_20_2D_20Additional_20Details_small.jpg" border="0"&gt;&lt;/p&gt;
&lt;p&gt;As you can see this is the same data, just a different way of looking at it. In a typical SharePoint environment you would define your views at the list level and would have somewhat limited options available to you unless you created your own XSLT. With IMM we do things a little differently. Our media library doesn't pull its configuration from SharePoint, instead it is all stored inside of an XML file that is defined in the web.config file. By default this configuration file is stored in ~\wpresources\ImmMediaLibrary\LibraryTemplates.xml. Instead of going into detail on every piece of this file I'll instead highlight the key sections.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://blogs.msdn.com/blogfiles/imm/LibraryTemplateXML.png" alt="LibraryTemplateXML" mce_src="http://blogs.msdn.com/blogfiles/imm/LibraryTemplateXML.png" border="0"&gt;&lt;/p&gt;
&lt;p&gt;As with all large XML files the first step is to know what you need to pay attention to when. There are usually two different reasons to be editing this file. You are going to either be defining your view/grid/columns or defining your data source. This is why I like to use an XML editor where I can collapse all unnecessary elements as I have done above.&lt;/p&gt;
&lt;h3&gt;What is a Column?&lt;/h3&gt;
&lt;p&gt;As you can see from the example above a Grid is made up of Columns. This naturally leads to two questions, What kinds of columns are supported out of box? and How can I make my own Column?. With the later question being more important. So what do we ship with? Since we are currently sold as a "solution" we only ship with two core column types: Menu and Workflow Selector. Menu is simply a column that can be bound to a result column and contain drop down menus that contain actions.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://blogs.msdn.com/blogfiles/imm/Menu_20Field_small.jpg" alt="Menu Field" mce_src="http://blogs.msdn.com/blogfiles/imm/Menu_20Field_small.jpg" border="0"&gt;&lt;/p&gt;
&lt;p&gt;The next field is the Workflow Selector. This field is simply a checkbox that can be tied back to the workflow drop down menu. Now you may be wondering how useful the media library is if we only ship with those two columns. Remember how I mentioned that we are sold as a "solution"? This means that this isn't an out of box piece of software that you can buy, like SharePoint or Exchange, but is something that requires customization to fit into your scenario. As a part of this customization we ship with sample code and extensions that have more column types. Included in these is a very handy column type called Html Field and Proxy Thumbnail Field. The Html Field column is one of the more flexible that allows us to&amp;nbsp; customize the grid with HTML markup that is based upon the type of result being returned. So for example if a TV Season is returned we can display it differently than a Movie.&lt;/p&gt;
&lt;h3&gt;Getting the Data&lt;/h3&gt;
&lt;p&gt;As I mentioned earlier the data is stored in an RDF store that we have running outside of SharePoint. In order to get to this data we use SPARQL queries. SPARQL is a W3C specification (&lt;a href="http://www.w3.org/TR/rdf-sparql-query/" mce_href="http://www.w3.org/TR/rdf-sparql-query/"&gt;http://www.w3.org/TR/rdf-sparql-query/&lt;/a&gt;) that specifies how to query RDF data. For the media library these queries are stored in the Data Source section of the template XML file.&lt;/p&gt;
&lt;p&gt;&lt;img src="http://blogs.msdn.com/blogfiles/imm/LibraryXML_2DSPARQL.png" alt="LibraryXML-SPARQL" mce_src="http://blogs.msdn.com/blogfiles/imm/LibraryXML_2DSPARQL.png" border="0"&gt;&lt;/p&gt;
&lt;p&gt;The syntax for these queries appears to be similar to SQL but that is as far as it goes. The similarity is truly only skin deep. Does this make it a shallow language? Not really as SPARQL is only able to do perform SELECT queries but it provides a lot of power around it.&lt;/p&gt;
&lt;p&gt;A SPARQL query consists of at least three different sections: PREFIX, SELECT, and WHERE. The PREFIX is used to define the namespaces for the types that will be used. The SELECT section is used to indicate which variables should be returned. This is similar to a SQL query. Then the WHERE section is used to put any conditions on the data. Unlike SQL this is a required field as without it nothing would be returned. Additionally unlike SQL instead of specifying a table to return results from, you specify what triple pattern you want results returned for by specifying any of the subject, predicate, or object. Please refer to the SPARQL specification for more information as this article is not intended to go into detail on this subject.&lt;/p&gt;
&lt;p&gt;Instead of dealing with a single query that does it all, the media library is broken down into two different queries. The first query gets back the list of subjects that will be displayed (RowIdSparql) and then the second is used to define what data to display about those subjects (RowDetailsSparql). Additionally since the media library allows you drill down the row query takes an optional "{CURRENTSUBJECT}" variable. This variable is passed is inserted automatically when being drilled down into. Then the same is true for the row details query exception that a different variable name is used. In this case "{ROWSUBJECT}" is used. ROWSUBJECT is taken from the ?rowId variable used in row query. Now that I'm bound to have you confused as to how this actually works, let us walk through an example.&lt;/p&gt;
&lt;p&gt;In my test environment my SharePoint Web ID is "58cedcd8-9398-4dfe-8205-45e3ef988799" and since I have not specified anything in the properties of the web part for the Root ID, the sites web id will be used as the container. The query then that is executing looks like the following:&lt;/p&gt;&lt;pre&gt;	PREFIX dc: &lt;HTTP: 1.1="" elements="" dc="" purl.org=""&gt;&lt;br&gt;	PREFIX did: &amp;lt;urn:mpeg:mpeg21:2002:02-didmodel-ns#&amp;gt;&lt;br&gt;	PREFIX rdf: &amp;lt;http: 22-rdf-syntax-ns# 02 1999 www.w3.org&amp;gt;&lt;br&gt;	&lt;br&gt;	SELECT ?rowId ?title&lt;br&gt;	WHERE&lt;br&gt;	{&lt;br&gt;	  &amp;lt;guid:_58cedcd8-9398-4dfe-8205-45e3ef988799&amp;gt; &amp;lt;did:itemcollection&amp;gt; ?rowId.&lt;br&gt;	  ?rowId &amp;lt;dc:title&amp;gt; ?title.&lt;br&gt;	  ?rowId &amp;lt;did:resourcecollection&amp;gt; ?proxyRes.&lt;br&gt;	}&lt;br&gt;&lt;/HTTP:&gt;&lt;/pre&gt;
&lt;p&gt;With the following result set being returned:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;table border="1"&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;rowId&lt;/th&gt;
&lt;th&gt;title&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;guid:_c0ea9f7d-02f1-4ea6-868b-e82855c4ed73&lt;/td&gt;
&lt;td&gt;Gelatin Video&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;guid:_f6da28c7-3f86-4ec0-847c-82ff9bcd32cf&lt;/td&gt;
&lt;td&gt;Fighter Pilot&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;guid:_bdeca860-127d-41e0-9530-f2653b90a7de&lt;/td&gt;
&lt;td&gt;Amsterdam Street Performer&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;guid:_275b1c0a-3d88-4ec0-8332-f154b845293a&lt;/td&gt;
&lt;td&gt;Media Player&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;guid:_973fe83b-8d39-4388-8916-85bff9a51d70&lt;/td&gt;
&lt;td&gt;Amsterdam Street Performer 2&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;guid:_69151f9e-2c57-40de-8c89-a4f05c4c5f16&lt;/td&gt;
&lt;td&gt;London Stock Exchange&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;guid:_0801d764-2ea6-49ea-a2c1-6e3c8aa5975a&lt;/td&gt;
&lt;td&gt;DEMO&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;guid:_cb9a8e86-8b7f-4332-81c4-eb3c1378f7ce&lt;/td&gt;
&lt;td&gt;BP MOSS Case Study&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;guid:_e8090739-e6b4-47cf-94fc-9028d5b7034c&lt;/td&gt;
&lt;td&gt;IBC 2007&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;guid:_d3ac0886-a6c7-4380-add9-234c0df3dc9d&lt;/td&gt;
&lt;td&gt;Universitat&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;guid:_fe67eca4-e480-40e2-9d2e-3b84d3d139d5&lt;/td&gt;
&lt;td&gt;helloworld&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;guid:_30411e27-2c80-4e13-b87e-9a7d007e2a5d&lt;/td&gt;
&lt;td&gt;Harris&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;guid:_cfa6f18f-6734-4a7e-88bd-e86d69c3edac&lt;/td&gt;
&lt;td&gt;Coffee&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;guid:_966eed5d-6e3d-4aee-97d5-dbcb6f9657da&lt;/td&gt;
&lt;td&gt;Party Boat&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;guid:_7aa32b57-19f6-491c-a4df-d48fbe899970&lt;/td&gt;
&lt;td&gt;Mediaset Demo&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;guid:_70447a00-a5d5-4a94-a323-4d543d130106&lt;/td&gt;
&lt;td&gt;Mikhail&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;guid:_fbbdeedc-68db-48e0-9fe6-06a3e86e6bb7&lt;/td&gt;
&lt;td&gt;Alliance&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;guid:_ca10bc92-0a60-4b78-a568-ec49e8eb8208&lt;/td&gt;
&lt;td&gt;Demo 123&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;guid:_10937f47-e088-4e41-a5d9-6c0c04ea10fa&lt;/td&gt;
&lt;td&gt;T-Online Video&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;guid:_476b5dc7-95c3-4cfc-864e-a15f0379c11b&lt;/td&gt;
&lt;td&gt;HP DEMO&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;guid:_1576c8ac-1199-467d-b403-4aeffb1180ad&lt;/td&gt;
&lt;td&gt;Last Presentation of IBC&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;guid:_b5389571-2641-4ce6-bd06-0dda75f67ed4&lt;/td&gt;
&lt;td&gt;Connections&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;With this data then another query is generated using the rowId this time as the key. This query is similar to the following:&lt;/p&gt;&lt;pre&gt;	PREFIX dc: &amp;lt;http://purl.org/dc/elements/1.1/&amp;gt;&lt;br&gt;	PREFIX did: &amp;lt;urn:mpeg:mpeg21:2002:02-DIDMODEL-NS#&amp;gt;&lt;br&gt;	PREFIX imm: &amp;lt;http://schemas.microsoft.com/imm/core/1.0#&amp;gt;&lt;br&gt;	PREFIX xsd: &amp;lt;http://www.w3.org/2001/XMLSchema#&amp;gt;&lt;br&gt;	&lt;br&gt;	SELECT ?rowId ?title ?thumbnail ?description&lt;br&gt;	WHERE&lt;br&gt;	{&lt;br&gt;	    ?rowId &amp;lt;dc:title&amp;gt; ?title.&lt;br&gt;	    ?rowId &amp;lt;dc:description&amp;gt; ?description.&lt;br&gt;	    ?rowId &amp;lt;did:ResourceCollection&amp;gt; ?proxyRes.&lt;br&gt;	    ?proxyRes &amp;lt;imm:IsProxy&amp;gt; 'true'^^&amp;lt;xsd:boolean&amp;gt;.&lt;br&gt;	    ?proxyRes &amp;lt;did:Ref&amp;gt; ?thumbnail.&lt;br&gt;	    FILTER(?rowId = &amp;lt;guid:_c0ea9f7d-02f1-4ea6-868b-e82855c4ed73&amp;gt;)&lt;br&gt;	}&lt;br&gt;&lt;/pre&gt;
&lt;p&gt;Please note that this is not the actual query that is used as that would result in X + 1 queries being executed where X is the number of results returned in the first query. Instead all of the queries are appended together and one large batch is sent to the RDF repository. The results for the previous query look like such: &lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;rowId&lt;/th&gt;
&lt;th&gt;Title&lt;/th&gt;
&lt;th&gt;Thumbnail&lt;/th&gt;
&lt;th&gt;description&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;guid:_c0ea9f7d-02f1-4ea6-868b-e82855c4ed73&lt;/td&gt;
&lt;td&gt;Gelatin Video&lt;/td&gt;
&lt;td&gt;\2007 09 08\guid__a6c5bbe6-dd1e-400f-ae7c-a3821158b857.wmv&lt;/td&gt;
&lt;td&gt;This is a video about Gelatin. This is a video about Gelatin. This is a video about Gelatin. This is a video about Gelatin. This is a video about Gelatin. &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;Since all of this SPARQL stuff can be very confusing, we have created a &lt;a href="http://blogs.msdn.com/imm/attachment/5464125.ashx" target="_blank" mce_href="http://blogs.msdn.com/imm/attachment/5464125.ashx"&gt;SPARQL Cheat Sheet&lt;/a&gt; that should be referenced. (I have mine on my wall beside me, where’s yours?)&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=5464125" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/imm/attachment/5464125.ashx" length="214646" type="application/pdf" /><category domain="http://blogs.msdn.com/imm/archive/tags/IMM/default.aspx">IMM</category><category domain="http://blogs.msdn.com/imm/archive/tags/SPARQL/default.aspx">SPARQL</category><category domain="http://blogs.msdn.com/imm/archive/tags/Media+Library/default.aspx">Media Library</category><category domain="http://blogs.msdn.com/imm/archive/tags/OWL/default.aspx">OWL</category><category domain="http://blogs.msdn.com/imm/archive/tags/RDF/default.aspx">RDF</category><category domain="http://blogs.msdn.com/imm/archive/tags/Display+Templates/default.aspx">Display Templates</category></item></channel></rss>