Data source data not linking to ontology

I have created a virtual graph tied to a database data source. I also loaded an RDF file into the same stardog db that the virtual graph was created for. This RDF file contains an ontology with classes, relationships, attributes, but no instances. The classes are based on the tables from the data source. I am having an issue with getting the virtual graph data to be linked/connected to the respective ontology classes when running SPARQL.

select ?s { graph <virtual://Students> { ?s a :courses. } ?s a owl:NamedIndividual. }

select ?s { graph <virtual://Students> { ?s a :courses. } ?s a ctgo:Course. }

Both of these SPARQL queries are returning no results.
That leads me to believe that the data from the data source is not linked/connected to the ontology Class. Is this true?


Hello Scott,

I believe that these queries are looking for entities ?s that occur in the virtual graph, and also in the default graph. However, you said there are no instances in the default. Could that be the issue?


So then my response is when an RDF file is loaded into a stardog database is it loaded into the "default graph" automatically? When I loaded the RDF file, there were no instances (NamedIndividuals) defined in the RDF file.

Yes. The RDF will, by default, go into the default graph. But that's not the problem, if I have understood it correctly. You are looking for instances (?s say), that belong to the virtual graph and are of class :courses, and at the same time belong to the default graph of type Owl:NamedIndividual. The data in the default graph are materialized in Stardog, while the data from the virtual graph remain in their original source database.

Have you tried writing each half of your query on its own? See if you can get data out of the virtual graph, then see what you can get out of the default.

yes. I ran a query from the virtual graph and can extract the data from the data source. When I run a query from the default I get results back. Those results are ONLY data from the ontology I loaded. What I need Stardog to do is to semantically link the instances from the data source (virtual graph) to the entities from the ontology. so for ex:

If linking is successful, then these can be represented in triples as:
<Mary, rdf:type, Student>
<John, rdf:type, Student>
<Peter, rdf:type, Student>
<Mary, rdf:type, owl:NamedIndividual>
<John, rdf:type, owl:NamedIndividual>
<Peter, rdf:type, owl:NamedIndividual>

After additional implicit relationships can be inferred.

Can Stardog do this?

Stupid question, but did you remember to turn reasoning on when you ran your query? You need stardog query execute –-reasoning myDB myquery.rq, if you are working from the command line.

Yes reasoning is turned on. I am working in Stardog studio. I want to run SPARQL queries in studio.

What happens if you do something like select * { graph virtual://students {?s rdf:type ?type}) limit 20

You should see every type that is defined in both the ontology and the virtual graph.

Or if you have many classes, just “select * {graph virtual://students {?s a :courses ; a ?type.}”

You can also check in the “models” section of Studio to see if your ontology is there. There is an icon along the left margin that looks like an org chart. That takes you to the models section.

When I run both of your queries separately, each time I get an error message:
"Failed to run query: com.complexible.stardog.plan.eval.ExecutionException: Service clause contains a pattern not supported by reasoning: prefix :
prefix rdf:
prefix rdfs:
prefix xsd:
prefix owl:
prefix stardog: tag:stardog:api:

Type(?s, ?type)
─ {** ** ─ Singleton [#1]
** }"**

The ontology is in the models section.

What this boils down to, can Stardog do what I need to do?

Hi Scott, you should be able to do this with Stardog. When you created the Virtual Graph did you check "Auto-generate mapping"? See my screenshot below for an example.

If so, when you did that did you see a mapping auto-generated for your tables in the database? Something like this....

This should return autogenerated mappings. From there you can take a snippet of a mapping you know has data from the "TO" clause and run it as a SPARQL query in the Stardog Studio Workspace like this:

This should return return data if everything is set up correctly. Can you comment if each one of the steps above worked for you? I know this doesn't solve your problem, but will help confirm the data source was set up correctly and can be queried.

Hi Tim,

I already did everything you suggested and the data source has been setup correctly. I must not explaining the problem correctly. If you go back to the diagram I uploaded a few posts back, this explains it clearly.
I want to have Stardog make explicit relationship connections between the data from the data source. Like "Mary" for example. To the "Students" entity from the loaded ontology file. So produce the rdf:type relationships.
Is this clear?

I think what you’re looking for is the “virtual transparency” option.

I’m not quite sure what you mean when you said “When I loaded the RDF file, there were no instances (NamedIndividuals) defined in the RDF file.”

What I meant from the quoted text I said, was that the RDF file only contained the classes, object properties, datatype properties, annotation properties. There were no owl:NamedIndividual items defined.

I have turned on Virtual Transparency as well as the query.all.graphs setting. Made no difference. At this point I have to assume that Stardog does not let me create the semantic data fabric that I need to create. That's a shame. I will be starting to work for a company which is a client of Stardog's. I will be in an influential position and will recommend that they use a different product.

I haven’t even had a chance to ask you what version you’re running, what platform you’re running on, what relational database you’re using, or to ask for your mappings, ontology, and logs.

This is the community forum and members like myself volunteer their time to help out other members. Once you’re working for the client you mention I’m sure you’ll have access to more formal channels of support where you can speak directly to Stardog engineers. They’re very helpful and responsive. Im sure if you mention your up coming position they would be happy to reach out to you directly.

What you are looking to do seems very straight forward and should be well within the capabilities of Stardog. I don’t know if any other system that would be more capable in this area. It wouldn’t be the first time I’ve seen a problem be as simple as a typo in a namespace or a character coding issue with a relational database. I’m sure with a little bit of patience this can be sorted out. It’s often a challenge just to get a clear understanding of what exactly the problem is especially in the context of a forum.

Hi Scott, thank you for your patience as we work through this. The data fabric capabilities you are looking for are definitely supported by the Stardog platform. I have put an example together that attempts to replicate your use case and will hopefully help us move forward in resolving your issue.

  1. To start, I created a sample mysql database with a table called "students" with columns STUDENT_ID and STUDENT_NAME. This table has 3 records...Mary, John and Peter.
STUDENT_ID integer,


  1. I created a Stardog database called "students" and uploaded the following ontology with a Student, Person and Course class. Student is a sub class of Person and Student is related to Course by an "enrolled in" object property.
@prefix test: <urn:test:model:> .
@prefix owl: <> .
@prefix xsd: <> .
@prefix rdfs: <> .

test:Person a owl:Class ;
            rdfs:label "Person".

test:Student a owl:Class ;
             rdfs:subClassOf test:Person;
             rdfs:label "Student".
test:Course a owl:Class;
            rdfs:label "Course".
test:enrolled_in a owl:ObjectProperty;
             rdfs:label "enrolled in";
             rdfs:domain test:Student ;
             rdfs:range test:Course.

test:name a owl:DatatypeProperty ;
          rdfs:label "name" ;
          rdfs:domain test:Student ;
          rdfs:range xsd:string .
test:course_name a owl:DatatypeProperty ;
          rdfs:label "course name" ;
          rdfs:domain test:Course ;
          rdfs:range xsd:string .
  1. In Stardog Studio I created a data source that connects to the mysql database I set up.
  2. Next I created a new Virtual Graph called "students_vg". Stardog will auto-generates mappings using Stardog's SMS mappings syntax. I chose to modify this mapping to align the source data to my ontology. Please note that the columns STUDENT_ID and STUDENT_NAME from my table become variables that I can pass in to the "TO" clause in the mapping.
PREFIX test: <urn:test:model:>
PREFIX owl: <>
PREFIX rdf: <>
PREFIX rdfs: <>
PREFIX stardog: <tag:stardog:api:>
PREFIX xsd: <>

  FROM `test`.`students`
TO {
?subject a test:Student;
         rdfs:label ?STUDENT_NAME;
         test:name ?STUDENT_NAME.

  BIND(template("urn:test:data:students:{STUDENT_ID}") AS ?subject)
  1. Now that the Virtual Graph is created I can query it using Stardog Studio's Workspace.
PREFIX test: <urn:test:model:>

select ?student ?studentName  {graph <virtual://students_vg> {
?student a test:Student;
rdfs:label ?studentLabel;
test:name ?studentName.

This results in returning 3 records from our virtualized mysql database.

  1. If we want to add data into Stardog and query across that data and the data from the Virtual Graph, we can do that too. I will show this by inserting 3 instances of the Courses Students are enrolled in:
INSERT DATA {<urn:test:data:students:1> <urn:test:model:enrolled_in> <urn:test:data:course:1>;
                                        <urn:test:model:course_name> "Algebra"}
INSERT DATA {<urn:test:data:students:2> <urn:test:model:enrolled_in> <urn:test:data:course:2>;
                                        <urn:test:model:course_name> "Physics"}
INSERT DATA {<urn:test:data:students:3> <urn:test:model:enrolled_in> <urn:test:data:course:3>;
                                        <urn:test:model:course_name> "Technical Writing"}

Once this data is inserted, we can now query for it and the data in the mysql database to see what courses our students are enrolled in.

PREFIX test: <urn:test:model:>

select ?student ?studentName ?course ?courseName  {graph <virtual://students_vg> {
?student a test:Student;
rdfs:label ?studentLabel;
test:name ?studentName.
?student test:enrolled_in ?course;
         test:course_name ?courseName.

I hope this example provided some insights into how Stardog's data fabric capabilities work. To better understand what is going on in your environment, would you be able to share your ontology and virtual graph mappings? Thank you!

Hi Zach,

Thank you for your reply.

I am running version 7.8.0. The platform is Windows 10. I am using postgresql DB. I am going to use the same steps that Tim used in his demo, with my data, and see if I can replicate the results. I will let you know what results I get.