Parsing RDF/XML problems

69 views
Skip to first unread message

mhausenblas

unread,
Apr 26, 2009, 10:18:10 AM4/26/09
to rdfQuery
Hey there,

Got a problem with RDF/XML parsing, maybe Jenni has a hint? ;)

I wanna deref a URI and list all subjects (of a certain type). Here is
my code:

function listTargetSubjects(subjectURI) {
$.ajax({ // dereference the subject URI and list the subjects of the
returned RDF graph
url: "relay.php",
data: "URI=" + escape("http://www.w3.org/People/Berners-Lee/card"),
success: function(data, status){
var subjectdb = $.rdf().databank.load(data);
var outsubjectlist = "<ul>";
var targetQuery = $.rdf({ databank: subjectdb })
.prefix('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#')
.prefix('foaf','http://xmlns.com/foaf/0.1/')
.where('?target rdf:type foaf:Person')
.each(function () {
var tURI = this.target.uri;
outsubjectlist += "<li>" + tURI + "</li>";
});
outsubjectlist += "</ul>";
return outsubjectlist;
},
error: function(XMLHttpRequest, status, errorThrown){
alert('Can not fetch data from ' + subjectURI);
}
});
}

The fetch works, but then I run into an out-of-memory. Any idea?

Cheers,
Michael

Jeni Tennison

unread,
Apr 26, 2009, 4:26:17 PM4/26/09
to rdfq...@googlegroups.com, mhausenblas
Michael,


Sorry, I don't. Not having the relay.php stuff, I tried the following:

$(document).ready(function () {
var req = new XMLHttpRequest();
req.open("GET", "card.rdf", false);
req.send(null);
var data = req.responseXML;


var subjectdb = $.rdf().databank.load(data);
var outsubjectlist = "<ul>";
var targetQuery = $.rdf({ databank: subjectdb })
.prefix('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#')
.prefix('foaf','http://xmlns.com/foaf/0.1/')

.where('?target a foaf:Person')
.each(function () {
var tURI = this.target.value;


outsubjectlist += "<li>" + tURI + "</li>";
});
outsubjectlist += "</ul>";

console.log(outsubjectlist);
});

and the RDF/XML parsing seems to have worked fine and pulled out a
bunch of people. Certainly there was no out of memory error (in fact
it worked surprisingly quickly!).

So I wonder if there's some bad interaction with the AJAX request
somehow. Either that or my Mac has more memory. Perhaps you can put in
some logging to discover which part of the code is causing the out-of-
memory error (the loading of the RDF/XML or the querying of it)?

Note that in the above I changed the line:

tURI = this.target.uri;

to

tURI = this.target.value;

and the line:

.where('?target rdf:type foaf:Person')

to:

.where('?target a foaf:Person')

The latter is aesthetic, the former a bug in the original code (I
removed the .uri property in favour of .value a while ago).

Sorry I can't be more help,

Jeni
--
Jeni Tennison
http://www.jenitennison.com

Michael Hausenblas

unread,
Apr 27, 2009, 4:24:57 PM4/27/09
to Jeni Tennison, rdfq...@googlegroups.com
Jeni,

Thanks a lot for your help; very much appreciated!

> req.open("GET", "card.rdf", false);

Hm. Anyway, still the parsing of a *remote* RDF/XML doesn't work. The
'relay.php' is essentially:

<?php
if (isset($_GET['URI'])) {
$URI = $_GET['URI'];
curl_get_file_contents($URI);
}

function curl_get_file_contents($URI) {
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_VERBOSE, 0);
curl_setopt($c, CURLOPT_HTTPGET, 1);
curl_setopt($c, CURLOPT_HEADER, 0);
curl_setopt($c, CURLOPT_URL, $URI);
curl_setopt($c, CURLOPT_TIMEOUT, 30);
echo curl_exec($c);
curl_close($c);
}

?>

But still, it takes ages to execute, then eats up all memory and I have to
force-quit FF.

> ... Either that or my Mac has more memory. ...

Are 4GB sufficient? ;)


