linkeddata / rdflib.js Goto Github PK
View Code? Open in Web Editor NEWLinked Data API for JavaScript
Home Page: http://linkeddata.github.io/rdflib.js/doc/
License: Other
Linked Data API for JavaScript
Home Page: http://linkeddata.github.io/rdflib.js/doc/
License: Other
We need to be able to read JSON/LD as well as the other formats. Just adding this formally to the issue list now. @martinmr has been working on this, possibly port from gold, possibly port from other JS implementation.
There is an issues with increasingly servers switching to https from http, and in the semantic web this causes the problem that the same thing may end up refereed to accidentally or deliberately with both URIs (where the rest of the URI after the scheme is the same). One approach we could try if to pickup the Strict-Transport-Security: header from an HTTPS response and remember it and us it to then in the triple store, in the whole RDF system from then on canonicalize every http://x/y for all y for the x of the request.
http://tools.ietf.org/html/rfc6797
http://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security
This needs level-breaking but that is life.
Hi,
Using the latest node version I have the folowing error :
B:\Dropbox\workspace\webid\lib\node-rdflib.js:2544
$rdf.Literal.prototype.hashString = $rdf.Literal.prototype.toNT;
^
TypeError: Cannot read property 'prototype' of undefined
at B:\Dropbox\workspace\webid\lib\node-rdflib.js:2544:13
at B:\Dropbox\workspace\webid\lib\node-rdflib.js:3012:2
at Object.<anonymous> (B:\Dropbox\workspace\webid\lib\node-rdflib.js:7072:14
rdflib uses the wrong mime type for JSON-LD: application/json+ld
instead of application/ld+json
.
The licence of the code is not clear. It should be plastered around as much as possible.
This is my code
var TIMEOUT = 90000;
var g = $rdf.graph();
var f = $rdf.fetcher(g, TIMEOUT);
var followURI = "http://schema.rdfs.org/all.nt";
var SCHEMA = $rdf.Namespace('http://www.w3.org/2000/01/rdf-schema')
f.nowOrWhenFetched(followURI, undefined, function(ok, body){
console.log(g.statementsMatching(undefined, SCHEMA("Class"), undefined));
})
Apparently I get an object g which is not the followURI I pass but this:
thisURI: 'http://dig.csail.mit.edu/2005/ajar/ajaw/rdf/sources.js#SourceFetcher',
Am I doing something wrong? What is the idea of passing followURI if it will use thisURI?
Henry's FOAF profile is not currently working; which means the socialbook example isn't working in the example for linkeddata.github.io.
Perhaps fix it or perhaps replace with a DOAP or similar example, which could then also incorporate foaf info.
Other thoughts; WAC, rww.io, WebID, FOAF Creation tool perhaps integrated with rww.io / data.fm, etc.
This is the second broken build on NPM, this is a clear call to have tests & travis soon!
/Users/mozilla/Proj/gits/node-webid/node_modules/rdflib/dist/rdflib.js:21085
module.exports = jsonldjs;
^
ReferenceError: jsonldjs is not defined
at Object.<anonymous> (/Users/mozilla/Proj/gits/node-webid/node_modules/rdflib/dist/rdflib.js:21085:18)
at Object../request (/Users/mozilla/Proj/gits/node-webid/node_modules/rdflib/dist/rdflib.js:21086:4)
at s (/Users/mozilla/Proj/gits/node-webid/node_modules/rdflib/dist/rdflib.js:7488:254)
at /Users/mozilla/Proj/gits/node-webid/node_modules/rdflib/dist/rdflib.js:7488:305
at Object.async (/Users/mozilla/Proj/gits/node-webid/node_modules/rdflib/dist/rdflib.js:24032:14)
at s (/Users/mozilla/Proj/gits/node-webid/node_modules/rdflib/dist/rdflib.js:7488:254)
at e (/Users/mozilla/Proj/gits/node-webid/node_modules/rdflib/dist/rdflib.js:7488:425)
at /Users/mozilla/Proj/gits/node-webid/node_modules/rdflib/dist/rdflib.js:7488:443
at Object.<anonymous> (/Users/mozilla/Proj/gits/node-webid/node_modules/rdflib/dist/rdflib.js:25646:3)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/Users/mozilla/Proj/gits/node-webid/test/webid.js:1:76)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at /Users/mozilla/Proj/gits/node-webid/node_modules/mocha/lib/mocha.js:192:27
at Array.forEach (native)
at Mocha.loadFiles (/Users/mozilla/Proj/gits/node-webid/node_modules/mocha/lib/mocha.js:189:14)
at Mocha.run (/Users/mozilla/Proj/gits/node-webid/node_modules/mocha/lib/mocha.js:422:31)
at Object.<anonymous> (/Users/mozilla/Proj/gits/node-webid/node_modules/mocha/bin/_mocha:398:16)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
When a callback is fired, the xhr object is not passed, neither the status code.
this.failFetch = function(xhr, status) {
console.error("failFetch called with",xhr,status);
this.addStatus(xhr.req, status)
kb.add(xhr.uri, ns.link('error'), status)
this.requested[$rdf.uri.docpart(xhr.uri.uri)] = false
this.fireCallbacks('fail', [xhr.requestedURI, status])
xhr.abort()
return xhr
}
The status here is a String usually, like "XHR Error: "
When the fetch failed it would be nice to have a way to get the http status code in the callbacks when calling requestURI
i have only cloned the repo and created the dist and if i open example/people/book.html the following error occurs:
Uncaught TypeError: Cannot call method 'protocol' of undefined
in rdflib.js:7238
var pcol = $rdf.Util.uri.protocol(docuri);
maybe i forgot something? do i need something else? thanks in advance!
Got the following error running under nodejs
node_modules/rdflib/dist/rdflib.js:24634
if ($rdf.Fetcher.crossSiteProxyTemplate && document && document.locati
^
ReferenceError: document is not defined
This was running under the latest npm so may be fixed already. I could not find it in
Line 6993 in bece080
For example
Right now I have no means of checking which version of rdflib.js I'm using, hence filing issues is not straight forward.
To use the the lib I need to build the package from source, it would be easier if there were releases with pre-build and minified version. This way one could just pull in a specific version with e.a. Bower
I just tried the following:
$ npm install rdflib
|
> [email protected] postinstall /Users/mozilla/Proj/gits/ldnode/node_modules/rdflib
> make clean all
make: *** No rule to make target `clean'. Stop.
npm ERR! Darwin 14.3.0
npm ERR! argv "/usr/local/bin/iojs" "/usr/local/bin/npm" "install" "rdflib"
npm ERR! node v2.2.1
npm ERR! npm v2.11.0
npm ERR! code ELIFECYCLE
npm ERR! [email protected] postinstall: `make clean all`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] postinstall script 'make clean all'.
npm ERR! This is most likely a problem with the rdflib package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! make clean all
npm ERR! You can get their info via:
npm ERR! npm owner ls rdflib
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/mozilla/Proj/gits/ldnode/npm-debug.log
Hi,
I'm looking for a basic example on how to parse RDF content and retrieve the triples it contains. I'm using Node.js. Something like:
rdflib.parse('<!-- RDF/XML content -->', function(triples) {
for(var i in triples)
console.log(triples[i].subject + triples[i].predicate + triples[i].object)
})
if (typeof module != 'undefined' && module && module.exports) { //Node.js
var XMLHttpRequest = require("XMLHttpRequest").XMLHttpRequest;
return new XMLHttpRequest()
}
https://github.com/linkeddata/rdflib.js/blob/master/util.js#L120
Is there any reason that this require is in camel case? When running in node I get the following error:
Error: Cannot find module 'XMLHttpRequest'
Lower case would appear to work fine, as per the docs.
https://www.npmjs.org/package/xmlhttprequest
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var xhr = new XMLHttpRequest();
I'd happily make the change here, but just wanted to know if there's anything that might break moving this to lowercase?
Hi,
I think i found a bug when i'am trying to serialize in N3 a foaf graph.
the bug is situated at the line 31
Only the name of de foaf person is loaded. In the second alert (line 36) I have nothing.
var FOAF = $rdf.Namespace("http://xmlns.com/foaf/0.1/");
var RDF = $rdf.Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#");
var RDFS = $rdf.Namespace("http://www.w3.org/2000/01/rdf-schema#");
var OWL = $rdf.Namespace("http://www.w3.org/2002/07/owl#");
var DC = $rdf.Namespace("http://purl.org/dc/elements/1.1/");
var RSS = $rdf.Namespace("http://purl.org/rss/1.0/");
var XSD = $rdf.Namespace("http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-");
var CONTACT = $rdf.Namespace("http://www.w3.org/2000/10/swap/pim/contact#");
function wall_loader(uri){
$rdf.Fetcher.crossSiteProxyTemplate="http://data.fm/proxy?uri={uri}";
load_foaf_profile(uri);
};
/**
* This function load the foaf profile of one person
* @param profiles : Tableau d'amis
*/
function load_foaf_profile(profile_uri){
var friends = [];
var store = new $rdf.IndexedFormula();
var docURI = profile_uri.slice(0, profile_uri.indexOf('#'));
var person = $rdf.sym(profile_uri);
var fetch = $rdf.fetcher(store, undefined, true);
var graph = $rdf.sym($rdf.Fetcher.crossSiteProxy(docURI));
function serialize_profile_store(document_uri){
var sz = $rdf.Serializer(store);
sz.suggestPrefix("foaf","http://xmlns.com/foaf/0.1/");
var newSts = store.statementsMatching(undefined, undefined, undefined, $rdf.sym(document_uri)).slice();
return sz.statementsToN3(newSts); // It's empty !
}
fetch.nowOrWhenFetched(docURI, undefined, function(){
alert(store.any(person, FOAF('name')));
alert(serialize_profile_store(docURI)); // This alert does not work.
});
}
I think I have a solution for this. The origin of the error is a Reference Function Error.
I have make patch to solve this with this current version of rdflib.js
I think that the problème is situated at the line 475 of the file serialize.js (serialize.js)
In this patch I add the keyword "this" before "termToN3(expr.datatype, stats)" and i put the function bellow after this.
__Serializer.prototype.termToN3 = function termToN3(expr, stats) {
switch (expr.termType) {
case 'formula':
var res = [ '{' ];
res = res.concat(statementListToTree(expr.statements));
return res.concat([ '}' ]);
case 'collection':
var res = [ '(' ];
for ( var i = 0; i < expr.elements.length; i++) {
res.push([ objectTree(expr.elements[i], stats) ]);
}
res.push(')');
return res;
default:
return this.atomicTermToN3(expr);
}
};
And after it works.
I uploaded the patch at : (http://grayfoxkiller.free.fr/Fix_N3_Serialization.patch)
use of patch : git apply Fix_N3_Serialization.patch
I posted a demo to view this bug at : (http://grayfoxkiller.free.fr/serialize.zip)
It would be great to have a really simple example of applying rdflib.js to example blocks in standards docs, maybe with:
Often, there's only RDF/XML; which is not as easy to read as N3/Turtle.
Challenges:
seeAlso: #42
I have had good success reading RDF/XML, Turtle and JSON-LD resources with rdflib, and doing in-memory SPQRQL-like queries on the graphs. However, I would like to explore using jsonld.js so that applications can use native JSON and sift.js instead of the rdflib IndexedFormulas and queries.
Unfortunately jsonld.js only parses application/nquads. But it has a means of registering other parsers. I tried to create a jsonld parser for RDF/XML using rdf-ext:
var rdf = require('rdf-ext')(); var rdfXmlParser = function(input, callback) { var parser = new rdf.RdfXmlParser(); parser.parse(input, function doneParsing(dataset) { callback(undefined, {'graph': dataset.toArray()}); }); } jsonld.registerRDFParser('application/rdf+xml', rdfXmlParser); jsonld.fromRDF(rs_xml.toString(), {}, function loadRDFXML(err, doc) { ...
But this doesn't work since the RDF dataset format expected by jsonld requires the triples to be URIs or primitive types, not the objects that are created by the rdf-ext parsers.
I noticed that rdflib.js wraps jsonld. Is there a way to use the wrapped jsonld fromRDF() method to convert an rdflib graph into JSON that can be used by jsonld and sift.js? Of is there a better way to accomplish what I'm trying to do?
Thanks for the help.
// Setup the request
if (typeof jQuery !== 'undefined' && jQuery.ajax) {
var xhr = jQuery.ajax({
url: uri2,
accepts: {'*': 'text/turtle,text/n3,application/rdf+xml'},
processData: false,
error: function(xhr, s, e) {
if (s == 'timeout')
sf.failFetch(xhr, "requestTimeout");
else
onerrorFactory(xhr)(e);
},
success: function(d, s, xhr) {
onreadystatechangeFactory(xhr)();
}
});
} else {
var xhr = $rdf.Util.XMLHTTPFactory();
xhr.onerror = onerrorFactory(xhr);
xhr.onreadystatechange = onreadystatechangeFactory(xhr);
try {
xhr.open('GET', uri2, this.async);
} catch (er) {
return this.failFetch(xhr, "XHR open for GET failed for <"+uri2+">:\n\t" + er);
}
}
I use the JQuery mode and the timeout attribute of ajax call is not set in this part of the code. I don't see it either in the non jquery code.
I've tried to setup an hardcoded value and it works as expected: the fail callbacks are fired. So it should be easy to fix :)
I am still very new to Javascript and tabulator. So I ported the
old card demo to the new rdflib library and added a sprinkling of
jquery too. It is now running here:
http://bblfish.github.com/rdflib.js/example/people/card.html
But it does not work in Firefox or Opera for me. There is no problem
with Chrome or Safari it seems.
( I changed the name from book to card, as I am going to be
working on a bigger demo next that can browse cards )
g = $rdf.graph()
$rdf.parse("_:x1 <http://example1> <http://example2> <http://graph> .\n"+
"_:x1 <http://example3> <http://example4> <http://graph> .\n",
g, null, 'application/nquads', function() {})
g.statements[0].subject.sameTerm(g.statements[1].subject)
false
That test should return true, since I referred to the subject as "_:x1" in both my input statements.
It would be nice to be able to specify additional headers to the fetcher (or to nowOrWhenFetched)
Our usecase with @bblfish is that some RWW WAC protected resources are public for all (wac mode READ) but the owner has additional permissions on it (like READ WRITE).
As the resource is public for all, the server doesn't need to auth the client using a X509 WebID certificate and can give the content to the client. The matter is that we introduced a response header Allow
that lists all http verbs that can be used by the client to use this resource.
So if anyone can READ, anyone can get the resource without auth/certificate, and will get Allow: GET
. The problem is for the resource owner. The resource owner can get its own resource in 2 different modes: authenticated and not authenticated. As the resource is public, the server doesn't ask for a certificate by default. The resource owner's client needs to send a hint to the server to ask for an authentication even if the resource is public. This way the server can return the appropriate header for the owner's client: Allow: GET,POST,PUT,PATCH,DELETE
This should probably be discussed with @deiu and @melvincarvalho but anyway I think it would be great to support some flexible way to customize the request in rdflib.js
At least in Firefox (tested with 19.0.2), #text nodes longer than 4096 are split into multiple adjacent text nodes (https://bugzilla.mozilla.org/show_bug.cgi?id=157299 and related). This seems to break parsing in RDFParser. It doesn't crash, the text node is simply ignored.
It will take me a while to figure out how to fix this without breaking anything else in the RDFParser. Perhaps it's a bit easier for someone with good knowledge of RDFParser internals.
E.g. the following Zotero generated RDF fails to parse the bib:Memo/rdf:value
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:z="http://www.zotero.org/namespaces/export#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:bib="http://purl.org/net/biblio#"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:link="http://purl.org/rss/1.0/modules/link/">
<bib:Book rdf:about="urn:isbn:0201634465">
<z:itemType>book</z:itemType>
<dcterms:isReferencedBy rdf:resource="#item_1282"/>
<dc:title>Essential Com: The Component Object Model</dc:title>
</bib:Book>
<bib:Memo rdf:about="#item_1282">
<rdf:value><p>2013-03-02 (HS) Chapter 1 "COM as a Better C++"</p>
<ul>
<li>C-style structs can be held invariant across compilers</li>
<li>all compilers can be coerced to pass function parameters in the same order, e.g. using Win32 API compiler directives: WINBASEAPI void WINAPI Sleep(DWORD dwMsecs);</li>
<li>all C++ compilers on a given platform implement the virtual function call mechanism equivalently (for classes that have no data members and at most one base class). Two basic techniques: CFRONT technique / adjustor thunk technique (Win32). But on any given platform, one technique dominates.</li>
</ul>
<p>Example:</p>
<pre>// ifaststring.h<br />class IFastString {<br />public:<br /> virtual int Length(void) const = 0;<br /> virtual int Find(const cha * psz) const = 0;<br />};<br />extern "C"<br />IFastString *CreateFastString(const char *psz);<br /><br />// faststring.cpp (part of DLL)<br />IFastString *CreateFastString(const char *psz) {<br /> return new FastString(psz);<br />}<br /></pre>
<p>Remaining problem: object destruction.</p>
<ul>
<li>not having virtual destructor results in memory leaks</li>
<li>provide virtual destructor and let client delete object - not compiler independent (position of virtual destructor in vtable varies)</li>
</ul>
<p>Solution:</p>
<ul>
<li>provide separate Delete() method</li>
</ul>
<p>Advantages:</p>
<ul>
<li>DLL binary compatible across compilers</li>
<li>different DLLs that implement the interface can be loaded dynamically</li>
</ul>
<p>Remaining problem:</p>
<ul>
<li>interface signature and semantics must never change (otherwise clients using different DLL versions would break)</li>
<li>how to provide additional functionality over time?</li>
</ul>
<p>Solution 1:</p>
<ul>
<li>add new methods at the end</li>
</ul>
<p>Drawback:</p>
<ul>
<li>not completely compatible: new client will not work with older DLL that provides fewer methods than newer client expects</li>
</ul>
<h2>Multiple abstract interfaces</h2>
<p>Description:</p>
<ul>
<li>add new methods in a new interface that extends the existing one; e.g. FindN() in addition to Find()</li>
<li>let the client use e.g. dynamic_cast to get access to the new interface</li>
<li>add new orthogonal functionality (e.g. persistence) in a separate interface, let the implementation class implement multiple interfaces</li>
</ul>
<p>Drawback:</p>
<ul>
<li>dynamic cast is compiler dependent</li>
</ul>
<h2>Method for dynamic cast</h2>
<ul>
<li>provide special method for dynamic cast in the DLL</li>
</ul>
<p>Example:</p>
<pre>class IPersistentObject {<br />public:<br /> virtual void *Dynamic_Cast(const char *pszType) = 0;<br /> virtual void Delete(void) = 0;<br /> ...<br />};<br />class IFastString {<br />public:<br /> virtual void *<strong>Dynamic_Cast</strong>(const char *pszType) = 0;<br /> virtual void Delete(void) = 0;<br /> ...<br />};<br /><br />// faststring<br />class FastString : public IFastString, public IPersistentObject { ... }<br /><br />void *FastString::Dynamic_Cast(const char *pszType) {<br /> if (strcmp(pszType, "IFastString") == 0)<br /> return static_cast&lt;IFastString*&gt;(this);<br />...<br />}<br /><br />// client<br />bool SaveString(IFastString *pfs, const char *pszFN) {<br /> bool bResult = false;<br /> IPersistentObject *ppo = (IPersistentObject*) pfs-&gt;Dynamic_Cast("IPersistentObject");<br /> if (ppo) bResult = ppo-&gt;Save(pszFN);<br /> return bResult;<br />}<br /></pre>
<p>Drawback:</p>
<ul>
<li>client may delete the same object once for each interface =&gt; disaster</li>
</ul>
<h2>Methods for resource management (reference counting)</h2>
<p>Example:</p>
<pre>class IExtensibleObject {<br />public:<br /> virtual void *Dynamic_Cast(const char *pszType) = 0;<br /> virtual void DuplicatePointer(void) = 0;<br /> virtual void DestroyPointer(void) = 0;<br />};<br /></pre>
<p>Rules:</p>
<ul>
<li>when an interface pointer is duplicated, a call to DuplicatePointer is required</li>
<li>when an interface pointer is no longer in use, a call to DestroyPointer is required</li>
</ul>
<h2>Where Are We?</h2>
<p>"... In short, we have just engineered the Component Object Model."</p></rdf:value>
</bib:Memo>
</rdf:RDF>
Let me know if there is any other info you need me to supply.
jra-ibm-work:node_modules jamsden$ npm install rdflib > [email protected] prepublish /Users/jamsden/Developer/node/node_modules/rdflib > make clean all make: *** No rule to make target `clean'. Stop. npm ERR! addLocalDirectory Could not pack /Users/jamsden/Developer/node/node_modules/rdflib to /Users/jamsden/.npm/rdflib/0.2.6/package.tgz npm ERR! addLocal Could not install /Users/jamsden/Developer/node/node_modules/rdflib npm ERR! Darwin 14.4.0 npm ERR! argv "node" "/usr/local/bin/npm" "install" "rdflib" npm ERR! node v0.12.7 npm ERR! npm v2.11.3 npm ERR! code ELIFECYCLE npm ERR! [email protected] prepublish: `make clean all` npm ERR! Exit status 2 npm ERR! npm ERR! Failed at the [email protected] prepublish script 'make clean all'. npm ERR! This is most likely a problem with the rdflib package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! make clean all npm ERR! You can get their info via: npm ERR! npm owner ls rdflib npm ERR! There is likely additional logging output above. npm ERR! Please include the following file with any support request: npm ERR! /Users/jamsden/Developer/node/node_modules/npm-debug.log jra-ibm-work:node_modules jamsden$ npm install io [email protected] io └── [email protected]
node version: v0.12.7
There might be some issues with the handling of base URI.
@base
or rdf/xml has xml:base
:xml:base
attribute in the <rdf:RDF>
?When compiled, $rdf in term.coffee is treated as local object throughout the entire file, so it's never exported into the global object. I couldn't find any way to expose $rdf without a significant rewrite to term.coffee though.
Could you also include the compiled coffee files in the repo?
Given some RDF/XML that contains:
<oslc:serviceProvider> <oslc:ServiceProvider rdf:about="https://oslclnx2.rtp.raleigh.ibm.com:9443/ccm/oslc/contexts/_pMhMgPsWEeSnQvDHoYok5w/workitems/services.xml"> <dcterms:title rdf:parseType="Literal">JKE Banking (Change Management)</dcterms:title> <oslc:details rdf:resource="https://oslclnx2.rtp.raleigh.ibm.com:9443/ccm/process/project-areas/_pMhMgPsWEeSnQvDHoYok5w"/> <jfs_proc:supportLinkDiscoveryViaLinkIndexProvider rdf:parseType="Literal">false</jfs_proc:supportLinkDiscoveryViaLinkIndexProvider> <jfs_proc:supportContributionsToLinkIndexProvider rdf:parseType="Literal">true</jfs_proc:supportContributionsToLinkIndexProvider> <jfs_proc:globalConfigurationAware rdf:parseType="Literal">compatible</jfs_proc:globalConfigurationAware> <jfs_proc:consumerRegistry rdf:resource="https://oslclnx2.rtp.raleigh.ibm.com:9443/ccm/process/project-areas/_pMhMgPsWEeSnQvDHoYok5w/links"/> </oslc:ServiceProvider> </oslc:serviceProvider>
An a query such as:
someKb.the(aServiceProvider, DCTERMS('title’));
returns:
<dcterms:title rdf:parseType="Literal">JKE Banking (Change Management)</dcterms:title>
instead of the text. Am I missing something of is the dcterms:title being parsed incorrectly?
It would be useful to be able to read microdata.
Using a microdata library would be useful?
Someone cal help me in how to start in order to implement this?
I see rdflib loads jsonld.js and $rdf.parse references contentType application/json+ld. Shouldn't this be application/ld+json (which is the registered MIME type)?
$rdf.parse(rs_json.toString(), kb2, catalogURI, 'application/ld+json');
In any case, attempting to parse a JSON-LD file fails. application/ld+json gives an error that says it isn't supported. application/json+ld fails with:
/Users/jamsden/Developer/node/node_modules/rdflib/dist/rdflib.js:25504 callback(null, kb); ^ TypeError: callback is not a function at Object.tripleCallback [as _callback] (/Users/jamsden/Developer/node/node_modules/rdflib/dist/rdflib.js:25504:13) at Object.N3Parser._readInTopContext (/Users/jamsden/Developer/node/node_modules/rdflib/dist/rdflib.js:22690:19) at /Users/jamsden/Developer/node/node_modules/rdflib/dist/rdflib.js:23209:35 at Object.N3Lexer._tokenizeToEnd (/Users/jamsden/Developer/node/node_modules/rdflib/dist/rdflib.js:22312:11) at Immediate._onImmediate (/Users/jamsden/Developer/node/node_modules/rdflib/dist/rdflib.js:22572:38) at processImmediate [as _immediateCallback] (timers.js:371:17)
I'm finding it hard to wrap my head around this library. Could you provide me with a simple example that would:
Thanks in advance!
Is there documentation or a tutorial on how to parse a simple RDFa document? Because I can't find nothing ...
Hi.
When using requestURI, it is not always possible to know that there were a failure.
https://github.com/linkeddata/rdflib.js/blob/master/web.js#L1016
// Setup the request
if (typeof jQuery !== 'undefined' && jQuery.ajax) {
var xhr = jQuery.ajax({
url: uri2,
accepts: {'*': 'text/turtle,text/n3,application/rdf+xml'},
processData: false,
error: function(xhr, s, e) {
if (s == 'timeout')
sf.failFetch(xhr, "requestTimeout");
else
onerrorFactory(xhr)(e);
},
success: function(d, s, xhr) {
onreadystatechangeFactory(xhr)();
}
});
} else {
var xhr = $rdf.Util.XMLHTTPFactory();
xhr.onerror = onerrorFactory(xhr);
xhr.onreadystatechange = onreadystatechangeFactory(xhr);
try {
xhr.open('GET', uri2, this.async);
} catch (er) {
return this.failFetch(xhr, "XHR open for GET failed for <"+uri2+">:\n\t" + er);
}
}
With JQuery + usage of a proxy, the onreadystatechangeFactory will not fire the failFetch method which triggers the fail callback hook.
var onerrorFactory = function(xhr) { return function(event) {
if ($rdf.Fetcher.crossSiteProxyTemplate && document && document.location && !xhr.proxyUsed) { // In mashup situation
//
// NEVER CALLED: sf.failFetch(xhr, "XHR Error: "+event)
// But it seems to re-do the request again but
//
} else {
sf.failFetch(xhr, "XHR Error: "+event)
}
}; }
https://github.com/linkeddata/rdflib.js/blob/master/web.js#L693
As expected, the fail hook is correctly triggered when there is a no proxy.
So, when using this method with a proxy, there is no way to know that the request has terminated.
The URL for documentation (http://tabulator.org/2005/ajar/ajaw/Developer.html) in the README only shows an error : "The requested URI is inaccessible or does not exist."
It seems the default behavior of RDFLib, when a proxy template is set, is:
It seems there is no way to always go with the proxy if we want to
Upon a successful XHR request, the fetcher calls into saveResponseMetadata which then stores & resets the response headers.
However, if the loaded URL is a relative URL, $rdf.uri.protocol returns undefined and therefore the headers are empty leading to an unparsed input.
I have been trying with 5 different files and this code:
request('http://schema.rdfs.org/all.rdf', function(err, response, body) {
var kb = new $rdf.IndexedFormula();
$rdf.parse(body, kb, 'http://schema.rdfs.org/all.rdf', 'application/rdf+xml');
console.log(kb)
});
but I get:
Error trying to parse <http://schema.rdfs.org/all.rdf> as application/rdf+xml:
Error: RDF/XML syntax error: No namespace for rdf:about in http://schema.rdfs.org/all.rdf:
Error: RDF/XML syntax error: No namespace for rdf:about in http://schema.rdfs.org/all.rdf
at null.<anonymous> (/Users/mozilla/Proj/schemas/node_modules/rdflib/dist/rdflib.js:1698:23)
at parseDOM (/Users/mozilla/Proj/schemas/node_modules/rdflib/dist/rdflib.js:1828:38)
at parse (/Users/mozilla/Proj/schemas/node_modules/rdflib/dist/rdflib.js:1688:14)
at Object.parse (/Users/mozilla/Proj/schemas/node_modules/rdflib/dist/rdflib.js:8221:20)
at Request._callback (/Users/mozilla/Proj/schemas/index.js:16:10)
at Request.self.callback (/Users/mozilla/Proj/schemas/node_modules/request/request.js:372:22)
at Request.emit (events.js:98:17)
at Request.<anonymous> (/Users/mozilla/Proj/schemas/node_modules/request/request.js:1317:14)
at Request.emit (events.js:117:20)
at IncomingMessage.<anonymous> (/Users/mozilla/Proj/schemas/node_modules/request/request.js:1265:12)
Am I parsing the right way?
I can't import rdflib into my code because of failed dependencies.
npm install -g browserify
npm install babelify rdflib
import rdf from 'rdflib'
console.log(rdf)
browserify test.es6.js -t babelify --outfile test.js
[reederz@reederz little-sister (master ✗)]$ browserify test.es6.js -t babelify --outfile test.js
Error: Cannot find module './lib/_stream_duplex.js' from '/home/reederz/Source/jolocom/little-sister/node_modules/rdflib/dist'
at /home/reederz/.nvm/versions/node/v0.12.7/lib/node_modules/browserify/node_modules/resolve/lib/async.js:55:21
at load (/home/reederz/.nvm/versions/node/v0.12.7/lib/node_modules/browserify/node_modules/resolve/lib/async.js:69:43)
at onex (/home/reederz/.nvm/versions/node/v0.12.7/lib/node_modules/browserify/node_modules/resolve/lib/async.js:92:31)
at /home/reederz/.nvm/versions/node/v0.12.7/lib/node_modules/browserify/node_modules/resolve/lib/async.js:22:47
at FSReqWrap.oncomplete (fs.js:95:15)
The error persists even I don't use babel and transform ES5 code.
I think i found a bug when i'am trying to load 3 foaf profiles with rdflib.js.
The bug is in the bug/js/loader.js file at line 34
Only the content from the last URI is loaded in the DOM it seems, even though all 3 uris are fetched as witenessed by the traffic on Wireshark.
var FOAF = $rdf.Namespace("http://xmlns.com/foaf/0.1/");
var RDF = $rdf.Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#");
var RDFS = $rdf.Namespace("http://www.w3.org/2000/01/rdf-schema#");
var OWL = $rdf.Namespace("http://www.w3.org/2002/07/owl#");
var DC = $rdf.Namespace("http://purl.org/dc/elements/1.1/");
var RSS = $rdf.Namespace("http://purl.org/rss/1.0/");
var XSD = $rdf.Namespace("http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#dt-");
var CONTACT = $rdf.Namespace("http://www.w3.org/2000/10/swap/pim/contact#");
graphs = {};
var foaf_profiles = ["http://b4mad.net/FOAF/goern.rdf#goern","http://bigasterisk.com/foaf.rdf#drewp","http://crschmidt.net/foaf.rdf#crschmidt"];
function initialize() {
$rdf.Fetcher.crossSiteProxyTemplate="http://data.fm/proxy?uri={uri}";
for(var i=0 ; i < foaf_profiles.length ; i++){
load_foaf_profile(foaf_profiles[i])
}
}
/**
* This function load all foaf profile and put her in the HTML5 DOM
* @param profile_uri
*/
function load_foaf_profile(profile_uri){
var profile = $rdf.sym(profile_uri);
var docURI = profile_uri.slice(0, profile_uri.indexOf('#'));
var kb = graphs[docURI];
if (!kb) {
kb = graphs[docURI] = new $rdf.IndexedFormula();
}
var fetch = $rdf.fetcher(kb, undefined, true);
fetch.nowOrWhenFetched($rdf.Fetcher.crossSiteProxy(docURI), undefined, function(){
// <---- here is the issue this function is not excuted with the 2 first URI.
var profile_picture = kb.any(profile, FOAF('img'));
if(profile_picture == undefined){
profile_picture = kb.any(profile, FOAF('depiction'));
}
if(profile_picture != undefined){
// Export data in dom.
$('#list').append('<p><img src="' + profile_picture.uri + '" alt="img" />' + kb.any(profile, FOAF('name')) +' </p>');
}
});
}
I post the code at : http://grayfoxkiller.free.fr/bug.zip
Hi,
I currently try to create an example on how to perform a SPARQL query with rdflib.js. Is it correct that rdflib.js's SPARQL engine doesn't support OPTIONAL at the moment (cf. sparql.js:424
)? At least the following example doesn't work:
// - load remote RDF document
var fetch = $rdf.fetcher(kb, 1000);
fetch.nowOrWhenFetched('http://dig.csail.mit.edu/2008/webdav/timbl/foaf.rdf', undefined, function(ok) {
var sparqlQuery = 'PREFIX foaf: <http://xmlns.com/foaf/0.1/> \
SELECT ?person ?name \
WHERE { \
<http://www.w3.org/People/Berners-Lee/card#i> foaf:knows ?person . \
OPTIONAL { ?person foaf:name ?name } \
}';
var query = $rdf.SPARQLToQuery(sparqlQuery, true, kb);
console.log($rdf.queryToSPARQL(query)); // prints an empty OPTIONAL clause
kb.query(query, function(result) {
// doesn't delivery any result
}, fetch);
});
If I remove the OPTIONAL part of the query, the example indeed returns results...
EDIT: rdflib.js supports OPTIONAL -- see comment below
Hi, I'm a friend of @melvincarvalho and lead dev of sockethub (http://github.com/sockethub/sockethub - http://sockethub.org). We were talking recently about working on an 'rdf' platform for sockethub. I was wondering a few things.
Thanks for your help, I look forward to helping where I can with rdflib and implementing support in sockethub.
The current version of the rdf parser d91da3b is broken,
was broekn at a727252.
Eg:
I think a high level problem is that we don't have the RDF parser tests working in the system and so the regression test doesn't pick them out. I have reverted myself to f9b535a which will mean I will lose somy of the cleanup done.
If editing a file like this please (a) separate logical changes and whitespace prettiness changes into separate commits and (b) figure out how to run a serious RDF/XML parser test suite on the file.
The RDF WG's parser test suite
which should be implemented here in test/tc0004
(There are a few cwm tests at http://www.w3.org/2000/10/swap/test/xml-syntax/detailed.tests)
Since it could be used as a node.js module, it could make it much more easy to distribute.
All infos are available on https://npmjs.org/
Hi,
when trying to parse an RDF/XML file with rdflib.js and node.js, I get the following error:
`jsdom 4.x onward only works on io.js, not Node.js™: https://github.com/tmpvar
rdflib.js defines "jsdom": "*"
as dependency in npm's package.json file, so the latest version will be loaded which is no longer compatible with node. If you want rdflib.js to be compatible with node.js, you will have to define something like "jsdom": "< 4.0.0"
in the package.json file.
$rdf.SPARQLToQuery
causes an error because it calls a non-existing function at sparql.js:534,539
-- usage: var query = $rdf.SPARQLToQuery(sparqlQuery, false, kb);
/opt/local/bin/node sparql_example.js
/home/ckristo/examples/rdflib.js/node_modules/rdflib/dist/rdflib.js:5578
if($rdf.fetcher) $rdf.fetcher.lookUpThing(st.subject,"sparql:"+st.subj
^
TypeError: undefined is not a function
at Object.$rdf.SPARQLToQuery (/home/ckristo/examples/rdflib.js/node_modules/rdflib/dist/rdflib.js:5578:39)
at null.userCallback (/home/ckristo/examples/rdflib.js/sparql_example.js:20:22)
at doneFetch (/home/ckristo/examples/rdflib.js/node_modules/rdflib/dist/rdflib.js:24606:17)
I tried adding a node.js example here, but the parser claims root is null, with the following error:
/mypath/rdflib.js/dist/rdflib.js:6999
if (root.nodeName == 'parsererror') { //@@ Mozilla only See is
^
TypeError: Cannot read property 'nodeName' of null
at xhr.handle (/mypath/rdflib.js/dist/rdflib.js:6999:25)
at null.onreadystatechange (/mypath/rdflib.js/dist/rdflib.js:7851:25)
at dispatchEvent (/mypath/rdflib.js/node_modules/XMLHttpRequest/lib/XMLHttpRequest.js:570:25)
at setState (/mypath/rdflib.js/node_modules/XMLHttpRequest/lib/XMLHttpRequest.js:589:14)
at IncomingMessage.<anonymous> (/mypath/rdflib.js/node_modules/XMLHttpRequest/lib/XMLHttpRequest.js:427:13)
at IncomingMessage.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:920:16
at process._tickCallback (node.js:415:13)
When I run an n3-example, the body is undefined.
Both of the above two were when running the code from my copy of the repo itself. When I npm install rdflib
in a directory containing just one file with the code from the n3 example, I get the following error:
Asynch fetch fail: Error trying to parse <http://bblfish.net/people/henry/card> as Notation3:
Line 1 of <http://bblfish.net/people/henry/card>: Bad syntax: ']' expected
at: "cert:modulus"B9234D5F150539282":
undefined for http://bblfish.net/people/henry/card
Hi,
I encountered that when loading a local file with a fetcher, node hangs until the timeout is reached. Is that intended behavior? Example:
// - load RDF file
var fetch = $rdf.fetcher(kb, 5000);
fetch.nowOrWhenFetched('file:foaf.rdf', undefined, function(ok) { /* ... */ });
(node.js v0.12.6, latest version of rdflib.js + patched RDF/XML parsing, see #47)
For those who encounter the same problem and need a quick work-around -- you could use node IO to read the file and use the parser directly. Example:
var fs = require('fs');
// - read RDF file
fs.readFile('foaf.rdf', function (err, data) {
if (err) { /* error handling */ }
// - parse RDF file
$rdf.parse(data.toString(), kb, 'foaf.rdf', 'application/rdf+xml', function(err, kb) { /* ... */ });
});
When in the main folder I run make
I get:
make
make: *** No rule to make target `green-turtle/src/RDFaProcessor.js', needed by `dist/rdflib.js'. Stop.
Am I doing something wrong?
So here are my two scenarios:
Scenario1: I fetch the file and I get all the tuples matching Class
var $rdf = require('rdflib');
var SCHEMA = $rdf.Namespace('http://www.w3.org/2000/01/rdf-schema#');
var g = $rdf.graph();
var f = $rdf.fetcher(g);
f.nowOrWhenFetched("http://schema.rdfs.org/all.nt", undefined, function(ok, body) {
console.log(g.statementsMatching(undefined, undefined, SCHEMA("Class")).length);
});
Outputs 0
, which is a wrong input. If you actually log g
, you will find all data about the request of the file, this is an example.
predicateIndex:
[ '<http://www.w3.org/2000/01/rdf-schema#label>': [ [Object], [Object] ],
'<http://www.w3.org/2007/ont/link#protocol>': [ [Object], [Object], [Object], [Object] ],
'<http://www.w3.org/2007/ont/link#requestedURI>': [ [Object] ],
'<http://www.w3.org/2007/ont/link#status>': [ [Object] ],
'<http://www.w3.org/2007/ont/link#response>': [ [Object] ],
'<http://www.w3.org/2007/ont/http#status>': [ [Object] ],
'<http://www.w3.org/2007/ont/http#statusText>': [ [Object] ],
'<http://www.w3.org/2007/ont/httph#date>': [ [Object] ],
'<http://www.w3.org/2007/ont/httph#server>': [ [Object] ],
'<http://www.w3.org/2007/ont/httph#last-modified>': [ [Object] ],
'<http://www.w3.org/2007/ont/httph#etag>': [ [Object] ],
'<http://www.w3.org/2007/ont/httph#accept-ranges>': [ [Object] ],
'<http://www.w3.org/2007/ont/httph#content-length>': [ [Object] ],
'<http://www.w3.org/2007/ont/httph#access-control-allow-origin>': [ [Object] ],
'<http://www.w3.org/2007/ont/httph#connection>': [ [Object] ],
'<http://www.w3.org/2007/ont/httph#content-type>': [ [Object] ],
'<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>': [ [Object] ] ],
Scenario 2: I download the file and parse it and get all the tuples
var $rdf = require('rdflib');
var SCHEMA = $rdf.Namespace('http://www.w3.org/2000/01/rdf-schema#');
var g = $rdf.graph();
request('http://schema.rdfs.org/all.nt', function(err, response, body) {
var kb = new $rdf.IndexedFormula();
$rdf.parse(body, kb, 'http://schema.rdfs.org/all.nt', 'text/n3');
console.log(kb.statementsMatching(undefined, undefined, SCHEMA("Class")).length);
});
Outputs: 656
, which is correct.
Is there something that I am doing wrong>
The function parse
in web.js invokes a function named
spaqlUpdateParser
but this should read
sparqlUpdateParser
as defined in patchParser.js.
see pull request #55
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.