Note that there are some explanatory texts on larger screens.

plurals
  1. POJava - Jena API - Output file
    primarykey
    data
    text
    <p>I'm using Java and Jena API.</p> <p>I have a class <code>Person</code> with the datatype properties <code>hasFirstName</code>, <code>hasLastName</code>, <code>hasDateOfBirth</code>, <code>hasGender</code>.</p> <p>Here is how one person is represented 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>For each person whose gender is <strong>female</strong> I want to generate a text file with this line below:</p> <pre><code>[label= \"" +firstName+ " \"\n\n\"D.Naiss:"+dnai1+"\", "+shape2+"] </code></pre> <p>so if there is, for example, 3 females the file must contain 3 lines with that format. The shape value( and then the output line) will depend on the gender, that's why i cannot not use the same line for both genders.</p> <p>For each person whose gender is <strong>male</strong> I want to output this line below:</p> <pre><code>[label= \"" +firstName+ " \"\n\n\"D.Naiss:"+dnai1+"\", "+**shape**+"] </code></pre> <p>The problem I have is that in the output file i only see one woman and one man with the corresponding line. I have more than one woman and man but he only outputs one for each gender. That's my problem... </p> <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 modify to solve my problem?</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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