Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright The Sett Ltd, 2005 to 2014.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package com.thesett.aima.logic.fol.wam;
 
TermWalkers is a helper class that supplies various types of searched over com.thesett.aima.logic.fol.Term abstract syntax trees.

CRC Card
Responsibilities Collaborations
Provide a walkers over term trees.

Author(s):
Rupert Smith
 
 public class TermWalkers
 {
    
Predicate matching conjunction and disjunction operators.
 
     public static final UnaryPredicate<TermCONJ_DISJ_OP_SYMBOL_PREDICATE =
         new UnaryPredicate<Term>()
         {
             public boolean evaluate(Term term)
             {
                 return (term instanceof OpSymbol) &&
                     (((OpSymbolterm).getTextName().equals(";") || ((OpSymbolterm).getTextName().equals(","));
             }
         };

    
Provides a simple depth first walk over a term.

Parameters:
visitor The visitor to apply to each term.
Returns:
A simple depth first walk over a term.
 
     public static TermWalker simpleWalker(TermVisitor visitor)
     {
 
         return new TermWalker(searchnew DefaultTraverser(), visitor);
     }

    
Provides a depth first walk over a term, visiting only when a goal predicate matches.

Parameters:
unaryPredicate The goal predicate.
visitor The visitor to apply to each term.
Returns:
A depth first walk over a term, visiting only when a goal predicate matches.
 
     public static TermWalker goalWalker(UnaryPredicate<TermunaryPredicateTermVisitor visitor)
     {
         TermWalker walker = simpleWalker(visitor);
         walker.setGoalPredicate(unaryPredicate);
 
         return walker;
     }

    
Provides a positional depth first walk over a term.

Parameters:
visitor The visitor to apply to each term, and to notify of positional context changes.
Returns:
A positional depth first walk over a term.
 
     public static TermWalker positionalWalker(PositionalTermVisitor visitor)
     {
         PositionalTermTraverser positionalTraverser = new PositionalTermTraverserImpl();
         positionalTraverser.setContextChangeVisitor(visitor);
         visitor.setPositionalTraverser(positionalTraverser);
 
         return new TermWalker(new DepthFirstBacktrackingSearch<TermTerm>(), positionalTraverservisitor);
     }

    
Provides a positional depth first walk over a term, visiting only when a goal predicate matches.

Parameters:
unaryPredicate The goal predicate.
visitor The visitor to apply to each term.
Returns:
A positional depth first walk over a term, visiting only when a goal predicate matches.
    public static TermWalker positionalGoalWalker(UnaryPredicate<TermunaryPredicatePositionalTermVisitor visitor)
    {
        TermWalker walker = positionalWalker(visitor);
        walker.setGoalPredicate(unaryPredicate);
        return walker;
    }

    
Provides a positional postfix walk over a term.

Parameters:
visitor The visitor to apply to each term, and to notify of positional context changes.
Returns:
A positional postfix first walk over a term.
    {
        PositionalTermTraverser positionalTraverser = new PositionalTermTraverserImpl();
        positionalTraverser.setContextChangeVisitor(visitor);
        visitor.setPositionalTraverser(positionalTraverser);
        return new TermWalker(new PostFixSearch<TermTerm>(), positionalTraverservisitor);
    }

    
Provides a walk over a term, that finds all conjunction and disjunction operators.

Parameters:
visitor The visitor to apply to each term.
Returns:
A walk over a term, that finds all conjunction and disjunction operators.
    {
        //return positionalGoalWalker(CONJ_DISJ_OP_SYMBOL_PREDICATE, visitor);
        return goalWalker(visitor);
    }
New to GrepCode? Check out our FAQ X