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. <
[email protected]> 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
>
>

Reply via email to