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] SQWRL through Java

Jdisc Sobrename jdiscum at yahoo.com.br
Mon Oct 6 19:12:05 PDT 2008


Hello,

I'm trying to run queries SQWRL through the following Java code:
import edu.stanford.smi.protege.model.*;
import edu.stanford.smi.protegex.owl.ProtegeOWL;
import edu.stanford.smi.protegex.owl.model.OWLModel;
import edu.stanford.smi.protegex.owl.swrl.sqwrl.SQWRLQueryEngine;

import edu.stanford.smi.protegex.owl.swrl.sqwrl.SQWRLQueryEngineFactory;
import edu.stanford.smi.protegex.owl.swrl.sqwrl.SQWRLResult;
import edu.stanford.smi.protegex.owl.swrl.sqwrl.DatatypeValue;
import edu.stanford.smi.protegex.owl.model.*;

import edu.stanford.smi.protegex.owl.swrl.model.*;
import java.util.*;
import edu.stanford.smi.protegex.owl.model.util.*;
import java.net.URI;
import edu.stanford.smi.protege.util.URIUtilities;
import edu.stanford.smi.protegex.owl.jena.JenaOWLModel;


public class importando2 {


    public static void main(String[] args ){
        try{
           
            OWLModel owlModel = ProtegeOWL.createJenaOWLModel();
           
            ImportHelper importHelper = new ImportHelper(owlModel);

            URI importUri = URIUtilities.createURI("http://sqwrl.stanford.edu/ontologies/built-ins/3.4/sqwrl.owl#");
            URI importUri1 = URIUtilities.createURI("http://swrl.stanford.edu/ontologies/3.3/swrla.owl#");

            URI importUri2 = URIUtilities.createURI("http://swrl.stanford.edu/ontologies/built-ins/3.3/swrlx.owl#");
            URI importUri3 = URIUtilities.createURI("http://swrl.stanford.edu/ontologies/built-ins/3.3/abox.owl#");

            URI importUri6 = URIUtilities.createURI("http://swrl.stanford.edu/ontologies/built-ins/3.3/temporal.owl#");
            //add the import


            importHelper.addImport(importUri);
            importHelper.addImport(importUri1);
            importHelper.addImport(importUri2);
            importHelper.addImport(importUri3);
            importHelper.addImport(importUri6);

            owlModel..getNamespaceManager().setPrefix(importUri, "xmlns:sqwrl");
            owlModel..getNamespaceManager().setPrefix(importUri1, "xmlns:swrla");
            owlModel..getNamespaceManager().setPrefix(importUri2, "xmlns:swrlx");

            owlModel..getNamespaceManager().setPrefix(importUri3, "xmlns:abox");
            owlModel..getNamespaceManager().setPrefix(importUri6, "xmlns:temporal");
      
            try {

                //do the import
                importHelper.importOntologies(false);
            } catch (Exception e) {      
                System.out.println(" ----------- ");
                e.printStackTrace();

            }

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

            OWLDatatypeProperty ageProperty = owlModel.createOWLDatatypeProperty("age");
            ageProperty.setRange(owlModel.getXSDint());

            ageProperty.setDomain(personClass);
       
            OWLObjectProperty childrenProperty = owlModel.createOWLObjectProperty("children");
            childrenProperty.setRange(personClass);

            childrenProperty.setDomain(personClass);
       
            RDFIndividual darwin = personClass.createRDFIndividual("Darwin");
            darwin.setPropertyValue(ageProperty, new Integer(0));

       
            RDFIndividual holgi = personClass.createRDFIndividual("Holger");
            holgi.setPropertyValue(childrenProperty, darwin);
            holgi.setPropertyValue(ageProperty, new Integer(33));

           
            SWRLFactory factory = new SWRLFactory(owlModel);
//            SWRLImp imp = factory.createImp("Query-1", "sameAs(Darwin, Holger)");
            SWRLImp imp = factory.createImp("Query-2", "Person(?p) -> sqwrl:select(?p)");

            Collection col = imp.getReferencedInstances();
            System.out.println("elements: "+col.toString());
           
        }catch(Exception error){
             System.out.println(error.getMessage());

         }
    }

}



and I am getting the following error:

Invalid atom name 'sqwrl: select'.


I'm loading the right ontology but it doesn't find the commands SQWRL. Is there anything else missing?


There is a line commented in the code. If I execute the query of
this line, which searches for "sameAs", I get the right results. So, I
know where is the problem, but I don't know why...

Could anyone help me?


regards,

Joao


      Novos endereços, o Yahoo! que você conhece. Crie um email novo com a sua cara @ymail.com ou @rocketmail.com.
http://br.new.mail.yahoo.com/addresses
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.stanford.edu/pipermail/protege-owl/attachments/20081006/7b59b1f9/attachment.html>


More information about the protege-owl mailing list