Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane
From: Martin O'Connor <martin.oconnor <at> stanford.edu>
Subject: Re: Hi SWRL rules
Newsgroups: gmane.comp.misc.ontology.protege.owl
Date: Friday 21st August 2009 15:13:37 UTC (over 8 years ago)
The code below will execute SWRL rules and place the inferred knowledge 
back into an OWL ontology and will also display the inferred knowledge.

What else are you trying to do?.

Martin

Antonio Astorga Rivera wrote:
> 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());
> 	            }
> 	        }
> 	        
> 	    }
> 	
> 	
> }
>
>
>
>
> _______________________________________________
> protege-owl mailing list
> [email protected]
> https://mailman.stanford.edu/mailman/listinfo/protege-owl
>
> Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03
>
>   

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

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