public static ATermList nnf(final ATermList list) { ATermList newList = factory.makeList(); for (final ATerm term : list) newList = newList.append(nnf((ATermAppl) term)); return newList; }
public static ATermList nnf(final ATermList list) { ATermList newList = factory.makeList(); for (final ATerm term : list) newList = newList.append(nnf((ATermAppl) term)); return newList; }
/** * {@inheritDoc} TODO */ @Override public ATermAppl rollUpTo(final ATermAppl var, final Collection<ATermAppl> stopList, final boolean stopOnConstants) { if (getDistVarsForType(VarType.LITERAL).contains(var) && !getDistVarsForType(VarType.INDIVIDUAL).contains(var) && !_individualsAndLiterals.contains(var)) throw new InternalReasonerException("Trying to roll up to the variable '" + var + "' which is not distinguished and _individual."); ATermList classParts = ATermUtils.EMPTY_LIST; final Set<ATermAppl> visited = new HashSet<>(); if (stopOnConstants) visited.addAll(getConstants()); final Collection<QueryAtom> inEdges = findAtoms(QueryPredicate.PropertyValue, null, null, var); for (final QueryAtom a : inEdges) classParts = classParts.append(rollEdgeIn(QueryPredicate.PropertyValue, a, visited, stopList)); final Collection<QueryAtom> outEdges = findAtoms(QueryPredicate.PropertyValue, var, null, null); for (final QueryAtom a : outEdges) classParts = classParts.append(rollEdgeOut(QueryPredicate.PropertyValue, a, visited, stopList)); classParts = classParts.concat(getClasses(var)); return ATermUtils.makeAnd(classParts); }
/** * {@inheritDoc} TODO */ @Override public ATermAppl rollUpTo(final ATermAppl var, final Collection<ATermAppl> stopList, final boolean stopOnConstants) { if (getDistVarsForType(VarType.LITERAL).contains(var) && !getDistVarsForType(VarType.INDIVIDUAL).contains(var) && !_individualsAndLiterals.contains(var)) throw new InternalReasonerException("Trying to roll up to the variable '" + var + "' which is not distinguished and _individual."); ATermList classParts = ATermUtils.EMPTY_LIST; final Set<ATermAppl> visited = new HashSet<>(); if (stopOnConstants) visited.addAll(getConstants()); final Collection<QueryAtom> inEdges = findAtoms(QueryPredicate.PropertyValue, null, null, var); for (final QueryAtom a : inEdges) classParts = classParts.append(rollEdgeIn(QueryPredicate.PropertyValue, a, visited, stopList)); final Collection<QueryAtom> outEdges = findAtoms(QueryPredicate.PropertyValue, var, null, null); for (final QueryAtom a : outEdges) classParts = classParts.append(rollEdgeOut(QueryPredicate.PropertyValue, a, visited, stopList)); classParts = classParts.concat(getClasses(var)); return ATermUtils.makeAnd(classParts); }
/** * {@inheritDoc} TODO */ @Override public ATermAppl rollUpTo(final ATermAppl var, final Collection<ATermAppl> stopList, final boolean stopOnConstants) { if (getDistVarsForType(VarType.LITERAL).contains(var) && !getDistVarsForType(VarType.INDIVIDUAL).contains(var) && !_individualsAndLiterals.contains(var)) throw new InternalReasonerException("Trying to roll up to the variable '" + var + "' which is not distinguished and _individual."); ATermList classParts = ATermUtils.EMPTY_LIST; final Set<ATermAppl> visited = new HashSet<>(); if (stopOnConstants) visited.addAll(getConstants()); final Collection<QueryAtom> inEdges = findAtoms(QueryPredicate.PropertyValue, null, null, var); for (final QueryAtom a : inEdges) classParts = classParts.append(rollEdgeIn(QueryPredicate.PropertyValue, a, visited, stopList)); final Collection<QueryAtom> outEdges = findAtoms(QueryPredicate.PropertyValue, var, null, null); for (final QueryAtom a : outEdges) classParts = classParts.append(rollEdgeOut(QueryPredicate.PropertyValue, a, visited, stopList)); classParts = classParts.concat(getClasses(var)); return ATermUtils.makeAnd(classParts); }
public void testList() { ATermList list = (ATermList) _factory.parse("[1,2,3]"); ATermList result = list.remove(_factory.parse("2")); test_assert(result.equals(_factory.parse("[1,3]"))); list = (ATermList) _factory.parse("[1,2,3]"); result = list.replace(_factory.parse("99"), 1); test_assert(result.equals(_factory.parse("[1,99,3]"))); list = _factory.makeList(); result = list.append(_factory.parse("1")); test_assert(result.equals(_factory.parse("[1]"))); list = (ATermList) _factory.parse("[]"); result = _factory.makeList(); test_assert(result.equals(list)); // System.out.println("pass: testList"); }
/** * Filter non-primes * * @param numbers * @return List of primes. */ private ATermList filterNonPrimes(final ATermList listOfnumbers) { ATermList numbers = listOfnumbers; ATermList primes = _factory.makeList(); numbers = numbers.getNext(); while (!numbers.isEmpty()) { final ATermInt prime = (ATermInt) numbers.getFirst(); numbers = filterMultiples(prime.getInt(), numbers); primes = primes.append(prime); } return _factory.makeList(_factory.makeInt(1), primes); }
test(Ts[4].append(_factory.makeInt(7)).equals(Ts[5]), "append-1");