04/11/2014
28/10/2014
parsing d'un fichier mm de Freemind avec Processing
XML xml;
XML xml_mm;
int indent=0;
ArrayList liens;
ArrayList lien;
void setup() {
//MM VERS RDF
xml_mm = loadXML("Smag0versrdf.mm");
//noeud principal
XML child_mm = xml_mm.getChild("node");
String ID_centre = child_mm.getString("ID");
String texte_centre = child_mm.getString("TEXT");
// String contenu = children_mm[i].getContent();
println("Noeud central : "+ID_centre + ", " + texte_centre + ", ");
list_node_rec( child_mm);
}
void list_node_rec(XML _noeud) {
//branches racines
//println (indent);
if (_noeud.hasChildren()) {
XML[] children_mm_branches = _noeud.getChildren("node");
print(children_mm_branches.length);
// String indentation=calcul_indentation(indent);
for (int i = 0; i < children_mm_branches.length; i++) {
indent++;
XML nouveauNoeud=children_mm_branches[i];
String ID = nouveauNoeud.getString("ID");
String texte = nouveauNoeud.getString("TEXT");
// liens.add(new Lien());
// lien.add(_noeud.getString("ID"));
// lien.add(ID);
// liens.add(lien);
// String contenu = children_mm[i].getContent();
// print(indentation);
println("");
print(indent);
for (int h=0; h< indent+1; h++){
print(" ");}
print(ID + ", " + texte + ", ");
list_node_rec(nouveauNoeud );
indent--;
//print("\n");
}
}
}
String calcul_indentation(int indent) {
String indentationTemp="";
for (int j=1; j<indent; j++) {
indentationTemp+=" ";
}
return indentationTemp;
}
le fichier Smag0versrdf.mm peut être vu /modifié grace à l'application FreemindXML xml_mm;
int indent=0;
ArrayList liens;
ArrayList lien;
void setup() {
//MM VERS RDF
xml_mm = loadXML("Smag0versrdf.mm");
//noeud principal
XML child_mm = xml_mm.getChild("node");
String ID_centre = child_mm.getString("ID");
String texte_centre = child_mm.getString("TEXT");
// String contenu = children_mm[i].getContent();
println("Noeud central : "+ID_centre + ", " + texte_centre + ", ");
list_node_rec( child_mm);
}
void list_node_rec(XML _noeud) {
//branches racines
//println (indent);
if (_noeud.hasChildren()) {
XML[] children_mm_branches = _noeud.getChildren("node");
print(children_mm_branches.length);
// String indentation=calcul_indentation(indent);
for (int i = 0; i < children_mm_branches.length; i++) {
indent++;
XML nouveauNoeud=children_mm_branches[i];
String ID = nouveauNoeud.getString("ID");
String texte = nouveauNoeud.getString("TEXT");
// liens.add(new Lien());
// lien.add(_noeud.getString("ID"));
// lien.add(ID);
// liens.add(lien);
// String contenu = children_mm[i].getContent();
// print(indentation);
println("");
print(indent);
for (int h=0; h< indent+1; h++){
print(" ");}
print(ID + ", " + texte + ", ");
list_node_rec(nouveauNoeud );
indent--;
//print("\n");
}
}
}
String calcul_indentation(int indent) {
String indentationTemp="";
for (int j=1; j<indent; j++) {
indentationTemp+=" ";
}
return indentationTemp;
}
Derniers test d'interface, parsing MindMap en RDF, parsing ontologie owl, et igeo avec Processing
voir en détail le fichier Freemind dans le data du "mm_vers_rdf_28-10" pour plus de détails
voir en détail le fichier Freemind dans le data du "mm_vers_rdf_28-10" pour plus de détails
Libellés :
agents,
carte mentale,
freemind,
igeo,
mind mapping,
ontologie,
ontology,
owl,
pasing Mindmap,
Processing,
rdf
Pays/territoire :
Lyon, France
01/10/2014
Android , Fuseki & RDF. Utilisation de APPINVENTOR 2 pour envoyer des triplets au serveur Fuseki
Pour rappel :
Le but est de faciliter l'échange d'information entre les différents objets connectés.
On utilise un serveur Fuseki. Le serveur fuseki permet de stocker les informations sous forme de triplets Sujet/propriété/Objet comme par exemple ("Voiture" "couleur" "rouge")
voir RDF / web sémantique / Jena / Fuseki ... pour plus d'infos sur le sujet.
pour résumer : RDF permet aux machines d'inférer ou de déduire des informations qui n'existent pas , à partir des relations entre les informations qui existent.
Dans le cadre du projet, nous avons besoin d'un serveur où sont partagées les informations.
Attention, les données ne sont pour l'instant pas sécurisées et tout le monde peut y mettre / remplacer, effacer tout et n'importe quoi.
Ce serveur est un peu un tableau blanc où chacun peut poser tout type d'information.
Le serveur est accessible via l'adresse : http://fuseki-smag0.rhcloud.com
pour consulter les informations qui y sont présentes, vous pouvez utiliser :
- les formulaires en cliquant sur "Control Panel", choisissez le dataset "ds" puis cliquez sur "Select".
ensuite dans la zone de texte "Sparql Query" saisissez la requete suivante :
cliquez ensuite sur "Get Result"
ceci vous affiche 100 informations
On trouve des infos pour faire des requetes sparql un peu partout : exemple là http://rdf.myexperiment.org/howtosparql?page=Using+the+SPARQL+Endpoint#
- ou directement :
http://fuseki-smag0.rhcloud.com/ds/query?query=select+*+WHERE+%7B%3Fs+%3Fp+%3Fo%7D&output=xml&stylesheet=%2Fxml-to-html.xsl
Depuis un bout de temps, je cherche le moyen d'envoyer des informations au format RDF sur ce serveur depuis mon smartphone Android pour pouvoir transmettre des informations au système Smag qui est sensé gérer les objets connectés que nous aurons dans nos habitations.
Plusieurs tests avec APDE, androjena, arqoid, (voir articles précédents...) mais je ne trouve pas ce qu'il faut, car l'utilisation de Jena plante les applis android
Par contre avec Appinventor j'ai un début de solution.
Le serveur Fuseki, n'acceptant que les requetes Post ou Put pour updater les informations, il a fallu décortiquer la requete http :
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX ns: <http://example.org/ns#>
INSERT DATA {
GRAPH <http://example/bookStore> {
<http://example/book14> ns:price 6 }
}
Pour tester, modifier l'appli, vous devez télécharger ce fichier : https://drive.google.com/file/d/0B0zEK4yLB5C6cTZvN01jemQ5bHM/edit?usp=sharing
et l'importer dans Appinventor : http://ai2.appinventor.mit.edu/
Reste maintenant à récupérer les Prefix, et proposer une liste de propriétés courantes, récupération des infos, recherches dans la base... modification des infos, et vote pour chaque info, pour valider leur véracité, sécurisation des données perso.
un coup de main pour l'utilisation de Appinventor ou de ce fichier ? n'hésitez pas à laisser un message
Le but est de faciliter l'échange d'information entre les différents objets connectés.
On utilise un serveur Fuseki. Le serveur fuseki permet de stocker les informations sous forme de triplets Sujet/propriété/Objet comme par exemple ("Voiture" "couleur" "rouge")
voir RDF / web sémantique / Jena / Fuseki ... pour plus d'infos sur le sujet.
pour résumer : RDF permet aux machines d'inférer ou de déduire des informations qui n'existent pas , à partir des relations entre les informations qui existent.
Dans le cadre du projet, nous avons besoin d'un serveur où sont partagées les informations.
Attention, les données ne sont pour l'instant pas sécurisées et tout le monde peut y mettre / remplacer, effacer tout et n'importe quoi.
Ce serveur est un peu un tableau blanc où chacun peut poser tout type d'information.
Le serveur est accessible via l'adresse : http://fuseki-smag0.rhcloud.com
pour consulter les informations qui y sont présentes, vous pouvez utiliser :
- les formulaires en cliquant sur "Control Panel", choisissez le dataset "ds" puis cliquez sur "Select".
ensuite dans la zone de texte "Sparql Query" saisissez la requete suivante :
select * WHERE { ?s ?p ?o} LIMIT 100
puis dans Output, choisissez "xml"cliquez ensuite sur "Get Result"
ceci vous affiche 100 informations
On trouve des infos pour faire des requetes sparql un peu partout : exemple là http://rdf.myexperiment.org/howtosparql?page=Using+the+SPARQL+Endpoint#
- ou directement :
http://fuseki-smag0.rhcloud.com/ds/query?query=select+*+WHERE+%7B%3Fs+%3Fp+%3Fo%7D&output=xml&stylesheet=%2Fxml-to-html.xsl
Depuis un bout de temps, je cherche le moyen d'envoyer des informations au format RDF sur ce serveur depuis mon smartphone Android pour pouvoir transmettre des informations au système Smag qui est sensé gérer les objets connectés que nous aurons dans nos habitations.
Plusieurs tests avec APDE, androjena, arqoid, (voir articles précédents...) mais je ne trouve pas ce qu'il faut, car l'utilisation de Jena plante les applis android
Par contre avec Appinventor j'ai un début de solution.
Le serveur Fuseki, n'acceptant que les requetes Post ou Put pour updater les informations, il a fallu décortiquer la requete http :
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX ns: <http://example.org/ns#>
INSERT DATA {
GRAPH <http://example/bookStore> {
<http://example/book14> ns:price 6 }
}
Pour tester, modifier l'appli, vous devez télécharger ce fichier : https://drive.google.com/file/d/0B0zEK4yLB5C6cTZvN01jemQ5bHM/edit?usp=sharing
et l'importer dans Appinventor : http://ai2.appinventor.mit.edu/
Reste maintenant à récupérer les Prefix, et proposer une liste de propriétés courantes, récupération des infos, recherches dans la base... modification des infos, et vote pour chaque info, pour valider leur véracité, sécurisation des données perso.
un coup de main pour l'utilisation de Appinventor ou de ce fichier ? n'hésitez pas à laisser un message
Libellés :
android,
androjena,
Appinventor,
jena,
post,
rdf,
semantic,
semantique,
sparql,
update
Pays/territoire :
Montreuil, France
15/09/2014
serveur Fuseki accessible depuis un smartphone Android grâce à Apde
Développé sur mon staraddict 4 avec Apde ( voir sur Google play). Les librairies que j'ai pu trouver ne sont pas compatibles avec Android ou Apde , j'ai donc utilisé http de apache ( androjena, rdfonthego, microjena)
Nota : le code est brut et pas nettoyé, avec tous les essais.
Nota 2 : pour insérer une information, modifiez la requête update , par exemple la ligne commençant par : " update+="smag:Robokaze"
Nota 3: pour en savoir plus sur Rdf et la manière de stocker les informations :
https://plus.google.com/114521704339515532783/posts/jcwovt7vTsZ
Pour enregistrer des infos sur le serveur :
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import android.view.inputmethod.InputMethodManager;
import android.content.Context;
//public class RequestParamExample {
//public static void main(String[] args) {
// }
String message;
String update;
HttpClient httpclient;
void setup(){
background(0);
try {
update="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ";
update+="PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>" ;
update+="PREFIX smag: <http://smag0.blogspot.fr/NS/>";
update+="PREFIX zoo: <http://example.org/zoo/>";
update+="PREFIX owl: <http://www.w3.org/2002/07/owl#>";
update+="PREFIX ex: <http://example.org/>";
update+="INSERT DATA {";
update+="GRAPH <http://smag0.blogspot.fr/GraphTest>{";
update+="smag:Robokaze rdf:type smag:Site .";
update+="smag:Robokaze smag:objectif 'un site de vente revente piece detachees , pour robots, et objets connectes' .";
update+="ex:cat rdfs:subClassOf ex:animal .";
update+="zoo:host rdfs:range ex:animal .";
update+="ex:zoo1 zoo:host ex:cat2 .";
update+="ex:cat3 owl:sameAs ex:cat2 .";
update+="}}";
// message="";
//String message;
//HttpParameterPost();
message=new String("Votre ecran peut vous apparaitre tout noir,\n a la premiere connexion au serveur, \n merci de patienter quelques dizaines de secondes au plus \n");
//private static void HttpParameterPost() {
httpclient = new DefaultHttpClient();
HttpPost httpPost=new HttpPost("http://fuseki-smag0.rhcloud.com/ds/update?");
// HttpPost httpPost = new HttpPost("http://192.168.1.52:3030/ds/update?");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
// nameValuePairs.add(new BasicNameValuePair("update", "INSERT {<bola> <bolb> <bolc>} WHERE {?s ?p ?o}" ));
nameValuePairs.add(new BasicNameValuePair("update", update));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
System.out.println("executing request " + httpPost.getRequestLine());
HttpResponse response = httpclient.execute(httpPost);
HttpEntity resEntity = response.getEntity();
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
if (resEntity != null) {
System.out.println("Response content length: " + resEntity.getContentLength());
System.out.println("Chunked?: " + resEntity.isChunked());
String responseBody = EntityUtils.toString(resEntity);
System.out.println("Data: " + responseBody);
message+= "Response content length: " + resEntity.getContentLength()+"\n";
message+="Chunked?: " + resEntity.isChunked()+"\n";
// String responseBody = EntityUtils.toString(resEntity);
message+="Data: " + responseBody+"\n";
// message="45" ;
}
// EntityUtils.consume(resEntity);
}
catch (Exception e) {
System.out.println(e);
message+=e;
}
finally {
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
httpclient.getConnectionManager().shutdown();
}
}
void draw(){
text(message,100,100);
}
void showVirtualKeyboard()
{
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
void hideVirtualKeyboard()
{
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
}
pour lire des infos sur le serveur :
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import java.util.Scanner;
//arqoid
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import com.hp.hpl.jena.ontology.Individual;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.InfModel;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.reasoner.Reasoner;
import com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasoner;
import com.hp.hpl.jena.reasoner.rulesys.Rule;
//import com.hp.hpl.jena.update.*;
import com.hp.hpl.jena.sparql.core.Prologue;
String err="";
String url="";
//UpdateRequest update;
DefaultHttpClient httpClient;
HttpEntity entity;
HttpResponse response;
String reponse;
PImage img;
String url_img="";
HttpEntity entity_img;
HttpResponse response_img;
String reponse_img;
void setup() {
background(0);
String req_insert_prefix="PREFIX+ns:+<http://example.org/ns#>";
req_insert_prefix+="PREFIX dc: <http://purl.org/dc/elements/1.1/>";
req_insert_prefix+="PREFIX d: <http://example.com/ns/data#>";
req_insert_prefix+="PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>";
String req_insert="INSERT DATA";
req_insert+="{ GRAPH <http://example/bookStore> { ";
req_insert+="<http://example/bidule> ns:price 42 ." ;
//req_insert+="d:i1 rdfs:label \"one\" .";
//d:i2 rdfs:label "two" .
req_insert+=" }}";
//url="http://fuseki-smag0.rhcloud.com/ds/update?update="+req_insert_prefix+req_insert;
//text(url,20,200);
//
//insert();
//img = loadImage("image.jpg");
img=loadImage("http://3.bp.blogspot.com/-MbiBWE4xcD0/Ux90q1F1RsI/AAAAAAAAAS8/hRpHBM5E4PE/s1600/Rover_5421698457340622361.JPG" ) ;
// img=loadImage("http://88.142.232.252:8090/?action=stream");
/*
try{
img=loadImage("http://88.142.232.252:8090/?action=stream");
}
catch( Exception e ) {
e.printStackTrace();
err+=e.toString();
text(e.toString(), 100, 200);
}
*/
//String url="http://127.0.0.1:8080" ;
//String url="http://88.142.232.252:3030/ds/query?query=construct+where+%7B%3Fs+%3Fp+%3Fo%7D";
String url="http://fuseki-smag0.rhcloud.com/ds/query?query=construct+where+%7B%3Fs+%3Fp+%3Fo%7D";
// String url="http://fuseki-smag0.rhcloud.com/ds/query?query=select+*+where+%7B%3Fs+%3Fp+%3Fo%7D";
// String url = "https://www.google.fr/search?q=test";
// https://www.google.fr/search?site=&source=hp&ei=PQX2U5qfMdPY0QXP_IGYAg&q=test&oq=test&gs_l=mobile-gws-hp.3..35i39j0l4.2250.2976.0.3886.6.5.1.1.1.0.168.532.0j4.4.0....0...1c.1.51.mobile-gws-hp..1.5.457.3.BSrYBhzULXU
text(" Recuperation des informations depuis :",100,100);
text(url,100,120);
try {
httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet( url );
// ArrayList<BasicNameValuePair> nameValuePairs = new ArrayList<BasicNameValuePair>(2);
// nameValuePairs.add(new BasicNameValuePair("q", "value1"));
// nameValuePairs.add(new BasicNameValuePair("param2", "value2"));
// httpGet.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// println( "executing request: " + httpPost.getRequestLine() );
response = httpClient.execute( httpGet );
entity = response.getEntity();
if ( entity != null ) {
// String reponse;
// entity.writeTo( reponse );
// String reponse=new String(entity.getContent());
reponse = new Scanner(entity.getContent(), "UTF-8").useDelimiter("\\A").next();
}
// if ( entity != null ) entity.consumeContent();
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
// httpClient.getConnectionManager().shutdown();
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
// httpClient.getConnectionManager().shutdown();
}
catch( Exception e ) {
e.printStackTrace();
err+=e.toString();
text(e.toString(), 100, 100);
}
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
httpClient.getConnectionManager().shutdown();
// exit();
}
void draw() {
background(0);
text("Smag", displayWidth-50, 10);
text(url, 20, 200);
text(err, 10, 100);
// text(update.toString(),50,100);
if ( entity != null ) {
text("----------------------------------------", 10, 10);
text( response.getStatusLine().toString(), 10, 20);
text("----------------------------------------", 10, 30);
// String reponse;
// entity.writeTo( reponse );
// String reponse=new String(entity.getContent());
// try{ String reponse = new Scanner(entity.getContent(), "UTF-8").useDelimiter("\\A").next();
text(reponse, 10, 100);
// }
// catch( Exception e ) {
// e.printStackTrace();
// err=e.toString();
// text(e.toString(), 100, 100);
//}
// Displays the image at its actual size at point (0,0)
// image(img, 0, 0);
// Displays the image at point (0, height/2) at half of its size
image(img, 0, displayHeight-100, img.width/2, img.height/2);
}
}
void insert() {
// update = UpdateFactory.create("");
// UpdateProcessRemote riStore = (UpdateProcessRemote) UpdateExecutionFactory.createRemote(update, "http://myendpointuri");
// riStore.execute();
}
// The following short JSON file called "data.json" is parsed // in the code below. It must be in the project's "data" folder. // // { // "id": 0, // "species": "Panthera leo", // "name": "Lion" // } JSONObject json; void setup() { json = loadJSONObject("data.json"); int id = json.getInt("id"); String species = json.getString("species"); String name = json.getString("name"); println(id + ", " + species + ", " + name); } // Sketch prints: // 0, Panthera leo, Lion
Nota : le code est brut et pas nettoyé, avec tous les essais.
Nota 2 : pour insérer une information, modifiez la requête update , par exemple la ligne commençant par : " update+="smag:Robokaze"
Nota 3: pour en savoir plus sur Rdf et la manière de stocker les informations :
https://plus.google.com/114521704339515532783/posts/jcwovt7vTsZ
Pour enregistrer des infos sur le serveur :
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import android.view.inputmethod.InputMethodManager;
import android.content.Context;
//public class RequestParamExample {
//public static void main(String[] args) {
// }
String message;
String update;
HttpClient httpclient;
void setup(){
background(0);
try {
update="PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ";
update+="PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>" ;
update+="PREFIX smag: <http://smag0.blogspot.fr/NS/>";
update+="PREFIX zoo: <http://example.org/zoo/>";
update+="PREFIX owl: <http://www.w3.org/2002/07/owl#>";
update+="PREFIX ex: <http://example.org/>";
update+="INSERT DATA {";
update+="GRAPH <http://smag0.blogspot.fr/GraphTest>{";
update+="smag:Robokaze rdf:type smag:Site .";
update+="smag:Robokaze smag:objectif 'un site de vente revente piece detachees , pour robots, et objets connectes' .";
update+="ex:cat rdfs:subClassOf ex:animal .";
update+="zoo:host rdfs:range ex:animal .";
update+="ex:zoo1 zoo:host ex:cat2 .";
update+="ex:cat3 owl:sameAs ex:cat2 .";
update+="}}";
// message="";
//String message;
//HttpParameterPost();
message=new String("Votre ecran peut vous apparaitre tout noir,\n a la premiere connexion au serveur, \n merci de patienter quelques dizaines de secondes au plus \n");
//private static void HttpParameterPost() {
httpclient = new DefaultHttpClient();
HttpPost httpPost=new HttpPost("http://fuseki-smag0.rhcloud.com/ds/update?");
// HttpPost httpPost = new HttpPost("http://192.168.1.52:3030/ds/update?");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
// nameValuePairs.add(new BasicNameValuePair("update", "INSERT {<bola> <bolb> <bolc>} WHERE {?s ?p ?o}" ));
nameValuePairs.add(new BasicNameValuePair("update", update));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
System.out.println("executing request " + httpPost.getRequestLine());
HttpResponse response = httpclient.execute(httpPost);
HttpEntity resEntity = response.getEntity();
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
if (resEntity != null) {
System.out.println("Response content length: " + resEntity.getContentLength());
System.out.println("Chunked?: " + resEntity.isChunked());
String responseBody = EntityUtils.toString(resEntity);
System.out.println("Data: " + responseBody);
message+= "Response content length: " + resEntity.getContentLength()+"\n";
message+="Chunked?: " + resEntity.isChunked()+"\n";
// String responseBody = EntityUtils.toString(resEntity);
message+="Data: " + responseBody+"\n";
// message="45" ;
}
// EntityUtils.consume(resEntity);
}
catch (Exception e) {
System.out.println(e);
message+=e;
}
finally {
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
httpclient.getConnectionManager().shutdown();
}
}
void draw(){
text(message,100,100);
}
void showVirtualKeyboard()
{
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
void hideVirtualKeyboard()
{
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
}
pour lire des infos sur le serveur :
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import java.util.Scanner;
//arqoid
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import com.hp.hpl.jena.ontology.Individual;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.InfModel;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.reasoner.Reasoner;
import com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasoner;
import com.hp.hpl.jena.reasoner.rulesys.Rule;
//import com.hp.hpl.jena.update.*;
import com.hp.hpl.jena.sparql.core.Prologue;
String err="";
String url="";
//UpdateRequest update;
DefaultHttpClient httpClient;
HttpEntity entity;
HttpResponse response;
String reponse;
PImage img;
String url_img="";
HttpEntity entity_img;
HttpResponse response_img;
String reponse_img;
void setup() {
background(0);
String req_insert_prefix="PREFIX+ns:+<http://example.org/ns#>";
req_insert_prefix+="PREFIX dc: <http://purl.org/dc/elements/1.1/>";
req_insert_prefix+="PREFIX d: <http://example.com/ns/data#>";
req_insert_prefix+="PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>";
String req_insert="INSERT DATA";
req_insert+="{ GRAPH <http://example/bookStore> { ";
req_insert+="<http://example/bidule> ns:price 42 ." ;
//req_insert+="d:i1 rdfs:label \"one\" .";
//d:i2 rdfs:label "two" .
req_insert+=" }}";
//url="http://fuseki-smag0.rhcloud.com/ds/update?update="+req_insert_prefix+req_insert;
//text(url,20,200);
//
//insert();
//img = loadImage("image.jpg");
img=loadImage("http://3.bp.blogspot.com/-MbiBWE4xcD0/Ux90q1F1RsI/AAAAAAAAAS8/hRpHBM5E4PE/s1600/Rover_5421698457340622361.JPG" ) ;
// img=loadImage("http://88.142.232.252:8090/?action=stream");
/*
try{
img=loadImage("http://88.142.232.252:8090/?action=stream");
}
catch( Exception e ) {
e.printStackTrace();
err+=e.toString();
text(e.toString(), 100, 200);
}
*/
//String url="http://127.0.0.1:8080" ;
//String url="http://88.142.232.252:3030/ds/query?query=construct+where+%7B%3Fs+%3Fp+%3Fo%7D";
String url="http://fuseki-smag0.rhcloud.com/ds/query?query=construct+where+%7B%3Fs+%3Fp+%3Fo%7D";
// String url="http://fuseki-smag0.rhcloud.com/ds/query?query=select+*+where+%7B%3Fs+%3Fp+%3Fo%7D";
// String url = "https://www.google.fr/search?q=test";
// https://www.google.fr/search?site=&source=hp&ei=PQX2U5qfMdPY0QXP_IGYAg&q=test&oq=test&gs_l=mobile-gws-hp.3..35i39j0l4.2250.2976.0.3886.6.5.1.1.1.0.168.532.0j4.4.0....0...1c.1.51.mobile-gws-hp..1.5.457.3.BSrYBhzULXU
text(" Recuperation des informations depuis :",100,100);
text(url,100,120);
try {
httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet( url );
// ArrayList<BasicNameValuePair> nameValuePairs = new ArrayList<BasicNameValuePair>(2);
// nameValuePairs.add(new BasicNameValuePair("q", "value1"));
// nameValuePairs.add(new BasicNameValuePair("param2", "value2"));
// httpGet.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// println( "executing request: " + httpPost.getRequestLine() );
response = httpClient.execute( httpGet );
entity = response.getEntity();
if ( entity != null ) {
// String reponse;
// entity.writeTo( reponse );
// String reponse=new String(entity.getContent());
reponse = new Scanner(entity.getContent(), "UTF-8").useDelimiter("\\A").next();
}
// if ( entity != null ) entity.consumeContent();
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
// httpClient.getConnectionManager().shutdown();
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
// httpClient.getConnectionManager().shutdown();
}
catch( Exception e ) {
e.printStackTrace();
err+=e.toString();
text(e.toString(), 100, 100);
}
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
httpClient.getConnectionManager().shutdown();
// exit();
}
void draw() {
background(0);
text("Smag", displayWidth-50, 10);
text(url, 20, 200);
text(err, 10, 100);
// text(update.toString(),50,100);
if ( entity != null ) {
text("----------------------------------------", 10, 10);
text( response.getStatusLine().toString(), 10, 20);
text("----------------------------------------", 10, 30);
// String reponse;
// entity.writeTo( reponse );
// String reponse=new String(entity.getContent());
// try{ String reponse = new Scanner(entity.getContent(), "UTF-8").useDelimiter("\\A").next();
text(reponse, 10, 100);
// }
// catch( Exception e ) {
// e.printStackTrace();
// err=e.toString();
// text(e.toString(), 100, 100);
//}
// Displays the image at its actual size at point (0,0)
// image(img, 0, 0);
// Displays the image at point (0, height/2) at half of its size
image(img, 0, displayHeight-100, img.width/2, img.height/2);
}
}
void insert() {
// update = UpdateFactory.create("");
// UpdateProcessRemote riStore = (UpdateProcessRemote) UpdateExecutionFactory.createRemote(update, "http://myendpointuri");
// riStore.execute();
}
// The following short JSON file called "data.json" is parsed // in the code below. It must be in the project's "data" folder. // // { // "id": 0, // "species": "Panthera leo", // "name": "Lion" // } JSONObject json; void setup() { json = loadJSONObject("data.json"); int id = json.getInt("id"); String species = json.getString("species"); String name = json.getString("name"); println(id + ", " + species + ", " + name); } // Sketch prints: // 0, Panthera leo, Lion
Pays/territoire :
Lyon, France
01/09/2014
Explorer les données d'un serveur fuseki/rdf
Dans Chrome Web Store, ajouter l'application " OpenLinkDataExplorer", lancer l'appli
ensuite dans la ligne "Data Source URI", saisissez l'adresse de requete de votre serveur Fuseki sous la forme :
http://fuseki-smag0.rhcloud.com/ds/query?query=select+*+where%7B%3FP+%3FS+%3FO%7D
ensuite dans la ligne "Data Source URI", saisissez l'adresse de requete de votre serveur Fuseki sous la forme :
http://fuseki-smag0.rhcloud.com/ds/query?query=select+*+where%7B%3FP+%3FS+%3FO%7D
Inscription à :
Articles (Atom)