antoniogarrote / rdfstore-js

JS RDF store with SPARQL support
MIT License
564 stars 109 forks source link

Concurrency issue when using store.load #70

Open slorber opened 10 years ago

slorber commented 10 years ago

I have the following code:

    this.fetchGraph = function fetchGraph(uri) {
      var uriToFetch = maybeCorsProxifiedUri(uri);
      return $http.get(uriToFetch,config)
        .then(function(response) {
          var mimeType = parseMimeType(response);
          console.debug("It seems we got a response with mimeType "+mimeType + " from "+ uri+" - will try to parse it as a graph");
          return loadGraph(uri,response.data,mimeType);
        })
        .then(function(triplesLoaded) {
          console.debug("Number of triples loaded in store for " + uri + " = " + triplesLoaded);
          return getGraph(uri,triplesLoaded);
        });
    };

    function loadGraph(graphUri,graphData,graphMimeType) {
      var deferred = $q.defer();
      RdfStore.load(graphMimeType,graphData,graphUri,function(success, results) {
        if ( success ) {
          deferred.resolve(results);
        } else {
          deferred.reject("Can't LOAD graph with GraphURI="+graphUri+" and graphMimeType="+graphMimeType+" -> "+results);
        }
      });
      return deferred.promise;
    }

    function getGraph(graphUri,expectedTriplesNumber) {
      var deferred = $q.defer();
      RdfStore.graph(graphUri,function(success,graph){
        if ( success ) {
          if ( graph.toArray().length != expectedTriplesNumber) {
            throw "Expected to find " + expectedTriplesNumber + " triples, but graph loaded has "+graph.toArray().length+" triples for uri "+graphUri+" ->\n" + graph.toNT();
          }
          deferred.resolve(graph);
        } else {
          deferred.reject("Can't GET graph with GraphURI="+graphUri);
        }
      });
      return deferred.promise;
    }

As part of an AngularJS prototype, I use Q to handle future results instead of callbacks.

Steps:

Most of the time, the graph returned by store.graph(graphUri,callback) is actually the appropriate graph, but it seems it randomly returns empty graphs as well as other graphs (graphs that do not correspond to the provided graphUri).

Here's a sample of logs to illustrate the problem:

It seems we got a response with mimeType text/turtle from http://bigasterisk.com/foaf.rdf - will try to parse it as a graph 

Number of triples loaded in store for http://bigasterisk.com/foaf.rdf = 62 

