Skip to content
Snippets Groups Projects
Commit 2f8632df authored by Sarra Ouelhadj's avatar Sarra Ouelhadj
Browse files

generate RDF instances

parent 29b62a9e
Branches
No related tags found
No related merge requests found
##### to review completly
import sys
import subprocess
import generateJSON as g
import generateSparqlGenerateQuery as q
import uuid
import os
from YKWIM import app, generateSparqlGenerateQuery as q, generateOntology as onto
def generateRDF (file, dataset) :
def generateRDF (dataset, path=app.config["UPLOAD_FOLDER"],ontology_namespace = "https://data.grandlyon.com/onto/", vocabulary_namespace ="https://data.grandlyon.com/vocab/", instances_namespace = "https://data.grandlyon.com/id/") :
"""generate RDF data from SPARQL Generate query"""
query_file=q.generateSparqlGenerateQuery(g.generateJSON(file),dataset)
base_name = str(uuid.uuid4())
result_file = base_name + ".ttl"
subprocess.run('java -jar sparql-generate*.jar --query-file '+ query_file+' --output '+result_file, shell=True)
onto.generateOntology(path, ontology_namespace,vocabulary_namespace)
query_file=q.generateSparqlGenerateQuery(dataset, path,vocabulary_namespace, instances_namespace)
return result_file
result_file = path + "instances.ttl"
subprocess.run('java -jar ./YKWIM/static/jar/sparql-generate*.jar --query-file '+ query_file+' --output '+result_file, shell=True)
if __name__ == "__main__":
#dataset = "https://download.data.grandlyon.com/wfs/grandlyon?SERVICE=WFS&VERSION=2.0.0&request=GetFeature&typename=adr_voie_lieu.adrcomgl&outputFormat=application/json;%20subtype=geojson&SRSNAME=EPSG:4171"
print (generateRDF(sys.argv[1], sys.argv[2]))
\ No newline at end of file
return result_file
\ No newline at end of file
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix iter: <http://w3id.org/sparql-generate/iter/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix fun: <http://w3id.org/sparql-generate/fn/> .
<https://data.grandlyon.com/id/Sitetraitementdechets/16>
a <https://data.grandlyon.com/onto/Sitetraitementdechets> ;
rdfs:label "Centre de tri Coved" ;
<https://data.grandlyon.com/onto/apouractivite>
<https://data.grandlyon.com/vocab/centre_de_tri> ;
<https://schema.org/address> "Rue du Broteau" ;
<https://schema.org/identifier>
"16" ;
<https://schema.org/location> <https://data.grandlyon.com/id/Commune/IRIGNY> .
<https://data.grandlyon.com/id/Sitetraitementdechets/961>
a <https://data.grandlyon.com/onto/Sitetraitementdechets> ;
rdfs:label "Centre de tri Onyx" ;
<https://data.grandlyon.com/onto/apouractivite>
<https://data.grandlyon.com/vocab/centre_de_tri> ;
<https://schema.org/address> "Avenue du 8 Mai1945" ;
<https://schema.org/identifier>
"961" ;
<https://schema.org/location> <https://data.grandlyon.com/id/Commune/RILLIEUX-LA-PAPE> .
<https://data.grandlyon.com/id/Commune/GIVORS>
a <http://data.ign.fr/def/geofla#Commune> ;
rdfs:label "GIVORS" .
<https://data.grandlyon.com/id/Commune/Venissieux>
a <http://data.ign.fr/def/geofla#Commune> ;
rdfs:label "Venissieux" .
<https://data.grandlyon.com/id/Commune/LYON 7EME>
a <http://data.ign.fr/def/geofla#Commune> ;
rdfs:label "LYON 7EME" .
<https://data.grandlyon.com/id/Sitetraitementdechets/322>
a <https://data.grandlyon.com/onto/Sitetraitementdechets> ;
rdfs:label "UTVE Lyon NORD" ;
<https://data.grandlyon.com/onto/apouractivite>
<https://data.grandlyon.com/vocab/incinération> ;
<https://schema.org/address> "110 Route du Mas Rillier" ;
<https://schema.org/identifier>
"322" ;
<https://schema.org/location> <https://data.grandlyon.com/id/Commune/RILLIEUX-LA-PAPE> .
<https://data.grandlyon.com/id/Sitetraitementdechets/15>
a <https://data.grandlyon.com/onto/Sitetraitementdechets> ;
rdfs:label "Centre de tri Nicollin" ;
<https://data.grandlyon.com/onto/apouractivite>
<https://data.grandlyon.com/vocab/centre_de_tri> ;
<https://schema.org/address> "12-14 rue Charles Martin" ;
<https://schema.org/identifier>
"15" ;
<https://schema.org/location> <https://data.grandlyon.com/id/Commune/SAINT-FONS> .
<https://data.grandlyon.com/id/Sitetraitementdechets/1350>
a <https://data.grandlyon.com/onto/Sitetraitementdechets> ;
rdfs:label "OUI_COMPOST" ;
<https://data.grandlyon.com/onto/apouractivite>
<https://data.grandlyon.com/vocab/centre_de_traitement> ;
<https://schema.org/address> "158 Cours Charlemagne" ;
<https://schema.org/identifier>
"1350" ;
<https://schema.org/location> <https://data.grandlyon.com/id/Commune/690002 Lyon> .
<https://data.grandlyon.com/id/Sitetraitementdechets/966>
a <https://data.grandlyon.com/onto/Sitetraitementdechets> ;
rdfs:label "Quai de transfert Villefrance" ;
<https://data.grandlyon.com/onto/apouractivite>
<https://data.grandlyon.com/vocab/quai_de_transfert> ;
<https://schema.org/address> "90 Rue Benoît Frachon" ;
<https://schema.org/identifier>
"966" ;
<https://schema.org/location> <https://data.grandlyon.com/id/Commune/VILLEFRANCHE-SUR-SAONE> .
<https://data.grandlyon.com/id/Commune/690002 Lyon>
a <http://data.ign.fr/def/geofla#Commune> ;
rdfs:label "690002 Lyon" .
<https://data.grandlyon.com/id/Sitetraitementdechets/321>
a <https://data.grandlyon.com/onto/Sitetraitementdechets> ;
rdfs:label "Centre de tri Décines" ;
<https://data.grandlyon.com/onto/apouractivite>
<https://data.grandlyon.com/vocab/centre_de_tri> ;
<https://schema.org/address> "26 rue Wilson" ;
<https://schema.org/identifier>
"321" ;
<https://schema.org/location> <https://data.grandlyon.com/id/Commune/DECINES-CHARPIEU> .
<https://data.grandlyon.com/id/Sitetraitementdechets/1014>
a <https://data.grandlyon.com/onto/Sitetraitementdechets> ;
rdfs:label "Givors Bans - CS" ;
<https://data.grandlyon.com/onto/apouractivite>
<https://data.grandlyon.com/vocab/quai_de_transfert> ;
<https://schema.org/address> "Chemin de la Lône" ;
<https://schema.org/identifier>
"1014" ;
<https://schema.org/location> <https://data.grandlyon.com/id/Commune/GIVORS> .
<https://data.grandlyon.com/id/Sitetraitementdechets/965>
a <https://data.grandlyon.com/onto/Sitetraitementdechets> ;
rdfs:label "UTVE Villefranche" ;
<https://data.grandlyon.com/onto/apouractivite>
<https://data.grandlyon.com/vocab/incinération> ;
<https://schema.org/address> "90 Rue Benoît Frachon" ;
<https://schema.org/identifier>
"965" ;
<https://schema.org/location> <https://data.grandlyon.com/id/Commune/VILLEFRANCHE-SUR-SAONE> .
<https://data.grandlyon.com/id/Sitetraitementdechets/1013>
a <https://data.grandlyon.com/onto/Sitetraitementdechets> ;
rdfs:label "Givors Bans - OM" ;
<https://data.grandlyon.com/onto/apouractivite>
<https://data.grandlyon.com/vocab/quai_de_transfert> ;
<https://schema.org/address> "Chemin de la Lône" ;
<https://schema.org/identifier>
"1013" ;
<https://schema.org/location> <https://data.grandlyon.com/id/Commune/GIVORS> .
<https://data.grandlyon.com/id/Commune/IRIGNY>
a <http://data.ign.fr/def/geofla#Commune> ;
rdfs:label "IRIGNY" .
<https://data.grandlyon.com/id/Sitetraitementdechets/964>
a <https://data.grandlyon.com/onto/Sitetraitementdechets> ;
rdfs:label "Plateforme Guérin" ;
<https://data.grandlyon.com/onto/apouractivite>
<https://data.grandlyon.com/vocab/centre_de_tri> ;
<https://schema.org/address> "2-3 Impasse Lucien Sampaix" ;
<https://schema.org/identifier>
"964" ;
<https://schema.org/location> <https://data.grandlyon.com/id/Commune/SAINT-FONS> .
<https://data.grandlyon.com/id/Commune/RILLIEUX-LA-PAPE>
a <http://data.ign.fr/def/geofla#Commune> ;
rdfs:label "RILLIEUX-LA-PAPE" .
<https://data.grandlyon.com/id/Commune/VILLEFRANCHE-SUR-SAONE>
a <http://data.ign.fr/def/geofla#Commune> ;
rdfs:label "VILLEFRANCHE-SUR-SAONE" .
<https://data.grandlyon.com/id/Commune/69680 Chassieu>
a <http://data.ign.fr/def/geofla#Commune> ;
rdfs:label "69680 Chassieu" .
<https://data.grandlyon.com/id/Commune/DECINES-CHARPIEU>
a <http://data.ign.fr/def/geofla#Commune> ;
rdfs:label "DECINES-CHARPIEU" .
<https://data.grandlyon.com/id/Sitetraitementdechets/1349>
a <https://data.grandlyon.com/onto/Sitetraitementdechets> ;
rdfs:label "LES ALCHIMISTES" ;
<https://data.grandlyon.com/onto/apouractivite>
<https://data.grandlyon.com/vocab/centre_de_traitement> ;
<https://schema.org/address> "USIN, 41-47 bld Marcel Sembat" ;
<https://schema.org/identifier>
"1349" ;
<https://schema.org/location> <https://data.grandlyon.com/id/Commune/Venissieux> .
<https://data.grandlyon.com/id/Sitetraitementdechets/11>
a <https://data.grandlyon.com/onto/Sitetraitementdechets> ;
rdfs:label "UTVE Lyon SUD" ;
<https://data.grandlyon.com/onto/apouractivite>
<https://data.grandlyon.com/vocab/incinération> ;
<https://schema.org/address> "7 Rue de Dole" ;
<https://schema.org/identifier>
"11" ;
<https://schema.org/location> <https://data.grandlyon.com/id/Commune/LYON 7EME> .
<https://data.grandlyon.com/id/Commune/SAINT-FONS>
a <http://data.ign.fr/def/geofla#Commune> ;
rdfs:label "SAINT-FONS" .
<https://data.grandlyon.com/id/Sitetraitementdechets/1333>
a <https://data.grandlyon.com/onto/Sitetraitementdechets> ;
rdfs:label "Trivalo 69" ;
<https://data.grandlyon.com/onto/apouractivite>
<https://data.grandlyon.com/vocab/centre_de_tri> ;
<https://schema.org/address> "12-16 rue Blaise Pascal" ;
<https://schema.org/identifier>
"1333" ;
<https://schema.org/location> <https://data.grandlyon.com/id/Commune/69680 Chassieu> .
PREFIX iter: <http://w3id.org/sparql-generate/iter/>
PREFIX fun: <http://w3id.org/sparql-generate/fn/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
GENERATE {
?Sitetraitementdechets a <https://data.grandlyon.com/onto/Sitetraitementdechets>;
<http://www.w3.org/2000/01/rdf-schema#label> ?Nom;
<https://schema.org/identifier> ?Identifiant;
<https://schema.org/address> ?Adresse.
?Commune a <http://data.ign.fr/def/geofla#Commune>;
<http://www.w3.org/2000/01/rdf-schema#label> ?Nomcommune.
?Sitetraitementdechets <https://data.grandlyon.com/onto/apouractivite> ?Activite.
?Sitetraitementdechets <https://schema.org/location> ?Commune.
}
SOURCE <https://download.data.grandlyon.com/wfs/grandlyon?SERVICE=WFS&VERSION=2.0.0&request=GetFeature&typename=gic_collecte.gicsitetraitement&outputFormat=application/json;%20subtype=geojson&SRSNAME=EPSG:4171> AS ?source
ITERATOR iter:GeoJSON(?source) AS ?geometricCoordinates ?properties
WHERE {
BIND (fun:JSONPath(?properties,"$.nom") AS ?Nom)
BIND (fun:JSONPath(?properties,"$.identifiant") AS ?Identifiant)
BIND(IRI(CONCAT("https://data.grandlyon.com/id/Sitetraitementdechets/",fun:JSONPath(?properties,"$.identifiant"))) AS ?Sitetraitementdechets)
BIND (fun:JSONPath(?properties,"$.adresse") AS ?Adresse)
BIND (fun:JSONPath(?properties,"$.commune") AS ?Nomcommune)
BIND(IRI(CONCAT("https://data.grandlyon.com/id/Commune/",fun:JSONPath(?properties,"$.commune"))) AS ?Commune)
BIND(IRI(CONCAT("https://data.grandlyon.com/vocab/",REPLACE(LCASE(fun:JSONPath(?properties,"$.activite"))," ","_"))) AS ?Activite)
}
File added
import subprocess
#from YKWIM import generateJSON as g
#import generateSparqlGenerateQuery as q, generateOntology as onto
def generateRDF (path="./",ontology_namespace = "https://data.grandlyon.com/onto/", vocabulary_namespace ="https://data.grandlyon.com/vocab/", instances_namespace = "https://data.grandlyon.com/id/") :
"""generate RDF data from SPARQL Generate query"""
#g.generateJSON(file, path)
#onto.generateOntology(path, ontology_namespace,vocabulary_namespace)
query_file="query.rq"
result_file = path + "instances.ttl"
subprocess.run('java -jar sparql-generate*.jar --query-file '+ query_file+' --output '+result_file, shell=True)
return result_file
print(generateRDF())
\ No newline at end of file
from YKWIM import app, plantUML2Image as pl, validateTemplate as val
from flask import render_template, request, send_from_directory, flash
from YKWIM import app, plantUML2Image as pl, validateTemplate as val, generateOntology as onto, generateSparqlGenerateQuery as sq, generateRDF as rdf
from flask import render_template, request, send_from_directory
from werkzeug.utils import secure_filename
import os
@app.route("/",methods=['POST', 'GET'])
def index():
if request.method == "POST":
datasetURL=request.form["datasetURL"]
datasetURL=request.form["datasetURL"].replace(' ','%20')
file = request.files["templateFile"]
file.save(os.path.join(app.config['UPLOAD_FOLDER'],secure_filename(file.filename)))
error_template = val.validateTemplate(app.config['UPLOAD_FOLDER']+secure_filename(file.filename))
if error_template == None :
uml_image = pl.plantUML2Image(app.config['UPLOAD_FOLDER']+secure_filename(file.filename),"svg")
rdf.generateRDF(datasetURL)
return render_template("index.html", uml_image=uml_image)
else:
return render_template("index.html", error_template=error_template)
else:
return render_template("index.html")
return render_template("index.html", vocabulary_namespace= app.config['VOCABULARY_NAMESPACE'],
ontology_namespace=app.config['ONTOLOGY_NAMESPACE'],
instances_namespace=app.config['INSTANCES_NAMESPACE']
)
@app.route("/<document_link>")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment