R2rml mapping in Stardog Studio or converter

Hi!

Since I use protege/ontop to define mappings, I have an r2rml file for my postgres database, which I wanted to use in Stardog Studio to no avail, since it only accepts SMS2. Is there a way import an r2rml file to a database in a Stardog Free account, or to convert an r2rml file to SMS2?

Thank you in advance!

Best regards,

Attila Horváth

Hi. You can use R2RML files for import. In Studio, create you PostgreSQL data source, then use the stardog-admin CLI to create the virtual graph. This is off the top of my head but it's something like (check the docs)

stardog-admin virtual add --format R2RML [graph name].properties [R2RML file].ttl

Thank you very much, I did not know that I could use the CLI on other than the local install :slight_smile: I did as you suggested, and got a funny error message:

Expected ], found '©' [L26]

although there is no such character in the mapping .ttl file.

This is the command I entered:

stardog-admin --server https://sd-f0b3808c.stardog.cloud:5820 virtual add -d stif -f r2rml -n vkg -s aws mbh_mini_ontologia_prov_101-mapping.ttl

If I leave out the mapping file from the command, then Stardog creates the virtual graph no problem. The "-v" option did not really give any meaningful addition to the error message. Is there a way to somehow get to the bottom of this, because I don't really get what the problem is.

Thank you in advance if you can help me out here!

Oh, I just found the solution, Stardog just doesn't like accented characters in IRIs, so removing an "é" just did the trick!

Thank you once again!

1 Like

I literally saw this post when I was going to post on a similar matter!

Much like @horvatha .. I started out using protege/ontop, and I migrated the VKG to Stardog by exporting the Ontop mappings as R2RML, and then importing them into Stardog.

As an aside .. the import process took a very long time .. like maybe 30 minutes-ish? I know for sure it was well over 20 minutes. The VKG in question has 530 tables, and there are several mapped fields for each table -- so maybe this is to be expected.

In any case, here's a quick summary of the tweaks I had to make to my R2RML, in case it helps others:

  • I was unable to import the R2RML using the VKG creation process in the UI.
    • My impression is that the UI will only accept SMS2 format for the mappings file, but I'm uncertain of that, because it turned out that my R2RML file had some issues (details below).
  • The stardog-admin virtual add command quits quietly if there is a problem. I could probably have gotten diagnostics by looking in the log, but I decided instead to turn on the -v (verbose) option when importing,
stardog-admin virtual add -v --format r2rml --name my_vkg_using_r2rml --data-source my_data_source my_r2rml.ttl
  • It turns out that trailing ";" characters in SQL statements are unwelcome. In other words, something like this fails:
  rr:logicalTable [ a rr:R2RMLView;
      rr:sqlQuery "SELECT id,  field_a, field_b, field_c FROM some_schema.some_table; 
    ];

But removing the trailing ";" makes the r2rml import happy:

  rr:logicalTable [ a rr:R2RMLView;
      rr:sqlQuery "SELECT id,  field_a, field_b, field_c FROM some_schema.some_table
    ];
  • Certain field names cause problems. I had to rename certain fields. Although postgres was hppy to accept these field names, as long as they were quoted, using their unquoted form as the object of an rr:column predicate caused an error.
    • Here is a list of the "problematic field names" that I encountered. It's unlikely to be complete.

      • condition
      • date
      • day
      • empty
      • full
      • method
      • result
      • time
      • timestamp
    • I dealt with the issue by renaming the fields in question. Here is an R2RML fragment (hopefully syntactically correct) for mapping a table whose columns consist solely of problematic names.

<urn:get_crazy_class> a rr:TriplesMap;
  rr:logicalTable [ a rr:R2RMLView;
      rr:sqlQuery "\"condition\" as condition_, \"date\" as date_, \"day\" as day_, \"empty\" as empty_, \"full\" as full_, \"method\" as method_, \"result\" as result_, \"time\" as time_, \"timestamp\" as timestamp_ from some_schema.crazy_table"
    ];
  rr:predicateObjectMap [ a rr:PredicateObjectMap;
      rr:objectMap [ a rr:ObjectMap, rr:TermMap;
          rr:column "condition_";
          rr:termType rr:Literal
        ];
      rr:predicate <http://example.com#data#condition>
    ], [ a rr:PredicateObjectMap;
      rr:objectMap [ a rr:ObjectMap, rr:TermMap;
          rr:column "date_";
          rr:termType rr:Literal
        ];
      rr:predicate <http://example.com/data#date>
    ], [ a rr:PredicateObjectMap;
      rr:objectMap [ a rr:ObjectMap, rr:TermMap;
          rr:column "day_";
          rr:termType rr:Literal
        ];
      rr:predicate <http://example.com/data#day>
    ], [ a rr:PredicateObjectMap;
      rr:objectMap [ a rr:ObjectMap, rr:TermMap;
          rr:column "empty_";
          rr:termType rr:Literal
        ];
      rr:predicate <http://example.com/data#empty>
    ], [ a rr:PredicateObjectMap;
      rr:objectMap [ a rr:ObjectMap, rr:TermMap;
          rr:column "full_";
          rr:termType rr:Literal
        ];
      rr:predicate <http://example.com/data#full>
    ], [ a rr:PredicateObjectMap;
      rr:objectMap [ a rr:ObjectMap, rr:TermMap;
          rr:column "method_";
          rr:termType rr:Literal
        ];
      rr:predicate <http://example.com/data#method>
    ], [ a rr:PredicateObjectMap;
      rr:objectMap [ a rr:ObjectMap, rr:TermMap;
          rr:column "result_";
          rr:termType rr:Literal
        ];
      rr:predicate <http://example.com/data#result>
    ], [ a rr:PredicateObjectMap;
      rr:objectMap [ a rr:ObjectMap, rr:TermMap;
          rr:column "time_";
          rr:termType rr:Literal
        ];
      rr:predicate <http://example.com/data#time>
    ], [ a rr:PredicateObjectMap;
      rr:objectMap [ a rr:ObjectMap, rr:TermMap;
          rr:column "timestamp_";
          rr:termType rr:Literal
        ];
      rr:predicate <http://example.com/data#timestamp>
    ];
  rr:subjectMap [ a rr:SubjectMap, rr:TermMap;
      rr:class :crazy_class;
      rr:template "http://example.com/{id}";
      rr:termType rr:IRI
    ] .