当前位置: 首页>>代码示例>>Java>>正文


Java IndexedWord类代码示例

本文整理汇总了Java中edu.stanford.nlp.ling.IndexedWord的典型用法代码示例。如果您正苦于以下问题:Java IndexedWord类的具体用法?Java IndexedWord怎么用?Java IndexedWord使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


IndexedWord类属于edu.stanford.nlp.ling包,在下文中一共展示了IndexedWord类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: wordsToPosMergedSeq

import edu.stanford.nlp.ling.IndexedWord; //导入依赖的package包/类
/**
 * Given a sequence of indexed words, return a string in the format "[POS1] [POS2] ... [POSn]"
 * Same as "wordsToPosMergedNerSeq", the difference being that this function returns sequence of POS tags only 
 * (ignores the NER types)  
 * When we have a verb, noun, adverb,...unify them under a "common" POS tag (e.g:VB for all verbs, NN for all nouns,etc.)
 * @param words: a list of indexed words
 * @return a string in the format "[POS1] [POS2] ... [POSn]"
 */
public static String wordsToPosMergedSeq(ObjectArrayList<IndexedWord> words){
    StringBuffer sbSeq = new StringBuffer();
    for (int i = 0; i < words.size(); i++){
        if (isAdj(words.get(i).tag()))
            sbSeq.append(POS_TAG.JJ);
        else if (isAdverb(words.get(i).tag()))
            sbSeq.append(POS_TAG.RB);
        else if (isNoun(words.get(i).tag()))
            sbSeq.append(POS_TAG.NN);
        else if (isPronoun(words.get(i).tag()))
            sbSeq.append(POS_TAG.PR);
        else if (isVerb(words.get(i).tag()))
            sbSeq.append(POS_TAG.VB);
        else if (isWhPronoun(words.get(i).tag()))
            sbSeq.append(POS_TAG.WP);
        else sbSeq.append(words.get(i).tag());
                
        sbSeq.append(SEPARATOR.SPACE); 
    }
    return sbSeq.toString().trim();
}
 
开发者ID:gkiril,项目名称:minie,代码行数:30,代码来源:CoreNLPUtils.java

示例2: getChainedNouns

import edu.stanford.nlp.ling.IndexedWord; //导入依赖的package包/类
/**
 * Given a sequence of words and a pivot-word index, return the chained nouns from the left and from the right
 * of the pivot word.  
 * @param sequence: a sequence of words (list of IndexedWord)
 * @param wordInd: the index of the pivot word
 * @return a list of chained nouns to the left and the right of the pivot word (the pivot word is included)
 */
public static ObjectArrayList<IndexedWord> getChainedNouns(ObjectArrayList<IndexedWord> sequence, int wordInd){
    IntArrayList chainedNounsInd = new IntArrayList();
    
    // Get the chained nouns from left and right
    IntArrayList chainedNounsLeft = getChainedNounsFromLeft(sequence, chainedNounsInd.clone(), wordInd);
    IntArrayList chainedNounsRight = getChainedNounsFromRight(sequence, chainedNounsInd.clone(), wordInd);
    
    // Add all the words to the chained nouns
    chainedNounsInd.addAll(chainedNounsLeft);
    chainedNounsInd.add(wordInd);
    chainedNounsInd.addAll(chainedNounsRight);
    
    // IndexedWord chained nouns
    ObjectArrayList<IndexedWord> iChainedNouns = new ObjectArrayList<IndexedWord>();
    for (int i: FastUtil.sort(chainedNounsInd)){
        iChainedNouns.add(sequence.get(i));
    }
    
    return iChainedNouns;
}
 
开发者ID:gkiril,项目名称:minie,代码行数:28,代码来源:CoreNLPUtils.java

示例3: isIncludedAdverbial

import edu.stanford.nlp.ling.IndexedWord; //导入依赖的package包/类
/**
 * Checks whether the adverbial at position {@code index} in {@link #adverbials} is required to be output by ClausIE 
 * (e.g., adverbials indicating negation, such as "hardly").
 */
