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


Java Annotation.get方法代码示例

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


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

示例1: extractSentences

import edu.stanford.nlp.pipeline.Annotation; //导入方法依赖的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: getStanfordSentimentRate

import edu.stanford.nlp.pipeline.Annotation; //导入方法依赖的package包/类
public int getStanfordSentimentRate(String sentimentText) {
    Properties props = new Properties();
    props.setProperty("annotators", "tokenize, ssplit, parse, sentiment");
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
    //StanfordCoreNLP
    int totalRate = 0;
    String[] linesArr = sentimentText.split("\\.");
    for (int i = 0; i < linesArr.length; i++) {
        if (linesArr[i] != null) {
            Annotation annotation = pipeline.process(linesArr[i]);
            for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
                Tree tree = sentence.get(SentimentCoreAnnotations.SentimentAnnotatedTree.class);
                int score = RNNCoreAnnotations.getPredictedClass(tree);
                totalRate = totalRate + (score - 2);
            }
        }
    }
    return totalRate;
}
 
开发者ID:wso2-incubator,项目名称:twitter-sentiment-analysis,代码行数:20,代码来源:StanfordNLP.java

示例3: traffer

import edu.stanford.nlp.pipeline.Annotation; //导入方法依赖的package包/类
public static String traffer(String word) {
    List<String> lemmas = new LinkedList<String>();
    // create an empty Annotation just with the given text
    Annotation document = new Annotation(word);
    // run all Annotators on this text
    stanfordCoreNLP.annotate(document);
    // Iterate over all of the sentences found
    List<CoreMap> sentences = document.get(SentencesAnnotation.class);
    for (CoreMap sentence : sentences) {
        // Iterate over all tokens in a sentence
        for (CoreLabel token : sentence.get(TokensAnnotation.class)) {
            // Retrieve and add the lemma for each word into the list of lemmas
            lemmas.add(token.get(LemmaAnnotation.class));
        }
    }
    if (lemmas.size() != 1) {
        System.out.println("bug!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    }
    return lemmas.get(0);
}
 
开发者ID:guozhaotong,项目名称:FacetExtract,代码行数:21,代码来源:StanfordLemmatizer.java

示例4: lemmatize

import edu.stanford.nlp.pipeline.Annotation; //导入方法依赖的package包/类
public List<List<String>> lemmatize(String documentText)
{
	List<List<String>> lemmas = new ArrayList<List<String>>();

	// create an empty Annotation just with the given text
	Annotation document = new Annotation(documentText);

	// run all Annotators on this text
	this.parser.annotate(document);

	// Iterate over all of the sentences found
	List<CoreMap> sentences = document.get(SentencesAnnotation.class);
	for(CoreMap sentence: sentences) {
		// Iterate over all tokens in a sentence
		List<String> sentence_lemmas = new ArrayList<String>();
		for (CoreLabel token: sentence.get(TokensAnnotation.class)) {
			// Retrieve and add the lemma for each word into the
			// list of lemmas
			sentence_lemmas.add(token.get(LemmaAnnotation.class));
		}
		lemmas.add(sentence_lemmas);
	}

	return lemmas;
}
 
开发者ID:uwnlp,项目名称:recipe-interpretation,代码行数:26,代码来源:Lemmatizer.java

示例5: tagAndTokenize

import edu.stanford.nlp.pipeline.Annotation; //导入方法依赖的package包/类
public Pair<List<String>, List<String>> tagAndTokenize(String documentText)
{
	List<String> tags = new ArrayList<String>();
	List<String> tokens = new ArrayList<String>();

	// create an empty Annotation just with the given text
	Annotation document = new Annotation(documentText);

	// run all Annotators on this text
	this.parser.annotate(document);

	// Iterate over all of the sentences found
	List<CoreMap> sentences = document.get(SentencesAnnotation.class);
	for(CoreMap sentence: sentences) {
		// Iterate over all tokens in a sentence
		for (CoreLabel token: sentence.get(TokensAnnotation.class)) {
			// Retrieve and add the lemma for each word into the
			// list of lemmas
			tags.add(token.get(PartOfSpeechAnnotation.class));
			tokens.add(token.word());
		}
	}

	return new Pair<List<String>, List<String>>(tags, tokens);
}
 
开发者ID:uwnlp,项目名称:recipe-interpretation,代码行数:26,代码来源:Lemmatizer.java

示例6: tag

import edu.stanford.nlp.pipeline.Annotation; //导入方法依赖的package包/类
public List<String> tag(String documentText)
{
	List<String> tags = new ArrayList<String>();

	// create an empty Annotation just with the given text
	Annotation document = new Annotation(documentText);

	// run all Annotators on this text
	this.parser.annotate(document);

	// Iterate over all of the sentences found
	List<CoreMap> sentences = document.get(SentencesAnnotation.class);
	for(CoreMap sentence: sentences) {
		// Iterate over all tokens in a sentence
		for (CoreLabel token: sentence.get(TokensAnnotation.class)) {
			// Retrieve and add the lemma for each word into the
			// list of lemmas
			tags.add(token.get(PartOfSpeechAnnotation.class));
		}
	}

	return tags;
}
 
开发者ID:uwnlp,项目名称:recipe-interpretation,代码行数:24,代码来源:Lemmatizer.java

示例7: lemmatizer

import edu.stanford.nlp.pipeline.Annotation; //导入方法依赖的package包/类
/** @return Lemmatized string, input string can be a word, sentence or paragraph */
public static String lemmatizer(String string) {
	List<String> lemmas = new ArrayList<>();
	// create an empty Annotation just with the given text
	Annotation annotation = new Annotation(string);
	// run all Annotators on this string
	pipeline.annotate(annotation);
	// Iterate over all of the sentences found
	List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
	for (CoreMap sentence : sentences) {
		// Iterate over all tokens in a sentence
		for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)) {
			// Retrieve and add the lemma for each word into the list of lemmas
			lemmas.add(token.get(CoreAnnotations.LemmaAnnotation.class));
		}
	}
	return String.join(" ", lemmas);
}
 
