reading owl in java application

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

reading owl in java application

Quratulain Rajput
 I have to read owl file in my java application. I am trying to read
  pizza.owl a popular example comes along with protege. I do'nt know how
  to do it.
  please tell me any tutorial, if available. I am working with eclipse
  and created RDF using Jena.
  Now I have to read OWL file. Please give me any sample code.
  waiting of your response.
  Quratulain
_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03 
Reply | Threaded
Open this post in threaded view
|

Re: reading owl in java application

Cedric Peeters
Hello,

To read an ontology in a Java application with Jena, you can do this:

OntModel ontologyModel =  
ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
ontologyModel.read(owlBaseFile, "RDF/XML-ABBREV"); //where owlBaseFile  
is a string containing the path to your pizza.owl file

The you can interact with your ontology. For instance you can get a  
class like this:

OntClass pizzaClass =  
ontologyModel.getOntClass(nameSpace+className);//where namespace is  
the namespace of your ontology (for instance  
http://www.semanticweb.org/2009/1/pizza.owl# (do not forget the #  
after the soruce)" and the className is a string containing the name  
of the class you want (for instance "Pizza").

When you have finish with your ontology, you can close it:
ontologyModel.close();

You can learn more here:
http://jena.sourceforge.net/tutorial/RDF_API/index.html
and here is a small tutorial : http://kill.devc.at/node/84

Hope it helps;

Cedric


Quratulain Rajput <[hidden email]> a écrit :

>  I have to read owl file in my java application. I am trying to read
>   pizza.owl a popular example comes along with protege. I do'nt know how
>   to do it.
>   please tell me any tutorial, if available. I am working with eclipse
>   and created RDF using Jena.
>   Now I have to read OWL file. Please give me any sample code.
>   waiting of your response.
>   Quratulain
> _______________________________________________
> protege-owl mailing list
> [hidden email]
> https://mailman.stanford.edu/mailman/listinfo/protege-owl
>
> Instructions for unsubscribing:  
> http://protege.stanford.edu/doc/faq.html#01a.03
>



_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03 
Reply | Threaded
Open this post in threaded view
|

Re: reading owl in java application

Leyla Jael García Castro
In reply to this post by Quratulain Rajput
Hello,

You can find some examples on Jena's web site. I am not sure whether or not there is an example about loading an existing ontology... anyway, you can also try with this: http://www.ibm.com/developerworks/xml/library/j-jena/. I think this could help you.

Best,

Leyla

> Date: Mon, 16 Feb 2009 14:45:45 +0500
> From: [hidden email]
> To: [hidden email]
> Subject: [protege-owl] reading owl in java application
>
> I have to read owl file in my java application. I am trying to read
> pizza.owl a popular example comes along with protege. I do'nt know how
> to do it.
> please tell me any tutorial, if available. I am working with eclipse
> and created RDF using Jena.
> Now I have to read OWL file. Please give me any sample code.
> waiting of your response.
> Quratulain
> _______________________________________________
> protege-owl mailing list
> [hidden email]
> https://mailman.stanford.edu/mailman/listinfo/protege-owl
>
> Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03


Windows Live™ Hotmail®…more than just e-mail. See how it works.
_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03 
Reply | Threaded
Open this post in threaded view
|

Re: reading owl in java application

Truong Thi Thu Hien
Hi,
you can use Protege library to load existing OWL file by:
try{              
            JenaOWLModel owlModel =
ProtegeOWL.createJenaOWLModelFromInputStream
                                (new FileInputStream("./pizza.owl"));
            } catch (Exception e) {
                System.err.println("Read OWL failed");
                }

Good luck!
TTT Hien

>
>
> > Date: Mon, 16 Feb 2009 14:45:45 +0500
> > From: [hidden email]
> > To: [hidden email]
> > Subject: [protege-owl] reading owl in java application
> >
> > I have to read owl file in my java application. I am trying to read
> > pizza.owl a popular example comes along with protege. I do'nt know how
> > to do it.
> > please tell me any tutorial, if available. I am working with eclipse
> > and created RDF using Jena.
> > Now I have to read OWL file. Please give me any sample code.
> > waiting of your response.
> > Quratulain
> > _______________________________________________
> > protege-owl mailing list
> > [hidden email]
> > https://mailman.stanford.edu/mailman/listinfo/protege-owl
> >
> > Instructions for unsubscribing:
> http://protege.stanford.edu/doc/faq.html#01a.03
>
> Windows Live™ Hotmail®…more than just e-mail. See how it works.
> <http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_hm_justgotbetter_howitworks_022009>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> protege-owl mailing list
> [hidden email]
> https://mailman.stanford.edu/mailman/listinfo/protege-owl
>
> Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03 
>  


