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/15 18:21:38 UTC
Jena Code has emptied my ontology
Hi
I am very surprised that this code, when executed, has vanished my ontology
and my ontology is now empty. I copied another ontology and after executing
few times, again the new ontology is empty. I just want to create the
individual of class and save it locally in the file. There is another
method also in my code but thats just read the file so the main trick is
here. It writed the whole ontology first as model.write() but when GUI
loads and I enter text, again it display output as in
JOptionPane.showMessageDialog() but after the whole exection, the Protege
ontology becomes empty.
*Note: It also create the intended individual but except the User1 class
created in Jena code and its individual, nothing remains in ontology.*
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,"RDF/XML-ABBREV");
//in.close();
model.write(System.out);
}
private static void read1(String str,OntModel model)
{
String ns="http://www.semanticweb.org/untitled-ontology-0012/";
OntClass user = model.createClass(ns + "User");
OntClass user1 = model.getOntClass(ns + "User");
Individual janeSmith = user1.createIndividual(ns + str);
JOptionPane.showMessageDialog(null, janeSmith.toString());
try {
String file="F://hello.owl";
FileWriter out=new FileWriter(file);
Re: Jena Code has emptied my ontology
Posted by "A. Soroka" <aj...@virginia.edu>.
If this is a class assignment, it might be worthwhile for your teacher or some other responsible person to contact this list on behalf of the class with any specifically Jena-related questions. As several people have pointed out by now, you are not asking questions about Jena, but about basic Java programming, and this really isn't the appropriate venue for such communication.
---
A. Soroka
The University of Virginia Library
> On Jul 16, 2016, at 11:00 AM, kumar rohit <ku...@gmail.com> wrote:
>
> Here is the full code,
>
> 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,"RDF/XML-ABBREV");
>
> //in.close();
>
>
>
> model.write(System.out);
>
>
>
> }
>
> _______________________________
>
> private static void read1(String str,OntModel model)
>
> {
>
>
>
> String ns="http://www.semanticweb.org/untitled-ontology-0012/";
>
> OntClass user = model.createClass(ns + "User");
>
>
>
> OntClass user1 = model.getOntClass(ns + "User");
>
> Individual janeSmith = user1.createIndividual(ns + str);
>
>
>
> JOptionPane.showMessageDialog(null, janeSmith.toString());
>
>
>
> try {
>
> String file="F://hello.owl";
>
>
>
>
>
> FileWriter out=new FileWriter(file);
>
> model.write( out, "RDF/XML-ABBREV" );
>
> } catch (IOException ex) {
>
> Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE,
> null, ex);
>
> }
>
> }
>
> _____________________________________________
>
>
> private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
>
>
>
> OntModel model=ModelFactory.createOntologyModel();
>
> String str=jTextField2.getText();
>
>
>
>
> read1(str, model);
>
> }
>
> _________________________________
>
>
> and finally main()
>
>
> public static void main(String args[]) {
>
>
>
>
>
>
>
> OntModel model = ModelFactory.createOntologyModel();
>
> String file="F://hello.owl";
>
> readOntology(file , model );
>
> On Sat, Jul 16, 2016 at 6:27 AM, Lorenz B. <
> buehmann@informatik.uni-leipzig.de> wrote:
>
>> That code doesn't write to disk, so it's impossible.
>>
>> The only part that COULD write to file, but doesn't is
>>
>> FileWriter out=new FileWriter(file);
>>
>>
>>
>> I'm sure that it's not the whole code, so it's impossible to help.
>> Moreover, it's more a Java related question - nothing for the Jena
>> mailing list.
>>
>>> Hi
>>>
>>> I am very surprised that this code, when executed, has vanished my
>> ontology
>>> and my ontology is now empty. I copied another ontology and after
>> executing
>>> few times, again the new ontology is empty. I just want to create the
>>> individual of class and save it locally in the file. There is another
>>> method also in my code but thats just read the file so the main trick is
>>> here. It writed the whole ontology first as model.write() but when GUI
>>> loads and I enter text, again it display output as in
>>> JOptionPane.showMessageDialog() but after the whole exection, the Protege
>>> ontology becomes empty.
>>>
>>>
>>> *Note: It also create the intended individual but except the User1 class
>>> created in Jena code and its individual, nothing remains in ontology.*
>>>
>>>
>>>
>>> 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,"RDF/XML-ABBREV");
>>>
>>> //in.close();
>>>
>>>
>>>
>>> model.write(System.out);
>>>
>>>
>>>
>>> }
>>>
>>>
>>>
>>>
>>>
>>> private static void read1(String str,OntModel model)
>>>
>>> {
>>>
>>>
>>>
>>> String ns="http://www.semanticweb.org/untitled-ontology-0012/";
>>>
>>> OntClass user = model.createClass(ns + "User");
>>>
>>>
>>>
>>> OntClass user1 = model.getOntClass(ns + "User");
>>>
>>> Individual janeSmith = user1.createIndividual(ns + str);
>>>
>>>
>>>
>>> JOptionPane.showMessageDialog(null, janeSmith.toString());
>>>
>>>
>>>
>>> try {
>>>
>>> String file="F://hello.owl";
>>>
>>>
>>>
>>>
>>>
>>> FileWriter out=new FileWriter(file);
>>>
>> --
>> Lorenz Bühmann
>> AKSW group, University of Leipzig
>> Group: http://aksw.org - semantic web research center
>>
>>
Re: Jena Code has emptied my ontology
Posted by Andy Seaborne <an...@apache.org>.
This is not a complete, minimal example.
http://stackoverflow.com/help/mcve
Complete: someone else can run the code as-is.
Not have to hack a bunch of fragments into a program.
Must compile.
Minimal: just what is needed for the point in query
Andy
On 16/07/16 16:00, kumar rohit wrote:
> Here is the full code,
>
> 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,"RDF/XML-ABBREV");
>
> //in.close();
>
>
>
> model.write(System.out);
>
>
>
> }
>
> _______________________________
>
> private static void read1(String str,OntModel model)
>
> {
>
>
>
> String ns="http://www.semanticweb.org/untitled-ontology-0012/";
>
> OntClass user = model.createClass(ns + "User");
>
>
>
> OntClass user1 = model.getOntClass(ns + "User");
>
> Individual janeSmith = user1.createIndividual(ns + str);
>
>
>
> JOptionPane.showMessageDialog(null, janeSmith.toString());
>
>
>
> try {
>
> String file="F://hello.owl";
>
>
>
>
>
> FileWriter out=new FileWriter(file);
>
> model.write( out, "RDF/XML-ABBREV" );
>
> } catch (IOException ex) {
>
> Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE,
> null, ex);
>
> }
>
> }
>
> _____________________________________________
>
>
> private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
>
>
>
> OntModel model=ModelFactory.createOntologyModel();
>
> String str=jTextField2.getText();
>
>
>
>
> read1(str, model);
>
> }
>
> _________________________________
>
>
> and finally main()
>
>
> public static void main(String args[]) {
>
>
>
>
>
>
>
> OntModel model = ModelFactory.createOntologyModel();
>
> String file="F://hello.owl";
>
> readOntology(file , model );
>
> On Sat, Jul 16, 2016 at 6:27 AM, Lorenz B. <
> buehmann@informatik.uni-leipzig.de> wrote:
>
>> That code doesn't write to disk, so it's impossible.
>>
>> The only part that COULD write to file, but doesn't is
>>
>> FileWriter out=new FileWriter(file);
>>
>>
>>
>> I'm sure that it's not the whole code, so it's impossible to help.
>> Moreover, it's more a Java related question - nothing for the Jena
>> mailing list.
>>
>>> Hi
>>>
>>> I am very surprised that this code, when executed, has vanished my
>> ontology
>>> and my ontology is now empty. I copied another ontology and after
>> executing
>>> few times, again the new ontology is empty. I just want to create the
>>> individual of class and save it locally in the file. There is another
>>> method also in my code but thats just read the file so the main trick is
>>> here. It writed the whole ontology first as model.write() but when GUI
>>> loads and I enter text, again it display output as in
>>> JOptionPane.showMessageDialog() but after the whole exection, the Protege
>>> ontology becomes empty.
>>>
>>>
>>> *Note: It also create the intended individual but except the User1 class
>>> created in Jena code and its individual, nothing remains in ontology.*
>>>
>>>
>>>
>>> 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,"RDF/XML-ABBREV");
>>>
>>> //in.close();
>>>
>>>
>>>
>>> model.write(System.out);
>>>
>>>
>>>
>>> }
>>>
>>>
>>>
>>>
>>>
>>> private static void read1(String str,OntModel model)
>>>
>>> {
>>>
>>>
>>>
>>> String ns="http://www.semanticweb.org/untitled-ontology-0012/";
>>>
>>> OntClass user = model.createClass(ns + "User");
>>>
>>>
>>>
>>> OntClass user1 = model.getOntClass(ns + "User");
>>>
>>> Individual janeSmith = user1.createIndividual(ns + str);
>>>
>>>
>>>
>>> JOptionPane.showMessageDialog(null, janeSmith.toString());
>>>
>>>
>>>
>>> try {
>>>
>>> String file="F://hello.owl";
>>>
>>>
>>>
>>>
>>>
>>> FileWriter out=new FileWriter(file);
>>>
>> --
>> Lorenz B�hmann
>> AKSW group, University of Leipzig
>> Group: http://aksw.org - semantic web research center
>>
>>
>
Re: Jena Code has emptied my ontology
Posted by kumar rohit <ku...@gmail.com>.
Here is the full code,
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,"RDF/XML-ABBREV");
//in.close();
model.write(System.out);
}
_______________________________
private static void read1(String str,OntModel model)
{
String ns="http://www.semanticweb.org/untitled-ontology-0012/";
OntClass user = model.createClass(ns + "User");
OntClass user1 = model.getOntClass(ns + "User");
Individual janeSmith = user1.createIndividual(ns + str);
JOptionPane.showMessageDialog(null, janeSmith.toString());
try {
String file="F://hello.owl";
FileWriter out=new FileWriter(file);
model.write( out, "RDF/XML-ABBREV" );
} catch (IOException ex) {
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE,
null, ex);
}
}
_____________________________________________
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
OntModel model=ModelFactory.createOntologyModel();
String str=jTextField2.getText();
read1(str, model);
}
_________________________________
and finally main()
public static void main(String args[]) {
OntModel model = ModelFactory.createOntologyModel();
String file="F://hello.owl";
readOntology(file , model );
On Sat, Jul 16, 2016 at 6:27 AM, Lorenz B. <
buehmann@informatik.uni-leipzig.de> wrote:
> That code doesn't write to disk, so it's impossible.
>
> The only part that COULD write to file, but doesn't is
>
> FileWriter out=new FileWriter(file);
>
>
>
> I'm sure that it's not the whole code, so it's impossible to help.
> Moreover, it's more a Java related question - nothing for the Jena
> mailing list.
>
> > Hi
> >
> > I am very surprised that this code, when executed, has vanished my
> ontology
> > and my ontology is now empty. I copied another ontology and after
> executing
> > few times, again the new ontology is empty. I just want to create the
> > individual of class and save it locally in the file. There is another
> > method also in my code but thats just read the file so the main trick is
> > here. It writed the whole ontology first as model.write() but when GUI
> > loads and I enter text, again it display output as in
> > JOptionPane.showMessageDialog() but after the whole exection, the Protege
> > ontology becomes empty.
> >
> >
> > *Note: It also create the intended individual but except the User1 class
> > created in Jena code and its individual, nothing remains in ontology.*
> >
> >
> >
> > 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,"RDF/XML-ABBREV");
> >
> > //in.close();
> >
> >
> >
> > model.write(System.out);
> >
> >
> >
> > }
> >
> >
> >
> >
> >
> > private static void read1(String str,OntModel model)
> >
> > {
> >
> >
> >
> > String ns="http://www.semanticweb.org/untitled-ontology-0012/";
> >
> > OntClass user = model.createClass(ns + "User");
> >
> >
> >
> > OntClass user1 = model.getOntClass(ns + "User");
> >
> > Individual janeSmith = user1.createIndividual(ns + str);
> >
> >
> >
> > JOptionPane.showMessageDialog(null, janeSmith.toString());
> >
> >
> >
> > try {
> >
> > String file="F://hello.owl";
> >
> >
> >
> >
> >
> > FileWriter out=new FileWriter(file);
> >
> --
> Lorenz Bühmann
> AKSW group, University of Leipzig
> Group: http://aksw.org - semantic web research center
>
>
Re: Jena Code has emptied my ontology
Posted by "Lorenz B." <bu...@informatik.uni-leipzig.de>.
That code doesn't write to disk, so it's impossible.
The only part that COULD write to file, but doesn't is
FileWriter out=new FileWriter(file);
I'm sure that it's not the whole code, so it's impossible to help.
Moreover, it's more a Java related question - nothing for the Jena
mailing list.
> Hi
>
> I am very surprised that this code, when executed, has vanished my ontology
> and my ontology is now empty. I copied another ontology and after executing
> few times, again the new ontology is empty. I just want to create the
> individual of class and save it locally in the file. There is another
> method also in my code but thats just read the file so the main trick is
> here. It writed the whole ontology first as model.write() but when GUI
> loads and I enter text, again it display output as in
> JOptionPane.showMessageDialog() but after the whole exection, the Protege
> ontology becomes empty.
>
>
> *Note: It also create the intended individual but except the User1 class
> created in Jena code and its individual, nothing remains in ontology.*
>
>
>
> 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,"RDF/XML-ABBREV");
>
> //in.close();
>
>
>
> model.write(System.out);
>
>
>
> }
>
>
>
>
>
> private static void read1(String str,OntModel model)
>
> {
>
>
>
> String ns="http://www.semanticweb.org/untitled-ontology-0012/";
>
> OntClass user = model.createClass(ns + "User");
>
>
>
> OntClass user1 = model.getOntClass(ns + "User");
>
> Individual janeSmith = user1.createIndividual(ns + str);
>
>
>
> JOptionPane.showMessageDialog(null, janeSmith.toString());
>
>
>
> try {
>
> String file="F://hello.owl";
>
>
>
>
>
> FileWriter out=new FileWriter(file);
>
--
Lorenz B�hmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center