Expected to find 62 triples, but graph loaded has 980 triples for uri http://bigasterisk.com/foaf.rdf ->
<http://B4mad.Net/FOAF/goern-visits.rdf> <http://purl.org/dc/elements/1.1/title> "der/G/oern's visited Countries"^^<http://www.w3.org/2001/XMLSchema#string> . 
<https://dr.jones.dk/me/#henry> <http://xmlns.com/foaf/0.1/firstName> "Henry"^^<http://www.w3.org/2001/XMLSchema#string> . 
<http://dbpedia.org/resource/Roy_Fielding> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/class/yago/YagoLegalActorGeo> . 
<http://creativecommons.org/licenses/by-nc-sa/2.5/> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://web.resource.org/cc/License> . 
<http://ws.audioscrobbler.com/rdf/history/goern> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://purl.org/rss/1.0/channel> . 
<http://www.daml.org/2001/09/countries/iso#NO> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.daml.org/2001/09/countries/iso-3166-ont#Country> . 
<https://dr.jones.dk/me/#henry> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> . 
_:91344 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/wot/0.1/PubKey> . 
_:91366 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/OnlineAccount> . 
<https://dr.jones.dk/me/#troels> <http://xmlns.com/foaf/0.1/name> "Troels Christian Jakobsen"^^<http://www.w3.org/2001/XMLSchema#string> . 
<http://dbpedia.org/resource/Roy_Fielding> <http://xmlns.com/foaf/0.1/givenName> "Roy"@en . 
_:91347 <http://xmlns.com/foaf/0.1/nick> "urandom"^^<http://www.w3.org/2001/XMLSchema#string> . 
<https://dr.jones.dk/me/#melvin> <http://xmlns.com/foaf/0.1/homepage> <http://melvincarvalho.com/> . 
_:91366 <http://xmlns.com/foaf/0.1/homepage> <http://alioth.debian.org/users/js> . 
<http://b4mad.net/goern> <http://xmlns.com/foaf/0.1/currentProject> <http://B4mad.Net/datenbrei/> . 
<http://b4mad.net/goern> <http://www.w3.org/2000/01/rdf-schema#seeAlso> <http://de.citeulike.org/rss/user/goern> . 
<http://www.ibiblio.org/hhalpin/foaf.rdf#me> <http://xmlns.com/foaf/0.1/knows> _:91329 . 
<https://dr.jones.dk/me/#me> <http://xmlns.com/foaf/0.1/knows> <https://dr.jones.dk/me/#melvin> . 
<http://B4mad.Net/datenbrei/wp-rdf.php> <http://xmlns.com/foaf/0.1/maker> <http://B4mad.Net/FOAF/goern.rdf#goern> . 
<http://dbpedia.org/resource/Roy_Fielding> <http://www.w3.org/2002/07/owl#sameAs> <http://es.dbpedia.org/resource/Roy_Fielding> . 
<http://ikiwiki.info/> <http://purl.org/dc/elements/1.1/title> "Ikiwiki"^^<http://www.w3.org/2001/XMLSchema#string> . 
<http://dbpedia.org/resource/Roy_Fielding> <http://www.w3.org/2000/01/rdf-schema#label> "Roy Fielding"@de . 
_:91354 <http://www.w3.org/2003/01/geo/wgs84_pos#lat> "55.647647"^^<http://www.w3.org/2001/XMLSchema#string> . 
<https://dr.jones.dk/me/#agus> <http://xmlns.com/foaf/0.1/account> _:91356 . 
<http://www.ibiblio.org/hhalpin/foaf.rdf#me> <http://xmlns.com/foaf/0.1/givenname> "Harry"^^<http://www.w3.org/2001/XMLSchema#string> . 
<https://dr.jones.dk/me/#alboy> <http://xmlns.com/foaf/0.1/mbox_sha1sum> "b9fe617c22f6f319c1fa8ae37d28b0a03ccddb92"^^<http://www.w3.org/2001/XMLSchema#string> . 
_:91328 <http://xmlns.com/foaf/0.1/mbox_sha1sum> "94b6eb0c835f928c5ed565dc3ed1a355ac1b41e5"^^<http://www.w3.org/2001/XMLSchema#string> . 
<http://www.ibiblio.org/hhalpin/foaf.rdf#me> <http://xmlns.com/foaf/0.1/depiction> <http://www.ibiblio.org/hhalpin/homepage/images/harrytrain.png> . 
_:91359 <http://xmlns.com/foaf/0.1/accountName> "arjakobsen"^^<http://www.w3.org/2001/XMLSchema#string> . 
<http://www.ibiblio.org/hhalpin/foaf.rdf#me> <http://xmlns.com/foaf/0.1/holdsAccount> <http://www.ibiblio.org/hhalpin/foaf.rdf#facebook> . 
<https://dr.jones.dk/me/#me> <http://xmlns.com/foaf/0.1/interest> <http://purl.org/rss/1.0/> . 
<http://www.ibiblio.org/hhalpin/foaf.rdf#me> <http://xmlns.com/foaf/0.1/schoolHomepage> <http://www.ibiblio.org/hhalpin/www.inf.ed.ac.uk> . 
<http://www.w3.org/2000/06/webdata/xslt?xslfile=http://www.wasab.dk/morten/2…sl&xmlfile=http://trust.mindswap.org/cgi-bin/FilmTrust/foaf.cgi?user=goern> <http://purl.org/dc/elements/1.1/description> "Film trust reviews by me and my friends"^^<http://www.w3.org/2001/XMLSchema#string> . 
<http://b4mad.net/goern> <http://xmlns.com/foaf/0.1/made> <http://b4mad.net/> . 
<https://dr.jones.dk/me/#me> <http://www.w3.org/2000/10/swap/pim/contact#nearestAirport> _:91370 . 
<http://www.ibiblio.org/hhalpin/foaf.rdf#me> <http://xmlns.com/foaf/0.1/geekcode> "gcs/gp>go d-- s++,s- a- c++ ul++ p++ L++ E+ W+++ 
N o-- K- w--- O M- V? PS++ PE-- Y++ PGP++ t+ 5? X++ R+ !tv b+++ DI++ D+ 
G e+++>e++++$ h* r z+"^^<http://www.w3.org/2001/XMLSchema#string> . 
<http://B4mad.Net/FOAF/goern.rdf> <http://purl.org/dc/elements/1.1/type> <http://purl.org/dc/dcmitype/Text> . 
<http://b4mad.net/goern> <http://purl.org/vocab/relationship/hasMet> <http://B4mad.Net/FOAF/goern.rdf#ds9> . 
<http://creativecommons.org/licenses/by-nc-sa/2.5/> <http://web.resource.org/cc/permits> <http://web.resource.org/cc/DerivativeWorks> . 
<http://www.daml.org/2001/09/countries/iso#IN> <http://www.daml.org/2001/09/countries/iso-3166-ont#code> "IN"^^<http://www.w3.org/2001/XMLSchema#string> . 
<http://www.daml.org/2001/09/countries/iso#IS> <http://www.daml.org/2001/09/countries/iso-3166-ont#name> "Iceland"^^<http://www.w3.org/2001/XMLSchema#string> . 
<https://dr.jones.dk/me/#me> <http://purl.org/vocab/relationship/childOf> <https://dr.jones.dk/me/#inger> . 
<https://dr.jones.dk/me/#me> <http://purl.org/net/vocab/2004/07/visit#country> <http://www.daml.org/2001/09/countries/iso#DE> . 
<https://dr.jones.dk/me/#me> <http://purl.org/net/vocab/2004/07/visit#country> <http://www.daml.org/2001/09/countries/iso#NO> . 
<https://dr.jones.dk/me/#me> <http://purl.org/vocab/relationship/friendOf> <https://dr.jones.dk/me/#anders> . 
<https://dr.jones.dk/me/#me> <http://purl.org/vocab/relationship/livesWith> <https://dr.jones.dk/me/#siri> . 
<https://dr.jones.dk/me/#me> <http://trust.mindswap.org/ont/trust.owl#trust8> <https://dr.jones.dk/me/#jgh> . 
<http://dbpedia.org/resource/Roy_Fielding> <http://dbpedia.org/ontology/thumbnail> <http://upload.wikimedia.org/wikipedia/commons/thumb/c/cd/Roy_Fielding.jpg/200px-Roy_Fielding.jpg> . 
<http://bblfish.net/people/henry/card#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> . 
<http://www.w3.org/People/Berners-Lee/card#i> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> . 
<http://dbpedia.org/resource/Roy_Fielding> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> . 
<http://dbpedia.org/resource/Roy_Fielding> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/class/yago/CausalAgent100007347> . 
<http://dbpedia.org/resource/Roy_Fielding> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/class/yago/ComputerUser109951274> . 
<http://dbpedia.org/resource/Roy_Fielding> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/class/yago/Engineer109615807> . 
<http://dbpedia.org/resource/Roy_Fielding> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/class/yago/FreeSoftwareProgrammers> . 
<http://dbpedia.org/resource/Roy_Fielding> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/class/yago/LivingPeople> . 
<http://dbpedia.org/resource/Roy_Fielding> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/class/yago/LivingThing100004258> . 
<http://dbpedia.org/resource/Roy_Fielding> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/class/yago/Object100002684> . 
<http://dbpedia.org/resource/Roy_Fielding> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/class/yago/Organism100004475> . 
<http://dbpedia.org/resource/Roy_Fielding> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/class/yago/Person100007846> . 
<http://dbpedia.org/resource/Roy_Fielding> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/class/yago/PhysicalEntity100001930> . 
<http://dbpedia.org/resource/Roy_Fielding> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/class/yago/Programmer110481268> . 
<http://dbpedia.org/resource/Roy_Fielding> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/class/yago/Whole100003553> . 
<http://dbpedia.org/resource/Roy_Fielding> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://dbpedia.org/class/yago/YagoLegalActor> . 
<http://www.ibiblio.org/hhalpin/foaf.rdf#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> . 
<https://dr.jones.dk/me/#me> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> . 
<http://bigasterisk.com/foaf.rdf#drewp> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> . 
<http://www.w3.org/2001/sw/> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Document> . 
<http://www.ibiblio.org/hhalpin/foaf.rdf#delicious> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://rdfs.org/sioc/ns#User> . 
<http://www.ibiblio.org/hhalpin/foaf.rdf#facebook> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://rdfs.org/sioc/ns#User> . 
<http://www.ibiblio.org/hhalpin/foaf.rdf#linkedin> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://rdfs.org/sioc/ns#User> . 
<http://www.ibiblio.org/hhalpin/homepage/images/harrytrain.png> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/image> . 
<http://B4mad.Net/FOAF/B4mad.rdf> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Document> . 
<http://B4mad.Net/FOAF/goern-accounts.rdf> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Document> . 
<http://B4mad.Net/FOAF/goern-menow.rdf> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Document> . 
<http://B4mad.Net/FOAF/goern-trust.rdf> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Document> . 
<http://B4mad.Net/FOAF/goern-visits.rdf> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Document> . 
<http://B4mad.Net/FOAF/goern.rdf> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/PersonalProfileDocument> . 
<http://B4mad.Net/FOAF/goern.rdf> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://web.resource.org/cc/Work> . 
<http://B4mad.Net/FOAF/goern.rdf#ds9> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> . 
<http://B4mad.Net/FOAF/goern.rdf#ulimit> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> . 
<http://B4mad.Net/FOAF/goern.rdf#null> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> . 
.............................................

