private ConverseException(final Object command, CycAccess cyc, final Object[] response) { super( response[1].toString() + "\nrequest " + (cyc.hasStaticCycServer() ? "to " + (cyc.getHostName() + ":" + cyc.getBasePort()) : "") + " : " + makeRequestString(command)); if (response[1] instanceof CycApiException) { this.initCause((CycApiException) response[1]); } }
public CycServerInfoImpl(CycAccess cyc) { this.cyc = cyc; if ((cyc != null) && !cyc.isClosed()) { this.server = cyc.getCycServer(); } else { server = null; } try { reloadCache(); } catch (SessionCommunicationException ex) { throw new SessionApiRuntimeException(ex); } }
@Test public void testFactCycObject() throws Exception { System.out.println("Running testFactCycObject"); CycAccess cyc = CycAccessManager.getCurrentAccess(); FormulaSentence cfs = CycFormulaSentence.makeCycSentence(cyc, "(isa Plane-APITest CommercialAircraft)"); CycConstant cc = cyc.getLookupTool().find("SomeAirlineEquipmentMt"); CycAssertion ca = new CycAssertionImpl(cfs, cc); System.out.println("Assertion OC API: " + ca); FactImpl f = new FactImpl(ca); assertEquals(ca, f.getCore()); }
/** * Test to see if <code>compactExternalId</code> is a compact HL-ID, and return the relevant * object iff <code>compactExternalId</code> is the canonical id for the object. This is intended * to be used in cases where it's not known whether compactExternalId is in fact a valid compact * HL-ID, as it performs extra checks to make sure that the string is in fact the HL-ID for the * returned object. * * @param compactExternalId * @param access * @return the object uniquely identified by compactExternalId * @see #fromCompactExternalId(java.lang.String, com.cyc.base.CycAccess) * @throws IOException */ public static Object fromPossibleCompactExternalId(String compactExternalId, CycAccess access) throws CycConnectionException { if ((compactExternalId == null) || ("".equals(compactExternalId))) { throw new IllegalArgumentException(compactExternalId + "is not a valid compact external id."); } // @todo support CompactHLIDConverter.converter() once we can simply identify // if a compact external id is a String or Number Object result = compactExternalIdToCycObjectCache.get(compactExternalId); if (result != null) { return result; } try { if (CompactHLIDConverter.converter().isNumberCompactHLId(compactExternalId)) { Number num = (Number) CompactHLIDConverter.converter().fromCompactHLId(compactExternalId); result = CycObjectFactory.makeCycNumber(num); } else { result = access .converse() .converseList( "(multiple-value-list (maybe-find-object-by-compact-hl-external-id-string " + DefaultCycObject.stringApiValue(compactExternalId) + "))"); if (((CycArrayList) result).second() == CycObjectFactory.nil) { return null; } } } catch (IOException ioe) { throw new CycConnectionException(ioe); } compactExternalIdToCycObjectCache.put(compactExternalId, ((CycArrayList) result).first()); return ((CycArrayList) result).first(); }
/** * Return the sources to which this answer is attributed. * * @return the sources to which this answer is attributed. */ @Override public Collection<InformationSource> getSources( InformationSource.CitationGenerator citationGenerator) throws CycConnectionException { final String command = SubLAPIHelper.makeSubLStmt( "inference-answer-sources-from-signature", getId().cycListApiValue()); final Set<InformationSource> sources = new HashSet<InformationSource>(); final CycAccess cycAccess = getCycAccess(); for (final Object sourceObj : cycAccess.converse().converseList(command)) { if (sourceObj instanceof DenotationalTerm) { sources.add( new InformationSourceImpl((DenotationalTerm) sourceObj, citationGenerator, cycAccess)); } } return sources; }
public static String toCompactExternalId(Object cycObject, CycAccess access) throws CycConnectionException { if ((cycObject == null) || (!DefaultCycObject.isCycLObject(cycObject))) { throw new IllegalArgumentException(cycObject + "is not a valid CycL object."); } try { if (cycObject instanceof Number) { return CompactHLIDConverter.converter().toCompactHLId((Number) cycObject); } if (cycObject instanceof CycNumberImpl) { return CompactHLIDConverter.converter() .toCompactHLId(((CycNumberImpl) cycObject).getNumber()); } if (cycObject instanceof String) { return CompactHLIDConverter.converter().toCompactHLId((String) cycObject); } } catch (IOException ioe) { throw new CycConnectionException(ioe); } Object result = cycObjectToCompactExternalIdCache.get(cycObject); if (result != null) { return (String) result; } result = access .converse() .converseObject( "(compact-hl-external-id-string " + DefaultCycObject.stringApiValue(cycObject) + ")"); if (!(result instanceof String)) { throw new BaseClientRuntimeException("Got invalid result: " + result); } cycObjectToCompactExternalIdCache.put(cycObject, (String) result); return (String) result; }
/** * Returns whether the given Object represents a Cyc Collection. * * @return whether the given Object represents a Cyc Collection. */ public static boolean isCollection(Object term, CycAccess cycAccess) throws CycConnectionException { return cycAccess.getInspectorTool().isCollection(term); }