Terminology updated: children renamed to arguments
This commit is contained in:
parent
5ee965a88d
commit
14aa99a727
|
|
@ -32,7 +32,7 @@ public interface Term extends Comparable<Term> {
|
|||
|
||||
Object symbol();
|
||||
|
||||
Collection<? extends Term> children();
|
||||
Collection<? extends Term> arguments();
|
||||
|
||||
Term get();
|
||||
|
||||
|
|
|
|||
|
|
@ -119,15 +119,15 @@ public class UnionFindTermGraphUnifier {
|
|||
union(s, t);
|
||||
}
|
||||
|
||||
Iterator<? extends Term> scit = zs.children().iterator();
|
||||
Iterator<? extends Term> tcit = zt.children().iterator();
|
||||
Iterator<? extends Term> scit = zs.arguments().iterator();
|
||||
Iterator<? extends Term> tcit = zt.arguments().iterator();
|
||||
while (scit.hasNext() && tcit.hasNext()) {
|
||||
if (!unifClosure(scit.next(), tcit.next())) {
|
||||
return false; // children mismatch
|
||||
return false; // arguments mismatch
|
||||
}
|
||||
}
|
||||
|
||||
// fail if different children count
|
||||
// fail if different arguments count
|
||||
return scit.hasNext() == tcit.hasNext();
|
||||
}
|
||||
else {
|
||||
|
|
@ -204,7 +204,7 @@ public class UnionFindTermGraphUnifier {
|
|||
if (z.is(FUN)) {
|
||||
setVisited(z, true);
|
||||
|
||||
for (Term c : z.children()) {
|
||||
for (Term c : z.arguments()) {
|
||||
substitution = findSolution(c, substitution);
|
||||
|
||||
if (!substitution.isSuccessful()) {
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ public class AssertStructurallyEquivalent {
|
|||
@Override
|
||||
public Collection<? extends Term> visit(Term term) throws Exception {
|
||||
signature.label(term);
|
||||
return term.children();
|
||||
return term.arguments();
|
||||
}
|
||||
}
|
||||
,
|
||||
|
|
@ -56,7 +56,7 @@ public class AssertStructurallyEquivalent {
|
|||
@Override
|
||||
public Collection<? extends Term> visit(Term term) throws Exception {
|
||||
signature.appendSignature("@").append(signature.getLabel(term)).append(term.symbol());
|
||||
return term.children();
|
||||
return term.arguments();
|
||||
}
|
||||
},
|
||||
new TermVisitor<Term>(Term.Kind.VAR) {
|
||||
|
|
@ -177,12 +177,12 @@ public class AssertStructurallyEquivalent {
|
|||
if (term.is(Term.Kind.FUN)) {
|
||||
visited.put(term, SINGLETON);
|
||||
}
|
||||
Collection<? extends Term> children = switchClass(term);
|
||||
for (Term child : children) {
|
||||
if (visited.containsKey(child)) {
|
||||
Collection<? extends Term> arguments = switchClass(term);
|
||||
for (Term arg : arguments) {
|
||||
if (visited.containsKey(arg)) {
|
||||
continue;
|
||||
}
|
||||
walk(child, visited);
|
||||
walk(arg, visited);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ public abstract class MockTerm implements Term {
|
|||
public MockTerm() {
|
||||
}
|
||||
|
||||
public static Term term(Object sym, Term... children) {
|
||||
return new MockFun(sym, children);
|
||||
public static Term term(Object sym, Term... arguments) {
|
||||
return new MockFun(sym, arguments);
|
||||
}
|
||||
|
||||
public static Term var(String name) {
|
||||
|
|
@ -54,7 +54,7 @@ public abstract class MockTerm implements Term {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends Term> children() {
|
||||
public Collection<? extends Term> arguments() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -72,9 +72,9 @@ public abstract class MockTerm implements Term {
|
|||
private List<Term> myArgs;
|
||||
private Object mySymbol;
|
||||
|
||||
public MockFun(Object symbol, Term... children) {
|
||||
public MockFun(Object symbol, Term... arguments) {
|
||||
mySymbol = symbol;
|
||||
this.myArgs = Arrays.asList(children);
|
||||
this.myArgs = Arrays.asList(arguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -83,7 +83,7 @@ public abstract class MockTerm implements Term {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Collection<Term> children() {
|
||||
public Collection<Term> arguments() {
|
||||
return Collections.unmodifiableList(myArgs);
|
||||
}
|
||||
|
||||
|
|
@ -98,9 +98,9 @@ public abstract class MockTerm implements Term {
|
|||
if (!myArgs.isEmpty()) {
|
||||
sb.append("{");
|
||||
String sep = "";
|
||||
for (Term child : myArgs) {
|
||||
for (Term arg : myArgs) {
|
||||
sb.append(sep); sep = " ";
|
||||
sb.append(child.toString());
|
||||
sb.append(arg.toString());
|
||||
}
|
||||
sb.append("}");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public class MockTermsParser {
|
|||
private Token lastToken;
|
||||
private LinkedList<String> termsStack = new LinkedList<String>();
|
||||
private LinkedList<Integer> termLabelsStack = new LinkedList<Integer>();
|
||||
private LinkedList<List<Term>> childrenStack = new LinkedList<List<Term>>();
|
||||
private LinkedList<List<Term>> argumentsStack = new LinkedList<List<Term>>();
|
||||
private int lastLabel = -1;
|
||||
private Map<Integer, Term> termRefs = new HashMap<Integer, Term>();
|
||||
// initialized on the parse finished
|
||||
|
|
@ -67,7 +67,7 @@ public class MockTermsParser {
|
|||
checkFinalState();
|
||||
checkAllRefsExist();
|
||||
lookupHelper.setTermRefs(Collections.unmodifiableMap(new HashMap<Integer, Term>(termRefs)));
|
||||
return Collections.unmodifiableList(childrenStack.pop());
|
||||
return Collections.unmodifiableList(argumentsStack.pop());
|
||||
}
|
||||
|
||||
private void loop(String toParse) {
|
||||
|
|
@ -93,7 +93,7 @@ public class MockTermsParser {
|
|||
private void parseNextToken(Token token, String value) {
|
||||
switch (token) {
|
||||
case START:
|
||||
childrenStack.push(new ArrayList<Term>());
|
||||
argumentsStack.push(new ArrayList<Term>());
|
||||
break;
|
||||
case END:
|
||||
checkLastTokenOneOf(Token.TERM, Token.VAR, Token.VARREF, Token.RBRACE);
|
||||
|
|
@ -171,13 +171,13 @@ public class MockTermsParser {
|
|||
}
|
||||
|
||||
private void checkFinalState() {
|
||||
if (childrenStack.size() != 1 || childrenStack.peek().isEmpty() || !termsStack.isEmpty()) {
|
||||
if (argumentsStack.size() != 1 || argumentsStack.peek().isEmpty() || !termsStack.isEmpty()) {
|
||||
throw new ParseException("unexpected end of input");
|
||||
}
|
||||
}
|
||||
|
||||
private void checkCloseBraceState() {
|
||||
if (childrenStack.isEmpty() || childrenStack.peek().isEmpty() || termsStack.isEmpty()) {
|
||||
if (argumentsStack.isEmpty() || argumentsStack.peek().isEmpty() || termsStack.isEmpty()) {
|
||||
throw new ParseException("unexpected closing brace");
|
||||
}
|
||||
}
|
||||
|
|
@ -200,43 +200,43 @@ public class MockTermsParser {
|
|||
String name = termsStack.pop();
|
||||
Integer label = termLabelsStack.pop();
|
||||
Term newTerm = term(name);
|
||||
childrenStack.peek().add(newTerm);
|
||||
argumentsStack.peek().add(newTerm);
|
||||
if (label != null) {
|
||||
termRefs.put(label, newTerm);
|
||||
}
|
||||
}
|
||||
|
||||
private void beginChildren(){
|
||||
childrenStack.push(new ArrayList<Term>());
|
||||
argumentsStack.push(new ArrayList<Term>());
|
||||
}
|
||||
|
||||
private void endChildren() {
|
||||
List<Term> children = childrenStack.pop();
|
||||
List<Term> arguments = argumentsStack.pop();
|
||||
String name = termsStack.pop();
|
||||
Integer label = termLabelsStack.pop();
|
||||
Term newTerm = term(name, children.toArray(new Term[children.size()]));
|
||||
childrenStack.peek().add(newTerm);
|
||||
Term newTerm = term(name, arguments.toArray(new Term[arguments.size()]));
|
||||
argumentsStack.peek().add(newTerm);
|
||||
if (label != null) {
|
||||
termRefs.put(label, newTerm);
|
||||
}
|
||||
}
|
||||
|
||||
private void addVar(String name) {
|
||||
childrenStack.peek().add(var(name));
|
||||
argumentsStack.peek().add(var(name));
|
||||
}
|
||||
|
||||
private void addVarRef(String name) {
|
||||
childrenStack.peek().add(ref(var(name)));
|
||||
argumentsStack.peek().add(ref(var(name)));
|
||||
}
|
||||
|
||||
private void addRef(String ref) {
|
||||
final int label = Integer.parseInt(ref.substring(1));
|
||||
if (termRefs.containsKey(label) && termRefs.get(label) != null) {
|
||||
childrenStack.peek().add(ref(termRefs.get(label)));
|
||||
argumentsStack.peek().add(ref(termRefs.get(label)));
|
||||
}
|
||||
else {
|
||||
termRefs.put(label, null);
|
||||
childrenStack.peek().add(ref(lookupHelper.lookup(label)));
|
||||
argumentsStack.peek().add(ref(lookupHelper.lookup(label)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue