当前位置: 首页>>代码示例>>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;未经允许,请勿转载。