I think I understand now - three step process from/to/bind - let me try it...
Thanks for your patience,
Radu
I think I understand now - three step process from/to/bind - let me try it...
Thanks for your patience,
Radu
@Radu glad it got resolve, the title was a little misleading ' How to leverage rdfs:subClassOf' threw me for a loop.
With the mapping above you will be able to get on Dramas and Documentories respectively with the following query
SELECT * FROM {
?s a :Drama .
?s ?p ?o
}
and
SELECT * FROM {
?s a :Drama .
?s ?p ?o
}
Now if you indeed were interested to leverage the rdfs:subClassOf to query all movies (assuming you have other things than movies in you dataset) you could add the following two triples
:Drama rdfs:subClassOf :Movie
:Documentory rdfs:subClassOf :Movie
now if you ran the following query with reasoning enabled
SELECT * FROM {
?s a :Movie .
?s ?p ?o
}
it would return all movies.
Indeed - that woudl be the case - on my to do list to verify - will let you know next week.
Thank you very much for your help!
Ok I have modified my SMS2 GraphQL mapping like that and errors out on "Save Changes" Log file isn't helping either ...
PREFIX : <http://movies/>
MAPPING <urn:movies>
FROM GraphQL {
movies {
movieId: movie-id
movieType: movie-type
}
}
TO {
?movie rdf:type :movieTypeClass ;
rdfs:label ?movieId .
}
WHERE {
BIND (template("http://movies/{movieType}") AS ?movieTypeClass)
BIND (template("http://movies/{movieId}") AS ?movie)
}
what's the error message? it should appear in the stardog.log
file
ERROR 2019-09-05 15:44:55,634 [stardog-user-14] com.complexible.stardog.virtual.DefaultVirtualGraphRegistry:createVirtualGraph(256): Cannot initialize virtual graph mongodb
org.antlr.v4.runtime.misc.ParseCancellationException: null
at org.antlr.v4.runtime.BailErrorStrategy.recoverInline(BailErrorStrategy.java:90) ~[antlr4-runtime-4.5.1.jar:4.5.1]
at org.antlr.v4.runtime.Parser.match(Parser.java:229) ~[antlr4-runtime-4.5.1.jar:4.5.1]
at graphql.parser.antlr.GraphqlParser.selectionSet(GraphqlParser.java:691) ~[graphql-java-4.2.jar:?]
at graphql.parser.antlr.GraphqlParser.operationDefinition(GraphqlParser.java:353) ~[graphql-java-4.2.jar:?]
at graphql.parser.antlr.GraphqlParser.definition(GraphqlParser.java:229) ~[graphql-java-4.2.jar:?]
at graphql.parser.antlr.GraphqlParser.document(GraphqlParser.java:167) ~[graphql-java-4.2.jar:?]
at graphql.parser.Parser.parseDocument(Parser.java:29) ~[graphql-java-4.2.jar:?]
at com.complexible.stardog.virtual.vega.mongo.GraphQlVgMappingParser.parse(GraphQlVgMappingParser.java:96) ~[stardog-virtual-core-6.1.0.jar:?]
at com.complexible.stardog.virtual.vega.mongo.MongoMappingsParser.lambda$parseMappings$4(MongoMappingsParser.java:239) ~[stardog-virtual-core-6.1.0.jar:?]
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[?:1.8.0_72]
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374) ~[?:1.8.0_72]
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[?:1.8.0_72]
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[?:1.8.0_72]
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[?:1.8.0_72]
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:1.8.0_72]
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[?:1.8.0_72]
at com.complexible.stardog.virtual.vega.mongo.MongoMappingsParser.parseMappings(MongoMappingsParser.java:275) ~[stardog-virtual-core-6.1.0.jar:?]
at com.complexible.stardog.virtual.vega.mongo.MongoVirtualGraphFactory.create(MongoVirtualGraphFactory.java:37) ~[stardog-virtual-core-6.1.0.jar:?]
at com.complexible.stardog.virtual.vega.mongo.MongoVirtualGraphFactory.create(MongoVirtualGraphFactory.java:21) ~[stardog-virtual-core-6.1.0.jar:?]
at com.complexible.stardog.virtual.DefaultVirtualGraphRegistry.createVirtualGraph(DefaultVirtualGraphRegistry.java:253) ~[stardog-virtual-core-6.1.0.jar:?]
at com.complexible.stardog.virtual.DefaultVirtualGraphRegistry.createVirtualGraph(DefaultVirtualGraphRegistry.java:239) ~[stardog-virtual-core-6.1.0.jar:?]
at com.complexible.stardog.virtual.DefaultVirtualGraphRegistry.add(DefaultVirtualGraphRegistry.java:124) ~[stardog-virtual-core-6.1.0.jar:?]
at com.complexible.stardog.protocols.http.server.virtual.admin.VirtualGraphHttpService.addVG(VirtualGraphHttpService.java:323) ~[stardog-virtual-protocols-http-server-6.1.0.jar:?]
at com.complexible.stardog.protocols.http.server.virtual.admin.VirtualGraphHttpService.update(VirtualGraphHttpService.java:120) ~[stardog-virtual-protocols-http-server-6.1.0.jar:?]
at com.stardog.http.server.undertow.jaxrs.ExtractRoutes.lambda$handleIt$5(ExtractRoutes.java:192) ~[stardog-protocols-http-server-6.1.0.jar:?]
at org.apache.shiro.subject.support.SubjectRunnable.doRun(SubjectRunnable.java:120) [shiro-core-1.2.3.jar:1.2.3]
at org.apache.shiro.subject.support.SubjectRunnable.run(SubjectRunnable.java:108) [shiro-core-1.2.3.jar:1.2.3]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_72]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_72]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_72]
Caused by: org.antlr.v4.runtime.InputMismatchException
at org.antlr.v4.runtime.BailErrorStrategy.recoverInline(BailErrorStrategy.java:85) ~[antlr4-runtime-4.5.1.jar:4.5.1]
... 29 more
ERROR 2019-09-05 15:44:55,635 [stardog-user-14] com.stardog.http.server.undertow.ErrorHandling:writeError(138): Unexpected error on the server
org.antlr.v4.runtime.misc.ParseCancellationException: null
at org.antlr.v4.runtime.BailErrorStrategy.recoverInline(BailErrorStrategy.java:90) ~[antlr4-runtime-4.5.1.jar:4.5.1]
at org.antlr.v4.runtime.Parser.match(Parser.java:229) ~[antlr4-runtime-4.5.1.jar:4.5.1]
at graphql.parser.antlr.GraphqlParser.selectionSet(GraphqlParser.java:691) ~[graphql-java-4.2.jar:?]
at graphql.parser.antlr.GraphqlParser.operationDefinition(GraphqlParser.java:353) ~[graphql-java-4.2.jar:?]
at graphql.parser.antlr.GraphqlParser.definition(GraphqlParser.java:229) ~[graphql-java-4.2.jar:?]
at graphql.parser.antlr.GraphqlParser.document(GraphqlParser.java:167) ~[graphql-java-4.2.jar:?]
at graphql.parser.Parser.parseDocument(Parser.java:29) ~[graphql-java-4.2.jar:?]
at com.complexible.stardog.virtual.vega.mongo.GraphQlVgMappingParser.parse(GraphQlVgMappingParser.java:96) ~[stardog-virtual-core-6.1.0.jar:?]
at com.complexible.stardog.virtual.vega.mongo.MongoMappingsParser.lambda$parseMappings$4(MongoMappingsParser.java:239) ~[stardog-virtual-core-6.1.0.jar:?]
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[?:1.8.0_72]
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374) ~[?:1.8.0_72]
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[?:1.8.0_72]
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[?:1.8.0_72]
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[?:1.8.0_72]
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:1.8.0_72]
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[?:1.8.0_72]
at com.complexible.stardog.virtual.vega.mongo.MongoMappingsParser.parseMappings(MongoMappingsParser.java:275) ~[stardog-virtual-core-6.1.0.jar:?]
at com.complexible.stardog.virtual.vega.mongo.MongoVirtualGraphFactory.create(MongoVirtualGraphFactory.java:37) ~[stardog-virtual-core-6.1.0.jar:?]
at com.complexible.stardog.virtual.vega.mongo.MongoVirtualGraphFactory.create(MongoVirtualGraphFactory.java:21) ~[stardog-virtual-core-6.1.0.jar:?]
at com.complexible.stardog.virtual.DefaultVirtualGraphRegistry.createVirtualGraph(DefaultVirtualGraphRegistry.java:253) ~[stardog-virtual-core-6.1.0.jar:?]
at com.complexible.stardog.virtual.DefaultVirtualGraphRegistry.createVirtualGraph(DefaultVirtualGraphRegistry.java:239) ~[stardog-virtual-core-6.1.0.jar:?]
at com.complexible.stardog.virtual.DefaultVirtualGraphRegistry.add(DefaultVirtualGraphRegistry.java:124) ~[stardog-virtual-core-6.1.0.jar:?]
at com.complexible.stardog.protocols.http.server.virtual.admin.VirtualGraphHttpService.addVG(VirtualGraphHttpService.java:323) ~[stardog-virtual-protocols-http-server-6.1.0.jar:?]
at com.complexible.stardog.protocols.http.server.virtual.admin.VirtualGraphHttpService.update(VirtualGraphHttpService.java:120) ~[stardog-virtual-protocols-http-server-6.1.0.jar:?]
at com.stardog.http.server.undertow.jaxrs.ExtractRoutes.lambda$handleIt$5(ExtractRoutes.java:192) ~[stardog-protocols-http-server-6.1.0.jar:?]
at org.apache.shiro.subject.support.SubjectRunnable.doRun(SubjectRunnable.java:120) [shiro-core-1.2.3.jar:1.2.3]
at org.apache.shiro.subject.support.SubjectRunnable.run(SubjectRunnable.java:108) [shiro-core-1.2.3.jar:1.2.3]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_72]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_72]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_72]
Here is how I set up my mongodb:
db = client['test']
cols = db.testCollection
movie1 = {
"movie-id": "m1",
"movie-type":"Drama",
"movie-name":"rama-drama",
"fiction-rate": 0.6
}
movie2 = {
"movie-id": "m2",
"movie-type":"Documentary",
"movie-name":"doc-doc-doc",
"realism-rate": 0.9
}
cols.replace_one(movie1, movie1, upsert = True)
cols.replace_one(movie2, movie2, upsert = True)
# print(cols.delete_many({}))
for col in cols.find({}):
print(col)
hope that helps
I think you are missing a comma between these two in the mapping:
movieId: movie-id
movieType: movie-type
the manual for GraphQL SMS2 mapping doesn't have commas:
PREFIX : <http://stardog.com/movies/>
MAPPING <urn:movies>
FROM GraphQL {
movie {
movieId: _id
name
datePublished
genre @array
boxOffice
description
director @array {
directorId: director
directorName: name
}
actor @array {
actorId: actor
actorName: name
}
}
}
TO {
?movie a :Movie ;
:name ?name ;
:datePublished ?xsdDatePublished ;
:genre ?genre ;
:boxOffice "?boxOffice"^^xsd:integer ;
:description ?description ;
:directed ?directedMovie ;
:actedIn ?actedInMovie .
?directedMovie a :DirectedMovie ;
:director ?director ;
:name ?directorName .
?director a :Person .
?actedInMovie a :ActedInMovie ;
:actor ?actor ;
:name ?actorName .
?actor a :Person .
}
WHERE {
BIND (template("http://stardog.com/movies/Job_{movieId}_{directorId}") AS ?directedMovie)
BIND (template("http://stardog.com/movies/Job_{movieId}_{actorId}") AS ?actedInMovie)
BIND (template("http://stardog.com/movies/Title_{movieId}") AS ?movie)
BIND (template("http://stardog.com/movies/Name_{directorId}") AS ?director)
BIND (template("http://stardog.com/movies/Name_{actorId}") AS ?actor)
BIND (xsd:date(?datePublished) AS ?xsdDatePublished)
You are right. My bad. It looks like the problem is that you can't have a dash (-
) in the GraphQL field name.
That was it - thank you - it works now
Upon a closer look the my triples returned by this query
SELECT * {
GRAPH <virtual://mongodb> { ?s ?p ?o }
}
return:
http://uri/id1 rdf:type http://uri/**movieTypeCls**
Instead I expected it to return
http://uri/id1 rdf:type http://uri/**Drama**
So we don't have a solution yet
Your mapping is
TO {
?movie rdf:type :movieTypeClass ;
rdfs:label ?movieId .
}
I believe you want ?movieTypeClass
(the variable) instead of :movieTypeClass
(the URI)
I have tried that too - but it will have an error - won't let me save it
Apologies for this lengthy thread. I should have created this sample data and mapping to begin with ... for all of us to be on the same page. Here are the steps:
import pymongo
from pymongo import MongoClient
from bson.objectid import ObjectId
#client = MongoClient('mongodb://user:pass@1.1.1.1:27017/?authSource=admin')
db = client['moviesdb']
colMovies = db.movies
# print(cols.delete_many({}))
movie1 = {
"movieId": "m1",
"movieType":"Drama",
"movieName":"drama-drama",
"fiction-rate": 0.6
}
movie2 = {
"movieId": "m2",
"movieType":"Documentary",
"movieName":"doc-doc-doc",
"realism-rate": 0.9
}
colMovies.replace_one(movie1, movie1, upsert = True)
colMovies.replace_one(movie2, movie2, upsert = True)
for m in colMovies.find({}):
print(m)
PREFIX : <http://movies/>
MAPPING <urn:movies>
FROM GraphQL {
movies {
movieId
movieName
movieTypeClass: movieType
}
}
TO {
?movie rdf:type :movieTypeClass ;
rdfs:label ?movieName .
}
WHERE {
BIND (template("http://movies/{movieType}") AS ?movieTypeClass)
BIND (template("http://movies/{movieId}") AS ?movie)
}
mongodb.uri=mongodb://testuser:pass@1.1.1.1:27017/moviesdb?authSource=admin
./stardog-admin virtual add --overwrite --format SMS2 movies.properties movies.sms
SELECT * {
GRAPH <virtual://movies> { ?s ?p ?o }
}
Unfortunately the query above doesn't produce Drama and Documentary rdf types :frowning
Radu,
The following changes should get you what you want:
movieTypeClass: movieType
to just movieType
. Since you're using {movieType}
in the WHERE, you don't want to rename it here.?movie rdf:type :movieTypeClass
to ?movie rdf:type ?movieTypeClass
. Right now you're binding a constant URI there instead of the URI that you are creating in the WHEREYes - this works fine now:
PREFIX : <http://movies/>
MAPPING <urn:movies>
FROM GraphQL {
movies {
movieId
movieName
movieType
}
}
TO {
?movie rdf:type ?movieTypeClass ;
rdfs:label ?movieName .
}
WHERE {
BIND (template("http://movies/{movieType}") AS ?movieTypeClass)
BIND (template("http://movies/{movieId}") AS ?movie)
}
P.S. Do I completely understand it yet... that is another question.
Thank you!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.