You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by wi...@apache.org on 2013/04/30 17:01:09 UTC

[2/2] git commit: MARMOTTA-227: keeping synchronized prefixes on snorql queries

MARMOTTA-227: keeping synchronized prefixes on snorql queries


Project: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/commit/33bb5501
Tree: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/tree/33bb5501
Diff: http://git-wip-us.apache.org/repos/asf/incubator-marmotta/diff/33bb5501

Branch: refs/heads/develop
Commit: 33bb55013eb2047be7ebaa5a6993b142d3fb93b3
Parents: 095ae4a
Author: Sergio Fernández <wi...@apache.org>
Authored: Tue Apr 30 16:59:43 2013 +0200
Committer: Sergio Fernández <wi...@apache.org>
Committed: Tue Apr 30 16:59:43 2013 +0200

----------------------------------------------------------------------
 .../main/resources/web/admin/snorql/snorql.html    |    7 +-
 .../src/main/resources/web/admin/snorql/snorql.js  |   96 ++++++++-------
 2 files changed, 55 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/33bb5501/platform/marmotta-sparql/src/main/resources/web/admin/snorql/snorql.html
----------------------------------------------------------------------
diff --git a/platform/marmotta-sparql/src/main/resources/web/admin/snorql/snorql.html b/platform/marmotta-sparql/src/main/resources/web/admin/snorql/snorql.html
index b45fcac..bc2b2c2 100755
--- a/platform/marmotta-sparql/src/main/resources/web/admin/snorql/snorql.html
+++ b/platform/marmotta-sparql/src/main/resources/web/admin/snorql/snorql.html
@@ -69,12 +69,15 @@
 
     <div class="section">
         <pre id="prefixestext"></pre>
-        <form id="queryform" action="#" method="get"><div>
+        <form id="queryform" action="#" method="get">
+          <div>
+            <input type="hidden" name="prefixes" value="" id="prefixes" />
             <input type="hidden" name="query" value="" id="query" />
             <input type="hidden" name="output" value="json" id="jsonoutput" disabled="disabled" />
             <input type="hidden" name="stylesheet" value="" id="stylesheet" disabled="disabled" />
             <input type="hidden" name="graph" value="" id="graph-uri" disabled="disabled" />
-        </div></form>
+          </div>
+        </form>
         <div>
             <textarea name="query" rows="9" cols="80" id="querytext"></textarea>
             <span style="color:#464646;">Results:</span>

