Author: anuzzolese
Date: Mon Jul 25 17:09:36 2011
New Revision: 1150782

URL: http://svn.apache.org/viewvc?rev=1150782&view=rev
Log:
STANBOL-179 Added Web view and Rest view to the HTTP home of Stanbol Rules.

Added:
    
incubator/stanbol/trunk/rules/web/src/main/resources/org/apache/stanbol/rules/web/static/actions/tutorial.js
    
incubator/stanbol/trunk/rules/web/src/main/resources/org/apache/stanbol/rules/web/static/img/
    
incubator/stanbol/trunk/rules/web/src/main/resources/org/apache/stanbol/rules/web/static/img/loading.gif
   (with props)
Modified:
    
incubator/stanbol/trunk/rules/web/src/main/java/org/apache/stanbol/rules/web/RulesFragment.java
    
incubator/stanbol/trunk/rules/web/src/main/resources/org/apache/stanbol/rules/web/templates/org/apache/stanbol/rules/web/resources/RulesRootResource/index.ftl

Modified: 
incubator/stanbol/trunk/rules/web/src/main/java/org/apache/stanbol/rules/web/RulesFragment.java
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/web/src/main/java/org/apache/stanbol/rules/web/RulesFragment.java?rev=1150782&r1=1150781&r2=1150782&view=diff
==============================================================================
--- 
incubator/stanbol/trunk/rules/web/src/main/java/org/apache/stanbol/rules/web/RulesFragment.java
 (original)
+++ 
incubator/stanbol/trunk/rules/web/src/main/java/org/apache/stanbol/rules/web/RulesFragment.java
 Mon Jul 25 17:09:36 2011
@@ -116,6 +116,7 @@ public class RulesFragment implements We
        public List<ScriptResource> getScriptResources() {
                List<ScriptResource> resources = new 
ArrayList<ScriptResource>();
                resources.add(new ScriptResource("text/javascript", 
"actions/actions.js", this, 10));
+               resources.add(new ScriptResource("text/javascript", 
"actions/tutorial.js", this, 10));
         return resources;
        }
 

Added: 
incubator/stanbol/trunk/rules/web/src/main/resources/org/apache/stanbol/rules/web/static/actions/tutorial.js
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/web/src/main/resources/org/apache/stanbol/rules/web/static/actions/tutorial.js?rev=1150782&view=auto
==============================================================================
--- 
incubator/stanbol/trunk/rules/web/src/main/resources/org/apache/stanbol/rules/web/static/actions/tutorial.js
 (added)
+++ 
incubator/stanbol/trunk/rules/web/src/main/resources/org/apache/stanbol/rules/web/static/actions/tutorial.js
 Mon Jul 25 17:09:36 2011