As you can see the graph for this uri has 62 triples so it seems it's not the loading that cause troubles (or at least the callback returns the appropriate quad number, I don't know...)

But when fetching the graph it seems it find the triples of another graph as well, a graph I also loaded in the store, but with a diifferent uri/graphname, so it is not expected for me to return these triples as a result right?

I ask for the graph: http://bigasterisk.com/foaf.rdf And it seems to return me the triples of some other graphs I added before like http://b4mad.net/FOAF/goern.rdf#goern

My code works fine for the first graphs to load, and then doesn't work anymore.

Note that I call store.load concurrently to load 20 graphs so it may be a concurrency issue during the loading, perhaps multiple graphs are loaded to the same graphName (which also explain why sometimes I retrieve big graphs, and sometimes I retrieve empty graphs)

Generally, I find it quite hard to use RDFStore to parse a graph in a random media type and get the appropriate parsed graph as RDFInterface. I don't need yet SPARQL in my app so I only use this low level interface.

Wouldn't it be easier to retrieve the RDF interface graph after loading in the store, instead of calling the callback with a count of the triples loaded?

slorber commented 10 years ago

I think there is a concurrency issue when loading multiple graphs in the quad backend because when I run the loadings sequentially it works fine in all cases

slorber commented 10 years ago

This is a problem during the loading I think.

