DaveS February 2016

How to get a CycAccess object?

There's a lisp function in ResearchCyc called random-assertion. I want to call that from some Java code. I'm using the Cyc Core API Suite v1.0.0-rc5 (from http://dev.cyc.com), but I don't see any way to call underlying Lisp code.

In the old OpenCyc API there was an object called CycAccess that you could use for this, but I can't figure out how to get one. If I could find it, I'd call this

access.converseObject("(random-assertion)");

At least in ResearchCyc, this would retrieve a pseudo-random assertion from the Cyc knowledge base. Not sure if it would work in OpenCyc, but it might also work there.

Can someone explain how to call lisp-code like this through Cyc's java API?

Answers


Nathan Winant February 2016

(Disclaimer: I am one of the developers of the Cyc APIs...)

The reference implementation of the Core API Suite is the Core Client, which is based on the Base Client... which, in turn, is derived from the old OpenCyc API. So, it's absolutely possible to call arbitrary lisp (SubL) code on ResearchCyc, in several different ways...

First of all, there already is a method which wraps random-assertion:

try {
  CycAccess access = CycAccessManager.getCurrentAccess();
  CycAssertion cycAssertion = access.getLookupTool().getRandomAssertion();
} catch (SessionException ex) {
  // Do something with the exception...
} catch (CycConnectionException connEx) {
  // Do something else...
}

Speaking to the general case, though, you'll find that the syntax is fairly similar to the OpenCyc API:

try {
  CycAccess access = CycAccessManager.getCurrentAccess();
  Object cycAssertion = access.converse().converseObject("(random-assertion)");
} catch (SessionException ex) {
  // Do something with the exception...
} catch (CycConnectionException connEx) {
  // Do something else...
}

Or, if it's safe to assume that the result will be a CycObject:

  ...
  CycAccess access = CycAccessManager.getCurrentAccess();
  CycObject cycAssertion = access.converse().converseCycObject("(random-assertion)");
  ...

However, the Base Client adds a new way of encapsulating SubL functions, via the com.cyc.baseclient.subl.SublFunction interface. The SublFunction interface itself is pretty minimal, but there are a number of classes under com.cyc.baseclient.subl.subtypes which provide implementations for you to extend. For example, if you're calling a no-arg function and expect back a CycObject, you could extend SublCycObjectNoArgFunction like so:

public static final SublCycObjectNoArgFunction RANDOM_ASSERTION_FUNCTION = 
      new SublCycObjectNoArgFunction("random-asserti 

Post Status

Asked in February 2016
Viewed 3,971 times
Voted 9
Answered 1 times

Search




Leave an answer