http://git-wip-us.apache.org/repos/asf/incubator-marmotta/blob/33bb5501/platform/marmotta-sparql/src/main/resources/web/admin/snorql/snorql.js
----------------------------------------------------------------------
diff --git a/platform/marmotta-sparql/src/main/resources/web/admin/snorql/snorql.js b/platform/marmotta-sparql/src/main/resources/web/admin/snorql/snorql.js
index 22f3b6a..93c2f48 100755
--- a/platform/marmotta-sparql/src/main/resources/web/admin/snorql/snorql.js
+++ b/platform/marmotta-sparql/src/main/resources/web/admin/snorql/snorql.js
@@ -28,9 +28,9 @@ String.prototype.startsWith = function(str) {
 function Snorql() {
     // modify this._endpoint to point to your SPARQL endpoint
     this._endpoint = _BASIC_URL + 'sparql/select';
-    // modify these to your likeing
-    this._poweredByLink = 'http://code.google.com/p/lmf';
-    this._poweredByLabel = 'Linked Media Framework';
+    // modify these to your liking
+    this._poweredByLink = 'http://marmotta.incubator.apache.org';
+    this._poweredByLabel = 'Snorql & Apache Marmotta';
     this._enableNamedGraphs = false;
 
     this._browserBase = null;
@@ -43,7 +43,6 @@ function Snorql() {
         this.setBrowserBase(document.location.href.replace(/\?.*/, ''));
         this._displayEndpointURL();
         //this._displayPoweredBy();
-        this.setNamespaces(D2R_namespacePrefixes);
         this.updateOutputMode();
         var match = document.location.href.match(/\?(.*)/);
         var queryString = match ? match[1] : '';
@@ -52,49 +51,49 @@ function Snorql() {
             this._updateGraph(null, false);
             return;
         }
+        
         var graph = queryString.match(/graph=([^&]*)/);
         graph = graph ? decodeURIComponent(graph[1]) : null;
         this._updateGraph(graph, false);
+        
         var browse = queryString.match(/browse=([^&]*)/);
-        var querytext = null;
-        if (browse && browse[1] == 'classes') {
-            var resultTitle = 'List of all classes:';
-            var query = 'SELECT DISTINCT ?class\n' +
-                    'WHERE { [] a ?class }\n' +
-                    'ORDER BY ?class';
-        }
-        if (browse && browse[1] == 'properties') {
-            var resultTitle = 'List of all properties:';
-            var query = 'SELECT DISTINCT ?property\n' +
-                    'WHERE { [] ?property [] }\n' +
-                    'ORDER BY ?property';
-        }
-        if (browse && browse[1] == 'graphs') {
-            var resultTitle = 'List of all named graphs:';
-            var querytext = 'SELECT DISTINCT ?namedgraph ?label\n' +
-                    'WHERE {\n' +
-                    '  GRAPH ?namedgraph { ?s ?p ?o }\n' +
-                    '  OPTIONAL { ?namedgraph rdfs:label ?label }\n' +
-                    '}\n' +
-                    'ORDER BY ?namedgraph';
-            var query = 'PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n' + querytext;
+        if (browse) {
+	        if (browse[1] == 'classes') {
+	            var resultTitle = 'List of all classes:';
+	            var query = 'SELECT DISTINCT ?class\n' +
+	                    'WHERE { [] a ?class }\n' +
+	                    'ORDER BY ?class';
+	        } else if (browse[1] == 'properties') {
+	            var resultTitle = 'List of all properties:';
+	            var query = 'SELECT DISTINCT ?property\n' +
+	                    'WHERE { [] ?property [] }\n' +
+	                    'ORDER BY ?property';
+	        } else if (browse[1] == 'graphs') {
+	            var resultTitle = 'List of all named graphs:';
+	            var query = 'SELECT DISTINCT ?namedgraph ?label\n' +
+	                    'WHERE {\n' +
+	                    '  GRAPH ?namedgraph { ?s ?p ?o }\n' +
+	                    '  OPTIONAL { ?namedgraph rdfs:label ?label }\n' +
+	                    '}\n' +
+	                    'ORDER BY ?namedgraph';
+	        }
         }
-        var match = queryString.match(/property=([^&]*)/);
-        if (match) {
+        
+        if (queryString.match(/property=([^&]*)/)) {
             var resultTitle = 'All uses of property ' + decodeURIComponent(match[1]) + ':';
             var query = 'SELECT DISTINCT ?resource ?value\n' +
                     'WHERE { ?resource <' + decodeURIComponent(match[1]) + '> ?value }\n' +
                     'ORDER BY ?resource ?value';
         }
-        var match = queryString.match(/class=([^&]*)/);
-        if (match) {
+        
+        if (queryString.match(/class=([^&]*)/)) {
             var resultTitle = 'All instances of class ' + decodeURIComponent(match[1]) + ':';
             var query = 'SELECT DISTINCT ?instance\n' +
                     'WHERE { ?instance a <' + decodeURIComponent(match[1]) + '> }\n' +
                     'ORDER BY ?instance';
         }
-        var match = queryString.match(/describe=([^&]*)/);
-        if (match) {
+        
+        if (queryString.match(/describe=([^&]*)/)) {
             var resultTitle = 'Description of ' + decodeURIComponent(match[1]) + ':';
             var query = 'SELECT DISTINCT ?property ?hasValue ?isValueOf\n' +
                     'WHERE {\n' +
@@ -104,15 +103,20 @@ function Snorql() {
                     '}\n' +
                     'ORDER BY (!BOUND(?hasValue)) ?property ?hasValue ?isValueOf';
         }
+        
         if (queryString.match(/query=/)) {
-            var resultTitle = 'SPARQL results:';
-            querytext = this._betterUnescape(queryString.match(/query=([^&]*)/)[1]);
-            var query = prefixes + querytext;
-        }
-        if (!querytext) {
-            querytext = query;
-        }
-        document.getElementById('querytext').value = querytext;
+        	var resultTitle = 'SPARQL results:';
+        	var query = this._betterUnescape(queryString.match(/query=([^&]*)/)[1]);
+        
+        }
+        
+        var prefixes = this._getPrefixes();
+        if (queryString.match(/prefixes=/)) {
+        	prefixes = this._betterUnescape(queryString.match(/prefixes=([^&]*)/)[1]);
+        }
+        
+        var querytext = prefixes + " " + query;
+        document.getElementById('querytext').value = query;
         this.displayBusyMessage();
         var service = new SPARQL.Service(this._endpoint);
         if (this._graph) {
@@ -123,7 +127,7 @@ function Snorql() {
         var dummy = this;
 
    	    var exp = /^\s*(?:PREFIX\s+\w*:\s+<[^>]*>\s*)*(\w+)\s*.*/i;
-   	    var match = exp.exec(querytext);
+   	    var match = exp.exec(query);
    	    if (match) {
 	        if (match[1].toUpperCase() == 'ASK') {
 	        	service.setOutput('boolean');
@@ -144,7 +148,7 @@ function Snorql() {
 	        }
    	    }
 
-        service.query(query, {
+        service.query(querytext, {
             success: successFunc,
             failure: function(report) {
                 var message = report.responseText.match(/<pre>([\s\S]*)<\/pre>/);
@@ -175,7 +179,9 @@ function Snorql() {
 
     this.setNamespaces = function(namespaces) {
         this._namespaces = namespaces;
-        this._display(document.createTextNode(this._getPrefixes()), 'prefixestext');
+        var prefixes = this._getPrefixes();
+        document.getElementById('prefixes').value = prefixes;
+        this._display(document.createTextNode(prefixes), 'prefixestext');
     }
 
     this.switchToGraph = function(uri) {
@@ -246,12 +252,10 @@ function Snorql() {
         var mode = this._selectedOutputMode();
         if (mode == 'browse') {
             document.getElementById('queryform').action = this._browserBase;
-            document.getElementById('query').value = document.getElementById('querytext').value;
         } else {
-            //fix { bug
-            document.getElementById('query').value = this._getPrefixes() + document.getElementById('querytext').value;
             document.getElementById('queryform').action = this._endpoint;
         }
+        document.getElementById('query').value = document.getElementById('querytext').value;
         document.getElementById('jsonoutput').disabled = (mode != 'json');
         if(mode == 'html') {
            document.getElementById('jsonoutput').disabled = false;