Note that there are some explanatory texts on larger screens.

plurals
  1. POJava - Jena API - Getting more than one datatypeproperty
    text
    copied!<p>I'm using Java and Jena API. I have a <strong><em>class Marriage</em></strong> which have 3 Object Properties called <strong>"hasHusband"</strong>, <strong>"Haswife"</strong> and <strong>"dateOfMarriage"</strong>. The first two are associated with a <strong><em>class Person</em></strong> which has the datatypeproperties <strong>hasFirstName</strong>, <strong>hasLastName</strong>, <strong>dateOfBirth</strong>....</p> <p>Through the code below I can access the hasFirstName property of the husband.</p> <pre><code>StmtIterator iter = onto.model.listStatements(null,onto.hasHusband,(RDFNode)null); while (iter.hasNext()) { Statement stmt = iter.nextStatement(); Resource P = ((Resource) stmt.getObject()); StmtIterator iter2 = onto.model.listStatements(((Resource) P),onto.hasFirstName,(RDFNode)null); while (iter2.hasNext()) { Statement stmt2 = iter2.nextStatement(); firstnameHusband = stmt2.getObject().toString(); }} </code></pre> <p><strong>I would like to modify this line</strong> </p> <pre><code> StmtIterator iter2 = onto.model.listStatements(((Resource) P),onto.hasFirstName,(RDFNode)null); </code></pre> <p><strong>in order to access also the hasLastName and hasDateofBirth...</strong></p> <p>Can you explain me how can I do this?</p> <p>Thanks</p> <p><strong>EDITED: @Pierre</strong> Now it concerns only the class Person. In case of womans I want to output in a new file (text file) this line below <em>for each woman</em>:</p> <pre><code>[label= \"" +firstName+ " \"\n\n\"D.Naiss:"+dnai1+"\", "+shape2+"] </code></pre> <p>And <em>for each man</em> this:</p> <pre><code>[label= \"" +firstName+ " \"\n\n\"D.Naiss:"+dnai1+"\", "+shape+"] </code></pre> <p>The diference is in the value of shape. The problem I have is that he only outputs one woman and one man.</p> <p>A person is represented like this in my rdf file:</p> <pre><code> &lt;rdf:Description rdf:about="http://www.fam.com/FAM#Bruno04/02/1980 "&gt; &lt;j.0:FAMhasGender&gt;H&lt;/j.0:FAMhasGender&gt; &lt;j.0:FAMhasDateOfBirth&gt;04/02/1980&lt;/j.0:FAMhasDateOfBirth&gt; &lt;j.0:FAMhasLastName&gt;DS &lt;/j.0:FAMhasLastName&gt; &lt;j.0:FAMhasFirstName&gt; Bruno&lt;/j.0:FAMhasFirstName&gt; &lt;/rdf:Description&gt; </code></pre> <p>Here is the relevant code:</p> <pre><code>public void accessProp() { readFile(inputFile); // rdf String fname; String dd; String gen; ExtendedIterator instances = onto.person.listInstances(); Individual instance = null; Individual firstInstance = null; while (instances.hasNext()) { instance = (Individual) instances.next(); gen = instance.getPropertyValue(onto.hasGender).toString(); fname = instance.getPropertyValue(onto.hasFirstName).toString(); dd = instance.getPropertyValue(onto.hasDateOfBirth).toString(); writeFile(fname, dd, genr); } } // Write text file public void writeFile(String fn, String dbir, String gn) { String fileout = "D:/file1.txt"; String firstName = fn; String dateB = dbir; String gender = gn; BufferedWriter out; try { out = new BufferedWriter(new FileWriter(fileout, true)); if (gender.equals("F")) { out.write("[label= \"" + firstName + " \"\n\n\"D.Naiss:" + dnai1 + "\", " + shape + "]"); } else if (gender.equals("M")) { out.write("[label= \"" + firstName + " \"\n\n\"D.Naiss:" + dnai1 + "\", " + shape2 + "]"); } out.newLine(); // flushes and closes the stream out.close(); } catch (IOException e) { System.out.println("There was a problem:" + e); } } </code></pre> <p>Can you tell me what should I do to solve my problem?</p> <p>Thanks</p>
 

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