@@ -0,0 +1,802 @@
+/**
+ * Author andrea.nuzzolese
+ *
+ **/
+
+var globalRDF = new Array();
+
+var globalDatabank = new Array();
+
+var databankCounter = 0;
+
+var inputRDF;
+
+/*
+* ExhibitDemo produce una serializzazione json del grafo RDF che pu˜ essere 
usata per visualizzare i risultati con Exhibit 
(http://www.simile-widgets.org/exhibit/).
+*/
+function ExhibitDemo(){
+
+}
+
+ExhibitDemo.prototype.serializeJSON = function(json){
+
+       // serializza il json+rdf in un formato compatibile con Exhibit (un 
esempio di json per exhibit si trova qui 
http://www.simile-widgets.org/exhibit/examples/presidents/presidents.js).
+       var jsonExhibit = "{ \"items\" : [";
+       
+       
+       // Carica il json+rdf nel databank di rdfquery. 
+       var databank = $.rdf.databank().load(json);
+       
+       // Prendi l'array di triple contenuto nel databank di rdfquery.
+       var triples = databank.triples();
+                                               
+                                               
+       /*
+        * Costruisci un array in modo che ad ogni individuo corrisponda un 
array di oggetti Statement che contengono coppie (proprietˆ, valore)
+        */ 
+       var myArray = new Array();
+               
+       for(var j=0; j<triples.length; j++) {
+                       
+               var index = 
triples[j].subject.toString().replace("<","").replace(">","");
+               
+               var predicate = 
triples[j].property.toString().replace("<","").replace(">","");
+               
+               var object = 
triples[j].object.toString().replace("<","").replace(">","");      
+               
+               var statements = myArray[index];
+               
+               if(statements == null){
+                       statements = new Array();
+               } 
+               
+               statements[statements.length] = new 
Statement(getLocalname(predicate), getLiteral(object)); 
+               
+               myArray[index] = statements;  
+       }
+       
+       
+       var first = true;
+       for(var index in myArray){
+       
+               var subject = getLocalname(index);
+               var statements = myArray[index];
+               
+               
+               
+               
+               var innerFirst = true;
+               
+               var item = "";
+               
+               var genre = "";
+               
+               var visitedProps = new Array();
+               
+               for(var i=0; i<statements.length; i++){
+                       var statement = statements[i];
+                       
+                       var prop = statement.getProperty();
+                       
+                       if(prop != "type"){
+                               
+                               if(prop == "genre"){
+                                       if(genre.length>0){
+                                               genre += ", ";
+                                       } 
+                                       genre += "\"" + statement.getObject() + 
"\"";
+                               }
+                               else if(!contains(visitedProps, prop)){
+                               
+                                       visitedProps[prop] = prop;
+                               
+                                       if(!innerFirst && !item.endsWith(",") 
&& item.length>0){
+                                               item += ",";
+                                       }
+                                       else{
+                                               innerFirst = false;
+                                       }
+                                       
+                                       
+                                       
+                                       item += "\"" + prop + "\" : \"" + 
statement.getObject() + "\"";
+                                       
+                               }
+                       }
+                       
+                       
+               }
+               
+               if(item.length > 0){
+                       
+                       if(!first){
+                               jsonExhibit += ",";
+                       }
+                       else{
+                               first = false;
+                       }
+                       
+                       if(genre.length > 0){
+                               item += ",  \"genre\" : [" + genre + "]";
+                       }
+                       jsonExhibit += "{" + item + ", \"type\" : \"Musician\" 
}";
+               }
+               
+               
+       }
+       
+       jsonExhibit += "]}";
+       
+       return jsonExhibit; 
+}
+
+
+// Oggetto Statement che contiene coppie (proprietˆ, valore)
+function Statement(property, object){
+       this.property = property;
+       this.object = object;
+       
+       this.getProperty = function() {
+               return this.property;
+       }
+       
+       this.getObject = function() {
+               return this.object;
+       }
+}
+
+
+/**
+ * Classe Tutorial.
+ * effettua le chiamate all'Enhancer, all'EntityHub e al Refactor
+ */
+function Tutorial(){
+
+       this.enhance = function(text, format){
+
+                       //dati da mandare in post
+                       var data = {
+                               // content  il parametro da passare a Stanbol
+                       content: text,
+                       // url  il parametro che identifica la locazione di 
Stanbol
+                       url: "http://localhost:8080/engines";,
+                       };
+                    
+                        $.ajaxSetup({ 
+                                       'beforeSend': function(xhr) {
+                                               xhr.setRequestHeader("Accept", 
"application/rdf+json")} 
+                                       }
+                               );
+                   
+                       $.ajax({
+                      type: "POST",
+                      url: "../proxy/proxy.php",
+                      data: data,
+                      success: function(result) {
+                          //alert(result);
+                               var jsonOBJ = jQuery.parseJSON(result);
+                               var databank = $.rdf.databank().load(jsonOBJ);
+                                   
+                                       var rdf = $.rdf({databank:databank});
+                           
+                           //seleziona con rdf query solo i 
fise:entity-reference, ossia solo le URI delle entitˆ trovate.
+                                       var references = rdf.prefix('fise', 
'http://fise.iks-project.eu/ontology/')
+                                                .where('?subject 
fise:entity-reference ?reference')
+                                                .select();
+                           var arrRefs = new Array();
+                               
+                           for(var subject in references){
+                               var referenceURI = 
references[subject].reference.toString().replace("<", "").replace(">", "");
+                               arrRefs.push(referenceURI);
+                           }
+                               
+                           arrRefs = unique(arrRefs);
+                               
+                           /*
+                            * Con questo ciclo for inserisco le uri delle 
entitˆ trovate.
+                            * Le uri vengono inserite all'interno del blocco 
div con ID entities.
+                            * La variabile contente contiene la lista delle 
entitˆ. 
+                            */
+                           var content = "";
+                           for(var uriRef in arrRefs){
+                               var uri = arrRefs[uriRef];
+                               content += "<input type=\"checkbox\" 
id=\""+uri+"\">" + uri + "</input><br>";
+                           }
+                          
+                           
+                           $('#entities').append(content);
+                           
+                                       $('#enginesOuput').show();
+                                       
+                      },
+                      error: function(result) {
+                        alert("Error");
+                      },
+                      dataType: "html"
+                    });
+               };
+       
+       this.queryEntityHub = function(){
+
+               var successfulRequests = 0;
+               
+               var entities = $('.indentLigth');
+               
+               
+               /*
+                * Add the recipe into the textarea identified by the ID 
recipecode.
+                * Show the recipe block. 
+                */
+               var recipeTMP = recipe.replaceAll("<", "&lt;").replaceAll(">", 
"&gt;");
+               $('#recipecode').html(recipeTMP);
+               $('#refactoringBlock').show();
+               
+               
+               for(var i=0; i<entities.length; i++){
+                       var entity = entities[i].id;
+                       
+                       
+                       $.ajaxSetup({ 
+                               'beforeSend': function(xhr) {
+                                       xhr.setRequestHeader("Accept", 
"application/rdf+json")} 
+                               }
+                       );
+                       
+                       var data = {
+                               id: entity.replace("-fetch", ""),
+                               url: 
"http://localhost:8080/entityhub/sites/entity";
+                       };
+                       
+                       $.ajax({
+                       type: "GET",
+                       
+                       // l'id  il parametro da inoltrare a Stanbol, url  il 
parametro che identifica la location di Stanbol (per il Proxy) 
+                       url: "../proxy/proxy.php",
+                       
+                       data: data,
+                       success: function(result) {
+                                       
+                               if(!result.startsWith("Entity")){
+                               
+                                       if(result.indexOf("gYear") != -1){
+                                               result = 
result.replaceAll("gYear", "string");
+                                               result = 
result.replaceAll("http://dbpedia.org/datatype/second";, "string");
+                                       }
+                                       
+                                       //alert(result);
+                                       var jsonGraph = $.parseJSON(result);
+                                       
+                                               
+                                               
+                                               var graphID = databankCounter;
+                                               
+                                               databankCounter += 1;
+                                               globalDatabank[graphID] = 
$.rdf.databank().load(jsonGraph);
+                                               
+                                               var rdf = 
$.rdf({databank:globalDatabank[graphID]});
+                                               
+                                               
+                                               
+                                               
+                                               var entities = 
rdf.prefix('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#')
+                                                                               
        .where('?s ?p ?o')
+                                                                               
        .select();
+                                                       
+                                               var ent = 
entities[0].s.toString().replace("<", "").replace(">", "");
+                                               
+                                               
+                                               ent = ent.replace(".meta", "");
+                                               
+                                               alert("ent " + ent);
+                                               
+                                               
+                                               entities = rdf.prefix('rdf', 
'http://www.w3.org/1999/02/22-rdf-syntax-ns#')
+                                                       .where('<'+ent+'> ?p 
?o')
+                                                       .select();
+                                               
+                                               /*
+                                                * var elem = 
document.getElementById(ent + "-fetch");
+                                                * var button = "<input 
type=\"button\" value=\"view\" 
onClick=\"javascript:document.getElementById('"+ent+"-summary').style.display = 
'block';\">";
+                                                * button += "<input 
type=\"button\" value=\"hide\" 
onClick=\"javascript:document.getElementById('"+ent+"-summary').style.display = 
'none';\"> Relevant entitytypes and properties";
+                                                * button += "<div id=\"" + ent 
+ "-summary\" class=\"indent\" style=\"display:none; margin-bottom:15px; 
width:90%; height: auto !important; min-height: 2em; overflow: hidden; 
border-style: dotted; border-width: 1px; padding:5px;\"><div id=\"" + ent + 
"-ref-types\" class=\"fetchedEntity\" style=\"width:50%; 
float:left;\"><b>Types</b><br/></div><div id=\"" + ent + "-ref-props\" 
class=\"fetchedEntity\" style=\"width:50%; 
float:right;\"><b>Properties</b><br/></div></div></div>";
+                                                * elem.innerHTML = 
elem.innerHTML + " " +  button; 
+                                                */
+                                               
+                                               
+                                               var content = "<li>"+ent;
+                                               content += "<input 
type=\"button\" value=\"view\" 
onClick=\"javascript:document.getElementById('"+ent+"-summary').style.display = 
'block';\">";
+                                               content += "<input 
type=\"button\" value=\"hide\" 
onClick=\"javascript:document.getElementById('"+ent+"-summary').style.display = 
'none';\"> Relevant entitytypes and properties";
+                                               content += "<div id=\"" + ent + 
"-summary\" class=\"indent\" style=\"display:none; margin-bottom:15px; 
width:90%; height: auto !important; min-height: 2em; overflow: hidden; 
border-style: dotted; border-width: 1px; padding:5px;\"><div id=\"" + ent + 
"-ref-types\" class=\"fetchedEntity\" style=\"width:50%; 
float:left;\"><b>Types</b><br/></div><div id=\"" + ent + "-ref-props\" 
class=\"fetchedEntity\" style=\"width:50%; 
float:right;\"><b>Properties</b><br/></div></div></div>";
+                                               
+                                               $('#graphs').append(content);
+                                               
+                                               
+                                               var propertyArray = new Array();
+                                               var typeArray = new Array();
+                                               
+                                               var typeArrayCounter = 0;
+                                               var propertyArrayCounter = 0;
+                                               for(var j=0; j<entities.length; 
j++){
+                                                       
+                                                       var property = 
entities[j].p.toString().replace("<", "").replace(">", "").replace(".meta", "");
+                                                       
+                                                       if(property == 
"http://www.w3.org/1999/02/22-rdf-syntax-ns#type";){
+                                                               var value = 
entities[j].o.toString().replace("<", "").replace(">", "").replace(".meta", "");
+                                                               
+                                                               
if(!contains(typeArray, value)){
+                                                                       var 
types = document.getElementById(ent + "-ref-types");
+                                                                       
types.innerHTML = types.innerHTML + value + "<br>";
+                                                                       
typeArray[typeArrayCounter] = value;
+                                                                       
typeArrayCounter += 1;
+                                                               }
+                                                       }
+                                                       else 
if(!contains(propertyArray, property)){
+                                                               var types = 
document.getElementById(ent + "-ref-props");
+                                                               types.innerHTML 
= types.innerHTML + property + "<br>";
+                                                               
propertyArray[typeArrayCounter] = property;
+                                                               
propertyArrayCounter += 1;
+                                                       }
+                                               }
+                               }
+                               
+                                       
+                               },
+                       error: function(result) {
+                                       alert("Error");
+                       },
+                    });
+               }
+               /*
+               var children = $('.fetchedEntity').children();
+               for(var i=0; i<children.length; i++){
+               
+                       var entity = $("#entities 
input:nth-child("+(i+1)+")").attr('id');
+                       //var entity = children[i].attr('id');
+                       
+                       
+                   
+                    
+               }
+               */
+       };
+       
+       
+       this.getSameAs = function(){
+               
+               
+               var children = $('#entities').children();
+               
+               for(var i=0; i<children.length; i++){
+               
+                       
+               
+                       var entity = $("#entities 
input:nth-child("+(i+1)+")").attr('id');
+                       
+                       if(entity != null){
+                               
+                               
+                               
+                               /*
+                                * Mostra il blocco div con ID sameas.
+                                * 
+                                */
+                               $('#sameas').show();
+                               
+                               var json = {
+                                                       "selected": 
["http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#type"], 
+                                                       "offset": "0", 
+                                                       "limit": "3", 
+                                                       "constraints": [ 
{"type": "reference", 
+                                                                               
                "field": "http:\/\/www.w3.org\/2002\/07\/owl#sameAs", 
+                                                                               
                "value": "" + entity + ""
+                                                                               
                        }] 
+                                                       };
+                               
+                               
+                               
+                               var jsontext = JSON.stringify(json);
+                               
+                               
+                               var data = {
+                                       query: encodeURI(jsontext),
+                                       binary: "true",
+                                       url: 
"http://localhost:8080/entityhub/sites/query";
+                               };
+                            
+                               $.ajax({
+                               type: "POST",
+                               
+                               // l'id  il parametro da inoltrare a Stanbol, 
url  il parametro che identifica la location di Stanbol (per il Proxy) 
+                               url: "../proxy/proxy.php",
+                               
+                               data: data,
+                               //contentType: "application/json",
+                               success: function(result) {
+                                               
+                                       
+                                       $('#sameasH3').show();
+                                       $('#showcodeoffetch').show();
+                                       
+                                       
+                                       result = 
result.replaceAll("http:\\/\\/www.w3.org\\/1999\\/02\\/22-rdf-syntax-ns#type", 
"rdftype")
+                                       
+                                               var jsonOBJ = 
$.parseJSON(result);
+                                               
+                                       var entityID = 
jsonOBJ.query.constraints[0].value; 
+                                       
+                                               var results = jsonOBJ.results;
+                                               
+                                               var reference;
+                                               
+                                               var content = "SameAs Entities 
found for " + entityID + "<br>";
+                                               
+                                               content += "<div id=\"" + 
entityID + "-fetch\" class=\"indentLigth\">" + entityID + "</div>";
+                                               for(var i=0; i<results.length; 
i++){
+                                                       var type = 
results[i].rdftype;
+                                                       
+                                                       var id = results[i].id
+                                                       
+                                                       
+                                                       content += "<div id=\"" 
+ id + "-fetch\" class=\"indentLigth\">" + id + "</div>";
+                                               }
+                                               
+                                               
+                                               /*
+                                                * Aggiungo le sameAs entity in 
testa al blocco div con ID sameas. 
+                                                */
+                                               
+                                               
$('#sameas').html(content+$('#sameas').html());
+                                               
+                                               
+                                       },
+                               error: function(result) {
+                                               alert("Error");
+                               },
+                            });
+                               
+                               
+                               
+                       }
+                       
+                       
+               }
+               
+       };
+       
+       
+       this.refactor = function(){
+       
+               
+               var graph = document.getElementById('input-rdf-graph');
+               var graphFile = graph.files[0];
+               //var graphString = graphFile.getAsText("")
+               
+               var reader = new FileReader();
+               reader.onload = function(e) { 
+                       
+                       
+                       var graphString = e.target.result; 
+                       
+               
+                       /*
+                        * Preparo il messaggio da mandare in post 
multipart/form-data.
+                        * E' come un messaggio di posta. Si compone di pi 
parti divise da un boundary.
+                        *
+                        */
+                       var boundary = 
"---------------------------7da24f2e50046";
+                       
+                       var rules = '--' + boundary + '\r\n'
+                        + 'Content-Disposition: form-data; name="recipe";' + 
'\r\n\r\n'
+                        + recipe + '\r\n';
+                       
+                       //rdf = Utf8.encode(rdf);
+                   
+                   /*
+                   rdf = Utf8.encode(rdf),
+                       
+                       rdf = rdf.replaceAll(" 
xmlns:xml=\"http://www.w3.org/XML/1998/namespace\"";, "");
+                       rdf = rdf.replaceAll(">\"", ">");
+                       rdf = rdf.replaceAll("\"<", "<");
+                       */
+                   
+                       rules += '--' + boundary + '\r\n'
+                        // Parameter name is "file" and local filename is 
"temp.txt"
+                        + 'Content-Disposition: form-data; name="input";'
+                        + 'filename="temp.txt"' + '\r\n'
+                        + 'Content-type: application/rdf+xml' + '\r\n\r\n'
+                        //+ rdf + '\r\n'
+                        + graphString + '\r\n'
+                        + '--' + boundary;
+                        
+                   
+                       
+               
+                        $.ajaxSetup({ 
+                               'beforeSend': function(xhr) {
+                                       //xhr.setRequestHeader("Accept", 
"application/manchester+owl")}
+                                       xhr.setRequestHeader("Accept", 
"application/turtle")}
+                               }
+                        );
+                        
+                            
+                       $.ajax({
+                       type: "POST",
+                       url: "http://localhost:8080/refactor/apply";,
+                       data: rules,
+                       contentType: 
'multipart/form-data;boundary=---------------------------7da24f2e50046',
+                       async: false,
+                       success: function(result) {
+                                       
+                               /*
+                                * Prepare the box with the refactored graph
+                                */
+                               
+                               var id = "refactoredGraph-0";
+                               
+                               result = result.replaceAll("<", 
"&lt;").replaceAll(">", "&gt;");
+                               
+                               var content =   "<li> OUTPUT "  +
+                                                               "<input 
type=\"button\" value=\"view\" onClick=\"javascript:$('#" + id + 
"').show();\">" +
+                                                               "<input 
type=\"button\" value=\"hide\" onClick=\"javascript:$('#" + id + 
"').hide();\"></li>" +
+                                                               "<div 
id=\"refactoredGraph-0\" style=\"display:none;\"><pre>" + result + 
"</pre></div>"
+                               
+                               $('#refactoringoutput').show();
+                               
+                               
+                               
+                               /*
+                                * Append the box with the refactored graph to 
the block with the ID refactoringoutput. 
+                                */
+                               
+                               $('#refactoringoutput').append(content);
+                               
+                                       
+                               },
+                       error: function(result) {
+                                       alert("Error");
+                       }
+                    });
+               
+               };  
+               var graphString = reader.readAsText(graphFile, "UTF-8");
+               
+                       
+       };
+               
+               
+       
+}
+
+
+function unique(arr) {
+       var r = new Array();
+       o:for(var i = 0, n = arr.length; i < n; i++)
+       {
+               for(var x = 0, y = r.length; x < y; x++)
+               {
+                       if(r[x]==arr[i])
+                       {
+                               continue o;
+                       }
+               }
+               r[r.length] = arr[i];
+       }
+       return r;
+};
+
+
+function getNamespace(resource) {
+
+       var slashIndex = resource.lastIndexOf("/");
+       var hashIndex = resource.lastIndexOf("#");
+       
+       var namespace;
+       if(slashIndex>hashIndex){
+               namespace = resource.substring(0, slashIndex+1);
+       }
+       else{
+               namespace = resource.substring(0, hashIndex+1);
+       }
+       
+       return namespace;
+}
+
+
+function getLiteral(resource){
+       if(resource.startsWith("\"\"")){
+               resource = resource.substring(2, resource.length);
+               if(resource.lastIndexOf("\"\"") > 0){
+                       resource = resource.substring(0, 
resource.lastIndexOf("\"\""));
+               }
+               
+       }
+       else if (resource.startsWith("\"")){
+               resource = resource.substring(1, resource.length);
+               if(resource.lastIndexOf("\"") > 0){
+                       resource = resource.substring(0, 
resource.lastIndexOf("\""));
+               }
+       }
+       return resource;
+}
+
+function getLocalname(resource) {
+
+       var slashIndex = resource.lastIndexOf("/");
+       var hashIndex = resource.lastIndexOf("#");
+       
+       var namespace;
+       if(slashIndex>hashIndex){
+               namespace = resource.substring(slashIndex+1, slashIndex.length);
+       }
+       else if(slashIndex<hashIndex){
+               namespace = resource.substring(hashIndex+1, hashIndex.length);
+       }
+       else{
+       
+               if(resource.startsWith("\"")){
+                       resource = resource.substring(2, resource.length);
+                       resource = resource.substring(0, 
resource.lastIndexOf("\"\""));
+               }
+               namespace = resource;
+       }
+       
+       return namespace;
+}
+
+String.prototype.replaceAll = function(stringToFind,stringToReplace){
+       var temp = this;
+       var index = temp.indexOf(stringToFind);
+    while(index != -1){
+        temp = temp.replace(stringToFind,stringToReplace);
+        index = temp.indexOf(stringToFind);
+    }
+    return temp;
+}
+
+String.prototype.startsWith = function(str){
+    return (this.indexOf(str) === 0);
+}
+
+String.prototype.endsWith = function(str){
+    return this.indexOf(str, this.length - str.length) !== -1;
+}
+
+function contains(a, obj){
+  for(var i in a) {
+    if(a[i] === obj){
+      return true;
+    }
+  }
+  return false;
+}
+
+var Utf8 = {
+ 
+       // public method for url encoding
+       encode : function (string) {
+               string = string.replace(/\r\n/g,"\n");
+               var utftext = "";
+ 
+               for (var n = 0; n < string.length; n++) {
+ 
+                       var c = string.charCodeAt(n);
+ 
+                       if (c < 128) {
+                               utftext += String.fromCharCode(c);
+                       }
+                       else if((c > 127) && (c < 2048)) {
+                               utftext += String.fromCharCode((c >> 6) | 192);
+                               utftext += String.fromCharCode((c & 63) | 128);
+                       }
+                       else {
+                               utftext += String.fromCharCode((c >> 12) | 224);
+                               utftext += String.fromCharCode(((c >> 6) & 63) 
| 128);
+                               utftext += String.fromCharCode((c & 63) | 128);
+                       }
+ 
+               }
+ 
+               return utftext;
+       },
+ 
+       // public method for url decoding
+       decode : function (utftext) {
+               var string = "";
+               var i = 0;
+               var c = c1 = c2 = 0;
+ 
+               while ( i < utftext.length ) {
+ 
+                       c = utftext.charCodeAt(i);
+ 
+                       if (c < 128) {
+                               string += String.fromCharCode(c);
+                               i++;
+                       }
+                       else if((c > 191) && (c < 224)) {
+                               c2 = utftext.charCodeAt(i+1);
+                               string += String.fromCharCode(((c & 31) << 6) | 
(c2 & 63));
+                               i += 2;
+                       }
+                       else {
+                               c2 = utftext.charCodeAt(i+1);
+                               c3 = utftext.charCodeAt(i+2);
+                               string += String.fromCharCode(((c & 15) << 12) 
| ((c2 & 63) << 6) | (c3 & 63));
+                               i += 3;
+                       }
+ 
+               }
+ 
+               return string;
+       }
+ 
+}
+
+function load_xml_content_string(xmlData) {
+       if (window.ActiveXObject) {
+               //for IE
+               xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
+               xmlDoc.async="false";
+               xmlDoc.loadXML(xmlData);
+               return xmlDoc;
+       } else if (document.implementation && 
document.implementation.createDocument) {
+               //for Mozila
+               parser=new DOMParser();
+               xmlDoc=parser.parseFromString(xmlData,"text/xml");
+               return xmlDoc;
+       }
+}
+
+function saveRecipe(){
+       var recipeTMP=$('#recipecode').val(); 
+       recipeTMP = recipeTMP.replaceAll("&lt;", "<").replaceAll("&gt;", ">"); 
+       recipe = recipeTMP; 
+       alert('The recipe as been saved');
+}
+
+var recipe = "dbpedia = <http://dbpedia.org/ontology/> . \n" +
+                       "dbpprop = <http://dbpedia.org/property/> . \n" +
+                       "google = <http://rdf.data-vocabulary.org/#> . \n" +
+                       "foaf = <http://xmlns.com/foaf/0.1/> . \n" +
+                       "rdf = <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . 
\n" +
+                       "skos = <http://www.w3.org/2004/02/skos/core#> . \n" +
+                       "gn = <http://www.geonames.org/ontology#> .\n" +
+                       "\n" +
+                       "peopleTypeRule [ is(dbpedia:Person, ?x) -> 
is(google:Person, ?x) ] . \n" +
+                       "peopleNameRule [ is(dbpedia:Person, ?x) . 
values(foaf:name, ?x, ?y) -> values(google:name, ?x, ?y) ] . \n" +
+                       "peopleNickRule [ is(dbpedia:Person, ?x) . 
values(foaf:nick, ?x, ?y) -> values(google:nickname, ?x, ?y) ] . \n" +
+                       "peoplePhotoRule [ is(dbpedia:Person, ?x) . 
has(dbpedia:thumbnail, ?x, ?y) -> has(google:photo, ?x, ?y) ] . \n" +
+                       "peopleProfessionRule [ is(dbpedia:Person, ?x) . 
has(dbpedia:profession, ?x, ?y) -> has(google:title, ?x, ?y) ] . \n" + 
+                       "peopleOccupationRule [ is(dbpedia:Person, ?x) . 
has(dbpedia:occupation, ?x, ?y) -> has(google:title, ?x, ?y) ] . \n" + 
+                       "peopleRoleRule [ is(dbpedia:Person, ?x) . 
values(dbpedia:role, ?x, ?y) -> values(google:role, ?x, ?y) ] . \n" + 
+                       "peopleHomepageRule [ is(dbpedia:Person, ?x) . 
has(foaf:homepage, ?x, ?y) -> has(google:url, ?x, ?y) ] . \n" + 
+                       "peopleAffiliationRule [ is(dbpedia:Person, ?x) . 
has(dbpedia:employer, ?x, ?y) -> has(google:affiliation, ?x, ?y) ] . \n" + 
+                       "peopleKnowsRule [ is(dbpedia:Person, ?x) . 
has(foaf:knows, ?x, ?y) -> has(google:friend, ?x, ?y) ] . \n" + 
+                       "peopleAddressRule [ is(dbpedia:Person, ?x) . 
values(dbpedia:address, ?x, ?y) -> values(google:address, ?x, ?y) ]";
+
+/*
+var recipe = rule = "dbpont = <http://dbpedia.org/ontology/> . \n" +
+                                       "foaf = <http://xmlns.com/foaf/0.1/> . 
\n" +
+                                       "rdfs = 
<http://www.w3.org/2000/01/rdf-schema#> . \n" +
+                                       "myNS = <http://www.cs.unibo.it/demo/> 
. \n" +
+                                       "yago = 
<http://dbpedia.org/class/yago/> . \n" +
+                                       
+                                       "musician[is(dbpont:MusicalArtist, 
?entity) -> is(myNS:Musician, ?entity)] . \n" +  
+                                       
+                                       // name
+                                       "name[is(dbpont:MusicalArtist, ?entity) 
. values(foaf:name, ?entity, ?name) -> values(rdfs:label, ?entity, ?name)] . 
\n" +
+                                       
+                                       // date and place of birh and death
+                                       "birthDate[is(dbpont:MusicalArtist, 
?entity) . has(dbpont:birthDate, ?entity, ?name) -> values(myNS:birth, ?entity, 
?name)] . \n" +
+                                       "birthDate[is(dbpont:MusicalArtist, 
?entity) . has(dbpont:deathDate, ?entity, ?name) -> values(myNS:death, ?entity, 
?name)] . \n" +
+                                       
+                                       "birthPlace[is(dbpont:MusicalArtist, 
?entity) . has(dbpont:birthPlace, ?entity, ?name) -> values(myNS:birthPlace, 
?entity, ?name)] . \n" +
+                                       "deathPlace[is(dbpont:MusicalArtist, 
?entity) . has(dbpont:deathPlace, ?entity, ?name) -> values(myNS:deathPlace, 
?entity, ?name)] . \n" +
+                                       
+                                       // picture
+                                       "dbpontImg[is(dbpont:MusicalArtist, 
?entity) . has(dbpont:thumbnail, ?entity, ?img) -> values(myNS:imageURL, 
?entity, ?img)] . \n" +
+                                       
+                                       // genre
+                                       "genre[is(dbpont:MusicalArtist, 
?entity) . has(dbpont:genre, ?entity, ?genre) -> values(myNS:genre, ?entity, 
?genre)]";
+
+*/
\ No newline at end of file

