@Test public void testFactFactories() throws KBTypeException, CreateException, ParseException, DeleteException { // Only GAFs can be Fact.class System.out.println("Running testFactFactories"); System.out.println("Testing that only GAFs can be Facts"); try { @SuppressWarnings("deprecation") Fact f = FactImpl.get(KBObjectImpl.getCore(TestConstants.flyingRule)); } catch (KBObjectNotFoundException kboe) { // @todo isn't this an error/failure??? System.out.println("Got Exception: " + kboe.toString()); } SimpleDateFormat sdf = new SimpleDateFormat("yyyy MM dd HH:mm"); Context airlineLogMt = ContextImpl.findOrCreate("SomeAirlineLogMt"); KBIndividual flight = KBIndividualImpl.get("FlightXYZ-APITest"); Date d = sdf.parse("2014 03 15 10:20"); SentenceImpl s = new SentenceImpl(TestConstants.kbapitc.endingDate, flight, d); Assertion a = AssertionImpl.get(s, airlineLogMt); @SuppressWarnings("deprecation") Fact flDate = FactImpl.get(KBObjectImpl.getCore(a)); System.out.println("Testing HLID Factory"); String hlid = a.getId(); Fact flDate1 = FactImpl.get(hlid); assertTrue("Fact not equal to one from HLID", flDate1 == flDate); // Get based on formula and context strings System.out.println("Testing factory get(formulaStr, ctxStr)"); Fact flDate2 = FactImpl.get(s.toString(), airlineLogMt.toString()); assertTrue("Fact not equal to one from formulaStr, ctxStr", flDate2 == flDate); System.out.println("Testing factory get(formula, ctx)"); Fact flDate3 = FactImpl.get(s, airlineLogMt); assertTrue("Fact not equal to one from formula, ctx", flDate3 == flDate); FirstOrderCollectionImpl flying2Col = FirstOrderCollectionImpl.get("Flying-Move"); KBIndividual flight2 = KBIndividualImpl.findOrCreate("FlightABC-APITest", flying2Col, airlineLogMt); SentenceImpl s2 = new SentenceImpl(TestConstants.kbapitc.endingDate, flight2, d); FactImpl fl2Date = FactImpl.findOrCreate(s2, airlineLogMt); fl2Date.delete(); Fact fl3Date = FactImpl.findOrCreate(s2.toString(), airlineLogMt.toString()); assertFalse("Probably failed to assert, HLID is empty string", fl2Date.getId().equals("")); }
/* (non-Javadoc) * @see com.cyc.kb.Relation#getArityMax() */ @Override public Integer getArityMax() { try { Context ctx = Constants.uvMt(); String command = SubLAPIHelper.makeSubLStmt( WITH_MT, ctx.getCore(), SubLAPIHelper.makeNestedSubLStmt("max-arity", this.getCore())); Object object = getAccess().converse().converseObject(command); if (object == null || object.equals(CycObjectFactory.nil)) { throw new IllegalArgumentException("No known max-arity for " + this); } else { return (Integer) object; } } catch (CycConnectionException e) { throw new KBApiRuntimeException(e.getMessage(), e); } }