You are on page 1of 25

Introduction to NetBeans and Protg API

CS560 Knowledge Discovery and Management

Create a new Java Web Application

Run the application created just to test if the application is created without errors

A simple Hello World application

Open Visual Studio and run the Web Service and copy the URL of the servicehere it is: http://localhost:56673/JavaWScall/javaws.asmx?WSDL

To call a web service, create a new Web service client by right clicking on the main application

In the Web Client Service window, paste the URL in the designated space and click Finish

Click on Web Service Reference and move down till the web method of the web service and drag and drop the method onto the web application.

Run the Application and you can see web browser starting up and your web methods running.

Protg API

Overview
Start a new project in netbeans Add Protege libraries to netbeans Write sample code to test the configuration Examples of Protege API

Start a new project


File-> New project-> Select Java Application Click Next

Set the project Name


Change the project name, and click Finish

Add Protege Libraries


Right Click the project name, select Properties

Add Jar Files


In the left panel, select Libraries, and in the right panel, click Add Folder/Jar Files add all jar files in the protege folder(four files lax.jar looks-2.1.3.jar protege.jar unicode_panel.jar), and all jar files under the folder protege/plugins/edu.stanford.smi.protegex.o wl

Add Jar Files - Ctnd

Write a sample code for testing


package protegeapi; import edu.stanford.smi.protege.exception.OntologyLoadException; import edu.stanford.smi.protegex.owl.model.OWLModel; import edu.stanford.smi.protegex.owl.model.OWLNamedClass; import edu.stanford.smi.protegex.owl.ProtegeOWL; import java.util.logging.Level; import java.util.logging.Logger; public class Main { public static void main(String[] args) { OWLModel owlModel; try { owlModel = ProtegeOWL.createJenaOWLModel(); owlModel.getNamespaceManager().setDefaultNamespace("http://hello.com#"); OWLNamedClass worldClass = owlModel.createOWLNamedClass("World"); System.out.println("Class URI: " + worldClass.getURI()); } catch (OntologyLoadException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } } }

Run and Result

Working With OWL Model


The most important model interface is OWLModel, which provides access to the toplevel container of the resources in the ontology. You can use OWLModel to create, query, and delete resources of various types and then use the objects returned by the OWLModel to do specific operations. Sample Code 1(sample1.java) creates a new OWLNamedClass (which corresponds to owl:Class in OWL), and then gets its URI

Loading Ontology from URI


ProtegeOWL provides a couple of convenient static methods to create OWLModels, also from existing OWL files. For example, you can load an existing ontology from the web using
String uri = "http://www.daml.org/researchers.owl"; OWLModel owlModel = ProtegeOWL.createJenaOWLModelFromURI(uri);

Get Class, Property, Individual


package protegeapi; import edu.stanford.smi.protege.exception.OntologyLoadException; import edu.stanford.smi.protegex.owl.model.OWLModel; import edu.stanford.smi.protegex.owl.model.OWLNamedClass; import edu.stanford.smi.protegex.owl.ProtegeOWL; import edu.stanford.smi.protegex.owl.model.OWLDatatypeProperty; import edu.stanford.smi.protegex.owl.model.OWLIndividual; import edu.stanford.smi.protegex.owl.model.OWLObjectProperty; import java.util.logging.Level; import java.util.logging.Logger; public class Main { public static void main(String[] args) { OWLModel owlModel; try { String uri = "http://www.daml.org/researchers.owl"; owlModel = ProtegeOWL.createJenaOWLModelFromURI(uri); OWLNamedClass destinationClass = owlModel.getOWLNamedClass("Destination"); OWLObjectProperty hasContactProperty = owlModel.getOWLObjectProperty("hasContact"); OWLDatatypeProperty hasZipCodeProperty = owlModel.getOWLDatatypeProperty("hasZipCode"); } catch (OntologyLoadException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } }} Sample2.java

Sample 2 Output

Creating Named Classes and Individuals


The sample3 provides ways to create a simple class, an individual of that class, and then assigns a couple of properties.

Creating SuperclassSubclass

OWLNamedClass personClass = owlModel.createOWLNamedClass("Person");

// Create subclass (complicated version) OWLNamedClass brotherClass = owlModel.createOWLNamedClass("Brother"); brotherClass.addSuperclass(personClass); brotherClass.removeSuperclass(owlModel.getOWLThingClass()); OWLNamedClass sisterClass = owlModel.createOWLNamedSubclass("Sister", personClass);

Thank You!!

You might also like