Post details: Javascript RDFParser from Tabulator

Nov 25, 2006 : Javascript RDFParser from Tabulator

David Sheets introduces himself and the new RDF/XML parser he added to the Tabulator all-javascript RDF browser. I've been using the RDF parser from Jim Ley in a generic JavaScript RDF Editor (to work with any OWL/schema files; no public release yet, but let me know if you're interested, especially in helping out). So recently I worked on using Tabulator's rdf parser to see if it was better. It seems to be designed a bit better (separate data store from parser from XML loading) and David's post says it is more accurate and often faster.

I had been hoping to find some additional functionality to use in my JsRdfEditor. Namely, modelling the RDF document instead of just getting all the triples. For example, knowing where a nodeID was used, and the XML arrangement of the triples. That way the JsRdfEditor could parse a file, add some triples, and output a new document that is arranged much like the one that was loaded. But no luck there; sounds like I'll have to add that capability to the parser myself, if I want to have elegant RDF/XML output.

So here's how you can use Tabulator's RDF Parser in your own projects:


// depends on:
//  dig.csail.mit.edu/2005/ajar/ajaw/rdf/term.js
//  dig.csail.mit.edu/2005/ajar/ajaw/uri.js
//  dig.csail.mit.edu/2005/ajar/ajaw/rdf/rdfparser.js

// TestStore implementation from dig.csail.mit.edu/2005/ajar/ajaw/test/rdf/rdfparser.test.html
// see also RDFIndexedFormula from dig.csail.mit.edu/2005/ajar/ajaw/rdf/identity.js
//  (extends RDFFormula from dig.csail.mit.edu/2005/ajar/ajaw/rdf/term.js no indexing and smushing)
// for the real implementation used by Tabulator which uses indexing and smushing
var store = new TestStore()
var parser = new RDFParser(store);
parser.reify = parser.forceRDF = true;
// forceRDF isn't used??


var url = 'http://something.or/other';

// get the XML
var xhr = XMLHTTPFactory(); // returns a new XMLHttpRequest, or ActiveX XMLHTTP object
if (xhr.overrideMimeType) {
    xhr.overrideMimeType("text/xml");
}
// the "data/" path and encoding is just how I store files locally
xhr.open("GET", "data/" + encodeURIComponent(encodeURIComponent(url)), false);
xhr.send("");
var nodeTree = xhr.responseXML;
if (nodeTree === null && xhr.responseText !== null) {
    // Only if the server fails to set Content-Type: text/xml AND xmlhttprequest doesn't have the overrideMimeType method
    console.debug("no responseXML, parsing responseText");
    nodeTree = (new DOMParser()).parseFromString(xhr.responseText, 'text/xml');
}
// must be an XML document node tree
parser.parse(nodeTree,url);

// use FireBug extension to inspect console.debug'd objects
// Using TestStore you can access store.triples
console.debug('store',store);
Technorati tags:

Comments, Pingbacks:

Comment from: Chris Zeriouz [Visitor] · http://productselected.com/zeriouz
I would like to present you Zeriouz.Zeriouz is the most simple traffic generating network online. All you have to do is enter your domain into the homepage. Then you will be taken to step 2 which allows you to check your referrers and make sure they are following the rules. Once you've moderated your referrers, hit submit at the bottom of that page and follow the directions from there. Becoming a zeriouz Network Partner takes only minutes.
Permalink 09/16/08 @ 18:47
Comment from: JavaScript Tutorials [Visitor] · http://www.freeitsolutions.com/javascript/
Cool! It just works man!
Permalink 08/11/09 @ 01:15
Comment from: Aliza [Visitor] · http://www.google.com
wow
Permalink 03/18/10 @ 05:58
Comment from: Dan Brickley [Visitor] · http://danbri.org/words/
Hi there! I've been trying to get this to work following your five-year old instructions. It's not quite doing it, ... but I have skeleton of how to add it into Firefox 'contacts in the browser' extension if you're interested, see http://wiki.foaf-project.org/w/FirefoxContacts#FOAF_patch
Permalink 06/12/10 @ 13:41

Leave a comment:

Your email address will not be displayed on this site.
Your URL will be displayed.
What is the 2-letter abbreviation for Michigan?
Allowed XHTML tags: <p, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small>
Options:
 
(Line breaks become <br />)
(Set cookies for name, email & url)

<  September 2017  >
Mon Tue Wed Thu Fri Sat Sun
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  

Categories


Archives

Misc

Syndicate this blog XML

powered by
b2evolution