• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java TimeAnnotator类的典型用法和代码示例

java 2次浏览

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

TimeAnnotator类属于edu.stanford.nlp.time包,在下文中一共展示了TimeAnnotator类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: initialize

点赞 3

import edu.stanford.nlp.time.TimeAnnotator; //导入依赖的package包/类
/**
 * Initializes the tokenizer to detect date columns.
 */
public void initialize() {
	Properties props = new Properties();
	pipeline.addAnnotator(new TokenizerAnnotator(false) {

		@Override
		public Tokenizer<CoreLabel> getTokenizer(Reader r) {
			// TODO Auto-generated method stub
			return new PTBTokenizer<CoreLabel>(r, new CoreLabelTokenFactory(), "");

		}

	});
	pipeline.addAnnotator(new WordsToSentencesAnnotator(false));
	pipeline.addAnnotator(new POSTaggerAnnotator(false));
	pipeline.addAnnotator(new TimeAnnotator("sutime", props));
}
 

开发者ID:olehmberg,
项目名称:winter,
代码行数:20,
代码来源:TypeClassifier.java

示例2: WiseOwlStanfordFactory

点赞 2

import edu.stanford.nlp.time.TimeAnnotator; //导入依赖的package包/类
public WiseOwlStanfordFactory(Map<String,String> args) {
   super(args);
   Properties props = new Properties();
props.setProperty("annotators", "tokenize, cleanxml, ssplit,pos,lemma,ner");
this.pipeline = new StanfordCoreNLP(props);
pipeline.addAnnotator(new TimeAnnotator("sutime", props));
 }
 

开发者ID:asmehra95,
项目名称:wiseowl,
代码行数:8,
代码来源:WiseOwlStanfordFactory.java

示例3: makeNumericPipeline

点赞 2

import edu.stanford.nlp.time.TimeAnnotator; //导入依赖的package包/类
private static AnnotationPipeline makeNumericPipeline() {
  AnnotationPipeline pipeline = new AnnotationPipeline();
  pipeline.addAnnotator(new TokenizerAnnotator(false, "en"));
  pipeline.addAnnotator(new WordsToSentencesAnnotator(false));
  pipeline.addAnnotator(new POSTaggerAnnotator(false));
  pipeline.addAnnotator(new TimeAnnotator(true));

  return pipeline;
}
 

开发者ID:vibhor1319,
项目名称:activent,
代码行数:10,
代码来源:SUTimeSimpleParser.java

示例4: main

点赞 2

import edu.stanford.nlp.time.TimeAnnotator; //导入依赖的package包/类
public static void main(String args[])
{
	Properties props = new Properties();
	props.setProperty("annotators", "tokenize, cleanxml, ssplit,pos,lemma,ner");
	
	StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
	pipeline.addAnnotator(new TimeAnnotator("sutime", props));
	String text = "<mydata> refeer</mydata>today is 12 jan 2016. what is tommorow? Who is Avtar? Does he work at Apple or Google? Sumit was born on 13 feb,2011.";

	Annotation document = new Annotation(text);
	pipeline.annotate(document);
    System.out.println(document.get(CoreAnnotations.TextAnnotation.class));
    List<CoreMap> timexAnnsAll = document.get(TimeAnnotations.TimexAnnotations.class);
    for (CoreMap cm : timexAnnsAll) {
    List<CoreLabel> tokens = cm.get(CoreAnnotations.TokensAnnotation.class);
    TimeData td=new TimeData();
    td.setTime(cm.get(TimeExpression.Annotation.class).getTemporal().toISOString());
    td.setStart(tokens.get(0).get(CoreAnnotations.CharacterOffsetBeginAnnotation.class));
    td.setEnd(tokens.get(tokens.size() - 1).get(CoreAnnotations.CharacterOffsetEndAnnotation.class));
    }
 
	List<CoreMap> sentences = document.get(SentencesAnnotation.class);
	for(CoreMap sentence: sentences) {
	  // traversing the words in the current sentence
	  // a CoreLabel is a CoreMap with additional token-specific methods
		System.out.println("in sent");
	  for (CoreLabel token: sentence.get(TokensAnnotation.class)) {
	    // this is the text of the token
		  System.out.println("in token");
	    String word = token.get(TextAnnotation.class);
	    // this is the POS tag of the token
	    String pos = token.get(PartOfSpeechAnnotation.class);
	    // this is the NER label of the token
	    String ne = token.get(NamedEntityTagAnnotation.class);
	    System.out.println("word : "+word+" pos: "+pos+" ner: "+ne);
	    
	  }

	}

}
 

开发者ID:asmehra95,
项目名称:wiseowl,
代码行数:42,
代码来源:WiseOwlStanfordFilter.java

示例5: getPipeline

点赞 2

import edu.stanford.nlp.time.TimeAnnotator; //导入依赖的package包/类
public static AnnotationPipeline getPipeline() throws Exception {

        Properties props = new Properties();

        AnnotationPipeline pipeline = new AnnotationPipeline();

        // include EOL when tokenizing
        props.put(WhitespaceTokenizerAnnotator.EOL_PROPERTY, "true");

        props.put("sutime.rules",
                "edu/stanford/nlp/models/sutime/distributed.defs.txt,"
                + "edu/stanford/nlp/models/sutime/distributed.defs.g.txt,"
                + "edu/stanford/nlp/models/sutime/defs.sutime.txt,"
                + "edu/stanford/nlp/models/sutime/english.sutime.txt,"
                + "edu/stanford/nlp/models/sutime/english.holidays.sutime.txt");

        props.put("sutime.verbose", true);

        pipeline.addAnnotator(new WhitespaceTokenizerAnnotator(props));
        //WhitespaceTokenizerFactory

        //pipeline.addAnnotator(new PTBTokenizerAnnotator(PTBTokenizerAnnotator.DEFAULT_OPTIONS + ",tokenizeNLs"));
        final boolean endOfLineIsEndOfSentence = true;

        String end_of_sentence_regex;

        // The default in WordToSentenceProcessor include the apostrophe ('), which causes problem parsing "Summer '11".
        if (endOfLineIsEndOfSentence) {
            end_of_sentence_regex = "(\\.|[!?]+)[\\r\\n]*";
        } else {
            end_of_sentence_regex = "\\.|[!?]+";
        }

        pipeline.addAnnotator(new WordsToSentencesAnnotator(true, end_of_sentence_regex)); // true to debug

//        pipeline.addAnnotator(new POSTaggerAnnotator(
//                props.getProperty("pos.model"),
//                false));
//    pipeline.addAnnotator(new NumberAnnotator(false));
//    pipeline.addAnnotator(new QuantifiableEntityNormalizingAnnotator(false, false));
        String timeAnnotator = props.getProperty("timeAnnotator", "sutime");
        if ("gutime".equals(timeAnnotator)) {
            //useGUTime = true;
            pipeline.addAnnotator(new GUTimeAnnotator());
        } else if ("heideltime".equals(timeAnnotator)) {
            //requiredDocDateFormat = "yyyy-MM-dd";
            pipeline.addAnnotator(new HeidelTimeAnnotator("heideltime", props));
        } else if ("sutime".equals(timeAnnotator)) {
            pipeline.addAnnotator(new TimeAnnotator("sutime", props));
        } else {
            throw new IllegalArgumentException("Unknown timeAnnotator: " + timeAnnotator);
        }
        return pipeline;
    }
 

开发者ID:benblamey,
项目名称:stanford-nlp,
代码行数:55,
代码来源:DistributedMain.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)