private boolean isIncludedAdverbial(int index, Options options) {
    Constituent constituent = constituents.get(index);
    String s;
    if (constituent instanceof IndexedConstituent) {
        IndexedConstituent indexedConstituent = (IndexedConstituent) constituent;
        IndexedWord root = indexedConstituent.getRoot();
        if (indexedConstituent.getSemanticGraph().hasChildren(root)) {
            return false;
        }
        s = root.lemma();
    } else {
        s = constituent.rootString();
    }
    return options.dictAdverbsInclude.contains(s);
}
 
开发者ID:gkiril,项目名称:minie,代码行数:20,代码来源:Clause.java

示例4: setQuantitiesFromWordList

import edu.stanford.nlp.ling.IndexedWord; //导入依赖的package包/类
/**
 * A helper function used in detectQuantities. When we have a list of quantity words, quantity edges and the 
 * sentence semantic graph, add quantities to the list of quantities and clear the reusable lists. 
 *  If there are quantities in the phrase, replace them with the word SOME_n_i, where i = the place of the quantity
 * (0 - subject, 1 - relation, 2 - object) and j = # of quantity within the phrase.
 * 
 * @param qWords: list of quantity indexed words
 * @param qEdges: list of semantic graph edges (reusable)
 * @param sentSemGraph: sentence semantic graph
 * @param i: used for ID-ying purposes of the quantities' annotations 
 * @param j: used for ID-ying purposes of the quantities' annotations 
 */
private void setQuantitiesFromWordList(ObjectArrayList<IndexedWord> qWords, ObjectArrayList<SemanticGraphEdge> qEdges, 
                                        SemanticGraph sentSemGraph, int i, int j){
    // Quantity ID
    StringBuffer sbId = new StringBuffer();
    if (i == 0)
        sbId.append(Quantity.SUBJECT_ID);
    else if (i == 1)
        sbId.append(Quantity.RELATION_ID);
    else
        sbId.append(Quantity.OBJECT_ID);
    sbId.append(CHARACTER.UNDERSCORE);
    sbId.append(j + 1); // Indexing starts from 1
    
    for (IndexedWord w: qWords){
        qEdges.add(sentSemGraph.getEdge(sentSemGraph.getParent(w), w));
    }
    
    // Add the quantity to the list
    this.quantities.add(new Quantity(qWords, qEdges, sbId.toString()));
    
    // Clear the lists
    qWords.clear();
    qEdges.clear();
}
 
开发者ID:gkiril,项目名称:minie,代码行数:37,代码来源:AnnotatedPhrase.java

示例5: findDescendantRelativeRelation

import edu.stanford.nlp.ling.IndexedWord; //导入依赖的package包/类
/** Finds the first occurrence of a grammatical relation or its descendants for a relative pronoun */
public static SemanticGraphEdge findDescendantRelativeRelation(SemanticGraph semanticGraph, IndexedWord root, 
        GrammaticalRelation rel) {
    List<SemanticGraphEdge> outedges = semanticGraph.getOutEdgesSorted(root);
    for (SemanticGraphEdge e : outedges) {
        if (e.getDependent().tag().charAt(0) == 'W' && rel.isAncestor(e.getRelation())) {
            return e;
        } else
            return findDescendantRelativeRelation(semanticGraph, e.getDependent(), rel);
    }
    return null;
}
 
开发者ID:gkiril,项目名称:minie,代码行数:13,代码来源:DpUtils.java

示例6: removeEdges

import edu.stanford.nlp.ling.IndexedWord; //导入依赖的package包/类
/** Removes some edges from the given semantic graph.
 * 
 * This method traverses the semantic graph starting from the given root. An edge is removed if
 * (1) its child appears in <code>excludeVertexes</code>, (2) its relation appears in
 * <code>excludeRelations</code>, or (3) the edge has the root as parent and its relation
 * appears in <code>excludeRelationsTop</code>. */
