Search Mailing List Archives


Limit search to: Subject & Body Subject Author
Sort by: Reverse Sort
Limit to: All This Week Last Week This Month Last Month
Select Date Range     through    

[protege-discussion] Creating Protege instances and saving OWL file

Intan Munirah Hamdan niera5 at gmail.com
Thu Aug 7 08:21:03 PDT 2008


Hi all,

I'm attempting to create instances in Protege (in an already existing owl
file) through Java. The code I have so far appears below:


****************************************************************************************************************************************************
import java.util.Collection;
import java.util.Iterator;
import java.io.FileInputStream;
import java.io.*;

import edu.stanford.smi.protegex.owl.*;
import edu.stanford.smi.protegex.owl.jena.JenaOWLModel;
import edu.stanford.smi.protegex.owl.model.*;

public class IRTStorage
{
      JenaOWLModel modelModel;
      /**
       * @param args
       */
      public void store()
      {
            try
            {
                  String fileName = "N:\\RESEARCH\\Protege\\IRTStorage.owl";
                  FileInputStream fin = new FileInputStream(fileName);
                  modelModel =
ProtegeOWL.createJenaOWLModelFromInputStream(fin);
                  fin.close();
                  OWLNamedClass EquipClass =
modelModel.getOWLNamedClass("Equipment");
                  OWLIndividual newInstance =
EquipClass.createOWLIndividual("Blender");
                  FileOutputStream fout = new FileOutputStream(fileName);
                  modelModel.save(fout,"",null);

            }catch (Exception err)
            {
                  System.out.println("ERROR: " + err);
            }
      }

      public static void main (String[] args)
      {
            System.out.println("1+1= "+(1+1));
            IRTStorage makeMe = new IRTStorage();
            makeMe.store();
      }


}
****************************************************************************************************************************************************

It is able to generate an instance the first time I run the code. However,
when I try to run the code again, I get a "NullPointerException". I then
realized that if after each run of my Java code, I were to open the OWL
file, click save, and then close the OWL file - I would be able to run my
java code again without any error. I suspect that it has something to do
with the way I'm attempting to save the changes to my OWL file (the "save"
function I'm currently using is "deprecated" and perhaps is not saving as it
should).

How should I save this instead?

Thanks in advance,
Intan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.stanford.edu/pipermail/protege-discussion/attachments/20080807/098a0ada/attachment.html>


More information about the protege-discussion mailing list