I replaced a part of my previous code:

    this.loadGraph = function loadGraph(graphUri,graphData,graphMimeType) {
      var deferred = $q.defer();
        RdfStore.load(graphMimeType,graphData,graphUri,function(success, results) {
          if ( success ) {
            deferred.resolve(results);
          } else {
            deferred.reject("Can't LOAD graph with GraphURI="+graphUri+" and graphMimeType="+graphMimeType+" -> "+results);
          }
        });
      return deferred.promise;
    }

has become:

    this.loadGraph = function loadGraph(graphUri,graphData,graphMimeType) {
      var deferred = $q.defer();
      setTimeout(function() {
        RdfStore.load(graphMimeType,graphData,graphUri,function(success, results) {
          if ( success ) {
            deferred.resolve(results);
          } else {
            deferred.reject("Can't LOAD graph with GraphURI="+graphUri+" and graphMimeType="+graphMimeType+" -> "+results);
          }
        });
      },getNextDelay());
      return deferred.promise;
    }

    // TODO temporary: to delete
    var delay = 0;
    function getNextDelay() {
      delay += 1000;
      return delay;
    }

By spacing the graph loadings of 1 second, it works perfectly fine. If I put delay += 0; then the problem appears again.

It is not a problem during the SPARQL Construct query used by store.graph(...).