> Perhaps you can put in
> some logging to discover which part of the code is causing the out-of-
> memory error (the loading of the RDF/XML or the querying of it)?

Unfortunately not. It dies before I even can react ...

Btw, the entire code is now available at [1] ... I still get weird
'uncaught exception: [object Object]' and I don't know where to look at (for
example using the lidaman bookmarklet from [2] on my FOAF homepage [3]).

> The latter is aesthetic, the former a bug in the original code (I
> removed the .uri property in favour of .value a while ago).

I guess we need to update the Wiki; it's still full of '.uri' ;)

> Sorry I can't be more help,

Your are! Always! :)

Cheers,
Michael

[1] http://bitbucket.org/mhausenblas/lidaman/
[2] http://ld2sd.deri.org/lidaman/
[3] http://sw-app.org/mic.xhtml
--
Dr. Michael Hausenblas
DERI - Digital Enterprise Research Institute
National University of Ireland, Lower Dangan,
Galway, Ireland, Europe
Tel. +353 91 495730
http://sw-app.org/about.html
http://webofdata.wordpress.com/

Dan Brickley

unread,
Apr 27, 2009, 5:40:25 PM4/27/09
to Michael Hausenblas, rdfq...@googlegroups.com
On 27/4/09 22:24, Michael Hausenblas wrote:
> Jeni,
>
> Thanks a lot for your help; very much appreciated!
>
>> req.open("GET", "card.rdf", false);
>
> Hm. Anyway, still the parsing of a *remote* RDF/XML doesn't work. The
> 'relay.php' is essentially:

[snip] Hmm, nope!

I just tried it locally at
http://localhost/proxy.php?URI=file:///etc/passwd and didn't like what I
saw... :)

Dan

Michael Hausenblas

unread,
Apr 28, 2009, 12:52:01 AM4/28/09
to Dan Brickley, rdfq...@googlegroups.com

Dan,

> [snip] Hmm, nope!

What, nope? :)

> I just tried it locally at
> http://localhost/proxy.php?URI=file:///etc/passwd and didn't like what I
> saw... :)

Based on your recent experience I do understand what you mean, but can you
be a bit more specific, please? Can you propose an alternative solution? I'm
certainly no skilled developer, just doing proof of concept things so that
one can take over to implement it properly. But I'm eager to learn ...

Cheers,
Michael

--
Dr. Michael Hausenblas
DERI - Digital Enterprise Research Institute
National University of Ireland, Lower Dangan,
Galway, Ireland, Europe
Tel. +353 91 495730
http://sw-app.org/about.html
http://webofdata.wordpress.com/

Dan Brickley

unread,
Apr 28, 2009, 3:02:05 AM4/28/09
to Michael Hausenblas, rdfq...@googlegroups.com
On 28/4/09 06:52, Michael Hausenblas wrote:
> Dan,
>
>> [snip] Hmm, nope!
>
> What, nope? :)
>
>> I just tried it locally at
>> http://localhost/proxy.php?URI=file:///etc/passwd and didn't like what I
>> saw... :)
>
> Based on your recent experience I do understand what you mean, but can you
> be a bit more specific, please? Can you propose an alternative solution? I'm
> certainly no skilled developer, just doing proof of concept things so that
> one can take over to implement it properly. But I'm eager to learn ...

Basic idea is that the code you shipped will dereference *any* URI that
the PHP interpreter can access. This includes file: URIs on the box it
runs on, plus perhaps http://intranet/ or others that shouldn't be
proxied. So it should minimally disallow file: URIs, and come with a big
health warning plus example of configuring to exclude URIs that
shouldn't be accessed.

cheers,

Dan

Michael Hausenblas

unread,
Apr 28, 2009, 4:32:05 AM4/28/09
to Dan Brickley, rdfq...@googlegroups.com

Dan,

Thanks, yeah, will do. Btw, anyone aware of a conneg module for JS?

Maybe worth an issue for rdfquery. Jenni, what do you think?

Cheers,
Michael

