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-owl] Hi SWRL rules

Antonio Astorga Rivera aastorga at nmg.upc.edu
Fri Aug 21 05:58:24 PDT 2009


Hi
I need help; I'm trying to make a simple java program with only one SWRLrule
using the ontology example family.swrl.owl.
The rule is one of that is provided in the example, but now to understand
the process without using the Protége software, I'm doing these.
So I have this code but I don't know what is the next step to obtain the
inference and the applied these in the ontology, also to call Jess to help
in this, somebody could help me?
This is the code

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

import edu.stanford.smi.protege.exception.OntologyLoadException;
import edu.stanford.smi.protegex.owl.jena.JenaOWLModel;
import edu.stanford.smi.protegex.owl.model.OWLIndividual;
import edu.stanford.smi.protegex.owl.model.OWLModel;
import edu.stanford.smi.protegex.owl.model.OWLNamedClass;
import
edu.stanford.smi.protegex.owl.swrl.bridge.exceptions.SWRLRuleEngineBridgeExc
eption;
import edu.stanford.smi.protegex.owl.swrl.bridge.jess.SWRLJessBridge;
import edu.stanford.smi.protegex.owl.swrl.model.SWRLAtomList;
import edu.stanford.smi.protegex.owl.swrl.model.SWRLFactory;
import edu.stanford.smi.protegex.owl.swrl.model.SWRLImp;
import edu.stanford.smi.protegex.owl.swrl.model.SWRLVariable;
import edu.stanford.smi.protegex.owl.swrl.parser.SWRLParseException;
import edu.stanford.smi.protegex.owl.ProtegeOWL;


public class ExampleRulesSWRL {
	public static void main(String[] args) throws OntologyLoadException,
FileNotFoundException, SWRLRuleEngineBridgeException, SWRLParseException {
		
		FileInputStream input=new
FileInputStream("C:/Toño/Ontologias/SWRL/family.swrl.owl");
   		JenaOWLModel owlModel =
ProtegeOWL.createJenaOWLModelFromInputStream(input);
		jess.Rete testrete = new jess.Rete();
		SWRLJessBridge bridge=new SWRLJessBridge
(owlModel,testrete);
			
	     //  OWLModel owlModel =
ProtegeOWL.createJenaOWLModelFromURI(uri);
	      SWRLFactory factory = new SWRLFactory(owlModel);

	      // SWRLVariable x = factory.createVariable("x");
	    //   SWRLVariable y = factory.createVariable("y");
	    //   SWRLVariable z = factory.createVariable("z");
	       	       

	              
	   SWRLImp imp = factory.createImp("Person(?x) ^ hasSibling(?x, ?y)
^ Man(?x) -> hasBrother(?x,?y)");     
	   bridge.resetRuleEngine();
		bridge.infer();   
		System.out.println("Inferred Individuals
:"+bridge.getInferredIndividuals());
	       	        
	       
	        Collection classes =
owlModel.getUserDefinedOWLNamedClasses();
	        for (Iterator it = classes.iterator(); it.hasNext();) {
	            OWLNamedClass cls = (OWLNamedClass) it.next();
	            Collection instances = cls.getInstances(false);
	            System.out.println("Class " + cls.getBrowserText() + "
(" + instances.size() + ")");
	            for (Iterator jt = instances.iterator(); jt.hasNext();)
{
	                OWLIndividual individual = (OWLIndividual)
jt.next();
	                System.out.println(" - " +
individual.getBrowserText());
	            }
	        }
	        
	    }
	
	
}







More information about the protege-owl mailing list