public List < Variable > unify ( Term query , Term statement ) { /*log.fine("unify(Term left = " + query + ", Term right = " + statement + "): called");*/ // Find all free variables in the query. Set < Variable > freeVars = TermUtils . findFreeNonAnonymousVariables ( query ) ; // Build up all the variable bindings in both sides of the unification in these bindings. List < Variable > queryBindings = new LinkedList < Variable > ( ) ; List < Variable > statementBindings = new LinkedList < Variable > ( ) ; // Fund the most general unifier, if possible. boolean unified = unifyInternal ( query , statement , queryBindings , statementBindings ) ; List < Variable > results = null ; // If a unification was found, only retain the free variables in the query in the results returned. if ( unified ) { queryBindings . retainAll ( freeVars ) ; results = new ArrayList < Variable > ( queryBindings ) ; } return results ; }
Unifies two terms and produces a list of bound variables that form the unification when it it possible .