Note that there are some explanatory texts on larger screens.

plurals
  1. POJava - Jena API - Get an attribute of another class
    text
    copied!<p>I'm using java and the Jena API. I have a class Marriage which has 3 Object Properties called "hasHusband", "Haswife" and "dateOfMarriage". The first two are associated with a class Person which has the datatype properties like first name, last name, date of birth...</p> <p>I'd like to retrieve the wife's first name and the husband's first name. Could you explain me how can I do this?</p> <p>Here is the relevant part of my rdf file:</p> <pre><code>(...) &lt;j.0:FAMmariage rdf:about=http://www.fam.com/FAM#BrunoCatherine&gt; &lt;j.0:FAMaDateMariage&gt;25/07/2011&lt;/j.0:FAMaDateMariage&gt; &lt;j.0:FAMhasWife&gt; &lt;rdf:Description rdf:about="http://www.fam.com/FAM#Catherine20/03/1982"&gt; &lt;j.0:FAMDateOfBirth&gt;20/03/1980&lt;/j.0:FAMDateOfBirth&gt; &lt;j.0:FAMHasName&gt;Gomez&lt;/j.0:FAMHasName&gt; &lt;j.0:FAMHasFirstName&gt;Catherine&lt;/j.0:FAMHasFirstName&gt; &lt;/rdf:Description&gt; &lt;/j.0:FAMHasWife&gt; &lt;j.0:FAMHusband&gt; &lt;rdf:Description rdf:about="http://www.fam.com/FAM# Bruno15/06/1980 "&gt; &lt;j.0:FAMaDateOfBirth&gt;15/06/1980 &lt;/j.0:FAMDateOfBirth&gt; &lt;j.0:FAMHasName&gt;Jeandet &lt;/j.0:FAMHasName&gt; &lt;j.0:FAMHasFirstName&gt;Bruno&lt;/j.0:FAMHasFirstName&gt; &lt;/rdf:Description&gt; &lt;/j.0:FAMHusband&gt; &lt;/j.0:FAMmariage&gt; (...) </code></pre> <p>Thanks</p> <p><strong>EDITED</strong> Through the code below I can get the hasWife object property. What should I add to get the firstName datatypeproperty?</p> <pre><code>//Object Property hasWife StmtIterator iter = onto.model.listStatements(null,onto.hasWife,(RDFNode)null); while (iter.hasNext()) { Statement stmt = iter.nextStatement(); System.out.println(stmt.getObject().toString()); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload