Skip to content

Commit

Permalink
- Avoided callbacks in intermediate store modifications for node obse…
Browse files Browse the repository at this point in the history
…rvers.

- Fixed problem with comments in turtle/sparql parsers
  • Loading branch information
antoniogarrote committed Aug 4, 2011
1 parent e6f8898 commit 979aeaf
Show file tree
Hide file tree
Showing 14 changed files with 634 additions and 475 deletions.
2 changes: 1 addition & 1 deletion configuration.rb
Expand Up @@ -49,7 +49,7 @@
],
:package => {
:name => "rdfstore",
:version => "0.2.0",
:version => "0.2.1",
:description => "RDF graph store supporting the SPARQL query language",
:keywords => ["RDF", "SPARQL", "graph", "store"],
:author => {
Expand Down
21 changes: 21 additions & 0 deletions data/with_comments.n3
@@ -0,0 +1,21 @@
# a comment
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
# another comment
@prefix swrc: <http://swrc.ontoware.org/ontology#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix bench: <http://localhost/vocabulary/bench/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix person: <http://localhost/persons/> .
bench:Journal rdfs:subClassOf foaf:Document.
bench:Proceedings rdfs:subClassOf foaf:Document.
bench:Inproceedings rdfs:subClassOf foaf:Document.
# this is a comment
bench:Article rdfs:subClassOf foaf:Document.
bench:Www rdfs:subClassOf foaf:Document.
bench:MastersThesis rdfs:subClassOf foaf:Document.
bench:PhDThesis rdfs:subClassOf foaf:Document.
bench:Incollection rdfs:subClassOf foaf:Document.
bench:Book rdfs:subClassOf foaf:Document.
86 changes: 57 additions & 29 deletions dist/browser/rdf_store.js
Expand Up @@ -2196,11 +2196,6 @@ TurtleParser.parser = (function(){
}

function parse_statement() {
statementCounter++;
if(statementCounter % 1000 == 0) {
console.log(""+statementCounter);
printTime();
}
var cacheKey = 'statement@' + pos;
var cachedResult = cache[cacheKey];
if (cachedResult) {
Expand Down Expand Up @@ -7186,7 +7181,7 @@ TurtleParser.parser = (function(){
}

var savedReportMatchFailures = reportMatchFailures;
reportMatchFailures = false
reportMatchFailures = false;
if (input.substr(pos).match(/^[ ]/) !== null) {
var result5 = input.charAt(pos);
pos++;
Expand Down Expand Up @@ -7279,24 +7274,24 @@ TurtleParser.parser = (function(){
}
if (result1 !== null) {
var result2 = [];
if (input.substr(pos).match(/^[^#xA#xD]/) !== null) {
if (input.substr(pos).match(/^[^\n\r]/) !== null) {
var result3 = input.charAt(pos);
pos++;
} else {
var result3 = null;
if (reportMatchFailures) {
matchFailed("[^#xA#xD]");
matchFailed("[^\\n\\r]");
}
}
while (result3 !== null) {
result2.push(result3);
if (input.substr(pos).match(/^[^#xA#xD]/) !== null) {
if (input.substr(pos).match(/^[^\n\r]/) !== null) {
var result3 = input.charAt(pos);
pos++;
} else {
var result3 = null;
if (reportMatchFailures) {
matchFailed("[^#xA#xD]");
matchFailed("[^\\n\\r]");
}
}
}
Expand Down Expand Up @@ -34501,24 +34496,24 @@ SparqlParser.parser = (function(){
}
if (result1 !== null) {
var result2 = [];
if (input.substr(pos).match(/^[^#xA#xD]/) !== null) {
if (input.substr(pos).match(/^[^\n\r]/) !== null) {
var result3 = input.charAt(pos);
pos++;
} else {
var result3 = null;
if (reportMatchFailures) {
matchFailed("[^#xA#xD]");
matchFailed("[^\\n\\r]");
}
}
while (result3 !== null) {
result2.push(result3);
if (input.substr(pos).match(/^[^#xA#xD]/) !== null) {
if (input.substr(pos).match(/^[^\n\r]/) !== null) {
var result3 = input.charAt(pos);
pos++;
} else {
var result3 = null;
if (reportMatchFailures) {
matchFailed("[^#xA#xD]");
matchFailed("[^\\n\\r]");
}
}
}
Expand Down Expand Up @@ -39920,13 +39915,15 @@ Callbacks.ANYTHING = {'token': 'var',

Callbacks.added = 'added';
Callbacks.deleted = 'deleted';
Callbacks.eventsFlushed = 'eventsFlushed';

Callbacks.CallbacksBackend = function() {
this.aqt = new AbstractQueryTree.AbstractQueryTree();
this.engine = arguments[0];
this.indexMap = {};
this.observersMap = {};
this.queriesIndexMap = {};
this.emptyNotificationsMap = {};
this.queriesList = [];
this.pendingQueries = [];
this.matchedQueries = [];
Expand Down Expand Up @@ -39979,8 +39976,10 @@ Callbacks.CallbacksBackend.prototype.endGraphModification = function(callback) {
that.updateInProgress = null;
this.sendNotification(Callbacks['deleted'], tmp[Callbacks['deleted']],function(){
that.sendNotification(Callbacks['added'], tmp[Callbacks['added']], function(){
that.dispatchQueries(function(){
callback(true);
that.sendEmptyNotification(Callbacks['eventsFlushed'], null, function(){
that.dispatchQueries(function(){
callback(true);
});
});
});
});
Expand Down Expand Up @@ -40014,6 +40013,14 @@ Callbacks.CallbacksBackend.prototype.sendNotification = function(event, quadsPai
doneCallback(true);
};

Callbacks.CallbacksBackend.prototype.sendEmptyNotification = function(event, value, doneCallback) {
var callbacks = this.emptyNotificationsMap[event] || [];
for(var i=0; i<callbacks.length; i++) {
callbacks[i](event, value);
}
doneCallback();
};

Callbacks.CallbacksBackend.prototype.dispatchNotifications = function(notificationsMap) {
for(var callbackId in notificationsMap) {
var callback = this.callbacksMap[callbackId];
Expand Down Expand Up @@ -40056,6 +40063,20 @@ Callbacks.CallbacksBackend.prototype._searchCallbacksInIndex = function(index, o
}
};

Callbacks.CallbacksBackend.prototype.subscribeEmpty = function(event, callback) {
var callbacks = this.emptyNotificationsMap[event] || [];
callbacks.push(callback);
this.emptyNotificationsMap[event] = callbacks;
};

Callbacks.CallbacksBackend.prototype.unsubscribeEmpty = function(event, callback) {
var callbacks = this.emptyNotificationsMap[event];
if(callbacks != null) {
callbacks = Utils.remove(callbacks, callback);
}
this.emptyNotificationsMap[event] = callbacks;
};

Callbacks.CallbacksBackend.prototype.subscribe = function(s,p,o,g,callback, doneCallback) {
var quad = this._tokenizeComponents(s,p,o,g);
var queryEnv = {blanks:{}, outCache:{}};
Expand Down Expand Up @@ -40179,25 +40200,31 @@ Callbacks.CallbacksBackend.prototype.observeNode = function() {
this.engine.execute(query, function(success, graph){
if(success) {
var node = graph;
var mustFlush = false;
var observer = function(event, triples){
for(var i = 0; i<triples.length; i++) {
var triple = triples[i];
var s = RDFJSInterface.buildRDFResource(triple.subject,bindings,that.engine,queryEnv);
var p = RDFJSInterface.buildRDFResource(triple.predicate,bindings,that.engine,queryEnv);
var o = RDFJSInterface.buildRDFResource(triple.object,bindings,that.engine,queryEnv);
if(s!=null && p!=null && o!=null) {
triple = new RDFJSInterface.Triple(s,p,o);
if(event === Callbacks['added']) {
node.add(triple);
} else if(event === Callbacks['deleted']) {
node.remove(triple);
if(event === 'eventsFlushed' && mustFlush ) {
mustFlush = false;
callback(node);
} else {
mustFlush = true;
for(var i = 0; i<triples.length; i++) {
var triple = triples[i];
var s = RDFJSInterface.buildRDFResource(triple.subject,bindings,that.engine,queryEnv);
var p = RDFJSInterface.buildRDFResource(triple.predicate,bindings,that.engine,queryEnv);
var o = RDFJSInterface.buildRDFResource(triple.object,bindings,that.engine,queryEnv);
if(s!=null && p!=null && o!=null) {
triple = new RDFJSInterface.Triple(s,p,o);
if(event === Callbacks['added']) {
node.add(triple);
} else if(event === Callbacks['deleted']) {
node.remove(triple);
}
}
}
}

callback(node);
};
that.observersMap[callback] = observer;
that.subscribeEmpty(Callbacks['eventsFlushed'], observer);
that.subscribe(uri,null,null,null,observer,doneCallback);
callback(node);
} else {
Expand All @@ -40210,6 +40237,7 @@ Callbacks.CallbacksBackend.prototype.stopObservingNode = function(callback) {
var observer = this.observersMap[callback];
if(observer) {
this.unsubscribe(observer);
this.unsubscribeEmpty(Callbacks['eventsFlushed'],observer);
return true;
} else {
return false;
Expand Down

0 comments on commit 979aeaf

Please sign in to comment.