home » esempi SPARQL

Esempi SPARQL

Query pronte all'uso su chem-pipeline. Per eseguirle scarica chem-pipeline.ttl e usalo con Apache Jena ARQ, Oxigraph, GraphDB, Stardog o qualunque triple store.

Prefisso comune per tutti gli esempi:
PREFIX chem: <https://ontology.siletto.it/chem-pipeline#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

1. Tutte le filiere che producono un dato prodotto

Es. trovare quali pipeline producono alluminio o idrogeno verde.

SELECT ?pipeline ?label WHERE {
  ?pipeline a chem:Pipeline ;
            chem:contains ?uo .
  ?uo chem:produces ?product .
  ?product rdfs:label "alluminio"@it .
  ?pipeline rdfs:label ?label . FILTER(LANG(?label) = "it")
}

2. CO₂eq cumulato per pipeline (kg CO₂ / kg prodotto principale)

Somma il contributo di ogni UnitOperation della filiera.

SELECT ?pipeline (SUM(?co2) AS ?totalCO2) WHERE {
  ?pipeline a chem:Pipeline ;
            chem:contains ?uo .
  ?uo chem:co2Equivalent ?co2 .
} GROUP BY ?pipeline ORDER BY DESC(?totalCO2)

3. Flow di una filiera (chain di feedsInto)

Sequenza ordinata di Unit Operation collegate. Es. cemento Portland.

SELECT ?from ?to WHERE {
  ?from chem:belongsTo chem:portlandCementPipeline ;
        chem:feedsInto ?to .
} ORDER BY ?from

4. Catalizzatori usati e in quali processi

SELECT ?catalyst ?catLabel ?uo ?uoLabel WHERE {
  ?uo chem:usesCatalyst ?catalyst .
  ?catalyst rdfs:label ?catLabel . FILTER(LANG(?catLabel) = "it")
  ?uo rdfs:label ?uoLabel . FILTER(LANG(?uoLabel) = "it")
} ORDER BY ?catalyst

5. Equipment più riutilizzato

Apparecchiature che ricorrono in più filiere.

SELECT ?equipment ?label (COUNT(DISTINCT ?uo) AS ?used_in) WHERE {
  ?uo chem:requiresEquipment ?equipment .
  ?equipment rdfs:label ?label . FILTER(LANG(?label) = "it")
} GROUP BY ?equipment ?label HAVING (?used_in > 1) ORDER BY DESC(?used_in)

6. Sostanze byproduct/waste con la pipeline che le emette

SELECT ?byproduct ?bLabel ?pipeline ?pLabel WHERE {
  ?pipeline a chem:Pipeline ;
            chem:contains ?uo .
  ?uo chem:producesByproduct|chem:producesWaste ?byproduct .
  ?byproduct rdfs:label ?bLabel . FILTER(LANG(?bLabel) = "it")
  ?pipeline rdfs:label ?pLabel . FILTER(LANG(?pLabel) = "it")
} ORDER BY ?byproduct

7. Operazioni che richiedono molta energia elettrica

SELECT ?uo ?label ?kWhPerKg WHERE {
  ?uo chem:requiresEnergy ?e ; rdfs:label ?label .
  ?e chem:energyForm "elettrica" ;
     chem:specificEnergy ?kWhPerKg .
  FILTER(LANG(?label) = "it")
} ORDER BY DESC(?kWhPerKg)

8. Sostanze con identificatori esterni (ChEBI o Wikidata)

Solo le sostanze già linkate a ontologie esterne.

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX chebi: <http://purl.obolibrary.org/obo/CHEBI_>

SELECT ?substance ?label ?wikidata ?chebi WHERE {
  ?substance a chem:Substance ; rdfs:label ?label .
  FILTER(LANG(?label) = "en")
  OPTIONAL { ?substance owl:sameAs ?wikidata . FILTER(STRSTARTS(STR(?wikidata), STR(wd:))) }
  OPTIONAL { ?substance owl:sameAs ?chebi    . FILTER(STRSTARTS(STR(?chebi),    STR(chebi:))) }
  FILTER(BOUND(?wikidata) || BOUND(?chebi))
} ORDER BY ?label

9. Path di reagenti: data una sostanza, da quali materie prime nasce?

Risale all'indietro la catena feedsInto partendo dall'UnitOperation che produce X.

SELECT ?rawMaterial ?label WHERE {
  ?uoEnd chem:produces chem:aluminium .
  ?uoStart (^chem:feedsInto)* ?uoEnd ;
           chem:consumes ?rawMaterial .
  FILTER NOT EXISTS { ?rawMaterial chem:isProducedBy ?_ }
  OPTIONAL { ?rawMaterial rdfs:label ?label . FILTER(LANG(?label) = "it") }
}

10. Ruoli contestuali: in quali filiere H₂ è prodotto finale vs sottoprodotto?

Sfrutta il modello RoleAssignment (Sprint 1b): una stessa sostanza può avere ruoli diversi in pipeline diverse.

SELECT ?role ?pipeline ?pLabel WHERE {
  chem:hydrogen chem:playsRole ?ra .
  ?ra chem:role ?role ;
      chem:inPipeline ?pipeline .
  ?pipeline rdfs:label ?pLabel . FILTER(LANG(?pLabel) = "it")
} ORDER BY ?role

11. Condizioni operative (range temperatura, pressione)

SELECT ?uo ?label ?Tmin_K ?Tmax_K ?P_atm WHERE {
  ?uo chem:operatesAt ?cond ; rdfs:label ?label .
  ?cond chem:temperatureMin ?Tmin_K ;
        chem:temperatureMax ?Tmax_K .
  OPTIONAL { ?cond chem:pressureMax ?Pmax . BIND(?Pmax/101325 AS ?P_atm) }
  FILTER(LANG(?label) = "it")
} ORDER BY DESC(?Tmax_K)

← home · filiere · ontologia completa