opencyc - How to get a CycAccess object? -
there's lisp function in researchcyc called random-assertion. want call java code. i'm using cyc core api suite v1.0.0-rc5 (from http://dev.cyc.com), don't see way call underlying lisp code.
in old opencyc api there object called cycaccess use this, can't figure out how one. if find it, i'd call this
access.converseobject("(random-assertion)");
at least in researchcyc, retrieve pseudo-random assertion cyc knowledge base. not sure if work in opencyc, might work there.
can explain how call lisp-code through cyc's java api?
(disclaimer: 1 of developers of cyc apis...)
the reference implementation of core api suite core client, based on base client... which, in turn, derived old opencyc api. so, it's absolutely possible call arbitrary lisp (subl) code on researchcyc, in several different ways...
first of all, there method wraps random-assertion:
try { cycaccess access = cycaccessmanager.getcurrentaccess(); cycassertion cycassertion = access.getlookuptool().getrandomassertion(); } catch (sessionexception ex) { // exception... } catch (cycconnectionexception connex) { // else... } speaking general case, though, you'll find syntax similar opencyc api:
try { cycaccess access = cycaccessmanager.getcurrentaccess(); object cycassertion = access.converse().converseobject("(random-assertion)"); } catch (sessionexception ex) { // exception... } catch (cycconnectionexception connex) { // else... } or, if it's safe assume result cycobject:
... cycaccess access = cycaccessmanager.getcurrentaccess(); cycobject cycassertion = access.converse().conversecycobject("(random-assertion)"); ... however, base client adds new way of encapsulating subl functions, via com.cyc.baseclient.subl.sublfunction interface. sublfunction interface pretty minimal, there number of classes under com.cyc.baseclient.subl.subtypes provide implementations extend. example, if you're calling no-arg function , expect cycobject, extend sublcycobjectnoargfunction so:
public static final sublcycobjectnoargfunction random_assertion_function = new sublcycobjectnoargfunction("random-assertion"); ... try { cycaccess access = cycaccessmanager.getcurrentaccess(); cycobject cycassertion = random_assertion_function.eval(access); } catch (sessionexception ex) { // exception... } catch (cycconnectionexception connex) { // else... } (for other examples of this, see com.cyc.baseclient.subl.functions.* in base client.)
this approach makes simple define subl functions static fields without writing (or re-writing) code. expect core client gradually migrate towards approach.
lastly, can use implementation classes in kb client convert results kbobjects. example:
try { cycaccess access = cycaccessmanager.getcurrentaccess(); cycobject cycassertion = random_assertion_function.eval(access); // convert com.cyc.kb.assertion: assertion assertion = assertionimpl.get(cycassertion); // or, convert more general kbobject: kbobject kbobj = kbobjectimpl.get(cycassertion); } catch (sessionexception ex) { // exception... } catch (cycconnectionexception connex) { // else... } catch (kbtypeexception ex) { // potentially thrown assertionimpl#get() & kbobjectimpl#get() } catch (createexception ex) { // potentially thrown assertionimpl#get() & kbobjectimpl#get() }
Comments
Post a Comment