Update app.py
Browse files
app.py
CHANGED
@@ -35,10 +35,11 @@ rdf_context = load_rdf_summary()
|
|
35 |
print("RDF Summary:", rdf_context) # Debug
|
36 |
|
37 |
# Valida le query SPARQL
|
38 |
-
def validate_sparql_query(query,
|
39 |
try:
|
40 |
g = Graph()
|
41 |
-
|
|
|
42 |
g.query(query) # Prova ad eseguire la query
|
43 |
return True
|
44 |
except Exception as e:
|
@@ -104,7 +105,7 @@ async def generate_query(request: QueryRequest):
|
|
104 |
"explanation": "Non posso generare una query SPARQL per questa richiesta. Assicurati che la domanda sia coerente con i dati RDF forniti."
|
105 |
}
|
106 |
|
107 |
-
if not validate_sparql_query(response,
|
108 |
return {
|
109 |
"query": None,
|
110 |
"explanation": "La query generata non è valida rispetto alla base di conoscenza RDF. Assicurati di chiedere informazioni che siano presenti nell'ontologia."
|
@@ -115,4 +116,4 @@ async def generate_query(request: QueryRequest):
|
|
115 |
# Endpoint di test
|
116 |
@app.get("/")
|
117 |
async def root():
|
118 |
-
return {"message": "Il server è attivo e pronto a generare query SPARQL!"}
|
|
|
35 |
print("RDF Summary:", rdf_context) # Debug
|
36 |
|
37 |
# Valida le query SPARQL
|
38 |
+
def validate_sparql_query(query, rdf_file_path):
|
39 |
try:
|
40 |
g = Graph()
|
41 |
+
# Caricamento del file RDF dal percorso
|
42 |
+
g.parse(rdf_file_path, format="xml")
|
43 |
g.query(query) # Prova ad eseguire la query
|
44 |
return True
|
45 |
except Exception as e:
|
|
|
105 |
"explanation": "Non posso generare una query SPARQL per questa richiesta. Assicurati che la domanda sia coerente con i dati RDF forniti."
|
106 |
}
|
107 |
|
108 |
+
if not validate_sparql_query(response, RDF_FILE):
|
109 |
return {
|
110 |
"query": None,
|
111 |
"explanation": "La query generata non è valida rispetto alla base di conoscenza RDF. Assicurati di chiedere informazioni che siano presenti nell'ontologia."
|
|
|
116 |
# Endpoint di test
|
117 |
@app.get("/")
|
118 |
async def root():
|
119 |
+
return {"message": "Il server è attivo e pronto a generare query SPARQL!"}
|