_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03 
Reply | Threaded
Open this post in threaded view
|

Re: reading owl in java application

Jennifer Vendetti
Administrator
In reply to this post by Quratulain Rajput
Quratulain,

Please refer to the Protege-OWL Programmer's Guide:

http://protege.stanford.edu/plugins/owl/api/guide.html

Our wiki also has a page devoted to developer documentation for Protege 3.x:

http://protegewiki.stanford.edu/index.php/Protege3DevDocs

Jennifer

Quratulain Rajput wrote:

>  I have to read owl file in my java application. I am trying to read
>   pizza.owl a popular example comes along with protege. I do'nt know how
>   to do it.
>   please tell me any tutorial, if available. I am working with eclipse
>   and created RDF using Jena.
>   Now I have to read OWL file. Please give me any sample code.
>   waiting of your response.
>   Quratulain
> _______________________________________________
> protege-owl mailing list
> [hidden email]
> https://mailman.stanford.edu/mailman/listinfo/protege-owl
>
> Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03 
>  
_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03 
Reply | Threaded
Open this post in threaded view
|

reading owl in java application

sheba wilfred
In reply to this post by Cedric Peeters
hi,
i m working with jena..m trying to input a owl file(created with protege 4.1) into my DOM parser program written in Java..
can u plz tel me the packages to import and syntax for inputg the owl file and display and to query its contents..and a sample code.???.refered ur tutorials ..bt we r new to owl and we r nt able to grasp idea of developing a code with thos..
waitg fr ur rly ,...
Reply | Threaded
Open this post in threaded view
|

Re: reading owl in java application

sheba wilfred
In reply to this post by Truong Thi Thu Hien
hi,
i m working with jena..m trying to input a owl file(created with protege 4.1) into my DOM parser program written in Java..
can u plz tel me the packages to import and syntax for inputg the owl file and display and to query its contents..and a sample code.???.refered ur tutorials ..bt we r new to owl and we r nt able to grasp idea of developing a code with thos..
waitg fr ur rly ,...
Reply | Threaded
Open this post in threaded view
|

Re: reading owl in java application

sheba wilfred
In reply to this post by Jennifer Vendetti
hi,
i m working with jena..m trying to input a owl file(created with protege 4.1) into my DOM parser program written in Java..
can u plz tel me the packages to import and syntax for inputg the owl file and display and to query its contents..and a sample code.???.refered ur tutorials ..bt we r new to owl and we r nt able to grasp idea of developing a code with thos..
waitg fr ur rly ,...
Reply | Threaded
Open this post in threaded view
|

reading owl in java application

sheba wilfred
In reply to this post by Truong Thi Thu Hien
hi,
i m working with jena..m trying to input a owl file(created with protege 4.1) into my DOM parser program written in Java..
can u plz tel me the packages to import and syntax for inputg the owl file and display and to query its contents..and a sample code.???.refered ur tutorials ..bt we r new to owl and we r nt able to grasp idea of developing a code with thos..
waitg fr ur rly ,...
Reply | Threaded
Open this post in threaded view
|

Re: reading owl in java application

Thomas Russ
In reply to this post by sheba wilfred

On Jul 2, 2011, at 8:25 AM, sheba wilfred wrote:

> hi,
> i m working with jena..m trying to input a owl file(created with  
> protege
> 4.1) into my DOM parser program written in Java..
> can u plz tel me the packages to import and syntax for inputg the  
> owl file
> and display and to query its contents..and a sample code.???.refered  
> ur
> tutorials ..bt we r new to owl and we r nt able to grasp idea of  
> developing
> a code with thos..
> waitg fr ur rly ,...

Protege 4.1 uses the OWL API for its interactions with the OWL file.

So I would suggest that you also use the OWL API to work with OWL  
constructs from your Java program.

See
   http://sourceforge.net/projects/owlapi/
   http://owlapi.sourceforge.net/documentation.html

The latter site also has sample code showing you how to do things.


_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03
Reply | Threaded
Open this post in threaded view
|

extracting the owl elements by java application

sheba wilfred
This post was updated on .
Hi,

I m trying to just retrieve the tag elements of an owl file.I used Dom parser and my program is

import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;


