0

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?

Ania David
  • 1,168
  • 1
  • 15
  • 36
  • Taken from the documentation: "If the columns used to create the literal value or object are not from the database table(s) that contains the ClassMap's columns, then the tables have to be joined together using one or more d2rq:join properties" – UninformedUser Apr 22 '16 at 18:17
  • @AKSW yes I saw that and they have an example about one to many or one to one, but I couldn't know how to do that with many to many, how am i going to tell them which table if i don't have a class map for it ? – Ania David Apr 23 '16 at 11:57
  • You should take a look at R2RML, which is the W3C standard for mapping relational data to RDF. – Juan Sequeda Apr 25 '16 at 12:53
  • @JuanSequeda the question is about how to use D2RQ to implement (achieve) a R2RML mapping, so my question is technical one – Ania David Apr 26 '16 at 12:56

1 Answers1

0

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

Ania David
  • 1,168
  • 1
  • 15
  • 36