{"id":809,"date":"2007-05-17T16:36:41","date_gmt":"2007-05-17T20:36:41","guid":{"rendered":"http:\/\/fgiasson.com\/blog\/index.php\/2007\/05\/17\/free-text-search-on-musicbrainz-literals-using-virtuoso-rdf-views\/"},"modified":"2007-05-17T16:36:41","modified_gmt":"2007-05-17T20:36:41","slug":"free-text-search-on-musicbrainz-literals-using-virtuoso-rdf-views","status":"publish","type":"post","link":"https:\/\/fgiasson.com\/blog\/index.php\/2007\/05\/17\/free-text-search-on-musicbrainz-literals-using-virtuoso-rdf-views\/","title":{"rendered":"Free text search on Musicbrainz literals using Virtuoso RDF Views"},"content":{"rendered":"<p> <a href=\"https:\/\/fgiasson.com\/blog\/index.php\/2007\/04\/17\/musicbrainz-relation-database-mapped-in-rdf-using-the-music-ontology\/\">I introduced a Virtuoso RDF View<\/a> that maps the <a href=\"http:\/\/musicbrainz.org\">Musicbrainz<\/a> relational database into RDF using the <a href=\"http:\/\/wiki.musicontology.com\">Music Ontology<\/a> a couple of weeks ago. Now I will show some query examples evolving a special feature of these <a href=\"http:\/\/www.openlinksw.com\/virtuoso\/\">Virtuoso<\/a> RDF Views: full text search on literals.<\/p>\n<h2>How RDF Views work<\/h2>\n<p>A <a href=\"http:\/\/virtuoso.openlinksw.com\/Whitepapers\/html\/rdf_views\/virtuoso_rdf_views_example.html\">Virtuoso RDF View<\/a> can be seen as a layer between a relational database schemas and its conceptualization in RDF. The role of this layer is to convert relation data in its RDF conceptualization.<\/p>\n<p>That is it. You can see it as a conversion tool or as a sort of lens to see RDF data out of relation data.<\/p>\n<h2>How full text search over literals works<\/h2>\n<p>Recently OpenLink Software introduced the full text feature of their Virtuoso&#8217;s SPARQL processor with the usage of the &#8220;bif:contains&#8221; operator (it is introduced into the SPARQL syntax like a FILTER).<\/p>\n<p>When a user sends a SPARQL query using the bif:contains operator against a Virtuoso triple store, the parser will use the triple store&#8217;s full text index to perform the full text search over the queried literal.<\/p>\n<p>With Virtuoso RDF View, instead of using the triple store&#8217;s full text index, it will use the relational database&#8217;s full text index (if the relational database is supporting full text indexes, naturally).<\/p>\n<h2>Some queries examples<\/h2>\n<p>In this section I will show you how the full text feature of the Virtuoso RDF Views can be used to increase the performance of a query against the Musicbrainz RDF View modeled using the Music Ontology<\/p>\n<p><em>Note: if the system asks you for a login and a password to see the page, use the login name &#8220;demo&#8221; and the password &#8220;demo&#8221; to see the results of these SPARQL queries.<\/em><\/p>\n<h3>Example #1<\/h3>\n<p>A user remember that first name of the music artist is <strong>Paul<\/strong>, and he remember that one of the albums composed by this artists is <strong>Press Play<\/strong>. So this user wants to get the full name of this artist with the following SPARQL query:<\/p>\n<blockquote><p>sparql<br \/>\ndefine input:storage virtrdf:MBZROOT<br \/>\nPREFIX rdf:   &lt;http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#&gt;<br \/>\nPREFIX foaf:  &lt;http:\/\/xmlns.com\/foaf\/0.1\/&gt;<br \/>\nPREFIX mo: &lt;http:\/\/purl.org\/ontology\/mo\/&gt;<br \/>\nPREFIX dc:  &lt;http:\/\/purl.org\/dc\/elements\/1.1\/&gt;<br \/>\nSELECT ?artist_name ?album_title<br \/>\nFROM &lt;http:\/\/musicbrainz.org\/&gt;<br \/>\nWHERE<br \/>\n{<br \/>\n?artist  rdf:type mo:SoloMusicArtist .<br \/>\n?artist foaf:name ?artist_name .<br \/>\n?artist mo:creatorOf ?album .<\/p>\n<p>?album  rdf:type mo:Record .<br \/>\n?album dc:title ?album_title .<\/p>\n<p>FILTER bif:contains(?artist_name, &#8220;Paul&#8221;) .<br \/>\nFILTER bif:contains(?album_title, &#8220;Press and Play&#8221;) .<br \/>\n};<\/p><\/blockquote>\n<p><a href=\"http:\/\/dbpedia2.openlinksw.com:8890\/DAV\/home\/demo\/mbz-rdfview-paul-play-by-play.isparql\">Results of this query against the musicbrainz virtuoso rdf view<\/a><\/p>\n<p>As you can notice with that query, the user will use the full text capabilities of Virtuoso over two different literals: the objects of these two properties foaf:name and dc:title.<\/p>\n<h3>Example #2<\/h3>\n<p>In this example, the user wants to know the name of the albums published by <strong>Madonna<\/strong> <strong>between 1990 and 2000<\/strong>. The answer to this question is returned by the following SPARQL query:<\/p>\n<blockquote><p>sparql<br \/>\ndefine input:storage virtrdf:MBZROOT<br \/>\nPREFIX rdf:   &lt;http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#&gt;<br \/>\nPREFIX foaf:  &lt;http:\/\/xmlns.com\/foaf\/0.1\/&gt;<br \/>\nPREFIX mo:    &lt;http:\/\/purl.org\/ontology\/mo\/&gt;<br \/>\nPREFIX dcterms: &lt;http:\/\/purl.org\/dc\/terms\/&gt;<br \/>\nprefix dc: &lt;http:\/\/purl.org\/dc\/elements\/1.1\/&gt;<br \/>\nSELECT DISTINCT ?albums_titles ?creation_date<br \/>\nFROM &lt;http:\/\/musicbrainz.org\/&gt;<br \/>\nWHERE<br \/>\n{<br \/>\n?madonna  rdf:type mo:SoloMusicArtist .<br \/>\n?madonna foaf:name ?madonna_name .<br \/>\nFILTER bif:contains(?madonna_name, &#8220;Madonna&#8221;) .<\/p>\n<p>?madonna mo:creatorOf ?albums .<br \/>\n?albums  rdf:type mo:Record .<br \/>\n?albums dcterms:created ?creation_date .<br \/>\nFILTER ( xsd:dateTime(?creation_date) &gt; &#8220;1990-01-01T00:00:00Z&#8221;^^xsd:dateTime ) .<br \/>\nFILTER ( xsd:dateTime(?creation_date) &lt; &#8220;2000-01-01T00:00:00Z&#8221;^^xsd:dateTime ) .<br \/>\n?albums dc:title ?albums_titles .<br \/>\n};<\/p><\/blockquote>\n<p><a href=\"http:\/\/dbpedia2.openlinksw.com:8890\/DAV\/home\/demo\/mbz-rdview-madonna-albums-1990-2000.isparql\">Results of this query against the musicbrainz virtuoso rdf view<\/a><\/p>\n<p>Here the user will use the full text capabilities of the Virtuoso RDF Views to find artists with the name Madonna and he uses two filters on xsd:dateTime objects to find the albums that have been created between 1990 and 2000.<\/p>\n<h3>Examples #3<\/h3>\n<p>In this last example, the user wants to know the name of the members of the music group <strong>U2<\/strong>.<\/p>\n<blockquote><p>sparql<br \/>\ndefine input:storage virtrdf:MBZROOT<br \/>\nPREFIX rdf:   &lt;http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#&gt;<br \/>\nPREFIX foaf:  &lt;http:\/\/xmlns.com\/foaf\/0.1\/&gt;<br \/>\nPREFIX mo:    &lt;http:\/\/purl.org\/ontology\/mo\/&gt;<br \/>\nSELECT ?band_name ?member_name<br \/>\nFROM &lt;http:\/\/musicbrainz.org\/&gt;<br \/>\nWHERE<br \/>\n{<br \/>\n?band  rdf:type mo:MusicGroup .<br \/>\n?band foaf:name ?band_name .<br \/>\n?band_name bif:contains &#8216;&#8221;U2&#8243;&#8216; .<br \/>\n?band foaf:member ?members .<br \/>\n?members  rdf:type mo:SoloMusicArtist .<br \/>\n?members foaf:name ?member_name .<br \/>\n};<\/p><\/blockquote>\n<p><a href=\"http:\/\/dbpedia2.openlinksw.com:8890\/DAV\/home\/demo\/mbz-rdfview-u2-members.isparql\">Results of this query against the musicbrainz virtuoso rdf view<\/a><\/p>\n<p>Here the user will use the full text feature to get the name of the music group, then the name of the members related to this (these) music group(s) will be returned as well.<\/p>\n<h2>Special operators of a full text search<\/h2>\n<p>Some full texts operators can be used in the literal parameter of the bif:contains clause. The operators are the same used in the full text feature of Virtuoso&#8217;s relational database. <a href=\"http:\/\/docs.openlinksw.com\/virtuoso\/queryingftcols.html#textexprsyntax\">A list and a description of the operators can be found on that page<\/a>.<\/p>\n<p>I would only add that the <strong>near<\/strong> operator is defined as +\/- 100 chars from the searched literal. And the <strong>wildcard &#8216;*&#8217;<\/strong> operator should at least be placed after the third character of the literal. So, &#8220;tes*t&#8221; or &#8220;tes*&#8221; or &#8220;test*&#8221; are legal usages of the wildcard operator, but &#8220;*test&#8221;, &#8220;t*&#8221; or &#8220;te*st&#8221; are illegal usages of the operator.<\/p>\n<h2>Conclusion<\/h2>\n<p>Finally, as you can see, the full text feature available with the Virtuoso RDF Views is a more than essential feature that people should use to increase the performance of their SPARQL queries. The only two other options they have are: (1) using a normal &#8220;literal&#8221; that as to be well written and with the good cases; in one word this option render such queries useless and (2) they can use a FILTER with a regular expression with the &#8220;I&#8221; parameter that is far too slow for normal usages.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I introduced a Virtuoso RDF View that maps the Musicbrainz relational database into RDF using the Music Ontology a couple of weeks ago. Now I will show some query examples evolving a special feature of these Virtuoso RDF Views: full text search on literals. How RDF Views work A Virtuoso RDF View can be seen [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[149,84],"tags":[],"class_list":["post-809","post","type-post","status-publish","format-standard","hentry","category-musicontology","category-semantic-web"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/809","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=809"}],"version-history":[{"count":0,"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/809\/revisions"}],"wp:attachment":[{"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=809"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}