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


Java Annotation类代码示例

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


Annotation类属于edu.stanford.nlp.pipeline包,在下文中一共展示了Annotation类的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: tokenize

import edu.stanford.nlp.pipeline.Annotation; //导入依赖的package包/类
public LinkedList<String> tokenize(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 (!stopwords.contains(lemma)) {
                    String rep = representativeProvider.getRepresentative(lemma, pos);
                    if (!stopwords.contains(rep)) {
                        res.add(rep);
                    }
                }
            }
        }
    }
    return res;
}
 
开发者ID:UCLA-BD2K,项目名称:aztec-text-analysis-tools,代码行数:23,代码来源:Tokenizer.java

示例4: annotate

import edu.stanford.nlp.pipeline.Annotation; //导入依赖的package包/类
protected void annotate(StanfordCoreNLP pipeline, Annotation ann) {
	if (ann.get(CoreAnnotations.SentencesAnnotation.class) == null) {
		pipeline.annotate(ann);
	}
	else {
		if (ann.get(CoreAnnotations.SentencesAnnotation.class).size() == 1) {
			CoreMap sentence = ann.get(CoreAnnotations.SentencesAnnotation.class).get(0);

			for (CoreLabel token : sentence.get(CoreAnnotations.TokensAnnotation.class)) {
				token.remove(NaturalLogicAnnotations.OperatorAnnotation.class);
				token.remove(NaturalLogicAnnotations.PolarityAnnotation.class);
			}

			sentence.remove(NaturalLogicAnnotations.RelationTriplesAnnotation.class);
			sentence.remove(NaturalLogicAnnotations.EntailedSentencesAnnotation.class);
			sentence.remove(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class);
			sentence.remove(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);
			sentence.remove(SemanticGraphCoreAnnotations.EnhancedPlusPlusDependenciesAnnotation.class);

			pipeline.annotate(ann);
		}
	}
}
 
开发者ID:igr,项目名称:parlo,代码行数:24,代码来源:CoreNLPEngine.java

示例5: 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

示例6: 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

示例7: 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

示例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: main

import edu.stanford.nlp.pipeline.Annotation; //导入依赖的package包/类
public static void main(String[] args) {

        // 载入自定义的Properties文件
        StanfordCoreNLP pipeline = new StanfordCoreNLP("CoreNLP-chinese.properties");

        // 用一些文本来初始化一个注释。文本是构造函数的参数。
        Annotation annotation;

        annotation = pipeline.process("我爱北京天安门");

        // 从注释中获取CoreMap List,并取第0个值
        List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
        CoreMap sentence = sentences.get(0);

        // 从CoreMap中取出CoreLabel List,逐一打印出来
        List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class);
        System.out.println("字/词");
        System.out.println("-----------------------------");
        for (CoreLabel token : tokens) {
            String word = token.getString(TextAnnotation.class);
//            String pos = token.getString(PartOfSpeechAnnotation.class);
//            String ner = token.getString(NamedEntityTagAnnotation.class);
            System.out.println(word);
        }

    }
 
开发者ID:huyang1,项目名称:LDA,代码行数:27,代码来源:CoreNLPSegment.java

示例10: findSentiment

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

示例11: 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

示例12: 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

示例13: addDescriptionForm

import edu.stanford.nlp.pipeline.Annotation; //导入依赖的package包/类
static public void addDescriptionForm(String form, HashMap<Integer, Integer> indexes, int start,
        int numberOfTokens, TreeMap<Integer, DescriptionForm> forms, Annotation annotation,
        HashMap<String, GlossarioEntry> glossario) {
    Integer lemmaIndex = indexes.get(start);
    if (lemmaIndex == null) {
        return;
    }

    CoreLabel firstToken = annotation.get(CoreAnnotations.TokensAnnotation.class).get(lemmaIndex);
    CoreLabel endToken = annotation.get(CoreAnnotations.TokensAnnotation.class)
            .get(lemmaIndex + numberOfTokens - 1);
    Integer beginOffset = firstToken.get(CoreAnnotations.CharacterOffsetBeginAnnotation.class);
    Integer endOffset = endToken.get(CoreAnnotations.CharacterOffsetEndAnnotation.class);

    GlossarioEntry glossarioEntry = glossario.get(form);
    if (glossarioEntry == null) {
        return;
    }

    DescriptionForm descriptionForm = new DescriptionForm(
            beginOffset, endOffset, glossarioEntry);

    forms.put(beginOffset, descriptionForm);
}
 
开发者ID:dhfbk,项目名称:tint,代码行数:25,代码来源:ItalianReadability.java

示例14: ExtractPosTagsFile

import edu.stanford.nlp.pipeline.Annotation; //导入依赖的package包/类
@Override
public List<ExtractPosTag> ExtractPosTagsFile(File filePath) throws Exception {
       List<String> lstData=ExtractData(filePath);
       List<ExtractPosTag> lstTaggedSentences = new ArrayList<>();
       Properties props = new Properties();
       props.setProperty("annotators", "tokenize,ssplit,pos");
       StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
       for(String str:lstData)
       {
       Annotation annotation = new Annotation(str);
       pipeline.annotate(annotation);
       List<CoreMap> senten=annotation.get(CoreAnnotations.SentencesAnnotation.class);
       for(CoreMap map:senten)
       {
           map.get(TokensAnnotation.class).stream().forEach((tok) -> {
               String PosTagg=tok.get(PartOfSpeechAnnotation.class);
               lstTaggedSentences.add(new ExtractPosTag(tok.originalText(),PosTagg));
           });
       }
     } 
    return lstTaggedSentences;
}
 
开发者ID:unsw-cse-soc,项目名称:Data-curation-API,代码行数:23,代码来源:ExtractPosTagData.java

示例15: ExtractPosTags

import edu.stanford.nlp.pipeline.Annotation; //导入依赖的package包/类
@Override
public List<ExtractPosTag> ExtractPosTags(List<String> inputData) 
{
	List<ExtractPosTag> lstTaggedSentences = new ArrayList<>();		
       Properties props = new Properties();
       props.setProperty("annotators", "tokenize,ssplit,pos");
       StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
       for(String str:inputData)
       {
       Annotation annotation = new Annotation(str);
       pipeline.annotate(annotation);
       List<CoreMap> senten=annotation.get(CoreAnnotations.SentencesAnnotation.class);
       for(CoreMap map:senten)
       {
           map.get(TokensAnnotation.class).stream().forEach((tok) -> {
               String getPosTag=tok.get(PartOfSpeechAnnotation.class);
               lstTaggedSentences.add(new ExtractPosTag(tok.originalText(),getPosTag));
           });
       }
     } 
    return lstTaggedSentences;
}
 
开发者ID:unsw-cse-soc,项目名称:Data-curation-API,代码行数:23,代码来源:ExtractPosTagData.java


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