Great. It looks like you are on the right track here -- my understanding is your use-case is supported and you do want to create an SMS mapping to translate your data in Mongo to triples query-able from Stardog.
I think one thing that may be confusing with how mappings work is if there is any part of your mapping file which does not apply to a particular Mongo document then it is simply ignored. For instance, if a mapping has ?movie :fictionRate ?fictionRate
and a JSON document in Mongo doesn't have the ?fictionRate
property then no triple will be returned with the predicate :fictionRate
with that ?movie
as the subject.
Below I sketched what you may want your mapping to look like (beware, I haven't tested so there may be syntax errors, missing namespace prefix declarations, etc).
The mapping can be roughly translated as:
"For each document in <mongo-collection-name>
, first associate each attribute I wish to expose to Stardog to a variable in the FROM
clause, then construct a URI to identify the document in the WHERE
clause, and finally populate as much of the template in the TO
clause as possible given the contents of this particular document -- in this example creating up to 4 triples from that document."
MAPPING FROM JSON {
"<mongo-collection-name>": {
"movie-type": ?movieTypeStr,
"movie-name": ?movieNameStr,
"fiction-rate": ?fictionRate,
"realism-rate": ?realismRate,
}
}
TO {
?movie rdf:type ?movieTypeCls ;
rdfs:label ?movieNameStr ;
:fictionRate ?fictionRate ;
:realismRate ?realismRate .
}
WHERE {
# TODO replace `http://foo.com` with a value appropriate to your setup
BIND (template("http://foo.com/{movieTypeStr}") AS ?movieTypeCls)
}
Please test and iterate based on this, and then let us know how it goes!
Here's a link to the SMS2 docs:
P.S. I see MAPPING FROM graphql
is used as an example in this blog post, Native MongoDB Support is Here! | Stardog . I haven't used that before, and the naming probably threw me off because it made me think of VGs consuming GraphQL APIs, but it should work just as well as the FROM JSON
clause I provided as a method of associating the structure of JSON documents in your Mongo database to variables for use elsewhere in the mapping.