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] SWRL Queries Problem & Question

Tania Tudorache tudorache at stanford.edu
Thu Apr 17 17:54:29 PDT 2008


Please post OWL and SWRL related questions on the Protege-OWL mailing list.

http://protege.stanford.edu/community/lists.html

Thanks,
Tania


Kafkalas Aggelos wrote:
>
>  
> Hi all,
>  
> I am working in project using ontologies and i encountered some 
> problems, during an example, while i was trying to make some queries 
> to my ontology.
> I am posting below the code that implements my model, and the code for 
> the query.  Compiling returns no errors  but when i run the program i 
> get this *exception :*
>  
> C:\Program Files\Protege_3.3.1\JavaApplication4\test>java NewClass
> WARNING: [Local Folder Repository] The specified file must be a 
> directory. (C:\P
> rogram 
> Files\Protege_3.3.1\JavaApplication4\test\plugins\edu.stanford.smi.proteg
> ex.owl) -- LocalFolderRepository.update()
> edwOntologies Document
> Rule engine 'SWRLJessBridge' registered with the SWRLTab bridge.
>
> *Exception in thread "main" java.lang.NullPointerException
>         at NewClass.main(NewClass.java:201)*
> ** 
> which refers to the  Result variable.   (result.getNumberOfRows();)
> I think that although SWRLJessBridge works fine it doen't get my 
> owlModel, so it returns a null pointer because no class or intsance is 
> provided from the owlModel.
> Same problem occurs if i don't use the SWRLFactory.
>  
> My question is about the SWRL Ontology. As i read from the 
> SWRLFactoryFaq wiki 
> (http://protege.cim3.net/cgi-bin/wiki.pl?SWRLFactoryFAQ) my owlModel 
> should import the SWRL Ontology to run the queries. How can i import 
> the SWRL Ontology with Java Code? If any tutorial exists please let me 
> know
>  
>  
>  
>  
> Thanx Aggelos Kafkalas
> ** 
>  
> ** 
>  
>  
> import edu.stanford.smi.protege.model.*;
> import edu.stanford.smi.protegex.owl.model.RDFIndividual;
> import edu.stanford.smi.protegex.owl.model.OWLNamedClass;
> import edu.stanford.smi.protegex.owl.ProtegeOWL;
> import edu.stanford.smi.protegex.owl.jena.JenaOWLModel;
> import edu.stanford.smi.protegex.owl.model.OWLDatatypeProperty;
> import edu.stanford.smi.protegex.owl.model.OWLObjectProperty;
> import 
> edu.stanford.smi.protegex.owl.inference.protegeowl.ProtegeOWLReasoner;
> import 
> edu.stanford.smi.protegex.owl.inference.protegeowl.ReasonerManager;
> import edu.stanford.smi.protegex.owl.swrl.bridge.BridgeFactory;
> import edu.stanford.smi.protegex.owl.swrl.bridge.SWRLRuleEngineBridge;
> import 
> edu.stanford.smi.protegex.owl.swrl.bridge.exceptions.SWRLRuleEngineBridgeException;
> import edu.stanford.smi.protegex.owl.swrl.bridge.query.Result;
> import edu.stanford.smi.protegex.owl.swrl.exceptions.SWRLFactoryException;
> import edu.stanford.smi.protegex.owl.swrl.parser.SWRLParseException;
> import java.util.*;
> import java.io.*;
> import java.util.logging.Level;
> import java.util.logging.Logger;
>
> public class NewClass {
>    
>     public static void main(String[] args) throws SWRLParseException, 
> SWRLFactoryException
>     {
>       
>             JenaOWLModel owlModel = ProtegeOWL.createJenaOWLModel();
>             
> owlModel.getNamespaceManager().setDefaultNamespace("http://example.com#");
>
>             //Organization
>              OWLNamedClass organizationClass = 
> owlModel.createOWLNamedClass("Organization");
>  
>             //Data Type Properties for Organization
>             OWLDatatypeProperty hasCompanyNameProperty = 
> owlModel.createOWLDatatypeProperty("hasCompanyName");
>             hasCompanyNameProperty.setRange(owlModel.getXSDstring());
>             hasCompanyNameProperty.setDomain(organizationClass);
>  
>             //Object Properties for Organizations
>             OWLObjectProperty hasEmployeeProperty = 
> owlModel.createOWLObjectProperty("hasEmployee");
>             hasEmployeeProperty.setRange(organizationClass);
>
>             //Person
>             OWLNamedClass personClass = 
> owlModel.createOWLNamedClass("Person");
>
>             //Data Type Properties for person
>             OWLDatatypeProperty hasFirstNameProperty = 
> owlModel.createOWLDatatypeProperty("hasFirstName");
>             hasFirstNameProperty.setRange(owlModel.getXSDstring());
>             hasFirstNameProperty.setDomain(personClass);
>             OWLDatatypeProperty hasLastNameProperty = 
> owlModel.createOWLDatatypeProperty("hasLastName");
>             hasLastNameProperty.setRange(owlModel.getXSDstring());
>             hasLastNameProperty.setDomain(personClass);
>             OWLDatatypeProperty hasMobilePhoneProperty = 
> owlModel.createOWLDatatypeProperty("hasMobilePhone");
>             hasMobilePhoneProperty.setRange(owlModel.getXSDstring());
>             hasMobilePhoneProperty.setDomain(personClass);
>  
>             // Object Properties for Persons
>             OWLObjectProperty hasEmployerProperty = 
> owlModel.createOWLObjectProperty("hasEmployer");
>             hasEmployerProperty.setRange(personClass);
>             OWLObjectProperty isAuthorOfProperty = 
> owlModel.createOWLObjectProperty("isAuthorOf");
>             hasEmployeeProperty.setRange(personClass);
>  
>             //Document
>             OWLNamedClass documentClass = 
> owlModel.createOWLNamedClass("Document");
>  
>             //Data Type Properties for Document
>             OWLDatatypeProperty hasNameProperty = 
> owlModel.createOWLDatatypeProperty("hasName");
>             hasNameProperty.setRange(owlModel.getXSDstring());
>             hasNameProperty.setDomain(documentClass);
>  
>             //Object Properties for Documents
>             OWLObjectProperty hasAuthorProperty = 
> owlModel.createOWLObjectProperty("hasAuthor");
>             hasEmployeeProperty.setRange(documentClass);
>
>             //Building Individuals for Organization
>             RDFIndividual google = 
> organizationClass.createRDFIndividual("Google");
>             google.setPropertyValue(hasCompanyNameProperty, "Google 
> Corp.");
>             RDFIndividual ibm = 
> organizationClass.createRDFIndividual("IMB");
>             ibm.setPropertyValue(hasCompanyNameProperty, "IBM");
>             RDFIndividual ups = 
> organizationClass.createRDFIndividual("UPS");
>             ups.setPropertyValue(hasCompanyNameProperty, "UPS");
>  
>
>             //Building Individuals for Persons
>             RDFIndividual aggelos = 
> personClass.createRDFIndividual("Aggelos");
>             aggelos.setPropertyValue(hasFirstNameProperty, "Aggelos");
>             aggelos.setPropertyValue(hasLastNameProperty, "Kafkalas");
>             aggelos.setPropertyValue(hasMobilePhoneProperty, "69999");
>             RDFIndividual george = 
> personClass.createRDFIndividual("George");
>             george.setPropertyValue(hasFirstNameProperty, "George");
>             george.setPropertyValue(hasLastNameProperty, "Georgiou");
>             george.setPropertyValue(hasMobilePhoneProperty, "69090");
>             RDFIndividual nikos = 
> personClass.createRDFIndividual("Nikos");
>             nikos.setPropertyValue(hasFirstNameProperty, "Nikos");
>             nikos.setPropertyValue(hasLastNameProperty, "Nikou");
>             nikos.setPropertyValue(hasMobilePhoneProperty, "690000");
>
>             //Building Individuals for Documents
>             RDFIndividual doc = 
> documentClass.createRDFIndividual("Semnatic Web Document");
>             doc.setPropertyValue(hasNameProperty, "Semantic Web 
> Document");
>             RDFIndividual doc1 = 
> documentClass.createRDFIndividual("Ontologies Document");
>             doc1.setPropertyValue(hasNameProperty, "Ontologies Document");
>             System.out.println("edw"+doc1.getBrowserText());
>  
>
>            SWRLFactory factory = new SWRLFactory(owlModel);
>                          
>             try{
>                
>            
>             SWRLRuleEngineBridge bridge = 
> BridgeFactory.createBridge(owlModel);
>            
>                        
>             bridge.infer();
>
>             //bridge.importSWRLRulesAndOWLKnowledge();   ???????
>
>
>              String query = "Person(?p) ->query:select(?p)";   //This 
> is My simply Query (which doesn't run)
>             Result result = bridge.getQueryResult(query);
>             
>             result.getNumberOfRows();
>           
>              //while (result.hasNext()) {
>             // System.out.println("" + result.getNumberOfRows());
>              //DatatypeValue nameValue = result.getDatatypeValue("?p");   
>              //System.out.println("Name: " + nameValue.getString());
>              //result.next();
>              //}
>             
>             }
>             catch (SWRLRuleEngineBridgeException ex) {
>             
> Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
>             }
>           
>                         
>  
> }
> }
> ------------------------------------------------------------------------
>
> _______________________________________________
> protege-discussion mailing list
> protege-discussion at lists.stanford.edu
> https://mailman.stanford.edu/mailman/listinfo/protege-discussion
>
> Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03 
>   




More information about the protege-discussion mailing list