sparqlsemantic-webowlontologyr2rml

D2RQ how to configue many to many relationship


I have a database tables and I'm changing the data to RDF.

So far I am able to do the one to one in which a row that has a primary key, has a value, which comes from a column in that row, like this:

map:Artist a d2rq:ClassMap;
    d2rq:dataStorage map:database;
    d2rq:class to:Artist;
    d2rq:uriPattern "to:Artist/@@M3.ARTIST.ARTIST_ID@@";
    .

map:ArtistName a d2rq:PropertyBridge;
    d2rq:belongsToClassMap map:Artist;
    d2rq:property to:hasName;
    d2rq:column "M3.ARTIST.ARTIST_NAME";
    d2rq:datatype xsd:string;
    .

here each Artist_ID will be the subject of the triple and there will be a property called hasName with its value comes from the ARTIST_NAME column

so far so good, now i have a table many to many like this:

Artist(table) Album(Table) ArtistAlbum(table)

the artistalbum has a foriegn key to both of Album and Artist

how can I do that in r2rq please?


Solution

  • I've contacted the people from D2RQ, and this is their reply:

    See here for an example that connects instances from two tables (but it's one to many, not many-to-many): http://d2rq.org/d2rq-language#example-refers

    See here for an example that takes a property from a different table, and the table is joined via a many-to-many relationship table: http://d2rq.org/d2rq-language#example-join

    Combine the two examples to address your scenario.

    I did what they've said, and came up with this mapping

    map:ArtistAlbum a d2rq:PropertyBridge;
        d2rq:property to:hasArtist;
        d2rq:belongsToClassMap map:Album;
        d2rq:refersToClassMap map:Artist;
        d2rq:join "blabla.ARTIST.ARTIST_ID = blabla.ARTISTALBUM.ARTIST_ID";
        d2rq:join "blabla.ARTISTALBUM.ALBUM_ID = blabla.ALBUM.ALBUM_ID";
        .
    

    and it works perfectly