Archive for the 'Commentary' Category

SPARQL and still sub-querying

Thursday, August 21st, 2008

for x in g.query(”SELECT ?xcreator WHERE { ?creator dc:creator ?xcreator }”,
initNs=ns):

print x

sub_query = “SELECT ?creator WHERE { ?xcreator ?creator }”

for sub_x in g.query(sub_query, initNs=dict(ns)):
print ‘Sub_x %s’ % sub_x

This can’t be the only way to do sub_queries with SPARQL and this doesn’t work well for me because the first result is on a blanknode. The stuff is really apart of rdf:seq which I haven’t figured out how to get yet even though my namespace is correct. ns#_1 contains all of the Literals for Dublin Core/Exif Metadata. I’m beginning to think maybe the binary tag from ExifTool is wrong or something.

SparQL and subquerying

Wednesday, August 20th, 2008

So more into XMP data issues and handling this properly. Parsing the formatted data from ExifTool I realize isn’t going to be a reliable method for this system. So this meant having to export the full tag in binary from Exiftool utilizing something like: exiftool -xmp -b sample.jpg > sample.metadata sample image comes from Douglas Hackney (thanks!)

import string, os
from rdflib import ConjunctiveGraph as Graph, Namespace

DC = Namespace(”http://purl.org/dc/elements/1.1/”)
RDF = Namespace(”http://www.w3.org/1999/02/22-rdf-syntax-ns#”)
EXIF = Namespace(”http://ns.adobe.com/exif/1.0/”)

ns = dict(dc=DC, rdf=RDF, exif=EXIF)
g = Graph()
g.parse(”sample.metadata”, format=”xml”)

for x in g.query(’SELECT ?bExifVersion WHERE {?x exif:ExifVersion ?bExifVersion }’,
initNs=ns):
print “Exif Version is: %s” % x

The problem line is the SparQL query which works for ExifVersion because it exists in the primary rdf:Description node and is listed properly in the metadata like exif:ExifVersion but because the Dublin Core Metadata has its own nodes I get blank nodes if I do something like SELECT ?acreator WHERE {?x dc:creator ?acreator }. After validating the metdata via W3.org and getting validation that the rdf is fine I am not sure how to handle this. Is it possible to do sub-queries with SparQL or how does one handle the extra node stuff. Can someone from the w3 comment?

Nevermind: I’m doing it wrong :-) Will update this entry when i’m complete.