public static void removeEdges(SemanticGraph graph, IndexedWord root, Collection<IndexedWord> excludeVertexes,
        Collection<GrammaticalRelation> excludeRelations, Collection<GrammaticalRelation> excludeRelationsTop) {
    if (!excludeVertexes.contains(root)) {
        Set<SemanticGraphEdge> edgesToRemove = new HashSet<SemanticGraphEdge>();
        subgraph(graph, root, excludeVertexes, excludeRelations, excludeRelationsTop, edgesToRemove, 0);
        for (SemanticGraphEdge edge : edgesToRemove) {
            graph.removeEdge(edge);
        }
    }
}
 
开发者ID:gkiril,项目名称:minie,代码行数:17,代码来源:DpUtils.java

示例7: removePunctFromSemGraph

import edu.stanford.nlp.ling.IndexedWord; //导入依赖的package包/类
public static void removePunctFromSemGraph(SemanticGraph semanticGraph){
    for (IndexedWord vertex : new ArrayList<>(semanticGraph.vertexSet())){
        if (vertex.value().equals(",") || vertex.value().equals(".") || vertex.value().equals("\'\'")){
            semanticGraph.removeVertex(vertex);
        } 
    }
}
 
开发者ID:gkiril,项目名称:minie,代码行数:8,代码来源:DpUtils.java

示例8: filterTokens

import edu.stanford.nlp.ling.IndexedWord; //导入依赖的package包/类
/**
 * The dependency parse might contain some special tokens (or whole words) which we don't want. 
 * Filter those out. 
 * @return boolean: if true, the token needs to be filtered, false -> otherwise
 */
public static boolean filterTokens(IndexedWord word){
    return word.word().equals(".") || word.word().equals(",") || word.word().equals("-RRB-") || 
            word.word().equals("-LRB-") || word.word().equals("\"") || word.word().equals("\'\'") || 
            word.word().equals("``") || word.word().equals(";") || word.word().equals(":") || 
            word.word().equals("-") || (word.word().equals("'") && !word.tag().equals("POS")) || 
            word.word().equals("!") || word.word().equals("--") || word.word().equals("`") || 
            word.word().equals("?") || word.word().equals("-RCB-") || word.word().equals("-LCB-");
}
 
开发者ID:gkiril,项目名称:minie,代码行数:14,代码来源:DpUtils.java

示例9: getRootFromWordList

import edu.stanford.nlp.ling.IndexedWord; //导入依赖的package包/类
/**
 * Given a list of indexed words and a semantic graph, return the root word of the word list. We assume that
 * all the words from the list can be found in the semantic graph sg, and the words in wordList are connected
 * within the semantic graph of the sentence - sg, and that they all share a common root.
 * @param sg: semantic graph of the sentence
 * @param wordList: the phrase from the sentence, represented as a list of words
 * @return the root word from the phrase
 */
public static IndexedWord getRootFromWordList(SemanticGraph sg, ObjectArrayList<IndexedWord> wordList){
    // If the word list is consisted of one word - return that word
    if (wordList.size() == 1) return wordList.get(0);
    
    IndexedWord constituentRoot = null;
    
    // We only search as high as grandparents
    // constituentRoot = sg.getCommonAncestor(wordList.get(0), wordList.get(wordList.size()-1));

    // If the commonancestor is deeper in the tree, the constituent root is the word with shortest distance
    // to the root of the sentence
    int minPathToRoot = Integer.MAX_VALUE;
    int pathToRoot = -1;
    for (int i = 0; i < wordList.size(); i++){
        // The words with index -2 are the ones that cannot be found in the semantic graph (synthetic words)
        // This happens in the relations (see in clausie.ClauseDetector.java), and those words are the head words
        if (wordList.get(i).index() == -2){
            return wordList.get(i);
        }
        pathToRoot = sg.getShortestDirectedPathNodes(sg.getFirstRoot(), wordList.get(i)).size();
        if (pathToRoot < minPathToRoot){ //TODO: throws NPE sometimes
            minPathToRoot = pathToRoot;
            constituentRoot = wordList.get(i);
        }
    }

    return constituentRoot;
}
 
开发者ID:gkiril,项目名称:minie,代码行数:37,代码来源:CoreNLPUtils.java

示例10: extractCityOfLocation

import edu.stanford.nlp.ling.IndexedWord; //导入依赖的package包/类
/** If "city|town of LOCATION" => "LOCATION" "is" "city|town" **/
public void extractCityOfLocation() {
    // Reusable variable
    ObjectArrayList<AnnotatedPhrase> tempProp = new ObjectArrayList<>();
    IndexedWord subjRoot;
    IndexedWord objRoot;
    
    // Set the relation to be "is-a" relation
    this.setIsARelation();
    
    this.tPattern = TokenSequencePattern.compile(REGEX.T_CITY_OF_LOC);
    this.tMatcher = tPattern.getMatcher(CoreNLPUtils.getCoreLabelListFromIndexedWordList(this.sentence));
    while (this.tMatcher.find()){    
        ObjectArrayList<IndexedWord> mWords = CoreNLPUtils.listOfCoreMapWordsToIndexedWordList(this.tMatcher.groupNodes());
        for (IndexedWord w: mWords) {
            if (!w.ner().equals(NE_TYPE.LOCATION) && !w.tag().equals(POS_TAG.IN))
                this.obj.addWordToList(w);
            else{ 
                if (!w.tag().equals(POS_TAG.IN))
                    this.subj.addWordToList(w);
            }
        }
        
        // Add the subj/rel/obj to the temporary proposition and then to the real propositions
        subjRoot = CoreNLPUtils.getRootFromWordList(this.sentenceSemGraph, this.subj.getWordList());
        objRoot = CoreNLPUtils.getRootFromWordList(this.sentenceSemGraph, this.obj.getWordList());
        tempProp.add(new AnnotatedPhrase(this.subj.getWordList().clone(), subjRoot));
        tempProp.add(new AnnotatedPhrase(this.rel.getWordList().clone(), this.rel.getRoot()));
        tempProp.add(new AnnotatedPhrase(this.obj.getWordList().clone(), objRoot));
        this.propositions.add(new AnnotatedProposition(tempProp.clone(), new Attribution()));
                
        // Clean the variables
        tempProp.clear();
        this.subj.clear();
        this.obj.clear();
    }
    
    // Clear the relation
    this.rel.clear();
}
 
开发者ID:gkiril,项目名称:minie,代码行数:41,代码来源:ImplicitExtractions.java

示例11: getVerbRootFromWordList

import edu.stanford.nlp.ling.IndexedWord; //导入依赖的package包/类
/**
 * Given a list of indexed words and a semantic graph, return the root word of the word list. We assume that
 * all the words from the list can be found in the semantic graph sg, and the words in wordList are connected
 * within the semantic graph of the sentence - sg. If there are multiple words which have the shortest distance
 * to the sentence root, then choose the most-left verb. 
 * 
 * @param sg: sentence semantic graph
 * @param wordsList: list of words from which to choose "root" from
 * @return
 */
public static IndexedWord getVerbRootFromWordList(SemanticGraph sg, ObjectArrayList<IndexedWord> wordList){
    IndexedWord constituentRoot = null;
    IntArrayList shortestDirectedPathDistances = new IntArrayList();
    
    int minPathToRoot = Integer.MAX_VALUE;
    int pathToRoot = -1;
    
    for (int i = 0; i < wordList.size(); i++){
        // The words with index -2 are the ones that cannot be found in the semantic graph (synthetic words)
        // This happens in the relations (see in clausie.ClauseDetector.java), and those words are the head words
        if (wordList.get(i).index() == -2){
            return wordList.get(i);
        }
        pathToRoot = sg.getShortestDirectedPathNodes(sg.getFirstRoot(), wordList.get(i)).size();
        if (pathToRoot < minPathToRoot){
            minPathToRoot = pathToRoot;
        }
        shortestDirectedPathDistances.add(pathToRoot);
    }
    
    // If the shortest path is one element, return it, else, return the first verb containing that index
    if (FastUtil.countElement(minPathToRoot, shortestDirectedPathDistances) == 1)
        return wordList.get(shortestDirectedPathDistances.indexOf(minPathToRoot));
    else {
        for (int i = 0; i < shortestDirectedPathDistances.size(); i++){
            if (shortestDirectedPathDistances.getInt(i) == minPathToRoot){
                if (isVerb(wordList.get(i).tag())){
                    constituentRoot = wordList.get(i);
                    break;
                }
            }
        }
    }
    
    return constituentRoot;
}
 
