當前位置: 首頁>>代碼示例>>Java>>正文


Java Node類代碼示例

本文整理匯總了Java中org.galagosearch.core.retrieval.query.Node的典型用法代碼示例。如果您正苦於以下問題:Java Node類的具體用法?Java Node怎麽用?Java Node使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Node類屬於org.galagosearch.core.retrieval.query包,在下文中一共展示了Node類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getIterator

import org.galagosearch.core.retrieval.query.Node; //導入依賴的package包/類
/**
 * Given a query node, generates the corresponding iterator object that can be used
 * for structured retrieval.  This method just calls getClass() on the node,
 * then instantiates the resulting class.
 * 
 * If the class returned by getClass() is a ScoringFunction, it must contain
 * a constructor that takes a single Parameters object.  If the class returned by 
 * getFeatureClass() is some kind of StructuredIterator (either a ScoreIterator,
 * ExtentIterator or CountIterator), it must take a Parameters object and an
 * ArrayList of DocumentDataIterators as parameters.
 */
public StructuredIterator getIterator(Node node, ArrayList<StructuredIterator> childIterators) throws Exception {
    NodeType type = getNodeType(node);
    
    Constructor constructor = type.getConstructor();
    Class[] types = type.getParameterTypes(1 + childIterators.size());
        
    if (!isUsableConstructor(types, childIterators)) {
        throw new Exception("Couldn't find a reasonable constructor.");
    }
    
    Parameters parametersCopy = new Parameters();
    parametersCopy.copy(node.getParameters());
    Object[] args = argsForConstructor(constructor.getParameterTypes(),
                                       parametersCopy,
                                       childIterators);
    RequiredStatistics required =
        type.getIteratorClass().getAnnotation(RequiredStatistics.class);
    if (required != null) {
        for (String statistic : required.statistics()) {
            parametersCopy.add(statistic, parameters.get(statistic, null));
        }
    }
    return (StructuredIterator) constructor.newInstance(args);
}
 
開發者ID:jjfiv,項目名稱:galagosearch,代碼行數:36,代碼來源:FeatureFactory.java

示例2: afterNode

import org.galagosearch.core.retrieval.query.Node; //導入依賴的package包/類
public Node afterNode(Node node) throws Exception {
    ArrayList<Node> children = node.getInternalNodes();
    if (node.getOperator().equals("weight")) {
        // first, verify that the appropriate children are weights
        if (children.size() % 2 == 1) {
            throw new IOException("A weighted node cannot have an odd number of internal nodes: " +
                    node.getInternalNodes().size());
        }
                    
        // now, reassemble everything:
        ArrayList<Node> newChildren = new ArrayList<Node>();
        for (int i = 0; i < children.size(); i += 2) {
            Node weightNode = children.get(i);
            Node childNode = children.get(i+1);
            
            ArrayList<Node> newChild = new ArrayList<Node>();
            newChild.add(childNode);
            Node scaledNode = new Node("scale", getWeight(weightNode), newChild);
            newChildren.add(scaledNode);
        }

        return new Node("combine", newChildren);
    } else {
        return node;
    }
}
 
開發者ID:jjfiv,項目名稱:galagosearch,代碼行數:27,代碼來源:WeightConversionTraversal.java

示例3: afterNode

import org.galagosearch.core.retrieval.query.Node; //導入依賴的package包/類
public Node afterNode(Node original) throws Exception {
    String operator = original.getOperator();

    if (operator.equals("text")) {
        if (index.containsPart("stemmedPostings")) {
            return stemmedNode(original);
        } else if (index.containsPart("postings")) {
            return transformedNode(original, "extents", "postings");
        } else {
            return original;
        }
    } else if (operator.equals("field") || operator.equals("any")) {
        if (index.containsPart("extents")) {
            return transformedNode(original, "extents", "extents");
        } else {
            return original;
        }
    } else {
        return original;
    }
}
 
開發者ID:jjfiv,項目名稱:galagosearch,代碼行數:22,代碼來源:TextFieldRewriteTraversal.java

示例4: afterNode