开发者ID:IsaacChanghau,项目名称:Word2VecfJava,代码行数:19,代码来源:Common.java

示例8: prepareSUTParser

import edu.stanford.nlp.pipeline.Annotation; //导入方法依赖的package包/类
/**
 * Prepares the check for a temporal expression.
 * 
 * @param cell
 *            Holds the column´s cell
 * @param pipeline
 *            Used for temporal expressions.
 * @param result
 *            Holds the intermediate result before executing this operation.
 * @return Holds the intermediate result after executing this operation.
 */

private int prepareSUTParser(String cell, AnnotationPipeline pipeline,
		int result) {
	if ((!cell.trim().isEmpty()) && (!cell.trim().equals("-")
			&& !cell.trim().equals("--") && !cell.trim().equals("---")
			&& !cell.trim().equals("n/a") && !cell.trim().equals("N/A")
			&& !cell.trim().equals("(n/a)")
			&& !cell.trim().equals("Unknown")
			&& !cell.trim().equals("unknown") && !cell.trim().equals("?")
			&& !cell.trim().equals("??") && !cell.trim().equals(".")
			&& !cell.trim().equals("null") && !cell.trim().equals("NULL")
			&& !cell.trim().equals("Null"))) {
		Annotation annotation = new Annotation(cell);
		annotation.set(CoreAnnotations.DocDateAnnotation.class,
				"2013-07-14");
		pipeline.annotate(annotation);

		List<CoreMap> timexAnnsAll = annotation
				.get(TimeAnnotations.TimexAnnotations.class);
		if (timexAnnsAll != null)
			if (!timexAnnsAll.isEmpty())
				result++;
	}
	return result;
}
 
