Exemplo n.º 1
0
  @Test
  public void testConstructAssertion() throws KBApiException {
    System.out.println("Running testConstructAssertion");
    // "(SomeAirlineEquipmentLogFn Plane-APITest)", "(flyingDoneBySomething-Move FlightXYZ-APITest
    // Plane-APITest)"
    KBPredicate p = KBPredicateImpl.get("flyingDoneBySomething-Move");
    KBIndividual flight = KBIndividualImpl.get("FlightXYZ-APITest");
    KBIndividual plane = KBIndividualImpl.get("Plane-APITest");
    List<Object> arguments = new ArrayList<Object>();
    arguments.add(flight);
    arguments.add(plane);

    Context ctx = ContextImpl.get("(SomeAirlineEquipmentLogFn Plane-APITest)");
    Fact a = new FactImpl(ctx, p, arguments.toArray());
    assertTrue("Unable to get a fact from " + p + " " + arguments, a instanceof Fact);
    // System.out.println("Fact string: " + a.toString());

    // With date

    ContextImpl airlineLog = ContextImpl.get("SomeAirlineLogMt");
    KBPredicate start = TestConstants.kbapitc.startingDate;

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy MM dd HH:mm");
    try {
      Date d = sdf.parse("2014 03 15 8:05");
      Fact wellA = new FactImpl(airlineLog, start, flight, d);
      Date checkd = wellA.<Date>getArgument(2);
      assertEquals(checkd, d);
    } catch (ParseException pe) {
      // ignore  ???@todo Aren't these failures, if we get here???
    }
  }
Exemplo n.º 2
0
  @Test
  public void testAddAndGetSentence() throws KBApiException {
    System.out.println("Running testAddAndGetSentence");
    KBIndividualImpl i = KBIndividualImpl.findOrCreate("SomeRandom-LS");
    i.isInstanceOf(KBCollectionImpl.get("LogicalSchema"));
    KBPredicateImpl p = KBPredicateImpl.get("meaningSentenceOfSchema");
    List<Object> l = new ArrayList<Object>();
    l.add(KBPredicateImpl.get("isa"));
    l.add(i);
    l.add(p);
    Sentence s = new SentenceImpl(l.toArray());

    i.addFact(ContextImpl.get("UniversalVocabularyMt"), p, 1, s);

    Collection<Fact> lfs = i.getFacts(p, 1, ContextImpl.get("UniversalVocabularyMt"));
    KBIndividual iback = lfs.iterator().next().<KBIndividual>getArgument(1);
    Sentence a = lfs.iterator().next().<Sentence>getArgument(2);
    assertTrue("Didn't get sentence", (a instanceof Sentence));
  }
Exemplo n.º 3
0
  @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(""));
  }
Exemplo n.º 4
0
  @Test
  public void testAddList() throws KBApiException {
    System.out.println("Running testAddList");

    // FIXME: this test is erroring again RCyc 4.0q. - nwinant, 2015-07-03
    assumeCycSessionRequirement(NotResearchCycRequirement.NOT_RESEARCHCYC);

    List<String> cities = new ArrayList<String>();
    cities.add("CityOfLosAngelesCA");
    cities.add("CityOfBrusselsBelgium");
    cities.add("CityOfCairoEgypt");

    SentenceImpl s =
        new SentenceImpl(
            BinaryPredicateImpl.get("flightDestinationList"),
            KBIndividualImpl.get("FlyingAPlane-APITest"),
            cities);
    Fact f = new FactImpl(ContextImpl.get("BaseKB"), s);
    assertTrue("Failed to get a Fact", f instanceof Fact);
  }