{"id":1022,"date":"2013-06-18T15:54:05","date_gmt":"2013-06-18T15:54:05","guid":{"rendered":"http:\/\/blog.soton.ac.uk\/webteam\/?p=1022"},"modified":"2013-06-19T13:58:02","modified_gmt":"2013-06-19T13:58:02","slug":"retreieve-by-path-feature-in-the-works-for-graphite-v2-0","status":"publish","type":"post","link":"https:\/\/blog.soton.ac.uk\/webteam\/2013\/06\/18\/retreieve-by-path-feature-in-the-works-for-graphite-v2-0\/","title":{"rendered":"Retreieve by Path feature in the works for Graphite v2.0"},"content":{"rendered":"<p>I&#8217;ve been working on a rather funky new feature for <a href=\"http:\/\/graphite.ecs.soton.ac.uk\/\">Graphite v2.0<\/a>. It&#8217;s a logical extension of the existing <a href=\"http:\/\/graphite.ecs.soton.ac.uk\/#resourcedescriptionclass\">Resource Description<\/a> feature, but it won&#8217;t replace it as th resource description feature lets you describe very simple paths out from a resource in a SPARQL endpoint, which gives a clear tree structure suitable for turning into JSON so that&#8217;s still kinda useful.<\/p>\n<p>This new function uses a modified version of the <a href=\"http:\/\/www.w3.org\/TR\/sparql11-query\/#pp-language\">SPARQL 1.1 path syntax<\/a>. I&#8217;ve added a couple of features and cheated a bit, but it&#8217;s damn useful.<\/p>\n<p>foaf:name or &lt;http:\/\/xmlns.com\/foaf\/0.1\/name&gt; would match triples having the topic as a subject.<\/p>\n<p>^foaf:member matches triples having the topic resource as the object.<\/p>\n<p>foaf:member\/foaf:name matches all the triples having the topic as the subject of a foaf:member triple AND where the object matches the subject of a foaf:name triple (and get that triple too). If wanted all foaf:member triples regardless of the foaf:name you can use foaf:member|foaf:member\/foaf:name<\/p>\n<p>You can use ! to negate a set of predicates ie. !(foaf:name|foaf:mbox) gives all triples with the topic as a subject EXCEPT foaf:name or foaf:mbox triples.<\/p>\n<p>You can use regexp style +, ?, * and {n,m} to indicate that a path should be repeated. However I&#8217;ve cheated a bit here so it&#8217;s not unlimited. By default it repeats things up to 8 times so + is treated as {1,8}. That&#8217;s a bit of a cheat but it works and you can change the depth.<\/p>\n<p>The additions I&#8217;ve made is &#8220;.&#8221; to match any predicate. So a path of &#8220;.&#8221;<\/p>\n<p>The call will be something like this:<\/p>\n<p>$graph = new Graphite();<br \/>\n$graph-&gt;ns( &#8220;sr&#8221;, &#8220;http:\/\/data.ordnancesurvey.co.uk\/ontology\/spatialrelations\/&#8221; );<br \/>\n$thing = $graph-&gt;resource( &#8220;http:\/\/id.southampton.ac.uk\/building\/32&#8221; );<br \/>\n$endpoint = &#8220;http:\/\/sparql.data.southampton.ac.uk\/&#8221; );<br \/>\n$n = $thing-&gt;loadSPARQLPath( $endpoint, &#8220;.|(.\/(rdfs:label|a))|(^sr:within)+\/(rdfs:label|a)?&#8221; );<\/p>\n<p>$n is set to the number of triples returned.<\/p>\n<p>What this actually does is returns:<\/p>\n<p>all the triples with &lt;&#8230;\/building\/32&gt; as the subject, their label and type, plus all the things within the building, or within things within the building etc. and their label and type, if any.<\/p>\n<p>OK. The above query is a bit much and takes about 5 seconds to return. Turning the + on within into a {1,3} cuts it to a more reasonable 0.8 seconds.<\/p>\n<p>This is just the first cut and I&#8217;m posting it here for suggestions. It&#8217;s not yet ready for integration into the core library but if you like it, have suggestions or other requests for Graphite v2.0 please leave a comment.<\/p>\n<p>If you would like to help out, we could really do with someone running some kind of user community, but I just don&#8217;t have the time.<\/p>\n<p>Update: <a href=\"http:\/\/lemur.ecs.soton.ac.uk\/~cjg\/pathdemo\/\">Try a live demo<\/a>!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been working on a rather funky new feature for Graphite v2.0. It&#8217;s a logical extension of the existing Resource Description feature, but it won&#8217;t replace it as th resource description feature lets you describe very simple paths out from a resource in a SPARQL endpoint, which gives a clear tree structure suitable for turning [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[281],"tags":[],"class_list":["post-1022","post","type-post","status-publish","format-standard","hentry","category-graphite"],"_links":{"self":[{"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/posts\/1022","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/comments?post=1022"}],"version-history":[{"count":3,"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/posts\/1022\/revisions"}],"predecessor-version":[{"id":1025,"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/posts\/1022\/revisions\/1025"}],"wp:attachment":[{"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/media?parent=1022"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/categories?post=1022"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.soton.ac.uk\/webteam\/wp-json\/wp\/v2\/tags?post=1022"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}