开发者ID:gkiril,项目名称:minie,代码行数:47,代码来源:CoreNLPUtils.java

示例12: getSubgraph

import edu.stanford.nlp.ling.IndexedWord; //导入依赖的package包/类
/**
 * Given a semantic graph of a whole sentence (sg) and a "local root" node, get the subgraph from 'sg' which has 
 * 'localRoot' as a root. 
 * @param sg: semantic graph of the whole sentence
 * @param localRoot: the root of the subgraph
 * @return semantic graph object which is the subgraph from 'sg'
 */
public static SemanticGraph getSubgraph(SemanticGraph sg, IndexedWord localRoot){
    ObjectArrayList<TypedDependency> subGraphDependencies = getSubgraphTypedDependencies(sg, localRoot, 
                                                                        new ObjectArrayList<TypedDependency>());
    TreeGraphNode rootTGN = new TreeGraphNode(new CoreLabel(localRoot));
    EnglishGrammaticalStructure gs = new EnglishGrammaticalStructure(subGraphDependencies, rootTGN);
    return SemanticGraphFactory.generateUncollapsedDependencies(gs);
}
 
开发者ID:gkiril,项目名称:minie,代码行数:15,代码来源:CoreNLPUtils.java

示例13: getSubgraphTypedDependencies

import edu.stanford.nlp.ling.IndexedWord; //导入依赖的package包/类
private static ObjectArrayList<TypedDependency> getSubgraphTypedDependencies(SemanticGraph sg, IndexedWord parent, 
        ObjectArrayList<TypedDependency> tds){
    Set<IndexedWord> children = sg.getChildren(parent);
    
    for (IndexedWord child: children){
        GrammaticalRelation gRel = sg.getEdge(parent, child).getRelation();
        tds.add(new TypedDependency(gRel, parent, child));
        if (sg.hasChildren(child))
            getSubgraphTypedDependencies(sg, child, tds);
    }
    
    return tds; 
}
 
开发者ID:gkiril,项目名称:minie,代码行数:14,代码来源:CoreNLPUtils.java

示例14: ImplicitExtractions

import edu.stanford.nlp.ling.IndexedWord; //导入依赖的package包/类
/** Default constructor with empty elements, given the sentence and the dependency parse graph
 * @param sent: sentence as a list of indexed words
 * @param sg: the dependency parse graph
 */
public ImplicitExtractions(ObjectArrayList<IndexedWord> sent, SemanticGraph sg) {
    this.subj = new AnnotatedPhrase();
    this.rel = new AnnotatedPhrase();
    this.obj = new AnnotatedPhrase();
    this.sentence = sent.clone();
    this.propositions = new ObjectArrayList<>();
    this.sentenceSemGraph = sg;
}
 
开发者ID:gkiril,项目名称:minie,代码行数:13,代码来源:ImplicitExtractions.java

示例15: SubConstituent

import edu.stanford.nlp.ling.IndexedWord; //导入依赖的package包/类
/** Initialize an object with semantic graph only. Everything else is empty. **/
public SubConstituent(SemanticGraph sentenceSg){
    this.sg = sentenceSg;
    this.phraseRoot = new IndexedWord();
    this.phraseWords = new ObjectArrayList<>();
    this.chainedCandidates = new ObjectOpenHashSet<>();
    this.subTreeCandidates = new ObjectOpenHashSet<>();
    this.subConstituents = new ObjectOpenHashSet<>();
    this.stSubconstituents = new ObjectOpenHashSet<>();
    this.siblingCandidates = new ObjectOpenHashSet<>();
}
 
开发者ID:gkiril,项目名称:minie,代码行数:12,代码来源:SubConstituent.java


注:本文中的edu.stanford.nlp.ling.IndexedWord类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。