After loading all the graphs in store (spaced by 1sec which takes some time), I finally run a concurrent call of store.graph on all successfully loaded graphUris and it retrieves the correct graph. So it seems it's really a loading problem.


Here's a fiinal debug output with loadings not spaced and run concurrently:

Got graph http://melvincarvalho.com/#me with size=0 services.js:127
Got graph http://www.w3.org/People/Berners-Lee/card#i with size=146 services.js:127
Got graph http://mmt.me.uk/foaf.rdf#mischa with size=0 services.js:127
Got graph http://www.dfki.uni-kl.de/~grimnes/foaf.rdf#ggrimnes with size=0 services.js:127
Got graph http://danbri.org/foaf.rdf#danbri with size=0 services.js:127
Got graph http://www.discoveringidentity.com/foaf.rdf#me with size=704 services.js:127
Got graph https://my-profile.eu/people/tim/card#me with size=0 services.js:127
Got graph http://dbpedia.org/resource/Roy_Fielding with size=0 services.js:127
Got graph https://dr.jones.dk/me/#me with size=0 services.js:127
Got graph http://bigasterisk.com/foaf.rdf#drewp with size=0 services.js:127
Got graph http://crschmidt.net/foaf.rdf#crschmidt with size=0 services.js:127
Got graph http://presbrey.mit.edu/foaf#presbrey with size=0 services.js:127
Got graph http://www.anjeve.de/foaf.rdf#AnjaJentzsch with size=0 services.js:127
Got graph http://id.myopenlink.net/dataspace/person/KingsleyUyiIdehen#this with size=0 services.js:127
Got graph http://axel.deri.ie/~axepol/foaf.rdf#me with size=0 services.js:127
Got graph http://www.informatik.uni-leipzig.de/~auer/foaf.rdf#me with size=0 services.js:127
Got graph http://richard.cyganiak.de/foaf.rdf#cygri with size=0 services.js:127
Got graph http://www.ibiblio.org/hhalpin/foaf.rdf#me with size=0 services.js:127
Got graph http://b4mad.net/FOAF/goern.rdf#goern with size=0 services.js:127
Got graph http://sebastian.tramp.name with size=0 services.js:127
Got graph https://my-profile.eu/people/deiu/card#me with size=0 services.js:127
Got graph http://dbpedia.org/resource/James_Gosling with size=3175 

And here the result when loadings are spaced by 1 second:

