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
] .