Coverage Report - org.galagosearch.core.retrieval.traversal.IndriWindowCompatibilityTraversal
 
Classes in this File Line Coverage Branch Coverage Complexity
IndriWindowCompatibilityTraversal
85%
11/13
62%
10/16
0
 
 1  
 // BSD License (http://www.galagosearch.org/license)
 2  
 package org.galagosearch.core.retrieval.traversal;
 3  
 
 4  
 import java.util.ArrayList;
 5  
 import org.galagosearch.core.retrieval.query.Node;
 6  
 import org.galagosearch.core.retrieval.query.Traversal;
 7  
 
 8  
 /**
 9  
  * Looks at the current node and attempts to rewrite Indri-style
 10  
  * operators in the Galago format.  It can rewrite three types of expressions:
 11  
  * <ul>
 12  
  *  <li>#<i>n</i> changes to #od:</i>n</i></li>
 13  
  *  <li>#od<i>n</i> changes to #od:<i>n</i></li>
 14  
  *  <li>#uw<i>n</i> changes to #uw:<i>n</i></li>
 15  
  * </ul>
 16  
  * @author trevor
 17  
  */
 18  12
 public class IndriWindowCompatibilityTraversal implements Traversal {
 19  
     public Node afterNode(Node original) {
 20  12
         String operator = original.getOperator();
 21  12
         ArrayList<Node> children = original.getInternalNodes();
 22  
 
 23  12
         if (operator.length() == 0) {
 24  0
             return original;
 25  
         }
 26  
 
 27  12
         if (Character.isDigit(operator.codePointAt(0))) {
 28  
             // this is a #n node, which is an ordered window node
 29  4
             return new Node("od", operator, children, original.getPosition());
 30  8
         } else if (operator.startsWith("od") &&
 31  
                 operator.length() > 2 &&
 32  
                 Character.isDigit(operator.codePointAt(2))) {
 33  
             // this is a #od3() node
 34  4
             return new Node("od", operator.substring(2),
 35  
                     children, original.getPosition());
 36  4
         } else if (operator.startsWith("uw") &&
 37  
                 operator.length() > 2 &&
 38  
                 Character.isDigit(operator.codePointAt(2))) {
 39  
             // this is a #uw3 node
 40  4
             return new Node("uw", operator.substring(2),
 41  
                     children, original.getPosition());
 42  
         }
 43  
 
 44  0
         return original;
 45  
     }
 46  
 
 47  
     public void beforeNode(Node object) throws Exception {
 48  
         // does nothing
 49  12
     }
 50  
 }