1
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 public class IndriWindowCompatibilityTraversal implements Traversal {
19 public Node afterNode(Node original) {
20 String operator = original.getOperator();
21 ArrayList<Node> children = original.getInternalNodes();
22
23 if (operator.length() == 0) {
24 return original;
25 }
26
27 if (Character.isDigit(operator.codePointAt(0))) {
28
29 return new Node("od", operator, children, original.getPosition());
30 } else if (operator.startsWith("od") &&
31 operator.length() > 2 &&
32 Character.isDigit(operator.codePointAt(2))) {
33
34 return new Node("od", operator.substring(2),
35 children, original.getPosition());
36 } else if (operator.startsWith("uw") &&
37 operator.length() > 2 &&
38 Character.isDigit(operator.codePointAt(2))) {
39
40 return new Node("uw", operator.substring(2),
41 children, original.getPosition());
42 }
43
44 return original;
45 }
46
47 public void beforeNode(Node object) throws Exception {
48
49 }
50 }