@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 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("")); }
@Test public void testFactContextObject() throws KBApiException { System.out.println("Running testFactContextObject"); Context uctx = Constants.uvMt(); Fact anA = new FactImpl( "(SomeAirlineEquipmentLogFn Plane-APITest)", "(flyingDoneBySomething-Move FlightXYZ-APITest Plane-APITest)"); Fact anAonA = new FactImpl( "(SomeAirlineEquipmentLogFn Plane-APITest)", "(#$assertionUtility (#$ist (SomeAirlineEquipmentLogFn Plane-APITest) (flyingDoneBySomething-Move FlightXYZ-APITest Plane-APITest)) 0.5 )"); KBPredicate p = KBPredicateImpl.get("assertionUtility"); FactImpl a = new FactImpl(uctx, p, anA, 0.89); assertEquals( "(ist UniversalVocabularyMt (assertionUtility (() ((#$flyingDoneBySomething-Move #$FlightXYZ-APITest #$Plane-APITest))) 0.89))", a.toString()); assertEquals(a.getContext().toString(), "UniversalVocabularyMt"); }
@Test public void testDelete() throws KBApiException { System.out.println("Running testDelete"); KBIndividual i = KBIndividualImpl.findOrCreate("PlaneTwo-APITest"); Fact a = new FactImpl("#$SomeAirlineEquipmentMt", "(#$isa #$PlaneTwo-APITest #$CommercialAircraft)"); assertEquals( "(ist SomeAirlineEquipmentMt (isa PlaneTwo-APITest CommercialAircraft))", a.toString()); a.delete(); try { Fact a2 = FactImpl.get( "(#$isa #$PlaneTwo-APITest #$CommercialAircraft)", "#$SomeAirlineEquipmentMt"); } catch (CreateException ce) { // @todo is this supposed to be a failure???? System.out.println("Exception: " + ce.getClass().getSimpleName() + " : " + ce.getMessage()); } }