import org.galagosearch.core.retrieval.query.Node; //導入依賴的package包/類
public Node afterNode(Node node) throws Exception {
    ArrayList<Node> newChildren = new ArrayList<Node>();
    NodeType nodeType = retrieval.getNodeType(node);
    if (nodeType == null) return node;
    ArrayList<Node> children = node.getInternalNodes();
    // Given that we're going to pass children.size() + 1 parameters to
    // this constructor, what types should those parameters have?
    Class[] types = nodeType.getParameterTypes(children.size() + 1);
    if (types == null) return node;

    for (int i = 1; i < types.length; ++i) {
        Node child = children.get(i-1);
        // If the parent will expect a ScoreIterator at this position, but
        // we've got a CountIterator here, we'll perform a conversion step.
        if (ScoreIterator.class.isAssignableFrom(types[i]) &&
            isCountNode(children.get(i-1))) {
            Node feature = createSmoothingNode(child);
            newChildren.add(feature);
        } else {
            newChildren.add(child);
        }
    }

    return new Node(node.getOperator(), node.getParameters(),
                    newChildren, node.getPosition());
}
 
開發者ID:jjfiv,項目名稱:galagosearch,代碼行數:27,代碼來源:ImplicitFeatureCastTraversal.java

示例5: testAfterWeighted

import org.galagosearch.core.retrieval.query.Node; //導入依賴的package包/類
public void testAfterWeighted() throws Exception {
    ArrayList<Node> internalNodes = new ArrayList<Node>();
    internalNodes.add(new Node("text", "1.0"));
    internalNodes.add(new Node("text", "dog"));
    Node root = new Node("weight", internalNodes);
    
    ArrayList<Node> expectedVeryInternal = new ArrayList<Node>();
    expectedVeryInternal.add(new Node("text", "dog"));
    ArrayList<Node> expectedInternal = new ArrayList<Node>();
    expectedInternal.add(new Node("scale", "1.0", expectedVeryInternal));
    Node expected = new Node("combine", expectedInternal);
    
    WeightConversionTraversal traversal = new WeightConversionTraversal(null, null);
    Node result = traversal.afterNode(root);
    assertEquals(expected, result);
}
 
開發者ID:jjfiv,項目名稱:galagosearch,代碼行數:17,代碼來源:WeightConversionTraversalTest.java

示例6: afterNode

import org.galagosearch.core.retrieval.query.Node; //導入依賴的package包/類
public Node afterNode(Node node) throws Exception {
    ArrayList<Node> children = new ArrayList<Node>();

    if (node.getOperator().equals("combine")) {
        ArrayList<Node> oldChildren = node.getInternalNodes();
        for (int i = 0; i < oldChildren.size(); i++) {
            Node child = oldChildren.get(i);
            boolean isStopword = child.getOperator().equals("text") &&
                                 words.contains(child.getDefaultParameter());
            if (!isStopword) {
                children.add(child);
            }
        }

        return new Node(node.getOperator(), children);
    }
    
    return node;
}
 
開發者ID:youngilcho,項目名稱:internet-application-2014,代碼行數:20,代碼來源:RemoveStopwordsTraversal.java

示例7: getNodeType

import org.galagosearch.core.retrieval.query.Node; //導入依賴的package包/類
public NodeType getNodeType(Node node) throws Exception {
    NodeType nodeType = index.getNodeType(node);
    if (nodeType == null) {
        nodeType = featureFactory.getNodeType(node);
    }
    return nodeType;
}
 
開發者ID:jjfiv,項目名稱:galagosearch,代碼行數:8,代碼來源:StructuredRetrieval.java

示例8: createIterator

import org.galagosearch.core.retrieval.query.Node; //導入依賴的package包/類
public StructuredIterator createIterator(Node node) throws Exception {
    ArrayList<StructuredIterator> internalIterators = new ArrayList<StructuredIterator>();

    for (Node internalNode : node.getInternalNodes()) {
        StructuredIterator internalIterator = createIterator(internalNode);
        internalIterators.add(internalIterator);
    }
    
    StructuredIterator iterator = index.getIterator(node);
    if (iterator == null) {
        iterator = featureFactory.getIterator(node, internalIterators);
    }
    
    return iterator;
}
 
開發者ID:jjfiv,項目名稱:galagosearch,代碼行數:16,代碼來源:StructuredRetrieval.java

示例9: transformQuery

import org.galagosearch.core.retrieval.query.Node; //導入依賴的package包/類
public Node transformQuery(Node queryTree) throws Exception {
    List<Traversal> traversals = featureFactory.getTraversals(this);
    for (Traversal traversal : traversals) {
        queryTree = StructuredQuery.copy(traversal, queryTree);
    }
    return queryTree;
}
 
開發者ID:jjfiv,項目名稱:galagosearch,代碼行數:8,代碼來源:StructuredRetrieval.java

示例10: runQuery

