|
@@ -136,6 +136,31 @@ class SparqlRouter(APIRouter):
|
|
|
return await sparql_endpoint_get(request, query)
|
|
|
|
|
|
|
|
|
+ @self.get("/cell/{file_name}/")
|
|
|
+ async def sparql_sheet_endpoint_get(request: Request, file_name, query: Optional[str] = Query(None)) -> Response:
|
|
|
+ logging.debug(f"Received sheet GET request [{file_name}].")
|
|
|
+ graph = ConjunctiveGraph()
|
|
|
+ graph_ns = dict(graph.namespaces())
|
|
|
+ # graph_ns["tabular"] = "http://ua.be/sdo2l/vocabulary/formalisms/tabular#"
|
|
|
+ df = pd.read_csv(f"data/{file_name}", index_col=None, header=None)
|
|
|
+ df.reset_index()
|
|
|
+
|
|
|
+ # Please forgive me pandas gods
|
|
|
+ for i in range(df.shape[0]):
|
|
|
+ for j in range(df.shape[1]):
|
|
|
+ cell_value = df.at[i, j]
|
|
|
+ cell = URIRef(f"http://ua.be/sdo2l/vocabulary/formalisms/tabular#Cell_{i}_{j}")
|
|
|
+ graph.add((cell, URIRef("http://ua.be/sdo2l/vocabulary/formalisms/tabular#holdsContent"), Literal(cell_value)))
|
|
|
+ graph.add((cell, URIRef("http://ua.be/sdo2l/vocabulary/formalisms/tabular#hasRowPosition"), Literal(int(i))))
|
|
|
+ graph.add((cell, URIRef("http://ua.be/sdo2l/vocabulary/formalisms/tabular#hasColumnPosition"), Literal(int(j))))
|
|
|
+
|
|
|
+ try:
|
|
|
+ query_results = graph.query(query, initNs=graph_ns)
|
|
|
+ except Exception as e:
|
|
|
+ logging.error("Error executing the SPARQL query on the RDFLib Graph: " + str(e))
|
|
|
+ return JSONResponse(status_code=400, content={"message": "Error executing the SPARQL query on the RDFLib Graph."})
|
|
|
+ return await encode_graph_query_results(request, query_results)
|
|
|
+
|
|
|
@self.get("/cell/{file_name}/{row}/{column}/")
|
|
|
async def sparql_cell_endpoint_get(request: Request, file_name, row, column, query: Optional[str] = Query(None)) -> Response:
|
|
|
"""
|