--
Dr. Michael Hausenblas
DERI - Digital Enterprise Research Institute
National University of Ireland, Lower Dangan,
Galway, Ireland, Europe
Tel. +353 91 495730
http://sw-app.org/about.html
http://webofdata.wordpress.com/


> From: Dan Brickley <dan...@danbri.org>
> Date: Tue, 28 Apr 2009 09:02:05 +0200
> To: Michael Hausenblas <michael.h...@deri.org>
> Cc: <rdfq...@googlegroups.com>
> Subject: Re: [rdfQuery] Re: Parsing RDF/XML problems
>

Dan Brickley

unread,
Apr 28, 2009, 4:36:36 AM4/28/09
to Michael Hausenblas, rdfq...@googlegroups.com
On 28/4/09 10:32, Michael Hausenblas wrote:
> Dan,
>
> Thanks, yeah, will do. Btw, anyone aware of a conneg module for JS?
>
> Maybe worth an issue for rdfquery. Jenni, what do you think?

I think you can set headers for this in the XML HTTP Request API,
http://www.w3.org/TR/XMLHttpRequest/#setrequestheader

You can do this from jquery, see
http://blog.jquery.com/2006/12/12/jquery-104/

cheers,

Dan

Michael Hausenblas

unread,
Apr 28, 2009, 4:56:51 AM4/28/09
to Dan Brickley, rdfq...@googlegroups.com

Thanks! Yes, seems to work. Nevertheless, I think I'm gonna put together an
RDF-conneg-module that handles some low-level stuff (esp., interesting re
RDF/XML, RDFa, etc.). If and when Jenni is ok with it, we can put it into
the 'official' rdfquery distribution.

Cheers,
Michael

--
Dr. Michael Hausenblas
DERI - Digital Enterprise Research Institute
National University of Ireland, Lower Dangan,
Galway, Ireland, Europe
Tel. +353 91 495730
http://sw-app.org/about.html
http://webofdata.wordpress.com/


> From: Dan Brickley <dan...@danbri.org>
> Date: Tue, 28 Apr 2009 10:36:36 +0200
> To: Michael Hausenblas <michael.h...@deri.org>
> Cc: <rdfq...@googlegroups.com>
> Subject: Re: [rdfQuery] Re: Parsing RDF/XML problems
>

Jeni Tennison

unread,
Apr 28, 2009, 4:18:39 PM4/28/09
to mhausenblas, rdfq...@googlegroups.com
Michael,

> Hm. Anyway, still the parsing of a *remote* RDF/XML doesn't work.

OK, but I'm not sure how I can help without you doing a little more
debugging. Could you check that your AJAX call is actually returning
an XML document rather than a string or something? Could you try
storing that XML document in an intermediate variable and then parsing
it outside the AJAX call? Could you try a smaller test RDF/XML
document to see whether it's the size of the document (though I don't
think it is)? Could you try the RDF/XML document on your local server
rather than getting it through your proxy, to see if there's some
issue there?

Let me know what you find out.

Michael Hausenblas

unread,
Apr 30, 2009, 1:41:42 AM4/30/09
to Jeni Tennison, rdfq...@googlegroups.com

Jeni,

Local seems to work fine. However, when I'm trying to parse a remote one
(via relay.php) it fails. My hunch is that I have to change relay.php to
serve the right media type and content. Will keep you posted ...

Thanks again for all your support!

Cheers,
Michael

--
Dr. Michael Hausenblas
DERI - Digital Enterprise Research Institute
National University of Ireland, Lower Dangan,
Galway, Ireland, Europe
Tel. +353 91 495730
http://sw-app.org/about.html
http://webofdata.wordpress.com/


> From: Jeni Tennison <je...@jenitennison.com>
> Date: Tue, 28 Apr 2009 21:18:39 +0100
> To: Michael Hausenblas <michael.h...@deri.org>
> Cc: <rdfq...@googlegroups.com>
> Subject: Re: [rdfQuery] Re: Parsing RDF/XML problems
>

Reply all
Reply to author
Forward
0 new messages