oeg-upm / morph-rdb

Virtual Knowledge Graph Creation from RDB with R2RML
https://morph.oeg.fi.upm.es/tool/morph-rdb
Other
40 stars 36 forks source link

Construct sparql queries #70

Open gkirtzou opened 2 years ago

gkirtzou commented 2 years ago

Hi, Does morph-rdb support construct sparql queries? I have a relational database with a mapping into RDF and I would like to extract a subgraph given a starting node x. I found that this could happen using the construct mechanism in a sparql endpoint, but when I tried it with morph-rdb it seems to generate an error.

ocorcho commented 2 years ago

No, there is no support for CONSTRUCT. @fpriyatna can you confirm?

fpriyatna commented 2 years ago

that's correct, there is no support for CONSTRUCT

gkirtzou commented 2 years ago

Thank you very much for the quick response. That's so pity that morph-rdb does not support CONSTRUCT queries. Any idea how one could extract a subgraph other that construct queries? Because I need apart from the SPARQL endpoint, which is useful, to be able to get a whole subgraph.

Imagine that my tables are a Person (email, name, website, etc) with her addresses (street, number, area, etc) and her affiliations with institutes, where both Person-Address and Person-Affiliation are 1-n relations (from an relational perspective). I would like to be able to get the whole information for a Person along with the related addresses and institutes and their address and so on, in a structured way, ie the whole subgraph. Any idea if something like this is supported in morph-rdb?

ocorcho commented 2 years ago

Maybe for this type of need you should go for a materialisation engine rather than a virtualisation one, such as morph-RDB. Why don't you try with morph-kgc? https://github.com/oeg-upm/morph-kgc

gkirtzou commented 2 years ago

I was trying to avoid having a materialized edition of my relational database, because I would need to keep them in sync, as the database is active and its data are constantly changing, via creation/edits/deletions/etc . That's why I was checking how morph-rdb is working. I would checkout morph-kgc, but keep them in sync the relational and the materialized knowledge graph is a painful problem.

fpriyatna commented 2 years ago

how about creating a view? then you map that view to your target ontology

gkirtzou commented 2 years ago

An SQL view you mean? My data are records that spread across multiple tables. So what I would like is to extract a single record dynamically every time given only its primary key. Let's say that i merge my whole db into a single view. How could then use this view to get a single row of it using morph-rdb?

Maybe I am missing something.

dachafra commented 2 years ago

@gkirtzou you can specify in R2RML a SQL view instead of the table name, see https://www.w3.org/TR/r2rml/#r2rml-views

fpriyatna commented 2 years ago

or you can also create a SQL view, refer it to a normal logicalTable, and use FILTER in your SPARQL query.

gkirtzou commented 2 years ago

I have already played with using SQL queries, as I need to transform some of the fields anyway. Unfortunately in order to filter the appropriate subset it's not always feasible or easy. My data have more like a document hierarchical structure (model as an ER model across multiple tables) and the criteria whether or not something would need to be modelled/exported as RDF lies in the top of the hierarchy. In some case, with very complicated SQL queries I could extract it, but I trying to keep the mapping as much as simple and modular as possible (as my schema is actively changing).

I found that using the RDF/XML serialization without blank nodes I could get much closer to the hierarchical structure that I need, but I need to verify that this is true for a bigger depth. FYI using blank nodes with RDF/XML serializer generates errors in the log and does not show the correct structure.