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.compiler;
 
Conjunctions and disjunctions are treated specially by this transform. The conjunction and disjunction operators may appear within any structure, but are only to be compiled as such if they are 'top-level'. They are considered top-level when they appear at the top-level within a clause, or directly beneath a parent conjunction or disjunction that is considered to be top-level. Effectively they are flattened into the top-level of the clause in which they appear, but the original structure is preserved rather than actually flattened at this time, as it can change meaning depending on how the term is bracketed.

This traversal simply marks all conjunctions and disjunctions that are part of the clause top-level, with the top-level flag. The functors appearing as arguments to those terms, are also marked as top-level, since they will be evaluated by the clause, not treated as structure definitions.

CRC Card
Responsibilities Collaborations
Check which functors are considered to be top-level within a clause.

Author(s):
Rupert Smith
 
 {
    
Used for debugging.
 
     /* private static final Logger log = Logger.getLogger(TopLevelCheckVisitor.class.getName()); */

    
Creates the visitor with the supplied interner, symbol table and traverser.

Parameters:
interner The name interner.
symbolTable The compiler symbol table.
traverser The positional context traverser.
 
         PositionalTermTraverser traverser)
     {
         super(internersymbolTabletraverser);
     }

    
 
     public void setPositionalTraverser(PositionalTermTraverser traverser)
     {
         this. = traverser;
     }

    

Sets the top-level flag on a functor, if appropriate.

 
     protected void enterFunctor(Functor functor)
     {
         if (isTopLevel())
         {
             .put(functor.getSymbolKey(), .true);
         }
     }

    
Functors are considered top-level when they appear at the top-level within a clause, or directly beneath a parent conjunction or disjunction that is considered to be top-level.

Returns:
true iff the current position is considered to be top-level.
 
     private boolean isTopLevel()
     {
         if (.isTopLevel())
         {
             return true;
         }
         else
         {
             PositionalContext parentContext = .getParentContext();
            if (parentContext != null)
            {
                Term parentTerm = parentContext.getTerm();
                if ((parentTerm instanceof Conjunction) || (parentTerm instanceof Disjunction))
                {
                    Boolean isTopLevel =
                        (Boolean.get(parentTerm.getSymbolKey(), .);
                    return (isTopLevel == null) ? false : isTopLevel;
                }
            }
        }
        return false;
    }
New to GrepCode? Check out our FAQ X