Friday, November 20, 2009

Hello Worlds!

We’re not yet where we’d like to be,  but we’ve been working hard behind the scenes to give developers access to the power of semantic computing with Cyc.  You can get OpenCyc 2.0, which is cleaner and more complete, on SourceForge. Every term in Cyc is available as a Semantic Web URI for example, here is the concept for Malmö, Sweden where this post is being written, and there are open web services for concept lookup and taxonomic reasoning. If you’re a researcher or developer, and you want to access richer capabilities, you can license  ResearchCyc, and may want to attend Cycorp’s  Semantic Training in May 2010.

But maybe you just want to get an idea of why semantic computing with Cyc is different. Here (from Tony Brusseau, one of our senior developers, and Larry Lefkowitz, who had an idea) is our version of “Hello World”. Make that “Hello Worlds”:

import org.opencyc.cycobject.CycList;
import org.opencyc.cycobject.CycObject;
import org.opencyc.cycobject.CycConstant;
import org.opencyc.cycobject.DefaultCycObject;
import org.opencyc.api.CycAccess;

public static final void helloWorlds() {
   CycAccess access = null;
   try {
     access = new CycAccess("localhost", 3600); // @note: use actual server and port
     CycConstant planetInSolarSystem = (CycConstant)
       DefaultCycObject.fromCompactExternalId("Mx4rWIie-jN6EduAAADggVbxzQ", access);
     CycList planets = access.getAllInstances(planetInSolarSystem);
     for (Object planet : planets) {
       System.out.println("Hello '" +
           access.getImpreciseSingularGeneratedPhrase((CycObject)planet) + "'.");
   } catch (Exception e) {     e.printStackTrace();   }
finally {     if (access != null) {       access.close();     }   }

Hello 'Jupiter'.
Hello 'Mercury'.
Hello 'Venus'.
Hello 'Earth'.
Hello 'Mars'.
Hello 'Saturn'.
Hello 'Uranus'
Hello 'Neptune'.

- Witbrock

Reblog this post [with Zemanta]

No comments: