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


Java CoreMap.toString方法代码示例

本文整理汇总了Java中edu.stanford.nlp.util.CoreMap.toString方法的典型用法代码示例。如果您正苦于以下问题:Java CoreMap.toString方法的具体用法?Java CoreMap.toString怎么用?Java CoreMap.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在edu.stanford.nlp.util.CoreMap的用法示例。


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

示例1: extractSentences

import edu.stanford.nlp.util.CoreMap; //导入方法依赖的package包/类
/**
 * Split a document into array of sentences
 * 
 * @param text
 * @return
 * @throws Exception
 */
public static String[] extractSentences(String text) throws Exception {
	Properties props = new Properties();
	props.put("annotators", "tokenize, ssplit");
	StanfordCoreNLP pipeline = new StanfordCoreNLP();

	Annotation document = new Annotation(text);
	pipeline.annotate(document);

	List<CoreMap> sentences = document.get(SentencesAnnotation.class);
	String[] sentenceList = new String[sentences.size()];

	for (int i = 0; i < sentenceList.length; i++) {
		CoreMap sentence = sentences.get(i);
		sentenceList[i] = sentence.toString();
	}

	return sentenceList;
}
 
开发者ID:NLPReViz,项目名称:emr-nlp-server,代码行数:26,代码来源:TextUtil.java

示例2: findSentiment

import edu.stanford.nlp.util.CoreMap; //导入方法依赖的package包/类
public static int findSentiment(String tweet) {

		int mainSentiment = 0;
		if (tweet != null && tweet.length() > 0) {
			int longest = 0;
			Annotation annotation = pipeline.process(tweet);
			for (CoreMap sentence : annotation
					.get(CoreAnnotations.SentencesAnnotation.class)) {
				Tree tree = sentence
						.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class);
				int sentiment = RNNCoreAnnotations.getPredictedClass(tree);
				String partText = sentence.toString();
				if (partText.length() > longest) {
					mainSentiment = sentiment;
					longest = partText.length();
				}

			}
		}
		return mainSentiment;
	}
 
开发者ID:Activiti,项目名称:activiti-cloud-examples,代码行数:22,代码来源:NLP.java

示例3: findSentiment

import edu.stanford.nlp.util.CoreMap; //导入方法依赖的package包/类
public static int findSentiment(String text) {

       int mainSentiment = 0;
       if (text != null && text.length() > 0) {
           int longest = 0;
           Annotation annotation = pipeline.process(text);
           for (CoreMap sentence : annotation
                   .get(CoreAnnotations.SentencesAnnotation.class)) {
               Tree tree = sentence
                       .get(SentimentCoreAnnotations.AnnotatedTree.class);
               int sentiment = RNNCoreAnnotations.getPredictedClass(tree);
               String partText = sentence.toString();
               if (partText.length() > longest) {
                   mainSentiment = sentiment;
                   longest = partText.length();
               }

           }
       }
       return mainSentiment;
   }
 
开发者ID:dflick-pivotal,项目名称:sentimentr-release,代码行数:22,代码来源:NLP.java

示例4: unitsCompatible

import edu.stanford.nlp.util.CoreMap; //导入方法依赖的package包/类
/**
 * Find out all the relations that can possibly go with a particular
 * relation
 * 
 * @param numArg
 *            The argument (a number)
 * @param sentence
 * @return A list of relation names that can be possibly associated with
 *         this number. For example, if the Argument has percent as a unit,
 *         the returned list will have INTERNET and INF.
 */
public static ArrayList<String> unitsCompatible(Argument numArg, CoreMap sentence) {

	String sentString = sentence.toString();
	String tokenStr = numArg.getArgName();
	String parts[] = tokenStr.split("\\s+");
	int beginIdx = sentString.indexOf(parts[0]);
	int endIdx = beginIdx + parts[0].length();

	String front = sentString.substring(0, beginIdx);
	if (front.length() > 20) {
		front = front.substring(front.length() - 20);
	}
	String back = sentString.substring(endIdx);
	if (back.length() > 20) {
		back = back.substring(0, 20);
	}
	String utString = front + "<b>" + parts[0] + "</b>" + back;
	float values[][] = new float[1][1];
	List<? extends EntryWithScore<Unit>> unitsS = ue.parser.getTopKUnitsValues(utString, "b", 1, 0, values);

	// check for unit here....

	String unit = "";
	if (unitsS != null && unitsS.size() > 0) {
		unit = unitsS.get(0).getKey().getBaseName();
	}

	ArrayList<String> validRelations = new ArrayList<String>();
	for (String rel : relations) {
		if (unitRelationMatch(rel, unit)) {
			validRelations.add(rel);
		}
	}
	return validRelations;
}
 
开发者ID:NEO-IE,项目名称:numbertron,代码行数:47,代码来源:UnitsUtils.java

示例5: testStanfordCoreNLP

import edu.stanford.nlp.util.CoreMap; //导入方法依赖的package包/类
private static String[] testStanfordCoreNLP(String text) throws Exception {
    StanfordCoreNLP coreNLP = getStanfordCoreNLP();
    Annotation document = new Annotation(text);
    coreNLP.annotate(document);

    List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class);
    String[] result = new String[sentences.size()];
    int i = 0;
    for (CoreMap sentence : sentences) {
        result[i] = sentence.toString();
        i++;
    }
    return result;
}
 
开发者ID:Vedenin,项目名称:java_in_examples,代码行数:15,代码来源:SentenceDetectors.java


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