Added: 
incubator/stanbol/trunk/rules/web/src/main/resources/org/apache/stanbol/rules/web/static/img/loading.gif
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/web/src/main/resources/org/apache/stanbol/rules/web/static/img/loading.gif?rev=1150782&view=auto
==============================================================================
Binary file - no diff available.

Propchange: 
incubator/stanbol/trunk/rules/web/src/main/resources/org/apache/stanbol/rules/web/static/img/loading.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: 
incubator/stanbol/trunk/rules/web/src/main/resources/org/apache/stanbol/rules/web/templates/org/apache/stanbol/rules/web/resources/RulesRootResource/index.ftl
URL: 
http://svn.apache.org/viewvc/incubator/stanbol/trunk/rules/web/src/main/resources/org/apache/stanbol/rules/web/templates/org/apache/stanbol/rules/web/resources/RulesRootResource/index.ftl?rev=1150782&r1=1150781&r2=1150782&view=diff
==============================================================================
--- 
incubator/stanbol/trunk/rules/web/src/main/resources/org/apache/stanbol/rules/web/templates/org/apache/stanbol/rules/web/resources/RulesRootResource/index.ftl
 (original)
+++ 
incubator/stanbol/trunk/rules/web/src/main/resources/org/apache/stanbol/rules/web/templates/org/apache/stanbol/rules/web/resources/RulesRootResource/index.ftl
 Mon Jul 25 17:09:36 2011
