ontolog-forum
[Top] [All Lists]

Re: [ontolog-forum] OWL to KIF translator?

To: "[ontolog-forum]" <ontolog-forum@xxxxxxxxxxxxxxxx>
From: "rick@xxxxxxxxxxxxxx" <rick@xxxxxxxxxxxxxx>
Date: Mon, 28 Jan 2008 19:19:43 -0500
Message-id: <479E711F.4080002@xxxxxxxxxxxxxx>
Pat:    (01)

See below for an EJB using JTP with the OWLReasoningContext and the 
KIF2CNF parser. This has never been validated, it just builds on a 
snippet from the JTP documentation. Feel free to call if you want to 
chat ...    (02)

Patrick Cassidy wrote:
> Does anyone have on hand a functioning ontology  translator to go from OWL
> to KIF or some other FOL format?    (03)


/**
  * @(#) TrustProviderProxyBean.java
  * @author <a href:mailto="rick@xxxxxxxxxxxxxx">Rick Murphy</a>
  * @version 0.1
  * @see <a href="http://www.rickmurphy.org/cps-license.html";>Citizen 
Privacy Service License</a>
  */    (04)

package org.rickmurphy.pep;    (05)

import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;    (06)

import java.net.URL;
import java.net.MalformedURLException;    (07)

import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;    (08)

import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.EJBLocalHome;
import javax.ejb.EJBLocalObject;    (09)

import jtp.ReasoningException;
import jtp.ReasoningStep;
import jtp.ReasoningStepIterator;    (010)

import jtp.context.owl.OWLReasoningContext;    (011)

import jtp.fol.kif.KIF2CNF;    (012)

import jtp.fol.parser.ParserBasedTranslator;    (013)

import jtp.frame.vc.Goal;    (014)

import jtp.modelim.AskingQueryProcessor;    (015)

import jtp.ui.RDFQueryUtils;    (016)

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;    (017)

/**
  *
  */
public class TrustProviderProxyBean implements 
TrustProviderProxy,SessionBean{    (018)

   private KIF2CNF kifParser;
   private OWLReasoningContext context;    (019)

   /**
    * @param goal
    * @return boolean
    * @throws ReasoningException
    */
   public boolean challenge(Goal goal) throws ReasoningException{    (020)

     AskingQueryProcessor queryProcessor = new AskingQueryProcessor();    (021)

queryProcessor.setTranslator((ParserBasedTranslator)kifParser.createTranslator());
     context.add(queryProcessor);    (022)

     return queryProcessor.acceptable(goal);    (023)

   }//challenge    (024)

   /**
    * @param goal
    * @return ReasoningStepIterator
    * @throws ReasoningException
    */
   public ReasoningStepIterator enforce(Goal goal) throws 
ReasoningException{    (025)

     ReasoningStepIterator iterator = context.ask(goal.toString());    (026)

     ReasoningStep step = null;    (027)

     while((step = iterator.next()) != null){
       step = iterator.next();
       //System.out.println("got step: " + step);
     }    (028)

     //persist and return provenance
     TrustProviderDAO dao = new TrustProviderDAO();    (029)

     return iterator;    (030)

   }//enforce    (031)

   /**
    * @throws CreateException
    * @throws ReasoningException
    * @throws IOException
    * @throws MalformedURLException
    */
   public void ejbCreate() throws 
MalformedURLException,IOException,ReasoningException{    (032)

     kifParser = new KIF2CNF();    (033)

     kifParser.setCaseSensitiveSymbols(true);
     kifParser.addNamespaceMapping("owl", "http://www.w3.org/2002/07/owl#";);
     kifParser.addNamespaceMapping("daml", 
"http://www.daml.org/2001/03/daml+oil#";);
     kifParser.addNamespaceMapping("rdf", 
"http://www.w3.org/1999/02/22-rdf-syntax-ns#";);
     kifParser.addNamespaceMapping("rdfs", 
"http://www.w3.org/2000/01/rdf-schema#";);    (034)

     context = new OWLReasoningContext();
     context.setUp();    (035)

     Model model = ModelFactory.createDefaultModel();    (036)

     URL pubLocURL = new URL("http://localhost/kb";);
     model.read(new BufferedReader(new InputStreamReader(new 
URL("http://www.osera.gov/privacy.owl";).openStream())), 
pubLocURL.toString());    (037)

     ((OWLReasoningContext)context).loadRDFKB(model, pubLocURL);    (038)

     HashMap nsToUriMap = new HashMap();
     RDFQueryUtils.addNamespaceMappingsFromKb(pubLocURL.toString(), 
model, nsToUriMap);
     for (Iterator it = nsToUriMap.entrySet().iterator(); it.hasNext();){
       Map.Entry ent = (Map.Entry)it.next();    (039)

kifParser.addNamespaceMapping((String)ent.getKey(),(String)ent.getValue());
     }
     context.add(kifParser);    (040)

   }//ejbCreate    (041)

   /**
    * @param sessioncontext
    */
   public void setSessionContext( SessionContext sessioncontext 
){}//setSessionContext    (042)

   /**
    *
    */
   public void ejbRemove( ){}//ejbRemove    (043)

   /**
    *
    */
   public void ejbPassivate( ){}//ejbPassivate    (044)

   /**
    *
    */
   public void ejbActivate( ){}//ejbActivate    (045)

   /**
    *
    */
   public void remove( ){}//remove    (046)

   /**
    * @param localObject
    * @return boolean
    */
   public boolean isIdentical(EJBLocalObject localObject){ return 
false;}//isIdentical    (047)

   /**
    * @return EJBLocalHome
    */
   public EJBLocalHome getEJBLocalHome(){return null;}//getEJBLocalHome    (048)

   /**
    * @return Object
    */
   public Object getPrimaryKey(){return null;}//getPrimaryKey    (049)

}//TrustProviderProxyBean    (050)


> Pat
> 
> Patrick Cassidy
> MICRA, Inc.
> 908-561-3416
> cell: 908-565-4053
> cassidy@xxxxxxxxx
> 
> 
>  
> _________________________________________________________________
> Message Archives: http://ontolog.cim3.net/forum/ontolog-forum/  
> Subscribe/Config: http://ontolog.cim3.net/mailman/listinfo/ontolog-forum/  
> Unsubscribe: mailto:ontolog-forum-leave@xxxxxxxxxxxxxxxx
> Shared Files: http://ontolog.cim3.net/file/
> Community Wiki: http://ontolog.cim3.net/wiki/ 
> To Post: mailto:ontolog-forum@xxxxxxxxxxxxxxxx
>  
> 
>     (051)


-- 
Thanks Rick,
blog http://spout.rickmurphy.org
web  http://www.rickmurphy.org
cell 703-201-9129    (052)

_________________________________________________________________
Message Archives: http://ontolog.cim3.net/forum/ontolog-forum/  
Subscribe/Config: http://ontolog.cim3.net/mailman/listinfo/ontolog-forum/  
Unsubscribe: mailto:ontolog-forum-leave@xxxxxxxxxxxxxxxx
Shared Files: http://ontolog.cim3.net/file/
Community Wiki: http://ontolog.cim3.net/wiki/ 
To Post: mailto:ontolog-forum@xxxxxxxxxxxxxxxx    (053)

<Prev in Thread] Current Thread [Next in Thread>