OpenCyc20.java
Go to the documentation of this file.
00001 package instruction.opencyc;
00002 
00003 import java.io.IOException;
00004 import java.net.UnknownHostException;
00005 import java.util.ArrayList;
00006 import java.util.Iterator;
00007 
00008 import org.opencyc.api.CycApiException;
00009 import org.opencyc.api.CycObjectFactory;
00010 import org.opencyc.cycobject.CycList;
00011 import org.opencyc.cycobject.CycObject;
00012 import org.opencyc.cycobject.CycVariable;
00013 
00014 public class OpenCyc20 extends OpenCyc {
00015         
00016         protected CycObject defaultMt = null;
00017         
00018         protected OpenCyc20() throws UnknownHostException, CycApiException,
00019                         IOException {
00020                 super();
00021                 defaultMt = cyc.getConstantByName( "#$CurrentWorldDataCollectorMt-NonHomocentric" );
00022         }
00023         
00024         public static OpenCyc getInstance() throws UnknownHostException, CycApiException, IOException {
00025 
00026                 if ( me == null ) {
00027                         me = new OpenCyc20();
00028                         me.initializeCyc();
00029                 }
00030                 return me;
00031         }
00032         
00033         @SuppressWarnings("deprecation")
00034         public ArrayList<String> getCycConceptFromWordNetID(String synsetURI)
00035                         throws Exception {
00036                 // Ask Cyc for the concepts
00037                 CycList query = cyc.makeCycList( "(#$ist (#$ContextOfPCWFn (#$OWLOntologyFn \"http://www.w3.org/2006/03/wn/wn20/instances\")) "
00038                                 + "(#$seeAlsoURI ?CONCEPT \"" + synsetURI + "\"))" );
00039                 
00040                 CycVariable var = CycObjectFactory.makeCycVariable( "?CONCEPT" );
00041                 
00042                 CycObject mt = defaultMt;
00043 
00044                 CycList ret = cyc.askWithVariable( query, var, mt );
00045 
00046                 ArrayList<String> list = new ArrayList<String>();
00047                 for ( Iterator i = ret.iterator(); i.hasNext(); ) {
00048                         String str = i.next().toString();
00049                         if ( str.indexOf( "(" ) == - 1 && str.indexOf( ")" ) == - 1 && str.indexOf( " " ) == - 1 )
00050                                 list.add( str );
00051                 }
00052                 return list;
00053         }
00054         
00055         @Override
00056         public void addMapping(String synset, String concept) throws UnknownHostException, CycApiException, IOException {
00057                 CycList assertion = cyc.makeCycList( "(#$ist (#$ContextOfPCWFn (#$OWLOntologyFn \"http://www.w3.org/2006/03/wn/wn20/instances\")) " +
00058                                 "(#$seeAlsoURI #$" + concept + " \"" + synset + "\"))");
00059                 
00060                 cyc.assertGaf( assertion, defaultMt );
00061         }
00062         
00063         public static void main(String[] args) {
00064                 OpenCyc cyc;
00065                 try {
00066                         cyc = OpenCyc20.getInstance();
00067                         
00068                         cyc.addMapping("http://www.w3.org/2006/03/wn/wn20/instances/synset-own-verb-3", "possesses");
00069                         
00070                 } catch (UnknownHostException e) {
00071                         e.printStackTrace();
00072                 } catch (CycApiException e) {
00073                         e.printStackTrace();
00074                 } catch (IOException e) {
00075                         e.printStackTrace();
00076                 } catch (Exception e) {
00077                         e.printStackTrace();
00078                 }
00079         }
00080 
00081 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends


comp_ehow
Author(s): Moritz Tenorth, Daniel Nyga
autogenerated on Tue Apr 16 2013 00:18:02