Got graph https://my-profile.eu/people/deiu/card#me with size=55 services.js:127
Got graph http://id.myopenlink.net/dataspace/person/KingsleyUyiIdehen#this with size=202 services.js:127
Got graph http://mmt.me.uk/foaf.rdf#mischa with size=301 services.js:127
Got graph http://presbrey.mit.edu/foaf#presbrey with size=35 services.js:127
Got graph http://melvincarvalho.com/#me with size=60 services.js:127
Got graph http://www.dfki.uni-kl.de/~grimnes/foaf.rdf#ggrimnes with size=101 services.js:127
Got graph http://danbri.org/foaf.rdf#danbri with size=278 services.js:127
Got graph http://www.discoveringidentity.com/foaf.rdf#me with size=26 services.js:127
Got graph http://dbpedia.org/resource/James_Gosling with size=237 services.js:127
Got graph https://my-profile.eu/people/tim/card#me with size=19 services.js:127
Got graph http://axel.deri.ie/~axepol/foaf.rdf#me with size=262 services.js:127
Got graph http://www.informatik.uni-leipzig.de/~auer/foaf.rdf#me with size=421 services.js:127
Got graph http://richard.cyganiak.de/foaf.rdf#cygri with size=296 services.js:127
Got graph http://dbpedia.org/resource/Roy_Fielding with size=70 services.js:127
Got graph http://www.ibiblio.org/hhalpin/foaf.rdf#me with size=63 services.js:127
Got graph http://b4mad.net/FOAF/goern.rdf#goern with size=231 services.js:127
Got graph https://dr.jones.dk/me/#me with size=554 services.js:127
Got graph http://bigasterisk.com/foaf.rdf#drewp with size=62 services.js:127
Got graph http://crschmidt.net/foaf.rdf#crschmidt with size=374 services.js:127
Got graph http://sebastian.tramp.name with size=58 services.js:127
Got graph http://www.anjeve.de/foaf.rdf#AnjaJentzsch with size=247 services.js:127
Got graph http://www.w3.org/People/Berners-Lee/card#i with size=86 

As you can see it seems in the concurrent version that the James Gosling uri graph name seems to get all the triples while the others doesn't get any triple.

I use Chrome browser and do not use RDFStoreClient but rdfstore.create. I removed the RDFStoreClient code and it still work so I don't think I am using WebWorkers. I don't really know yet how javascript concurrency works or what could be the problem.

slorber commented 10 years ago

As I do not need a real store but just want to retrieve a RDF Interface api Graph, I tried to create a new rdfstore for each request.

    this.fetchGraph = function fetchGraph(uri) {
      var uriToFetch = maybeCorsProxifiedUri(uri);
      return $http.get(uriToFetch,config)
        .then(function(response) {
          var mimeType = parseMimeType(response);
          console.debug("It seems we got a response with mimeType "+mimeType + " from "+ uri+" - will try to parse it as a graph");
          return parseGraph(uri, response.data, mimeType);
        })
    };

    function parseGraph(graphUri, graphData, graphMimeType) {
      var deferred = $q.defer();
      var temporaryRdfStore = rdfstore.create();
      temporaryRdfStore.load(graphMimeType, graphData, graphUri, function(success, results) {
        if ( success ) {
          temporaryRdfStore.graph(graphUri,function(success,graph){
            if ( success ) {
              deferred.resolve(graph);
            } else {
              deferred.reject("Can't GET graph with GraphURI="+graphUri);
            }
          });
        } else {
          deferred.reject("Can't LOAD graph with GraphURI="+graphUri+" and graphMimeType="+graphMimeType+" -> "+results);
        }
      });
      return deferred.promise;
    }

The following does not work when. So there may be an isolation problem in the lib between different instances of RDFStore.

But a workaround that seems to work is to use the default graph:

    this.fetchGraph = function fetchGraph(uri) {
      var uriToFetch = maybeCorsProxifiedUri(uri);
      return $http.get(uriToFetch,config)
        .then(function(response) {
          var mimeType = parseMimeType(response);
          console.debug("It seems we got a response with mimeType "+mimeType + " from "+ uri+" - will try to parse it as a graph");
          return parseGraph(uri, response.data, mimeType);
        })
    };

    function parseGraph(graphUri, graphData, graphMimeType) {
      var deferred = $q.defer();
      var temporaryRdfStore = rdfstore.create();
      temporaryRdfStore.load(graphMimeType, graphData, function(success, results) {
        if ( success ) {
          temporaryRdfStore.graph(function(success,graph){
            if ( success ) {
              deferred.resolve(graph);
            } else {
              deferred.reject("Can't GET graph with GraphURI="+graphUri);
            }
          });
        } else {
          deferred.reject("Can't LOAD graph with GraphURI="+graphUri+" and graphMimeType="+graphMimeType+" -> "+results);
        }
      });
      return deferred.promise;
    }

Funny right? :)