@@ -50,14 +50,357 @@
 
        </div> <!-- end rules-tutorial -->
        
-       <div id="rules-syntax" class="title-point">
+       <!-- REFACTOR -->
+<div id="step13" style="margin-top:60px;">
+<h3>Hands-on about refactoring RDF graphs</h3>
+
+<!-- REFACTOR TUTORIAL-->
+
+<div id="showcodeofrefactoring" style="margin-top:10px;">
+
+<p><a href=http://localhost:8080/rules>Stanbol refactor</a> coverts RDF graphs 
given a set of mapping rules i.e. transformation patterns. Stanbol rule syntax 
is described in detail in the <a href=http://localhost:8080/rules>Stanbol 
rules</a> documentation page. </p>
+
+<p>Below you can see an example of transformation patterns defined for the GRS 
patterns</p>
+
+<div class="showcode">
+
+<input id="input-rdf-graph" type="file" value="upload"/>
+RDF graph in input to which the refactoring should be applied. <br/><br/>
+<input type="button" onClick="$('#recipe').show()" value="view"/> 
+<input type="button" onClick="$('#recipe').hide()" value="hide"/> 
+Transformation patterns defined as Stanbol Rules 
+<div id="recipe" class="indent" style="display:none;">
+<textarea id="recipecode" style="height:400px;">
+</textarea>
+<script type="text/javascript">
+var recipeTmp = recipe.replaceAll("<", "&lt;").replaceAll(">", "&gt;");
+$('#recipecode').val(recipeTmp);
+</script>
+<input type="button" style="float:right;" value="save" 
onClick="javascript:saveRecipe()">
+</div>
+<p>Click on the button below and view results!</p>
+<input type="button" value="refactor" onClick="javascript:var tutorial=new 
Tutorial(); tutorial.refactor();">
+<div id="refactoringoutput" class="indent" style="display:none"></div>
+<br>
+<p> See how to access the refactor service through cURL command as well as 
Javascript.</p>
+<input type="button" onClick="$('#refactoringcurl').show()" value="view"/> 
+<input type="button" onClick="$('#refactoringcurl').hide()" value="hide"/> 
+cURL command for refactor 
+<div id="refactoringcurl" class="indent" style="display:none">
+<pre>
+curl -X POST -H "Accept: application/rdf+xml" -F input=@<span 
style="color:red;">%rdfGraph%</span> -F recipe=<span 
style="color:red;">%refactoringRecipe%</span>
+</pre>
+</div>
+<br>
+<input type="button" onClick="$('#refactoringjavascript').show()" 
value="view"/> 
+<input type="button" onClick="$('#refactoringjavascript').hide()" 
value="hide"/> 
+Example of access to Stanbol refactor from a Javascript application 
+<div id="refactoringjavascript" class="indent" style="display:none">
+<pre>
+var message = "-----------------------------7da24f2e50046" +
+       "'Content-Disposition: form-data; name=\\"recipe\\";'" +
+       "<span style="color:red;">here goes the recipe</span>" +
+       "-----------------------------7da24f2e50046" +
+       "'Content-Disposition: form-data; name=\"input\";" +
+       "'filename=\"temp.txt\"'" + 
+       "'Content-type: application/rdf+xml'" + 
+       "<span style="color:red;">here goes the RDF graph</span>" +
+       "-----------------------------7da24f2e50046";
+
+$.ajax({
+       type: "POST",
+       url: "http://localhost:8080/refactor/apply";,
+       data: message,
+       contentType: 
'multipart/form-data;boundary=---------------------------7da24f2e50046',
+       success: function(result) {
+               ...
+       },
+       error: function(result) {
+               ...
+       }
+});
+</pre>
+</div> 
+</div>
+<!-- input type="button" value="next step" 
onClick="javascript:$('#step14').show();" / -->
+</div>
+<div id="step14">
+
+<!-- REFACTOR HANDSON (ex2)  -->
+
+</div>
+
+<!-- FINE BLOCCO DI OUTPUT DELL'ENTITY HUB PER IL FETCHING  -->
+
+<!-- INIZIO BLOCCO DI OUTPUT DEL REFACTOR  -->
+
+<!-- FINE BLOCCO DI OUTPUT DEL REFACTOR  -->
+
+
+</div>
+       
+       <div id="rules-syntax" class="title-point" style="margin-top:60px;">
                <h3>Rules syntax in BNF</h3>
                <div id="syntax-body"><@ruleSyntax.view /></div>
        </div>
 
 </div> <!-- end webview -->
 
