Skip to content

Commit 5bdb8c4

Browse files
committed
feature:make everything work upto the point of fuzon entering the equation
1 parent 989b354 commit 5bdb8c4

1 file changed

Lines changed: 44 additions & 18 deletions

File tree

src/main.py/main.py

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,22 @@
55

66
apikey = os.getenv("OPEN-AI-KEY")
77

8-
print(apikey)
9-
108
from agents import Agent, ModelSettings, function_tool
119
import rdflib
10+
1211
knowledge_graph_path = os.getenv("KNOWLEDGE_GRAPH_PATH")
1312

1413
ontologies_path = os.getenv("ONTOLOGIES_PATH")
14+
# SPARQLwrapper
15+
dataset = rdflib.Dataset()
1516

17+
onto = dataset.graph("https://imaging-plaza.epfl.ch/ontology#")
18+
onto.parse(ontologies_path)
19+
20+
data = dataset.graph("https://imaging-plaza.epfl.ch/finalGraph")
21+
data.parse(knowledge_graph_path)
1622
# Load the knowledge graph
1723

18-
# SPARQLwrapper
19-
onto = rdflib.Graph()
20-
onto.parse(knowledge_graph_path)
2124

2225
#Query
2326
query = r"""
@@ -26,23 +29,46 @@
2629
PREFIX schema: <http://schema.org/>
2730
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
2831
29-
SELECT DISTINCT ?o
30-
31-
WHERE {
32-
?s ?p ?o .
33-
FILTER (!(?p IN (schema:name, schema:description, rdfs:comment, skos:definition)))
34-
FILTER (!regex(STR(?o), "^[ \t]*https?://"))
35-
FILTER (!regex(STR(?o), "^\\d{4}-\\d{2}-\\d{2}T00:00:00\\.000Z$"))
36-
FILTER (datatype(?o) = xsd:string)
32+
CONSTRUCT {
33+
?s ?p ?result .
34+
}
35+
WHERE {
36+
GRAPH <https://imaging-plaza.epfl.ch/finalGraph> {
37+
?s ?p ?o .
38+
FILTER (!(?p IN (schema:name, schema:description, rdfs:comment, skos:definition)))
39+
FILTER (!regex(STR(?o), "^[ \t]*https?://"))
40+
FILTER (!regex(STR(?o), "^\\d{4}-\\d{2}-\\d{2}T00:00:00\\.000Z$"))
41+
FILTER (datatype(?o) = xsd:string)
3742
}
43+
GRAPH <https://imaging-plaza.epfl.ch/ontology#> {
44+
OPTIONAL {
45+
?s2 rdfs:label ?o.
46+
}
47+
48+
# Ensure only one IRI is bound to the label, skipping rows with multiple IRIs
49+
FILTER NOT EXISTS {
50+
?s3 rdfs:label ?o.
51+
FILTER (?s3 != ?s2) # Ensures ?s2 is the only IRI bound to the label
52+
}
53+
}
54+
55+
BIND(IF(BOUND(?s2), ?s2, ?o) AS ?result)
56+
}
57+
3858
"""
39-
results = onto.query(query)
59+
results = dataset.query(query)
4060
# Print the results
4161
for row in results:
42-
print(row.o)
43-
#count the number of rows:
44-
print("Number of rows: ", len(results))
45-
# Find all objects of triples that are strings (Agent 1 using SPARQL SELECT query)
62+
print(row)
63+
64+
# Create a new graph to store the constructed triples
65+
constructed_graph = rdflib.Graph()
66+
67+
# Add the results of the CONSTRUCT query to the new graph
68+
for triple in results.graph:
69+
constructed_graph.add(triple)
70+
71+
4672

4773
# Attempt to match those strings to strings in the ontology (Agent 2 - FUZON )
4874
#

0 commit comments

Comments
 (0)