开发者ID:olehmberg,项目名称:winter,代码行数:37,代码来源:FeatureSet.java

示例9: extractNER

import edu.stanford.nlp.pipeline.Annotation; //导入方法依赖的package包/类
public static List<String> extractNER(String doc){
    Annotation document = new Annotation(doc);

    pipeline.annotate(document);
    List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class);
    List<String> result = new ArrayList<String>();
    for(CoreMap sentence: sentences) {
        // traversing the words in the current sentence
        // a CoreLabel is a CoreMap with additional token-specific methods
        for (CoreLabel token: sentence.get(CoreAnnotations.TokensAnnotation.class)) {
            // this is the text of the token
            String word = token.get(CoreAnnotations.TextAnnotation.class);
            // this is the POS tag of the token
            String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class);
            // this is the NER label of the token
            String ne = token.get(CoreAnnotations.NamedEntityTagAnnotation.class);
            result.add(ne);
        }
    }
    return result;
}
 
开发者ID:intel-analytics,项目名称:InformationExtraction,代码行数:22,代码来源:RegexNerTest.java

示例10: getGender

import edu.stanford.nlp.pipeline.Annotation; //导入方法依赖的package包/类
@Override
public Gender getGender(String name) {
	Annotation document = new Annotation(name);

	pipeline.annotate(document);

	for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) {
		for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)) {
			String gender = token.get(MachineReadingAnnotations.GenderAnnotation.class);
			// System.out.println(token + ":" + gender);
			if (gender != null) {
				if (gender.equals("MALE")) {
					return Gender.MALE;
				} else if (gender.equals("FEMALE")) {
					return Gender.FEMALE;
				}
			}
		}
	}
	return Gender.UNKNOWN;
}
 
开发者ID:dice-group,项目名称:BENGAL,代码行数:22,代码来源:CoreNLPGenderDetector.java

示例11: getExampleTextFromSerGz

import edu.stanford.nlp.pipeline.Annotation; //导入方法依赖的package包/类
private static String getExampleTextFromSerGz(File f)
{
	String result = "";
	
		Annotation deserDoc = EntityLabeler.deserializeAnnotatedDoc(f.getAbsolutePath());
		List<CoreMap> sentences = deserDoc.get(SentencesAnnotation.class);
		for (int sentencenum = 0; sentencenum < sentences.size(); sentencenum++) 
		{
			CoreMap sentence = sentences.get(sentencenum);
			
			List<CoreLabel> labels = sentence.get(TokensAnnotation.class);
			
		 	for (int i = 0; i < labels.size(); i++) 
		 	{
		 		CoreLabel token = labels.get(i);
		 		String tokenstring = token.get(TextAnnotation.class);
		 		result += " " + tokenstring;
		 	}
		 	result = result.trim() + "\n";
		}
		
	return result;
}
 
开发者ID:stucco,项目名称:relation-bootstrap,代码行数:24,代码来源:Test.java

示例12: simpleTokenization

import edu.stanford.nlp.pipeline.Annotation; //导入方法依赖的package包/类
public LinkedList<String> simpleTokenization(String text) {
    LinkedList<String> res = new LinkedList<>();
    if (text != null) {
        Annotation qaTokens = new Annotation(text);
        pipelineTokens.annotate(qaTokens);
        List<CoreMap> qssTokens = qaTokens.get(CoreAnnotations.SentencesAnnotation.class);
        for (CoreMap sentenceTokens : qssTokens) {
            ArrayList<CoreLabel> tokens = (ArrayList<CoreLabel>) sentenceTokens.get(CoreAnnotations.TokensAnnotation.class);
            for (CoreLabel t : tokens) {
                String lemma = t.lemma();
                String pos = t.tag();
                if ((pos.startsWith("N") || pos.startsWith("V")) && !stopwords.contains(lemma)) {
                    res.add(lemma);
                }
            }
        }
    }
    return res;
}
 
开发者ID:UCLA-BD2K,项目名称:aztec-text-analysis-tools,代码行数:20,代码来源:Tokenizer.java

示例13: parsingTest

import edu.stanford.nlp.pipeline.Annotation; //导入方法依赖的package包/类
private static void parsingTest()
{
	//	String exampleText = "The software developer who inserted a major security flaw into OpenSSL 1.2.4.8, using the file foo/bar/blah.php has said the error was \"quite trivial\" despite the severity of its impact, according to a new report.  The Sydney Morning Herald published an interview today with Robin Seggelmann, who added the flawed code to OpenSSL, the world's most popular library for implementing HTTPS encryption in websites, e-mail servers, and applications. The flaw can expose user passwords and potentially the private key used in a website's cryptographic certificate (whether private keys are at risk is still being determined). This is a new paragraph about Apache Tomcat's latest update 7.0.1.";
	String exampleText = "Microsoft Windows 7 before SP1 has Sun Java cross-site scripting vulnerability Java SE in file.php (refer to CVE-2014-1234).";
	//	String exampleText = "Oracle DBRM has vulnerability in ABCD plug-in via abcd.1234 (found on abcd.com).";
	EntityLabeler labeler = new EntityLabeler();
	Annotation doc = labeler.getAnnotatedDoc("My Doc", exampleText);
	
	List<CoreMap> sentences = doc.get(SentencesAnnotation.class);

	for ( CoreMap sentence : sentences) 
	{
		for ( CoreLabel token : sentence.get(TokensAnnotation.class)) 
		{
			System.out.println(token.get(TextAnnotation.class) + "\t" + token.get(CyberAnnotation.class));
		}
		
		System.out.println("Entities:\n" + sentence.get(CyberEntityMentionsAnnotation.class));
	
		System.out.println("Parse Tree:\n" + sentence.get(TreeAnnotation.class));		
	}
}
 
开发者ID:stucco,项目名称:relation-bootstrap,代码行数:23,代码来源:Test.java

示例14: annotate

import edu.stanford.nlp.pipeline.Annotation; //导入方法依赖的package包/类
@Override
public void annotate(Annotation annotation) {
    if (annotation.has(CoreAnnotations.SentencesAnnotation.class)) {
        for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
            List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);

            for (CoreLabel token : tokens) {
                String pos = token.get(CoreAnnotations.PartOfSpeechAnnotation.class);
                if (pos != null) {
                    token.set(PikesAnnotations.SimplePosAnnotation.class, AnnotatorUtils.getSimplePos(pos));
                }
            }

        }
    } else {
        throw new RuntimeException("unable to find words/tokens in: " + annotation);
    }

}
 
开发者ID:dkmfbk,项目名称:pikes,代码行数:20,代码来源:SimplePosAnnotator.java

示例15: main

import edu.stanford.nlp.pipeline.Annotation; //导入方法依赖的package包/类
public static void main(String[] s) {
    Properties props = new Properties();
    props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
    StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

    // read some text in the text variable
    String text = "\"But I do not want to go among mad people,\" Alice remarked.\n" +
            "\"Oh, you can not help that,\" said the Cat: \"we are all mad here. I am mad. You are mad.\"\n" +
            "\"How do you know I am mad?\" said Alice.\n" +
            "\"You must be,\" said the Cat, \"or you would not have come here.\" This is awful, bad, disgusting";

    // create an empty Annotation just with the given text
    Annotation document = new Annotation(text);

    // run all Annotators on this text
    pipeline.annotate(document);

    List<CoreMap> sentences = document.get(CoreAnnotations.SentencesAnnotation.class);
    for (CoreMap sentence : sentences) {
        String sentiment = sentence.get(SentimentCoreAnnotations.SentimentClass.class);
        System.out.println(sentiment + "\t" + sentence);
    }
}
 
开发者ID:Vedenin,项目名称:java_in_examples,代码行数:24,代码来源:StanfordCoreNLPTest.java


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