import org.galagosearch.core.retrieval.query.Node; //導入依賴的package包/類
/**
 * Evaluates a query.
 *
 * @param queryTree A query tree that has been already transformed with StructuredRetrieval.transformQuery.
 * @param requested The number of documents to retrieve, at most.
 * @return
 * @throws java.lang.Exception
 */
public ScoredDocument[] runQuery(Node queryTree, int requested) throws Exception {
    // construct the query iterators
    ScoreIterator iterator = (ScoreIterator) createIterator(queryTree);

    // now there should be an iterator at the root of this tree
    PriorityQueue<ScoredDocument> queue = new PriorityQueue<ScoredDocument>();

    while (!iterator.isDone()) {
        int document = iterator.nextCandidate();
        int length = index.getLength(document);
        double score = iterator.score(document, length);

        if (queue.size() <= requested || queue.peek().score < score) {
            ScoredDocument scoredDocument = new ScoredDocument(document, score);
            queue.add(scoredDocument);

            if (queue.size() > requested) {
                queue.poll();
            }
        }

        iterator.movePast(document);
    }

    return getArrayResults(queue);
}
 
開發者ID:jjfiv,項目名稱:galagosearch,代碼行數:35,代碼來源:StructuredRetrieval.java

示例11: getClassName

import org.galagosearch.core.retrieval.query.Node; //導入依賴的package包/類
public String getClassName(Node node) throws Exception {
    String operator = node.getOperator();

    if (operator.equals("feature")) {
        return getFeatureClassName(node.getParameters());
    }
    OperatorSpec operatorType = operatorLookup.get(operator);

    if (operatorType == null) {
        throw new IllegalArgumentException(
                "Unknown operator name: #" + operator);
    }
    return operatorType.className;
}
 
開發者ID:jjfiv,項目名稱:galagosearch,代碼行數:15,代碼來源:FeatureFactory.java

示例12: getClass

import org.galagosearch.core.retrieval.query.Node; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public Class<StructuredIterator> getClass(Node node) throws Exception {
    String className = getClassName(node);
    Class c = Class.forName(className);

    if (StructuredIterator.class.isAssignableFrom(c)) {
        return (Class<StructuredIterator>) c;
    } else {
        throw new Exception("Found a class, but it's not a DocumentDataIterator: " + className);
    }
}
 
開發者ID:jjfiv,項目名稱:galagosearch,代碼行數:12,代碼來源:FeatureFactory.java

示例13: getWeight

import org.galagosearch.core.retrieval.query.Node; //導入依賴的package包/類
public String getWeight(Node weightNode) {
    if (weightNode.getOperator().equals("inside")) {
        if (weightNode.getInternalNodes().size() != 2) {
            return "1";
        } else {
            Node inner = weightNode.getInternalNodes().get(0);
            Node outer = weightNode.getInternalNodes().get(1);
            return inner.getDefaultParameter() + "." + outer.getDefaultParameter();
        }
    } else {
        return weightNode.getDefaultParameter();
    }
}
 
開發者ID:jjfiv,項目名稱:galagosearch,代碼行數:14,代碼來源:WeightConversionTraversal.java

示例14: stemmedNode

import org.galagosearch.core.retrieval.query.Node; //導入依賴的package包/類
private Node stemmedNode(Node original) {
    Parameters parameters = original.getParameters().clone();
    parameters.add("part", "stemmedPostings");
    String term = parameters.get("default");
    stemmer.setCurrent(term);
    stemmer.stem();
    String stemmed = stemmer.getCurrent();
    parameters.set("default", stemmed);
    return new Node("extents", parameters, original.getInternalNodes(), original.getPosition());
}
 
開發者ID:jjfiv,項目名稱:galagosearch,代碼行數:11,代碼來源:TextFieldRewriteTraversal.java

示例15: afterNode

import org.galagosearch.core.retrieval.query.Node; //導入依賴的package包/類
public Node afterNode(Node original) throws Exception {
    levels--;
    if (levels > 0) {
        return original;
    } else if (!original.getOperator().equals("combine")) {
        // Only add a combine if the top level operator is not already a combine
        ArrayList<Node> originalChild = new ArrayList<Node>();
        originalChild.add(original);
        return new Node("combine", originalChild);
    } else {
        return original;
    }
}
 
開發者ID:jjfiv,項目名稱:galagosearch,代碼行數:14,代碼來源:AddCombineTraversal.java


注:本文中的org.galagosearch.core.retrieval.query.Node類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。