本文整理匯總了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;
}