You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by kumar rohit <ku...@gmail.com> on 2016/07/21 19:00:02 UTC
Can not write to the file
*When I run this program without writing it to the file, it runs smoothly.
But when I copy it to a file (both newly created and existing file),
sometime it adds the garbage claases to the file like Seq, Bag, Resource
and most of the time it does nothing except it empties the destination
file.*
*I have copied the whole code except the code auto generated by netbeans*
*public class NewJFrame extends javax.swing.JFrame {*
* public static void readOntology(String file,OntModel model)*
* {*
* InputStream in =FileManager.get().open(file);*
*if (in==null) {*
*throw new IllegalArgumentException( "File: " + file + " not found");*
*}*
* model.read(in,null);*
* //in.close();}}*
private void read1(String str, OntModel model)
{
String ns="
http://www.semanticweb.org/ontologies/untitled-ontology-54/";
OntClass user = model.createClass(ns + "User");
OntClass user1 = model.getOntClass(ns + "User");
Individual janeSmith = user1.createIndividual(ns + str)
try {
String file="F://newontology.owl";
FileOutputStream f1=new FileOutputStream(file);
RDFWriter d = model.getWriter("RDF/XML-ABBREV");
d.write(model,f1,null);
}catch(Exception e) {}
*private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
*
*OntModel model=ModelFactory.createOntologyModel();*
* String str=jTextField2.getText()*
* read1(str, model); }}*
* public static void main(String args[]) {*
* OntModel model = ModelFactory.createOntologyModel();*
* String file="F://updated.owl";*
* readOntology(file , model );*
*}*
Re: Can not write to the file
Posted by Andy Seaborne <an...@apache.org>.
On 22/07/16 13:17, kumar rohit wrote:
> I dont know if attaching screen shot is allowed or not, but kindly if
> you can check it.
You can see what we all see of your emails by looking in the archives:
https://lists.apache.org/thread.html/43dbb59ca0b17f780957ed5bb5d430707ab6de516e11f77e79dbfcd5@%3Cusers.jena.apache.org%3E
Badly broken code.
https://lists.apache.org/thread.html/412dd17ef1f7ae8b77f564c36a7849b365aea50e643cfe21ace0e752@%3Cusers.jena.apache.org%3E
No attachments
Andy
>
> After running the code , it has added the garbage classes to the file.
> User class is also there as I have created it, but again it has
> disappeared my classes in ontology.
>
> *Note:* I have added new class in the same file I have read it and used
> the same namespace of the ontology for new class (User class).
> My ontology uri is : *String
> ns="http://www.semanticweb.org/ontologies/2016/7/untitled-54/";*
> *
> *
> And I used this for *User* class also.
>
> On Fri, Jul 22, 2016 at 2:47 AM, Dave Reynolds
> <dave.e.reynolds@gmail.com <ma...@gmail.com>> wrote:
>
> On 22/07/16 10:44, kumar rohit wrote:
>
> Yes because the model.write() works but the FileWriter does not.
> I also
> tried something like this to append data but failed:
>
> FileOutputStream f1=new FileOutputStream(file, *true*);
>
> Any solution please you suggest to write it to the same file I
> have read
> from?
>
>
> You can't, at least not in RDF/XML format.
>
> As Lorenz says, you would have to read in the current file, add your
> new assertions, then write out the whole file again.
>
>
> Dave
>
> On Fri, Jul 22, 2016 at 2:22 AM, Lorenz B. <
> buehmann@informatik.uni-leipzig.de
> <ma...@informatik.uni-leipzig.de>> wrote:
>
> Hello Dave,
>
> I think the problem is that he writes to another file - and
> I guess this
> one already contains some data. Of course the write method
> cannot append
> data, but just overwrites the file. Am I right? Anything
> else would
> sound like some magic.
>
> Otherwise, to append data, one would have to load it into a
> separate
> model and add data directly to this model.
>
>
>
> Kind regards,
> Lorenz
>
> On 22/07/16 09:58, kumar rohit wrote:
>
> The main() pass the required file and then just the
> GUI loads because we
> have to deal with a text field where user enter his
> name and we will
> create
> individual of that name.
>
> The main purpose of this code is to create
> individual (after user
> enter the
> name) and store it locally in a file *(either a
> separate file or to the
> file we have read **InputStream in
> =FileManager.get().open(file);*)
>
> It writes the required result to the
> console(model.write method) but
> when I
> try to write it in a file, it just remove all the
> data from the
> destination
> file and even the ontology URI.
>
> For writing to a file, I used these both methods but
> both does not work.
>
> (1) FileWriter out = new FileWriter( fileName );
>
> try {
> model.write( out, "RDF/XML-ABBREV" );}
>
> 2) FileOutputStream out=new
> FileOutputStream(filename);
> RDFWriter d =
> model.getWriter("RDF/XML-ABBREV");
> d.write(model,out,null);
> }catch(Exception e) {}
>
>
>
> Make sure you close the stream, that's probably the
> source of your
> random loss of output.
>
> The reason you see Seq and other such junk is because
> you are writing
> the whole model, with inference, and a default OntModel
> includes RDFS
> inference. Use model.write which for an OntModel
> defaults to writing
> just the base model. Also, unless you need inference use
> an explicit
> OntModelSpec which doesn't have any (e.g. OWL_MEM).
>
> Dave
>
> On Fri, Jul 22, 2016 at 12:30 AM, Lorenz B. <
> buehmann@informatik.uni-leipzig.de
> <ma...@informatik.uni-leipzig.de>> wrote:
>
> 1.) This is not a minimal running example! that
> means, nobody can test
> it without some (in your case too much) effort
> to get it running.
> 2.) w.r.t. 1), look at your main() method, it
> reads a file and then?
> 2.) Please tell us exactly WHAT does not work
> and WHAT you expect.
> 3.) The OntModel object has a method write, not
> sure what you did there
> with calling getWriter and the like
>
> *When I run this program without writing it
> to the file, it runs
>
> smoothly.
>
> But when I copy it to a file (both newly
> created and existing file),
> sometime it adds the garbage claases to the
> file like Seq, Bag,
> Resource
> and most of the time it does nothing except
> it empties the destination
> file.*
>
> *I have copied the whole code except the
> code auto generated by
> netbeans*
>
>
>
>
>
> *public class NewJFrame extends
> javax.swing.JFrame {*
>
>
>
>
>
>
> * public static void readOntology(String
> file,OntModel model)*
>
> * {*
>
>
> * InputStream in
> =FileManager.get().open(file);*
>
>
>
> *if (in==null) {*
>
> *throw new IllegalArgumentException( "File:
> " + file + " not
> found");*
>
> *}*
>
> * model.read(in,null);*
>
> * //in.close();}}*
>
>
>
> private void read1(String str, OntModel
> model)
>
> {
>
>
>
>
>
>
>
> String ns="
> http://www.semanticweb.org/ontologies/untitled-ontology-54/";
>
>
> OntClass user = model.createClass(ns
> + "User");
>
>
>
>
>
> OntClass user1 = model.getOntClass(ns
> + "User");
>
> Individual janeSmith =
> user1.createIndividual(ns + str)
>
>
>
> try {
>
> String file="F://newontology.owl";
>
>
>
>
>
> FileOutputStream f1=new
> FileOutputStream(file);
>
> RDFWriter d =
> model.getWriter("RDF/XML-ABBREV");
>
> d.write(model,f1,null);
>
> }catch(Exception e) {}
>
>
> *private void
> jButton1ActionPerformed(java.awt.event.ActionEvent
> evt) {
> *
>
>
>
> *OntModel
> model=ModelFactory.createOntologyModel();*
>
>
> * String str=jTextField2.getText()*
>
>
>
> * read1(str, model); }}*
>
>
>
> * public static void main(String args[]) {*
>
>
>
>
>
>
>
> * OntModel model =
> ModelFactory.createOntologyModel();*
>
> * String file="F://updated.owl";*
>
> * readOntology(file , model );*
>
> *}*
>
> --
> Lorenz B�hmann
> AKSW group, University of Leipzig
> Group: http://aksw.org - semantic web research
> center
>
>
>
>
> --
> Lorenz B�hmann
> AKSW group, University of Leipzig
> Group: http://aksw.org - semantic web research center
>
>
>
>
Re: Can not write to the file
Posted by "Lorenz B." <bu...@informatik.uni-leipzig.de>.
Kumar,
we told you that it does not work if you write to another file and use
RDF/XML format. The file will be overwritten. Do you understand?
You have to read the target file as model and add the data to this model
and write this model to the same file.
> I dont know if attaching screen shot is allowed or not, but kindly if
> you can check it.
>
> After running the code , it has added the garbage classes to the file.
> User class is also there as I have created it, but again it has
> disappeared my classes in ontology.
>
> *Note:* I have added new class in the same file I have read it and
> used the same namespace of the ontology for new class (User class).
> My ontology uri is : *String
> ns="http://www.semanticweb.org/ontologies/2016/7/untitled-54/";*
> *
> *
> And I used this for *User* class also.
>
> On Fri, Jul 22, 2016 at 2:47 AM, Dave Reynolds
> <dave.e.reynolds@gmail.com <ma...@gmail.com>> wrote:
>
> On 22/07/16 10:44, kumar rohit wrote:
>
> Yes because the model.write() works but the FileWriter does
> not. I also
> tried something like this to append data but failed:
>
> FileOutputStream f1=new FileOutputStream(file, *true*);
>
> Any solution please you suggest to write it to the same file I
> have read
> from?
>
>
> You can't, at least not in RDF/XML format.
>
> As Lorenz says, you would have to read in the current file, add
> your new assertions, then write out the whole file again.
>
>
> Dave
>
> On Fri, Jul 22, 2016 at 2:22 AM, Lorenz B. <
> buehmann@informatik.uni-leipzig.de
> <ma...@informatik.uni-leipzig.de>> wrote:
>
> Hello Dave,
>
> I think the problem is that he writes to another file -
> and I guess this
> one already contains some data. Of course the write method
> cannot append
> data, but just overwrites the file. Am I right? Anything
> else would
> sound like some magic.
>
> Otherwise, to append data, one would have to load it into
> a separate
> model and add data directly to this model.
>
>
>
> Kind regards,
> Lorenz
>
> On 22/07/16 09:58, kumar rohit wrote:
>
> The main() pass the required file and then just
> the GUI loads because we
> have to deal with a text field where user enter
> his name and we will
> create
> individual of that name.
>
> The main purpose of this code is to create
> individual (after user
> enter the
> name) and store it locally in a file *(either a
> separate file or to the
> file we have read **InputStream in
> =FileManager.get().open(file);*)
>
> It writes the required result to the
> console(model.write method) but
> when I
> try to write it in a file, it just remove all the
> data from the
> destination
> file and even the ontology URI.
>
> For writing to a file, I used these both methods
> but both does not work.
>
> (1) FileWriter out = new FileWriter( fileName );
>
> try {
> model.write( out, "RDF/XML-ABBREV" );}
>
> 2) FileOutputStream out=new
> FileOutputStream(filename);
> RDFWriter d =
> model.getWriter("RDF/XML-ABBREV");
> d.write(model,out,null);
> }catch(Exception e) {}
>
>
>
> Make sure you close the stream, that's probably the
> source of your
> random loss of output.
>
> The reason you see Seq and other such junk is because
> you are writing
> the whole model, with inference, and a default
> OntModel includes RDFS
> inference. Use model.write which for an OntModel
> defaults to writing
> just the base model. Also, unless you need inference
> use an explicit
> OntModelSpec which doesn't have any (e.g. OWL_MEM).
>
> Dave
>
> On Fri, Jul 22, 2016 at 12:30 AM, Lorenz B. <
> buehmann@informatik.uni-leipzig.de
> <ma...@informatik.uni-leipzig.de>> wrote:
>
> 1.) This is not a minimal running example!
> that means, nobody can test
> it without some (in your case too much) effort
> to get it running.
> 2.) w.r.t. 1), look at your main() method, it
> reads a file and then?
> 2.) Please tell us exactly WHAT does not work
> and WHAT you expect.
> 3.) The OntModel object has a method write,
> not sure what you did there
> with calling getWriter and the like
>
> *When I run this program without writing
> it to the file, it runs
>
> smoothly.
>
> But when I copy it to a file (both newly
> created and existing file),
> sometime it adds the garbage claases to
> the file like Seq, Bag,
> Resource
> and most of the time it does nothing
> except it empties the destination
> file.*
>
> *I have copied the whole code except the
> code auto generated by
> netbeans*
>
>
>
>
>
> *public class NewJFrame extends
> javax.swing.JFrame {*
>
>
>
>
>
>
> * public static void
> readOntology(String file,OntModel model)*
>
> * {*
>
>
> * InputStream in
> =FileManager.get().open(file);*
>
>
>
> *if (in==null) {*
>
> *throw new IllegalArgumentException(
> "File: " + file + " not
> found");*
>
> *}*
>
> * model.read(in,null);*
>
> * //in.close();}}*
>
>
>
> private void read1(String str,
> OntModel model)
>
> {
>
>
>
>
>
>
>
> String ns="
> http://www.semanticweb.org/ontologies/untitled-ontology-54/";
>
>
> OntClass user =
> model.createClass(ns + "User");
>
>
>
>
>
> OntClass user1 =
> model.getOntClass(ns + "User");
>
> Individual janeSmith =
> user1.createIndividual(ns + str)
>
>
>
> try {
>
> String
> file="F://newontology.owl";
>
>
>
>
>
> FileOutputStream f1=new
> FileOutputStream(file);
>
> RDFWriter d =
> model.getWriter("RDF/XML-ABBREV");
>
> d.write(model,f1,null);
>
> }catch(Exception e) {}
>
>
> *private void
> jButton1ActionPerformed(java.awt.event.ActionEvent
> evt) {
> *
>
>
>
> *OntModel
> model=ModelFactory.createOntologyModel();*
>
>
> * String str=jTextField2.getText()*
>
>
>
> * read1(str, model); }}*
>
>
>
> * public static void main(String args[]) {*
>
>
>
>
>
>
>
> * OntModel model =
> ModelFactory.createOntologyModel();*
>
> * String
> file="F://updated.owl";*
>
> * readOntology(file , model );*
>
> *}*
>
> --
> Lorenz B�hmann
> AKSW group, University of Leipzig
> Group: http://aksw.org - semantic web research
> center
>
>
>
>
> --
> Lorenz B�hmann
> AKSW group, University of Leipzig
> Group: http://aksw.org - semantic web research center
>
>
>
>
--
Lorenz B�hmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
Re: Can not write to the file
Posted by kumar rohit <ku...@gmail.com>.
I dont know if attaching screen shot is allowed or not, but kindly if you
can check it.
After running the code , it has added the garbage classes to the file. User
class is also there as I have created it, but again it has disappeared my
classes in ontology.
*Note:* I have added new class in the same file I have read it and used the
same namespace of the ontology for new class (User class).
My ontology uri is : *String
ns="http://www.semanticweb.org/ontologies/2016/7/untitled-54/
<http://www.semanticweb.org/ontologies/2016/7/untitled-54/>";*
And I used this for *User* class also.
On Fri, Jul 22, 2016 at 2:47 AM, Dave Reynolds <da...@gmail.com>
wrote:
> On 22/07/16 10:44, kumar rohit wrote:
>
>> Yes because the model.write() works but the FileWriter does not. I also
>> tried something like this to append data but failed:
>>
>> FileOutputStream f1=new FileOutputStream(file, *true*);
>>
>> Any solution please you suggest to write it to the same file I have read
>> from?
>>
>
> You can't, at least not in RDF/XML format.
>
> As Lorenz says, you would have to read in the current file, add your new
> assertions, then write out the whole file again.
>
>
> Dave
>
> On Fri, Jul 22, 2016 at 2:22 AM, Lorenz B. <
>> buehmann@informatik.uni-leipzig.de> wrote:
>>
>> Hello Dave,
>>>
>>> I think the problem is that he writes to another file - and I guess this
>>> one already contains some data. Of course the write method cannot append
>>> data, but just overwrites the file. Am I right? Anything else would
>>> sound like some magic.
>>>
>>> Otherwise, to append data, one would have to load it into a separate
>>> model and add data directly to this model.
>>>
>>>
>>>
>>> Kind regards,
>>> Lorenz
>>>
>>> On 22/07/16 09:58, kumar rohit wrote:
>>>>
>>>>> The main() pass the required file and then just the GUI loads because
>>>>> we
>>>>> have to deal with a text field where user enter his name and we will
>>>>> create
>>>>> individual of that name.
>>>>>
>>>>> The main purpose of this code is to create individual (after user
>>>>> enter the
>>>>> name) and store it locally in a file *(either a separate file or to the
>>>>> file we have read **InputStream in =FileManager.get().open(file);*)
>>>>>
>>>>> It writes the required result to the console(model.write method) but
>>>>> when I
>>>>> try to write it in a file, it just remove all the data from the
>>>>> destination
>>>>> file and even the ontology URI.
>>>>>
>>>>> For writing to a file, I used these both methods but both does not
>>>>> work.
>>>>>
>>>>> (1) FileWriter out = new FileWriter( fileName );
>>>>>
>>>>> try {
>>>>> model.write( out, "RDF/XML-ABBREV" );}
>>>>>
>>>>> 2) FileOutputStream out=new FileOutputStream(filename);
>>>>> RDFWriter d = model.getWriter("RDF/XML-ABBREV");
>>>>> d.write(model,out,null);
>>>>> }catch(Exception e) {}
>>>>>
>>>>
>>>>
>>>> Make sure you close the stream, that's probably the source of your
>>>> random loss of output.
>>>>
>>>> The reason you see Seq and other such junk is because you are writing
>>>> the whole model, with inference, and a default OntModel includes RDFS
>>>> inference. Use model.write which for an OntModel defaults to writing
>>>> just the base model. Also, unless you need inference use an explicit
>>>> OntModelSpec which doesn't have any (e.g. OWL_MEM).
>>>>
>>>> Dave
>>>>
>>>> On Fri, Jul 22, 2016 at 12:30 AM, Lorenz B. <
>>>>> buehmann@informatik.uni-leipzig.de> wrote:
>>>>>
>>>>> 1.) This is not a minimal running example! that means, nobody can test
>>>>>> it without some (in your case too much) effort to get it running.
>>>>>> 2.) w.r.t. 1), look at your main() method, it reads a file and then?
>>>>>> 2.) Please tell us exactly WHAT does not work and WHAT you expect.
>>>>>> 3.) The OntModel object has a method write, not sure what you did
>>>>>> there
>>>>>> with calling getWriter and the like
>>>>>>
>>>>>> *When I run this program without writing it to the file, it runs
>>>>>>>
>>>>>> smoothly.
>>>>>>
>>>>>>> But when I copy it to a file (both newly created and existing file),
>>>>>>> sometime it adds the garbage claases to the file like Seq, Bag,
>>>>>>> Resource
>>>>>>> and most of the time it does nothing except it empties the
>>>>>>> destination
>>>>>>> file.*
>>>>>>>
>>>>>>> *I have copied the whole code except the code auto generated by
>>>>>>> netbeans*
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> *public class NewJFrame extends javax.swing.JFrame {*
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> * public static void readOntology(String file,OntModel model)*
>>>>>>>
>>>>>>> * {*
>>>>>>>
>>>>>>>
>>>>>>> * InputStream in =FileManager.get().open(file);*
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> *if (in==null) {*
>>>>>>>
>>>>>>> *throw new IllegalArgumentException( "File: " + file + " not
>>>>>>> found");*
>>>>>>>
>>>>>>> *}*
>>>>>>>
>>>>>>> * model.read(in,null);*
>>>>>>>
>>>>>>> * //in.close();}}*
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> private void read1(String str, OntModel model)
>>>>>>>
>>>>>>> {
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> String ns="
>>>>>>> http://www.semanticweb.org/ontologies/untitled-ontology-54/";
>>>>>>>
>>>>>>>
>>>>>>> OntClass user = model.createClass(ns + "User");
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> OntClass user1 = model.getOntClass(ns + "User");
>>>>>>>
>>>>>>> Individual janeSmith = user1.createIndividual(ns + str)
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> try {
>>>>>>>
>>>>>>> String file="F://newontology.owl";
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> FileOutputStream f1=new FileOutputStream(file);
>>>>>>>
>>>>>>> RDFWriter d = model.getWriter("RDF/XML-ABBREV");
>>>>>>>
>>>>>>> d.write(model,f1,null);
>>>>>>>
>>>>>>> }catch(Exception e) {}
>>>>>>>
>>>>>>>
>>>>>>> *private void jButton1ActionPerformed(java.awt.event.ActionEvent
>>>>>>> evt) {
>>>>>>> *
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> *OntModel model=ModelFactory.createOntologyModel();*
>>>>>>>
>>>>>>>
>>>>>>> * String str=jTextField2.getText()*
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> * read1(str, model); }}*
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> * public static void main(String args[]) {*
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> * OntModel model = ModelFactory.createOntologyModel();*
>>>>>>>
>>>>>>> * String file="F://updated.owl";*
>>>>>>>
>>>>>>> * readOntology(file , model );*
>>>>>>>
>>>>>>> *}*
>>>>>>>
>>>>>>> --
>>>>>> Lorenz Bühmann
>>>>>> AKSW group, University of Leipzig
>>>>>> Group: http://aksw.org - semantic web research center
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>> --
>>> Lorenz Bühmann
>>> AKSW group, University of Leipzig
>>> Group: http://aksw.org - semantic web research center
>>>
>>>
>>>
>>
Re: Can not write to the file
Posted by Dave Reynolds <da...@gmail.com>.
On 22/07/16 10:44, kumar rohit wrote:
> Yes because the model.write() works but the FileWriter does not. I also
> tried something like this to append data but failed:
>
> FileOutputStream f1=new FileOutputStream(file, *true*);
>
> Any solution please you suggest to write it to the same file I have read
> from?
You can't, at least not in RDF/XML format.
As Lorenz says, you would have to read in the current file, add your new
assertions, then write out the whole file again.
Dave
> On Fri, Jul 22, 2016 at 2:22 AM, Lorenz B. <
> buehmann@informatik.uni-leipzig.de> wrote:
>
>> Hello Dave,
>>
>> I think the problem is that he writes to another file - and I guess this
>> one already contains some data. Of course the write method cannot append
>> data, but just overwrites the file. Am I right? Anything else would
>> sound like some magic.
>>
>> Otherwise, to append data, one would have to load it into a separate
>> model and add data directly to this model.
>>
>>
>>
>> Kind regards,
>> Lorenz
>>
>>> On 22/07/16 09:58, kumar rohit wrote:
>>>> The main() pass the required file and then just the GUI loads because we
>>>> have to deal with a text field where user enter his name and we will
>>>> create
>>>> individual of that name.
>>>>
>>>> The main purpose of this code is to create individual (after user
>>>> enter the
>>>> name) and store it locally in a file *(either a separate file or to the
>>>> file we have read **InputStream in =FileManager.get().open(file);*)
>>>>
>>>> It writes the required result to the console(model.write method) but
>>>> when I
>>>> try to write it in a file, it just remove all the data from the
>>>> destination
>>>> file and even the ontology URI.
>>>>
>>>> For writing to a file, I used these both methods but both does not work.
>>>>
>>>> (1) FileWriter out = new FileWriter( fileName );
>>>>
>>>> try {
>>>> model.write( out, "RDF/XML-ABBREV" );}
>>>>
>>>> 2) FileOutputStream out=new FileOutputStream(filename);
>>>> RDFWriter d = model.getWriter("RDF/XML-ABBREV");
>>>> d.write(model,out,null);
>>>> }catch(Exception e) {}
>>>
>>>
>>> Make sure you close the stream, that's probably the source of your
>>> random loss of output.
>>>
>>> The reason you see Seq and other such junk is because you are writing
>>> the whole model, with inference, and a default OntModel includes RDFS
>>> inference. Use model.write which for an OntModel defaults to writing
>>> just the base model. Also, unless you need inference use an explicit
>>> OntModelSpec which doesn't have any (e.g. OWL_MEM).
>>>
>>> Dave
>>>
>>>> On Fri, Jul 22, 2016 at 12:30 AM, Lorenz B. <
>>>> buehmann@informatik.uni-leipzig.de> wrote:
>>>>
>>>>> 1.) This is not a minimal running example! that means, nobody can test
>>>>> it without some (in your case too much) effort to get it running.
>>>>> 2.) w.r.t. 1), look at your main() method, it reads a file and then?
>>>>> 2.) Please tell us exactly WHAT does not work and WHAT you expect.
>>>>> 3.) The OntModel object has a method write, not sure what you did there
>>>>> with calling getWriter and the like
>>>>>
>>>>>> *When I run this program without writing it to the file, it runs
>>>>> smoothly.
>>>>>> But when I copy it to a file (both newly created and existing file),
>>>>>> sometime it adds the garbage claases to the file like Seq, Bag,
>>>>>> Resource
>>>>>> and most of the time it does nothing except it empties the destination
>>>>>> file.*
>>>>>>
>>>>>> *I have copied the whole code except the code auto generated by
>>>>>> netbeans*
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> *public class NewJFrame extends javax.swing.JFrame {*
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> * public static void readOntology(String file,OntModel model)*
>>>>>>
>>>>>> * {*
>>>>>>
>>>>>>
>>>>>> * InputStream in =FileManager.get().open(file);*
>>>>>>
>>>>>>
>>>>>>
>>>>>> *if (in==null) {*
>>>>>>
>>>>>> *throw new IllegalArgumentException( "File: " + file + " not
>>>>>> found");*
>>>>>>
>>>>>> *}*
>>>>>>
>>>>>> * model.read(in,null);*
>>>>>>
>>>>>> * //in.close();}}*
>>>>>>
>>>>>>
>>>>>>
>>>>>> private void read1(String str, OntModel model)
>>>>>>
>>>>>> {
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> String ns="
>>>>>> http://www.semanticweb.org/ontologies/untitled-ontology-54/";
>>>>>>
>>>>>>
>>>>>> OntClass user = model.createClass(ns + "User");
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> OntClass user1 = model.getOntClass(ns + "User");
>>>>>>
>>>>>> Individual janeSmith = user1.createIndividual(ns + str)
>>>>>>
>>>>>>
>>>>>>
>>>>>> try {
>>>>>>
>>>>>> String file="F://newontology.owl";
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> FileOutputStream f1=new FileOutputStream(file);
>>>>>>
>>>>>> RDFWriter d = model.getWriter("RDF/XML-ABBREV");
>>>>>>
>>>>>> d.write(model,f1,null);
>>>>>>
>>>>>> }catch(Exception e) {}
>>>>>>
>>>>>>
>>>>>> *private void jButton1ActionPerformed(java.awt.event.ActionEvent
>>>>>> evt) {
>>>>>> *
>>>>>>
>>>>>>
>>>>>>
>>>>>> *OntModel model=ModelFactory.createOntologyModel();*
>>>>>>
>>>>>>
>>>>>> * String str=jTextField2.getText()*
>>>>>>
>>>>>>
>>>>>>
>>>>>> * read1(str, model); }}*
>>>>>>
>>>>>>
>>>>>>
>>>>>> * public static void main(String args[]) {*
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> * OntModel model = ModelFactory.createOntologyModel();*
>>>>>>
>>>>>> * String file="F://updated.owl";*
>>>>>>
>>>>>> * readOntology(file , model );*
>>>>>>
>>>>>> *}*
>>>>>>
>>>>> --
>>>>> Lorenz B�hmann
>>>>> AKSW group, University of Leipzig
>>>>> Group: http://aksw.org - semantic web research center
>>>>>
>>>>>
>>>>
>>>
>> --
>> Lorenz B�hmann
>> AKSW group, University of Leipzig
>> Group: http://aksw.org - semantic web research center
>>
>>
>
Re: Can not write to the file
Posted by kumar rohit <ku...@gmail.com>.
Yes because the model.write() works but the FileWriter does not. I also
tried something like this to append data but failed:
FileOutputStream f1=new FileOutputStream(file, *true*);
Any solution please you suggest to write it to the same file I have read
from?
On Fri, Jul 22, 2016 at 2:22 AM, Lorenz B. <
buehmann@informatik.uni-leipzig.de> wrote:
> Hello Dave,
>
> I think the problem is that he writes to another file - and I guess this
> one already contains some data. Of course the write method cannot append
> data, but just overwrites the file. Am I right? Anything else would
> sound like some magic.
>
> Otherwise, to append data, one would have to load it into a separate
> model and add data directly to this model.
>
>
>
> Kind regards,
> Lorenz
>
> > On 22/07/16 09:58, kumar rohit wrote:
> >> The main() pass the required file and then just the GUI loads because we
> >> have to deal with a text field where user enter his name and we will
> >> create
> >> individual of that name.
> >>
> >> The main purpose of this code is to create individual (after user
> >> enter the
> >> name) and store it locally in a file *(either a separate file or to the
> >> file we have read **InputStream in =FileManager.get().open(file);*)
> >>
> >> It writes the required result to the console(model.write method) but
> >> when I
> >> try to write it in a file, it just remove all the data from the
> >> destination
> >> file and even the ontology URI.
> >>
> >> For writing to a file, I used these both methods but both does not work.
> >>
> >> (1) FileWriter out = new FileWriter( fileName );
> >>
> >> try {
> >> model.write( out, "RDF/XML-ABBREV" );}
> >>
> >> 2) FileOutputStream out=new FileOutputStream(filename);
> >> RDFWriter d = model.getWriter("RDF/XML-ABBREV");
> >> d.write(model,out,null);
> >> }catch(Exception e) {}
> >
> >
> > Make sure you close the stream, that's probably the source of your
> > random loss of output.
> >
> > The reason you see Seq and other such junk is because you are writing
> > the whole model, with inference, and a default OntModel includes RDFS
> > inference. Use model.write which for an OntModel defaults to writing
> > just the base model. Also, unless you need inference use an explicit
> > OntModelSpec which doesn't have any (e.g. OWL_MEM).
> >
> > Dave
> >
> >> On Fri, Jul 22, 2016 at 12:30 AM, Lorenz B. <
> >> buehmann@informatik.uni-leipzig.de> wrote:
> >>
> >>> 1.) This is not a minimal running example! that means, nobody can test
> >>> it without some (in your case too much) effort to get it running.
> >>> 2.) w.r.t. 1), look at your main() method, it reads a file and then?
> >>> 2.) Please tell us exactly WHAT does not work and WHAT you expect.
> >>> 3.) The OntModel object has a method write, not sure what you did there
> >>> with calling getWriter and the like
> >>>
> >>>> *When I run this program without writing it to the file, it runs
> >>> smoothly.
> >>>> But when I copy it to a file (both newly created and existing file),
> >>>> sometime it adds the garbage claases to the file like Seq, Bag,
> >>>> Resource
> >>>> and most of the time it does nothing except it empties the destination
> >>>> file.*
> >>>>
> >>>> *I have copied the whole code except the code auto generated by
> >>>> netbeans*
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> *public class NewJFrame extends javax.swing.JFrame {*
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> * public static void readOntology(String file,OntModel model)*
> >>>>
> >>>> * {*
> >>>>
> >>>>
> >>>> * InputStream in =FileManager.get().open(file);*
> >>>>
> >>>>
> >>>>
> >>>> *if (in==null) {*
> >>>>
> >>>> *throw new IllegalArgumentException( "File: " + file + " not
> >>>> found");*
> >>>>
> >>>> *}*
> >>>>
> >>>> * model.read(in,null);*
> >>>>
> >>>> * //in.close();}}*
> >>>>
> >>>>
> >>>>
> >>>> private void read1(String str, OntModel model)
> >>>>
> >>>> {
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> String ns="
> >>>> http://www.semanticweb.org/ontologies/untitled-ontology-54/";
> >>>>
> >>>>
> >>>> OntClass user = model.createClass(ns + "User");
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> OntClass user1 = model.getOntClass(ns + "User");
> >>>>
> >>>> Individual janeSmith = user1.createIndividual(ns + str)
> >>>>
> >>>>
> >>>>
> >>>> try {
> >>>>
> >>>> String file="F://newontology.owl";
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> FileOutputStream f1=new FileOutputStream(file);
> >>>>
> >>>> RDFWriter d = model.getWriter("RDF/XML-ABBREV");
> >>>>
> >>>> d.write(model,f1,null);
> >>>>
> >>>> }catch(Exception e) {}
> >>>>
> >>>>
> >>>> *private void jButton1ActionPerformed(java.awt.event.ActionEvent
> >>>> evt) {
> >>>> *
> >>>>
> >>>>
> >>>>
> >>>> *OntModel model=ModelFactory.createOntologyModel();*
> >>>>
> >>>>
> >>>> * String str=jTextField2.getText()*
> >>>>
> >>>>
> >>>>
> >>>> * read1(str, model); }}*
> >>>>
> >>>>
> >>>>
> >>>> * public static void main(String args[]) {*
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>> * OntModel model = ModelFactory.createOntologyModel();*
> >>>>
> >>>> * String file="F://updated.owl";*
> >>>>
> >>>> * readOntology(file , model );*
> >>>>
> >>>> *}*
> >>>>
> >>> --
> >>> Lorenz Bühmann
> >>> AKSW group, University of Leipzig
> >>> Group: http://aksw.org - semantic web research center
> >>>
> >>>
> >>
> >
> --
> Lorenz Bühmann
> AKSW group, University of Leipzig
> Group: http://aksw.org - semantic web research center
>
>
Re: Can not write to the file
Posted by Dave Reynolds <da...@gmail.com>.
On 22/07/16 10:22, Lorenz B. wrote:
> Hello Dave,
>
> I think the problem is that he writes to another file - and I guess this
> one already contains some data. Of course the write method cannot append
> data, but just overwrites the file. Am I right? Anything else would
> sound like some magic.
Sure. While you can open a file in append mode that's not what's
happening here (and is only useful for formats like N-Triples that are
appendable). So any previous file content will be lost.
I was just trying to answer why he sometimes sees an empty results and
sometimes sees contents - failing to close a stream could explain that.
Dave
>
> Otherwise, to append data, one would have to load it into a separate
> model and add data directly to this model.
>
>
>
> Kind regards,
> Lorenz
>
>> On 22/07/16 09:58, kumar rohit wrote:
>>> The main() pass the required file and then just the GUI loads because we
>>> have to deal with a text field where user enter his name and we will
>>> create
>>> individual of that name.
>>>
>>> The main purpose of this code is to create individual (after user
>>> enter the
>>> name) and store it locally in a file *(either a separate file or to the
>>> file we have read **InputStream in =FileManager.get().open(file);*)
>>>
>>> It writes the required result to the console(model.write method) but
>>> when I
>>> try to write it in a file, it just remove all the data from the
>>> destination
>>> file and even the ontology URI.
>>>
>>> For writing to a file, I used these both methods but both does not work.
>>>
>>> (1) FileWriter out = new FileWriter( fileName );
>>>
>>> try {
>>> model.write( out, "RDF/XML-ABBREV" );}
>>>
>>> 2) FileOutputStream out=new FileOutputStream(filename);
>>> RDFWriter d = model.getWriter("RDF/XML-ABBREV");
>>> d.write(model,out,null);
>>> }catch(Exception e) {}
>>
>>
>> Make sure you close the stream, that's probably the source of your
>> random loss of output.
>>
>> The reason you see Seq and other such junk is because you are writing
>> the whole model, with inference, and a default OntModel includes RDFS
>> inference. Use model.write which for an OntModel defaults to writing
>> just the base model. Also, unless you need inference use an explicit
>> OntModelSpec which doesn't have any (e.g. OWL_MEM).
>>
>> Dave
>>
>>> On Fri, Jul 22, 2016 at 12:30 AM, Lorenz B. <
>>> buehmann@informatik.uni-leipzig.de> wrote:
>>>
>>>> 1.) This is not a minimal running example! that means, nobody can test
>>>> it without some (in your case too much) effort to get it running.
>>>> 2.) w.r.t. 1), look at your main() method, it reads a file and then?
>>>> 2.) Please tell us exactly WHAT does not work and WHAT you expect.
>>>> 3.) The OntModel object has a method write, not sure what you did there
>>>> with calling getWriter and the like
>>>>
>>>>> *When I run this program without writing it to the file, it runs
>>>> smoothly.
>>>>> But when I copy it to a file (both newly created and existing file),
>>>>> sometime it adds the garbage claases to the file like Seq, Bag,
>>>>> Resource
>>>>> and most of the time it does nothing except it empties the destination
>>>>> file.*
>>>>>
>>>>> *I have copied the whole code except the code auto generated by
>>>>> netbeans*
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> *public class NewJFrame extends javax.swing.JFrame {*
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> * public static void readOntology(String file,OntModel model)*
>>>>>
>>>>> * {*
>>>>>
>>>>>
>>>>> * InputStream in =FileManager.get().open(file);*
>>>>>
>>>>>
>>>>>
>>>>> *if (in==null) {*
>>>>>
>>>>> *throw new IllegalArgumentException( "File: " + file + " not
>>>>> found");*
>>>>>
>>>>> *}*
>>>>>
>>>>> * model.read(in,null);*
>>>>>
>>>>> * //in.close();}}*
>>>>>
>>>>>
>>>>>
>>>>> private void read1(String str, OntModel model)
>>>>>
>>>>> {
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> String ns="
>>>>> http://www.semanticweb.org/ontologies/untitled-ontology-54/";
>>>>>
>>>>>
>>>>> OntClass user = model.createClass(ns + "User");
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> OntClass user1 = model.getOntClass(ns + "User");
>>>>>
>>>>> Individual janeSmith = user1.createIndividual(ns + str)
>>>>>
>>>>>
>>>>>
>>>>> try {
>>>>>
>>>>> String file="F://newontology.owl";
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> FileOutputStream f1=new FileOutputStream(file);
>>>>>
>>>>> RDFWriter d = model.getWriter("RDF/XML-ABBREV");
>>>>>
>>>>> d.write(model,f1,null);
>>>>>
>>>>> }catch(Exception e) {}
>>>>>
>>>>>
>>>>> *private void jButton1ActionPerformed(java.awt.event.ActionEvent
>>>>> evt) {
>>>>> *
>>>>>
>>>>>
>>>>>
>>>>> *OntModel model=ModelFactory.createOntologyModel();*
>>>>>
>>>>>
>>>>> * String str=jTextField2.getText()*
>>>>>
>>>>>
>>>>>
>>>>> * read1(str, model); }}*
>>>>>
>>>>>
>>>>>
>>>>> * public static void main(String args[]) {*
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> * OntModel model = ModelFactory.createOntologyModel();*
>>>>>
>>>>> * String file="F://updated.owl";*
>>>>>
>>>>> * readOntology(file , model );*
>>>>>
>>>>> *}*
>>>>>
>>>> --
>>>> Lorenz B�hmann
>>>> AKSW group, University of Leipzig
>>>> Group: http://aksw.org - semantic web research center
>>>>
>>>>
>>>
>>
Re: Can not write to the file
Posted by "Lorenz B." <bu...@informatik.uni-leipzig.de>.
Hello Dave,
I think the problem is that he writes to another file - and I guess this
one already contains some data. Of course the write method cannot append
data, but just overwrites the file. Am I right? Anything else would
sound like some magic.
Otherwise, to append data, one would have to load it into a separate
model and add data directly to this model.
Kind regards,
Lorenz
> On 22/07/16 09:58, kumar rohit wrote:
>> The main() pass the required file and then just the GUI loads because we
>> have to deal with a text field where user enter his name and we will
>> create
>> individual of that name.
>>
>> The main purpose of this code is to create individual (after user
>> enter the
>> name) and store it locally in a file *(either a separate file or to the
>> file we have read **InputStream in =FileManager.get().open(file);*)
>>
>> It writes the required result to the console(model.write method) but
>> when I
>> try to write it in a file, it just remove all the data from the
>> destination
>> file and even the ontology URI.
>>
>> For writing to a file, I used these both methods but both does not work.
>>
>> (1) FileWriter out = new FileWriter( fileName );
>>
>> try {
>> model.write( out, "RDF/XML-ABBREV" );}
>>
>> 2) FileOutputStream out=new FileOutputStream(filename);
>> RDFWriter d = model.getWriter("RDF/XML-ABBREV");
>> d.write(model,out,null);
>> }catch(Exception e) {}
>
>
> Make sure you close the stream, that's probably the source of your
> random loss of output.
>
> The reason you see Seq and other such junk is because you are writing
> the whole model, with inference, and a default OntModel includes RDFS
> inference. Use model.write which for an OntModel defaults to writing
> just the base model. Also, unless you need inference use an explicit
> OntModelSpec which doesn't have any (e.g. OWL_MEM).
>
> Dave
>
>> On Fri, Jul 22, 2016 at 12:30 AM, Lorenz B. <
>> buehmann@informatik.uni-leipzig.de> wrote:
>>
>>> 1.) This is not a minimal running example! that means, nobody can test
>>> it without some (in your case too much) effort to get it running.
>>> 2.) w.r.t. 1), look at your main() method, it reads a file and then?
>>> 2.) Please tell us exactly WHAT does not work and WHAT you expect.
>>> 3.) The OntModel object has a method write, not sure what you did there
>>> with calling getWriter and the like
>>>
>>>> *When I run this program without writing it to the file, it runs
>>> smoothly.
>>>> But when I copy it to a file (both newly created and existing file),
>>>> sometime it adds the garbage claases to the file like Seq, Bag,
>>>> Resource
>>>> and most of the time it does nothing except it empties the destination
>>>> file.*
>>>>
>>>> *I have copied the whole code except the code auto generated by
>>>> netbeans*
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> *public class NewJFrame extends javax.swing.JFrame {*
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> * public static void readOntology(String file,OntModel model)*
>>>>
>>>> * {*
>>>>
>>>>
>>>> * InputStream in =FileManager.get().open(file);*
>>>>
>>>>
>>>>
>>>> *if (in==null) {*
>>>>
>>>> *throw new IllegalArgumentException( "File: " + file + " not
>>>> found");*
>>>>
>>>> *}*
>>>>
>>>> * model.read(in,null);*
>>>>
>>>> * //in.close();}}*
>>>>
>>>>
>>>>
>>>> private void read1(String str, OntModel model)
>>>>
>>>> {
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> String ns="
>>>> http://www.semanticweb.org/ontologies/untitled-ontology-54/";
>>>>
>>>>
>>>> OntClass user = model.createClass(ns + "User");
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> OntClass user1 = model.getOntClass(ns + "User");
>>>>
>>>> Individual janeSmith = user1.createIndividual(ns + str)
>>>>
>>>>
>>>>
>>>> try {
>>>>
>>>> String file="F://newontology.owl";
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> FileOutputStream f1=new FileOutputStream(file);
>>>>
>>>> RDFWriter d = model.getWriter("RDF/XML-ABBREV");
>>>>
>>>> d.write(model,f1,null);
>>>>
>>>> }catch(Exception e) {}
>>>>
>>>>
>>>> *private void jButton1ActionPerformed(java.awt.event.ActionEvent
>>>> evt) {
>>>> *
>>>>
>>>>
>>>>
>>>> *OntModel model=ModelFactory.createOntologyModel();*
>>>>
>>>>
>>>> * String str=jTextField2.getText()*
>>>>
>>>>
>>>>
>>>> * read1(str, model); }}*
>>>>
>>>>
>>>>
>>>> * public static void main(String args[]) {*
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> * OntModel model = ModelFactory.createOntologyModel();*
>>>>
>>>> * String file="F://updated.owl";*
>>>>
>>>> * readOntology(file , model );*
>>>>
>>>> *}*
>>>>
>>> --
>>> Lorenz B�hmann
>>> AKSW group, University of Leipzig
>>> Group: http://aksw.org - semantic web research center
>>>
>>>
>>
>
--
Lorenz B�hmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
Re: Can not write to the file
Posted by Dave Reynolds <da...@gmail.com>.
On 22/07/16 09:58, kumar rohit wrote:
> The main() pass the required file and then just the GUI loads because we
> have to deal with a text field where user enter his name and we will create
> individual of that name.
>
> The main purpose of this code is to create individual (after user enter the
> name) and store it locally in a file *(either a separate file or to the
> file we have read **InputStream in =FileManager.get().open(file);*)
>
> It writes the required result to the console(model.write method) but when I
> try to write it in a file, it just remove all the data from the destination
> file and even the ontology URI.
>
> For writing to a file, I used these both methods but both does not work.
>
> (1) FileWriter out = new FileWriter( fileName );
>
> try {
> model.write( out, "RDF/XML-ABBREV" );}
>
> 2) FileOutputStream out=new FileOutputStream(filename);
> RDFWriter d = model.getWriter("RDF/XML-ABBREV");
> d.write(model,out,null);
> }catch(Exception e) {}
Make sure you close the stream, that's probably the source of your
random loss of output.
The reason you see Seq and other such junk is because you are writing
the whole model, with inference, and a default OntModel includes RDFS
inference. Use model.write which for an OntModel defaults to writing
just the base model. Also, unless you need inference use an explicit
OntModelSpec which doesn't have any (e.g. OWL_MEM).
Dave
> On Fri, Jul 22, 2016 at 12:30 AM, Lorenz B. <
> buehmann@informatik.uni-leipzig.de> wrote:
>
>> 1.) This is not a minimal running example! that means, nobody can test
>> it without some (in your case too much) effort to get it running.
>> 2.) w.r.t. 1), look at your main() method, it reads a file and then?
>> 2.) Please tell us exactly WHAT does not work and WHAT you expect.
>> 3.) The OntModel object has a method write, not sure what you did there
>> with calling getWriter and the like
>>
>>> *When I run this program without writing it to the file, it runs
>> smoothly.
>>> But when I copy it to a file (both newly created and existing file),
>>> sometime it adds the garbage claases to the file like Seq, Bag, Resource
>>> and most of the time it does nothing except it empties the destination
>>> file.*
>>>
>>> *I have copied the whole code except the code auto generated by netbeans*
>>>
>>>
>>>
>>>
>>>
>>> *public class NewJFrame extends javax.swing.JFrame {*
>>>
>>>
>>>
>>>
>>>
>>>
>>> * public static void readOntology(String file,OntModel model)*
>>>
>>> * {*
>>>
>>>
>>> * InputStream in =FileManager.get().open(file);*
>>>
>>>
>>>
>>> *if (in==null) {*
>>>
>>> *throw new IllegalArgumentException( "File: " + file + " not found");*
>>>
>>> *}*
>>>
>>> * model.read(in,null);*
>>>
>>> * //in.close();}}*
>>>
>>>
>>>
>>> private void read1(String str, OntModel model)
>>>
>>> {
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> String ns="
>>> http://www.semanticweb.org/ontologies/untitled-ontology-54/";
>>>
>>>
>>> OntClass user = model.createClass(ns + "User");
>>>
>>>
>>>
>>>
>>>
>>> OntClass user1 = model.getOntClass(ns + "User");
>>>
>>> Individual janeSmith = user1.createIndividual(ns + str)
>>>
>>>
>>>
>>> try {
>>>
>>> String file="F://newontology.owl";
>>>
>>>
>>>
>>>
>>>
>>> FileOutputStream f1=new FileOutputStream(file);
>>>
>>> RDFWriter d = model.getWriter("RDF/XML-ABBREV");
>>>
>>> d.write(model,f1,null);
>>>
>>> }catch(Exception e) {}
>>>
>>>
>>> *private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
>>> *
>>>
>>>
>>>
>>> *OntModel model=ModelFactory.createOntologyModel();*
>>>
>>>
>>> * String str=jTextField2.getText()*
>>>
>>>
>>>
>>> * read1(str, model); }}*
>>>
>>>
>>>
>>> * public static void main(String args[]) {*
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> * OntModel model = ModelFactory.createOntologyModel();*
>>>
>>> * String file="F://updated.owl";*
>>>
>>> * readOntology(file , model );*
>>>
>>> *}*
>>>
>> --
>> Lorenz B�hmann
>> AKSW group, University of Leipzig
>> Group: http://aksw.org - semantic web research center
>>
>>
>
Re: Can not write to the file
Posted by kumar rohit <ku...@gmail.com>.
The main() pass the required file and then just the GUI loads because we
have to deal with a text field where user enter his name and we will create
individual of that name.
The main purpose of this code is to create individual (after user enter the
name) and store it locally in a file *(either a separate file or to the
file we have read **InputStream in =FileManager.get().open(file);*)
It writes the required result to the console(model.write method) but when I
try to write it in a file, it just remove all the data from the destination
file and even the ontology URI.
For writing to a file, I used these both methods but both does not work.
(1) FileWriter out = new FileWriter( fileName );
try {
model.write( out, "RDF/XML-ABBREV" );}
2) FileOutputStream out=new FileOutputStream(filename);
RDFWriter d = model.getWriter("RDF/XML-ABBREV");
d.write(model,out,null);
}catch(Exception e) {}
On Fri, Jul 22, 2016 at 12:30 AM, Lorenz B. <
buehmann@informatik.uni-leipzig.de> wrote:
> 1.) This is not a minimal running example! that means, nobody can test
> it without some (in your case too much) effort to get it running.
> 2.) w.r.t. 1), look at your main() method, it reads a file and then?
> 2.) Please tell us exactly WHAT does not work and WHAT you expect.
> 3.) The OntModel object has a method write, not sure what you did there
> with calling getWriter and the like
>
> > *When I run this program without writing it to the file, it runs
> smoothly.
> > But when I copy it to a file (both newly created and existing file),
> > sometime it adds the garbage claases to the file like Seq, Bag, Resource
> > and most of the time it does nothing except it empties the destination
> > file.*
> >
> > *I have copied the whole code except the code auto generated by netbeans*
> >
> >
> >
> >
> >
> > *public class NewJFrame extends javax.swing.JFrame {*
> >
> >
> >
> >
> >
> >
> > * public static void readOntology(String file,OntModel model)*
> >
> > * {*
> >
> >
> > * InputStream in =FileManager.get().open(file);*
> >
> >
> >
> > *if (in==null) {*
> >
> > *throw new IllegalArgumentException( "File: " + file + " not found");*
> >
> > *}*
> >
> > * model.read(in,null);*
> >
> > * //in.close();}}*
> >
> >
> >
> > private void read1(String str, OntModel model)
> >
> > {
> >
> >
> >
> >
> >
> >
> >
> > String ns="
> > http://www.semanticweb.org/ontologies/untitled-ontology-54/";
> >
> >
> > OntClass user = model.createClass(ns + "User");
> >
> >
> >
> >
> >
> > OntClass user1 = model.getOntClass(ns + "User");
> >
> > Individual janeSmith = user1.createIndividual(ns + str)
> >
> >
> >
> > try {
> >
> > String file="F://newontology.owl";
> >
> >
> >
> >
> >
> > FileOutputStream f1=new FileOutputStream(file);
> >
> > RDFWriter d = model.getWriter("RDF/XML-ABBREV");
> >
> > d.write(model,f1,null);
> >
> > }catch(Exception e) {}
> >
> >
> > *private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
> > *
> >
> >
> >
> > *OntModel model=ModelFactory.createOntologyModel();*
> >
> >
> > * String str=jTextField2.getText()*
> >
> >
> >
> > * read1(str, model); }}*
> >
> >
> >
> > * public static void main(String args[]) {*
> >
> >
> >
> >
> >
> >
> >
> > * OntModel model = ModelFactory.createOntologyModel();*
> >
> > * String file="F://updated.owl";*
> >
> > * readOntology(file , model );*
> >
> > *}*
> >
> --
> Lorenz Bühmann
> AKSW group, University of Leipzig
> Group: http://aksw.org - semantic web research center
>
>
Re: Can not write to the file
Posted by "Lorenz B." <bu...@informatik.uni-leipzig.de>.
1.) This is not a minimal running example! that means, nobody can test
it without some (in your case too much) effort to get it running.
2.) w.r.t. 1), look at your main() method, it reads a file and then?
2.) Please tell us exactly WHAT does not work and WHAT you expect.
3.) The OntModel object has a method write, not sure what you did there
with calling getWriter and the like
> *When I run this program without writing it to the file, it runs smoothly.
> But when I copy it to a file (both newly created and existing file),
> sometime it adds the garbage claases to the file like Seq, Bag, Resource
> and most of the time it does nothing except it empties the destination
> file.*
>
> *I have copied the whole code except the code auto generated by netbeans*
>
>
>
>
>
> *public class NewJFrame extends javax.swing.JFrame {*
>
>
>
>
>
>
> * public static void readOntology(String file,OntModel model)*
>
> * {*
>
>
> * InputStream in =FileManager.get().open(file);*
>
>
>
> *if (in==null) {*
>
> *throw new IllegalArgumentException( "File: " + file + " not found");*
>
> *}*
>
> * model.read(in,null);*
>
> * //in.close();}}*
>
>
>
> private void read1(String str, OntModel model)
>
> {
>
>
>
>
>
>
>
> String ns="
> http://www.semanticweb.org/ontologies/untitled-ontology-54/";
>
>
> OntClass user = model.createClass(ns + "User");
>
>
>
>
>
> OntClass user1 = model.getOntClass(ns + "User");
>
> Individual janeSmith = user1.createIndividual(ns + str)
>
>
>
> try {
>
> String file="F://newontology.owl";
>
>
>
>
>
> FileOutputStream f1=new FileOutputStream(file);
>
> RDFWriter d = model.getWriter("RDF/XML-ABBREV");
>
> d.write(model,f1,null);
>
> }catch(Exception e) {}
>
>
> *private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
> *
>
>
>
> *OntModel model=ModelFactory.createOntologyModel();*
>
>
> * String str=jTextField2.getText()*
>
>
>
> * read1(str, model); }}*
>
>
>
> * public static void main(String args[]) {*
>
>
>
>
>
>
>
> * OntModel model = ModelFactory.createOntologyModel();*
>
> * String file="F://updated.owl";*
>
> * readOntology(file , model );*
>
> *}*
>
--
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center