-<div class="panel" id="restapi" style="display: none;"/>
+<div class="panel" id="restapi" style="display: none;">
+<h3> Getting rules from the rule store ("/rule") </h3>
+Request type: GET<br><br>
+Accepted MIME types:
+<ul>
+<li>application/rdf+xml</li>
+<li>text/owl-manchester</li>
+<li>application/rdf+json</li>
+<li>application/turtle</li>
+<li>application/owl-functional</li>
+</ul>
+
+Parameters:
+
+<ul>
+<li> <b>uri (Mandatory).</b> The URI which identifies the rule in the rule 
store. The
+ parameter has to be passed as a path parameter</li> 
+</ul>
+Possible outputs:
+<ul>
+  <li> 200 The rule is retrieved (import declarations point to KReS Services) 
</li>
+  <li> 404 The rule does not exists in the manager </li>
+  <li> 500 Some error occurred </li>
+</ul>
+
+Request example which returns the RDF representation of a rule identified
+by the URI <http://iks-project.eu/rules/rule1> in its RDF/XML serialization.
+<pre style="margin-bottom:40px;">
+$ curl -X GET -H "Accept: application/rdf+xml" \
+  http://localhost:8080/rule/http://iks-project.eu/rules/rule1
+</pre>
+
+<h3> Adding rules to the rule store ("/rule") </h3>
+Request type: POST<br><br>
+
+Parameters:
+
+<ul>
+<li> <b>recipe (Mandatory).</b> The recipe's identifier. It is the recipe to 
which the
+ rules should be added</li>
+ <li> <b>rule (Mandatory).</b> The rule's identifier. It can be any unique 
string, e.g. a URI</li> 
+ <li> <b>kres-syntax (Mandatory).</b> The rule content expressed with the 
Stanbol Rules
+ syntax</li>
+ <li> <b>description.</b> A textual description of the behaviour of the 
rule</li>
+</ul>
+Possible outputs:
+<ul>
+  <li> 200 The rule has been added </li>
+  <li> 204 The rule has not been added </li>
+  <li> 400 The rule and recipe are not specified </li>
+  <li> 404 Recipe or rule not found </li>
+  <li> 409 The rule has not been added </li>
+  <li> 500 Some error occurred </li>
+</ul>
+
+Request example which shows how can be used the service in order to
+create a rule:
+<pre style="margin-bottom:40px;">
+$ curl -X POST -d recipe="http://iks-project.eu/recipies/recipeA"; \
+      -d rule="http://iks-project.eu/rule/uncleRule"; \
+      -d kres-syntax= \
+                  "has(<http://www.foo.org/myont.owl#hasFather>, ?x, ?z) . \
+                  has(<http://www.foo.org/myont.owl#hasBrother>, ?z, ?y) \
+                    -> \
+                  has(<http://www.foo.org/myont.owl#hasUncle>, ?x, ?y)" \
+      -d description="The rule which allows to infer hasUncle relations." \
+      http://localhost:8080/rule \
+</pre>
+
+<h3> Removing rules from the rule store ("/rule") </h3>
+Request type: DELETE<br><br>
+
+Parameters:
+
+<ul>
+ <li> <b>rule (Mandatory).</b> The rule's identifier. It can be any unique 
string, e.g. a URI</li> 
+ <li> <b>recipe.</b> The recipe's identifier. It is the recipe from which
+ the rules should be removed. When the parameter is provided, the rule is
+ removed only from the recipe, but it is still availavle in the rule base.
+ Otherwise, if the parameter is not provided, the rule is completely deleted
+ from the rule store</li>
+</ul>
+Possible outputs:
+<ul>
+  <li> 200 The rule has been deleted </li>
+  <li> 204 The rule has not been deleted </li>
+  <li> 404 Recipe or rule not found </li>
+  <li> 409 The recipe has not been deleted </li>
+  <li> 500 Some error occurred </li>
+</ul>
+
+Request example which shows how to delete a rule from a recipe leaving it
+into the rule store:
+<pre style="margin-bottom:40px;">
+$ curl -X DELETE -G -d recipe="http://iks-project.eu/recipies/recipeA"; \
+      -d rule="http://iks-project.eu/rule/uncleRule"; \
+      http://localhost:8080/rule
+</pre>
+
+<h3> Getting recipes from the rule store ("/recipe") </h3>
+Request type: GET<br><br>
+
+Accepted MIME types:
+<ul>
+<li>application/rdf+xml</li>
+<li>text/owl-manchester</li>
+<li>application/rdf+json</li>
+<li>application/turtle</li>
+<li>application/owl-functional</li>
+</ul>
+
+Parameters:
+
+<ul>
+ <li> <b>uri (Mandatory).</b> The recipe's identifier that is basically an 
URI</li>
+</ul>
+Possible outputs:
+<ul>
+  <li> 200 The recipe is retrieved </li>
+  <li> 404 The recipe does not exists in the manager </li>
+  <li> 500 Some error occurred </li>
+</ul>
+
+Request example which shows how to get a recipe from the rule store:
+<pre style="margin-bottom:40px;">
+$ curl -X GET \
+      http://localhost:8080/recipe/http://iks-project.eu/recipies/recipeA
+</pre>
+
+<h3> Adding recipes to the rule store ("/recipe") </h3>
+Request type: POST<br><br>
+
+Parameters:
+
+<ul>
+ <li> <b>recipe (Mandatory).</b> The recipe's identifier that is basically an 
URI</li>
+ <li> <b>description.</b> The textual description of the recipe</li>
+</ul>
+Possible outputs:
+<ul>
+  <li> 200 The recipe has been added </li>
+  <li> 409 The recipe has not been added </li>
+  <li> 500 Some error occurred </li>
+</ul>
+
+Request example which shows how to create a recipe and add it into the rule
+store:
+<pre style="margin-bottom:40px;">
+$ curl -X POST \
+      -d recipe="http://iks-project.eu/recipies/recipeA"; \
+      -d description="Example of recipe." \
+      http://localhost:8080/recipe
+</pre>
+
+<h3> Removing recipes from the rule store ("/recipe") </h3>
+Request type: DELETE<br><br>
+
+Parameters:
+
+<ul>
+ <li> <b>recipe (Mandatory).</b> The recipe's identifier that is basically an 
URI</li>
+</ul>
+Possible outputs:
+<ul>
+  <li> 200 The recipe has been delted </li>
+  <li> 409 The recipe has not been deleted </li>
+  <li> 500 Some error occurred </li>
+</ul>
+
+Request example which shows how to delete a recipe from the rule
+store:
+<pre style="margin-bottom:40px;">
+$ curl -X DELETE -G \
+      -d recipe="http://iks-project.eu/recipies/recipeA"; \
+      http://localhost:8080/recipe
+</pre>
+
+
+<h3> Refactoring RDF graphs ("/refactor") </h3>
+Request type: GET<br><br>
+
+Accepted MIME types:
+<ul>
+<li>application/rdf+xml</li>
+<li>text/owl-manchester</li>
+<li>application/rdf+json</li>
+<li>application/turtle</li>
+<li>application/owl-functional</li>
+</ul>
+
+Parameters:
+
+<ul>
+ <li> <b>recipe (Mandatory).</b> The recipe's identifier that is basically an 
URI</li>
+ <li> <b>input-graph (Mandatory).</b> The ID of the graph to transform</li>
+ <li> <b>output-graph (Mandatory).</b> The ID that the transformed graph has 
to have in
+ the IKS triple store</li>
+</ul>
+Possible outputs:
+<ul>
+  <li> 200 The refactoring is performed and a new RDF graph is returned </li>
+  <li> 404 The recipe does not exists in the manager </li>
+  <li> 500 Some error occurred </li>
+</ul>
+
+Request example which shows how to perform a refactoring
+applying an existing recipe in the rule store:
+<pre style="margin-bottom:40px;">
+$ curl -X GET -G -H "Accept: application/rdf+xml" \
+      -d recipe="http://iks-project.eu/recipies/recipeA"; \
+      -d input-graph="http://iks-project.eu/graphs/graphIn"; \
+      -d output-graph="http://iks-project.eu/graphs/graphOut"; \
+      http://localhost:8080/refactor
+</pre>
+
+<h3> Refactoring RDF graphs ("/refactor/apply") </h3>
+Request type: POST<br><br>
+
+Accepted MIME types:
+<ul>
+<li>application/rdf+xml</li>
+<li>text/owl-manchester</li>
+<li>application/rdf+json</li>
+<li>application/turtle</li>
+<li>application/owl-functional</li>
+</ul>
+
+Parameters:
+
+<ul>
+ <li> <b>recipe (Mandatory).</b> The recipe's identifier that is basically an 
URI</li>
+ <li> <b>input-graph (Mandatory).</b> The ID of the graph to transform</li>
+ <li> <b>output-graph (Mandatory).</b> The ID that the transformed graph has 
to have in
+ the IKS triple store</li>
+</ul>
+Possible outputs:
+<ul>
+  <li> 200 The refactoring is performed and a new RDF graph is returned </li>
+  <li> 404 The recipe does not exists in the manager </li>
+  <li> 500 Some error occurred </li>
+</ul>
 
+Request example which shows how to perform a refactoring
+applying an existing recipe in the rule store:
+<pre style="margin-bottom:40px;">
+$ curl -X POST -H "Content-Type: multipart/form-data" \
+      -H "Accept: application/turtle" \
+      -F recipe="
+           has(<http://www.foo.org/myont.owl#hasFather>, ?x, ?z) . \
+           has(<http://www.foo.org/myont.owl#hasBrother>, ?z, ?y) \
+              -> \
+           has(<http://www.foo.org/myont.owl#hasUncle>, ?x, ?y)" \
+      -F [email protected]
+      http://localhost:8080/refactor/apply
+</pre>
+</div>
 </@common.page>
 </#escape>
\ No newline at end of file


Reply via email to