當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。