Exemplo n.º 1
0
 /**
  * Returns an array of all {@link Term}s that make up the conjunction represented by the specified
  * {@link Term}.
  *
  * <p>If the specified {@link Term} does not represent a conjunction then it will be used as the
  * only element in the returned array.
  */
 public static Term[] toArrayOfConjunctions(Term t) {
   List<Term> l = new ArrayList<>();
   while (isConjunction(t)) {
     l.add(0, t.getArgs()[1]);
     t = t.getArgs()[0];
   }
   l.add(0, t);
   return l.toArray(new Term[l.size()]);
 }
 private void assertMultipleResultsTailRecursive(String input) {
   Term parsedSentence = TestUtils.parseSentence(input);
   assertFalse(isSingleResultTailRecursive(copyClauses(), parsedSentence.getArgs()));
 }
Exemplo n.º 3
0
 /** Returns a {@link Predicate} instance for the specified {@link Term}. */
 public static Predicate getPredicate(KnowledgeBase kb, Term t) {
   return kb.getPredicateFactory(t).getPredicate(t.getArgs());
 }
Exemplo n.º 4
0
 /**
  * Returns {@code true} if the specified {@link Term} represent a conjunction, else {@code false}.
  *
  * <p>A {@link Term} is judged to represent a conjunction if is a structure with a functor of
  * {@link #CONJUNCTION_PREDICATE_NAME} and exactly two arguments.
  */
 public static boolean isConjunction(Term t) {
   // is relying on assumption that conjunctions are only, and always, represented by a comma
   return t.getType() == TermType.STRUCTURE
       && CONJUNCTION_PREDICATE_NAME.equals(t.getName())
       && t.getArgs().length == 2;
 }