本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}