Read array of Json-Ld Objects into a Model In Apache Jena.How to retrieve individual objects from Model?

387 views Asked by At

This is Json Array of Object(Student Data) . I am loaded that Json-Ld Data in Jena Model

[
    { 
       "@context" : {
                       "myvocab" : "http://mywebsite.com/vocab/",
                       "name"  : "myvocab:name",
                       "firstname" : "myvocab:firstname",
                       "lastname"  : "myvocab:lastname",
                       "rollNumber" : "myvocab:rollNumber"
                    },
       "name" : { 
                   "firstname" : "Dhannan",
                   "lastname"  : "Chaudhary"
                },
       "rollNumber" : "26"
    },
    { 
       "@context" : {
                       "myvocab" : "http://mywebsite.com/vocab/",
                       "name"  : "myvocab:name",
                       "firstname" : "myvocab:firstname",
                       "lastname"  : "myvocab:lastname",
                       "rollNumber" : "myvocab:rollNumber"
                    },
       "name" : { 
                   "firstname" : "Maakin",
                   "lastname"  : "Dhayaal"
                },
       "rollNumber" : "69"
    }
]

This is my model output for above example ( by using SPARQL )

-------------------------------------------------------------------
| Subject | Predicate                               | Object      |
===================================================================
| _:b0    | <http://mywebsite.com/vocab/lastname>   | "Chaudhary" |
| _:b0    | <http://mywebsite.com/vocab/firstname>  | "Dhannan"   |
| _:b1    | <http://mywebsite.com/vocab/lastname>   | "Dhayaal"   |
| _:b1    | <http://mywebsite.com/vocab/firstname>  | "Maakin"    |
| _:b2    | <http://mywebsite.com/vocab/rollNumber> | "62"        |
| _:b2    | <http://mywebsite.com/vocab/name>       | _:b1        |
| _:b3    | <http://mywebsite.com/vocab/rollNumber> | "61"        |
| _:b3    | <http://mywebsite.com/vocab/name>       | _:b0        |
-------------------------------------------------------------------

From this model I want only Subjects(Resources in term of Jena) of every Student for my case it should ( _:b2 , _:b3) .
But by using model.listSubjects() it gives iterator to all subjects ( _:b0 , _:b1 , _:b2 , _:b3)

My main goal is to be able to get individual models for student 1 and student 2.
How can I achieve this?
Every Suggestions are welcome.

1

There are 1 answers

0
berezovskyi On

First, you can use RDF Type literal to define Student class as well as the StudentName class (not sure why you'd need to break them up).

You can then check if the subject has the property that you are looking for. You can see how we do this in Eclipse Lyo Jena provider.

Finally, you can model your domain with Lyo modelling tools and generate the POJOs for your domain that can be converted from/to Jena models in a single method call.