public class DOMElements{
 static public void main(String[] arg){
 try {
     
   
 BufferedReader bf = new BufferedReader(
   new InputStreamReader(System.in));
 System.out.print("Enter  File name: ");
 String File = bf.readLine();
 File file = new File(File);
 if(file.exists()){
 
 DocumentBuilderFactory factory =
   DocumentBuilderFactory.newInstance();
 
 DocumentBuilder builder = factory.newDocumentBuilder();
 Document doc = builder.parse(File);
 
 NodeList list = doc.getElementsByTagName("*");
 System.out.println(" Elements: ");
 for (int i=0; i<list.getLength(); i++) {
 
 Element element = (Element)list.item(i);
 System.out.println(element.getNodeName());
 }
 }
 else{
 System.out.print("File not found!");
 }
 }
 catch (Exception e) {
 System.exit(1);
 }
 }
}

But this code works well if i input a xml file,but my owl file looks lik

<owl:Class rdf:about="http://www.semanticweb.org/ontologies/2011/5/Ontology1308296943439.owl#bachelor">
        <rdfs:subClassOf rdf:resource="http://www.semanticweb.org/ontologies/2011/5/Ontology1308296943439.owl#qualification"/>
    </owl:Class>
 
Here class and subClassOf are retrieved instead of bachelor and qualification.Can you please tel me ,how should i alter my program to get the desired output.

Thank You
Reply | Threaded
Open this post in threaded view
|

Re: extraxting the owl elements by java application

Timothy Redmond

> Here class and subClassOf are retrieved instead of bachelor and
> qualification.Can you please tel me ,how should i alter my program to get
> the desired output.

The answer is don't do this!  RDF is difficult to parse - for a computer
or a human-  and you should use an rdf or owl tool for this purpose.  
There are many very different looking things that mean the same thing.  
If you want an example of how challenging this is consider the two
attached pizza files that are identical as RDF.  How are you going to
get your DOM parser to come to the same result in both cases?

There are several OWL and RDF api's that are available.  For OWL I
recommend the Manchester OWL api (owlapi.sourceforge.net).  For RDF I am
less sure but I was using sesame lately and I liked that and Jena also
has a long record of success.

-Timothy


On 08/31/2011 09:09 AM, sheba wilfred wrote:

> Hi,
>
> I m trying to just retrieve the tag elements of an owl file.I used Dom
> parser and my program is
>
> import java.io.*;
> import javax.xml.parsers.*;
> import org.w3c.dom.*;
>
>
> public class DOMElements{
>   static public void main(String[] arg){
>   try {
>
>
>   BufferedReader bf = new BufferedReader(
>     new InputStreamReader(System.in));
>   System.out.print("Enter  File name: ");
>   String File = bf.readLine();
>   File file = new File(File);
>   if(file.exists()){
>
>   DocumentBuilderFactory factory =
>     DocumentBuilderFactory.newInstance();
>
>   DocumentBuilder builder = factory.newDocumentBuilder();
>   Document doc = builder.parse(File);
>
>   NodeList list = doc.getElementsByTagName("*");
>   System.out.println(" Elements: ");
>   for (int i=0; i&lt;list.getLength(); i++) {
>
>   Element element = (Element)list.item(i);
>   System.out.println(element.getNodeName());
>   }
>   }
>   else{
>   System.out.print(&quot;File not found!&quot;);
>   }
>   }
>   catch (Exception e) {
>   System.exit(1);
>   }
>   }
> }
>
> But this code works well if i input a xml file,but my owl file looks lik
>
> &lt;owl:Class
> rdf:about=&quot;http://www.semanticweb.org/ontologies/2011/5/Ontology1308296943439.owl#bachelor&quot;&gt;
>          <rdfs:subClassOf
> rdf:resource="http://www.semanticweb.org/ontologies/2011/5/Ontology1308296943439.owl#qualification"/>
>      </owl:Class>
>
> Here class and subClassOf are retrieved instead of bachelor and
> qualification.Can you please tel me ,how should i alter my program to get
> the desired output.
>
> Thank You
>
> --
> View this message in context: http://protege-ontology-editor-knowledge-acquisition-system.136.n4.nabble.com/reading-owl-in-java-application-tp13798p3781464.html
> Sent from the Protege OWL mailing list archive at Nabble.com.
> _______________________________________________
> protege-owl mailing list
> [hidden email]
> https://mailman.stanford.edu/mailman/listinfo/protege-owl
>
> Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03

_______________________________________________
protege-owl mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-owl

Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03

pizza.owl (176K) Download Attachment
pizza-unabbreviated.owl (259K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: extraxting the owl elements by java application

sheba wilfred
Sir my project goes like this.
creating an OWL file,then taking the tags from OWL and using it to display in a form that gets input from users.so i must do this step and cant skip it.so only i thought of using a DOM parser,but i could not get the desired output.I have only a little idea about OWL so i could not understand about that manchestor owl api.i downloaded owlapi 3.2.4 zip file.can you tel me what's its purpose...? can it solve my problem.Or can i use java program with string tokenizer and retrieve those tags ?