mapping a ontology

99 views
Skip to first unread message

Alberto Soki

unread,
Apr 12, 2023, 12:53:08 PM4/12/23
to ontop4obda
Dear, how can I map an ontology to a database with a one-to-many relationship?

image.png

In the example above I have an ontology with a class "Service", an object property "hasBasePath" and a subclass "Server". "Title" is data property of Class "Service" and "base_path" is data property of subClass "Server"

On the other hand, I have a database with two tables: a "Service" can have several server addresses, that is, several base paths.

Grateful.

Martin Just

unread,
Apr 12, 2023, 1:42:28 PM4/12/23
to ontop4obda
Hello Alberto,

this should be fairly easy. Especially if you take a look into the Ontop Tutorial.

The OBDA could look somewhat like this:

mappingId        Service_title_hasBasePath
target        :ontologyName/service/{serviceIdFromDB} a :Service ; :title {titleFromDB}^^xsd:string; :hasBasePath : ontologyName/server/{serverIdFromDB} .
source        SELECT service.id AS serviceIdFromDB, server.id AS  serverIdFromDB
                    FROM ServiceTable AS service
                        JOIN serverTable AS server ON (server.service_id = service.id)

mappingId        Server_basePath
target        :ontologyName/server/{serverIdFromDB} a :Server; :basePath {basePathFromDB}^^xsd:string .
source        SELECT id AS serverIdFromDB, base_path AS basePathFromDB
                    FROM ServerTable AS server

Via SPARQL you could query accordingly:
PREFIX : <http://www.domain.de/ontologies/ontologyName#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT * {
  ?service a :Service ;
    :title ? ?title ;
    :hasBasePath ?server .
  ?server a :Server ;
    :basePath ?BasePath .
}

Best
Martin


davide lanti

unread,
Apr 13, 2023, 4:40:59 AM4/13/23
to ontop4obda

Hi,

on how to write mappings, I suggest reading this excellent book (for a more practical perspective, not focused on VKGs though):

https://link.springer.com/chapter/10.1007/978-3-031-01916-6_3

or reading this article (for a more foundational perspective, focused on mappings for VKGs):

https://authors.elsevier.com/a/1gn1J,3rzWzLDk

Coming to your example, on top of the suggestion by Martin I just add that, if you want to preserve the semantics of the original database, that is, if you do not want to lose those information about those services with no servers assigned, you need a further mapping only creating services (and their titles). Hence, the specification would become something like:

mappingId        Service
target        :ontologyName/service/{id} a :Service ; :title {title}^^xsd:string .
source        SELECT id, title FROM service

mappingId        Server
target        :ontologyName/server/{id} a :Server; :basePath {base_path}^^xsd:string .
source        SELECT id, base_path FROM server

mappingId     hasBasePath
target        :ontologyName/service/{service_id} :hasBasePath : ontologyName/server/{id} .
source        SELECT id, service_id FROM server

Note that I have omitted the SQL join in the last mapping, which is redundant, and that the second and third mapping can in fact be merged into a single mapping (since they have the same logical table).

Best, Davide.

Alberto Soki

unread,
Apr 13, 2023, 12:18:56 PM4/13/23
to ontop4obda
Dear Davide and Martin Thank you very much for your feedback.

tir

unread,
Apr 16, 2023, 9:45:00 AM4/16/23
to ontop...@googlegroups.com

Hi,

on how to write mappings, I suggest reading this excellent book (for a more practical perspective, not focused on VKGs though):

https://link.springer.com/chapter/10.1007/978-3-031-01916-6_3

or reading this article (for a more foundational perspective, focused on mappings for VKGs):

https://authors.elsevier.com/a/1gn1J,3rzWzLDk

Coming to your example, on top of the suggestion by Martin I just add that, if you want to preserve the semantics of the original database, that is, if you do not want to lose those information about those services with no servers assigned, you need a further mapping only creating services (and their titles). Hence, the specification would become something like:

mappingId        Service
target        :ontologyName/service/{id} a :Service ; :title {title}^^xsd:string .
source        SELECT id, title FROM service

mappingId        Server
target        :ontologyName/server/{id} a :Server; :basePath {base_path}^^xsd:string .
source        SELECT id, base_path FROM server

mappingId     hasBasePath
target        :ontologyName/service/{service_id} :hasBasePath : ontologyName/server/{id} .
source        SELECT id, service_id FROM server

Note that I have omitted the SQL join in the last mapping, which is redundant, and that the second and third mapping can in fact be merged into a single mapping (since they have the same logical table).

Best, Davide.

--
Please follow our guidelines on how to report a bug https://ontop-vkg.org/community/contributing/bug-report
---
You received this message because you are subscribed to the Google Groups "ontop4obda" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ontop4obda+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ontop4obda/712681b5-ea11-4bd3-9973-7b119bc9bcddn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages