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


Java TimeAnnotations类代码示例

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


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

示例1: prepareSUTParser

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

示例2: annotationToXmlDocument

import edu.stanford.nlp.time.TimeAnnotations; //导入依赖的package包/类
public static Document annotationToXmlDocument(Annotation annotation)
{
  List<CoreMap> timexAnnsAll = annotation.get(TimeAnnotations.TimexAnnotations.class);
  Element dateElem = XMLUtils.createElement("DATE");
  dateElem.setTextContent(annotation.get(CoreAnnotations.DocDateAnnotation.class));
  Element textElem = XMLUtils.createElement("TEXT");
  List<Node> timexNodes = createTimexNodes(
          annotation.get(CoreAnnotations.TextAnnotation.class),
          annotation.get(CoreAnnotations.CharacterOffsetBeginAnnotation.class),
          timexAnnsAll);
  for (Node node:timexNodes) {
    textElem.appendChild(node);
  }

  Element docElem = XMLUtils.createElement("DOC");
  docElem.appendChild(dateElem);
  docElem.appendChild(textElem);

  // Create document and import elements into this document....
  Document doc = XMLUtils.createDocument();
  doc.appendChild(doc.importNode(docElem, true));
  return doc;
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:24,代码来源:SUTimeMain.java

示例3: transferAnnotations

import edu.stanford.nlp.time.TimeAnnotations; //导入依赖的package包/类
/**
 * Transfer from src to dst all annotations generated bu SUTime and NumberNormalizer
 * @param src
 * @param dst
 */
public static void transferAnnotations(CoreLabel src, CoreLabel dst) {
  //
  // annotations potentially set by NumberNormalizer
  //
  if(src.containsKey(CoreAnnotations.NumericCompositeValueAnnotation.class)){
    dst.set(CoreAnnotations.NumericCompositeValueAnnotation.class,
        src.get(CoreAnnotations.NumericCompositeValueAnnotation.class));
  }

  if(src.containsKey(CoreAnnotations.NumericCompositeTypeAnnotation.class))
    dst.set(CoreAnnotations.NumericCompositeTypeAnnotation.class,
        src.get(CoreAnnotations.NumericCompositeTypeAnnotation.class));

  //
  // annotations set by SUTime
  //
  if(src.containsKey(TimeAnnotations.TimexAnnotation.class))
    dst.set(TimeAnnotations.TimexAnnotation.class,
        src.get(TimeAnnotations.TimexAnnotation.class));
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:26,代码来源:NumberSequenceClassifier.java

示例4: printOutput

import edu.stanford.nlp.time.TimeAnnotations; //导入依赖的package包/类
private static void printOutput(Annotation annotation) {
        List<CoreMap> sents = annotation.get(CoreAnnotations.SentencesAnnotation.class);
        for (CoreMap thisSent : sents) {

            List<CoreLabel> tokens = thisSent.get(CoreAnnotations.TokensAnnotation.class);
            for (CoreLabel token : tokens) {
                System.out.println("Token: " + token);
                System.out.println("Index: " + token.index());
                System.out.println("Sent index: " + token.sentIndex());
                System.out.println("Begin: " + token.get(CoreAnnotations.CharacterOffsetBeginAnnotation.class));
                System.out.println("End: " + token.get(CoreAnnotations.CharacterOffsetEndAnnotation.class));
                System.out.println("NER: " + token.get(CoreAnnotations.NamedEntityTagAnnotation.class));
                System.out.println(token.get(CoreAnnotations.NamedEntityTagAnnotation.class));
                System.out.println(token.get(CoreAnnotations.NormalizedNamedEntityTagAnnotation.class));
                System.out.println(token.get(CoreAnnotations.ValueAnnotation.class));
//                System.out.println(token.get(TimeExpression.Annotation.class));
//                System.out.println(token.get(TimeExpression.TimeIndexAnnotation.class));
//                System.out.println(token.get(CoreAnnotations.DistSimAnnotation.class));
//                System.out.println(token.get(CoreAnnotations.NumericCompositeTypeAnnotation.class));
                System.out.println(token.get(TimeAnnotations.TimexAnnotation.class));
//                System.out.println(token.get(CoreAnnotations.NumericValueAnnotation.class));
//                System.out.println(token.get(TimeExpression.ChildrenAnnotation.class));
//                System.out.println(token.get(CoreAnnotations.NumericTypeAnnotation.class));
//                System.out.println(token.get(CoreAnnotations.ShapeAnnotation.class));
//                System.out.println(token.get(Tags.TagsAnnotation.class));
//                System.out.println(token.get(CoreAnnotations.NumerizedTokensAnnotation.class));
//                System.out.println(token.get(CoreAnnotations.AnswerAnnotation.class));
//                System.out.println(token.get(CoreAnnotations.NumericCompositeValueAnnotation.class));

                System.out.println();
            }

            System.out.println("---");
            System.out.println();
        }
    }
 
开发者ID:dkmfbk,项目名称:pikes,代码行数:37,代码来源:StanfordTest.java

示例5: fetchTimexFromSUTime

import edu.stanford.nlp.time.TimeAnnotations; //导入依赖的package包/类
private static <E extends CoreMap> Timex fetchTimexFromSUTime(List<E> l) {
  for(E e: l) {
    if(e.containsKey(TimeAnnotations.TimexAnnotation.class)){
      return e.get(TimeAnnotations.TimexAnnotation.class);
    }
  }
  return null;
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:9,代码来源:QuantifiableEntityNormalizer.java

示例6: testSummer

import edu.stanford.nlp.time.TimeAnnotations; //导入依赖的package包/类
@org.junit.Test
public void testSummer() throws Exception {
    Annotation annotation = new Annotation("Summer");
    _pipeline.annotate(annotation);
    assertTrue(annotation.has(TimeAnnotations.TimexAnnotations.class));
    "".toCharArray();
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:8,代码来源:DistributedSUTimeTest.java

示例7: main

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

示例8: findTokens

import edu.stanford.nlp.time.TimeAnnotations; //导入依赖的package包/类
public Iterator findTokens() throws IOException
{
	/*char[] c = new char[256];
    int sz = 0;
    StringBuilder b = new StringBuilder();
    
    while ((sz = input.read(c)) >= 0) {
      b.append(c, 0, sz);
    }*/
    //String text = b.toString();
	if (!input.incrementToken()) return null;
    String text;
    text = input.getAttribute(CharTermAttribute.class).toString();
	// read some text in the text variable
	//System.out.println("before annotation");
	Annotation document = new Annotation(text);
	// these are all the sentences in this document
	// a CoreMap is essentially a Map that uses class objects as keys and has values with custom types
	pipeline.annotate(document);
	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().toString());
    td.setStart(tokens.get(0).get(CoreAnnotations.CharacterOffsetBeginAnnotation.class));
    td.setEnd(tokens.get(tokens.size() - 1).get(CoreAnnotations.CharacterOffsetEndAnnotation.class));
    timeQueue.add(td);
    }
	List<CoreMap> sentences = document.get(SentencesAnnotation.class);
	
	//System.out.println("after annotation and sentence getting"+sentences.size());
	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(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);
	    TokenData tok=new TokenData();
	    tok.setNER(ne);
	    tok.setToken(word);
	    tok.setPOS(pos);
	    tokenQueue.add(tok);
	  }

	}
	Iterator<TokenData> it=tokenQueue.iterator();
	itr_cpy=tokenQueue.iterator();
	tokenOffset=0;
	start=0;
	end=0;
	return it;
}
 
开发者ID:asmehra95,项目名称:wiseowl,代码行数:59,代码来源:WiseOwlStanfordFilter.java

示例9: annotate

import edu.stanford.nlp.time.TimeAnnotations; //导入依赖的package包/类
public void annotate(Annotation annotation) {
      TimeIndex timeIndex = new TimeIndex();
  String docDate = annotation.get(CoreAnnotations.DocDateAnnotation.class);
  if(docDate == null){
    Calendar cal = annotation.get(CoreAnnotations.CalendarAnnotation.class);
    if(cal == null){
      Redwood.log(Redwood.WARN, "No document date specified");
    } else {
      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd:hh:mm:ss");
      docDate = dateFormat.format(cal.getTime());
    }
  }
  List<CoreMap> allTimeExpressions; // initialized below = null;
  List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class);
  if (sentences != null) {
    allTimeExpressions = new ArrayList<CoreMap>();
    List<CoreMap> allNumerics = new ArrayList<CoreMap>();
    for (CoreMap sentence: sentences) {
      // make sure that token character offsets align with the actual sentence text
      // They may not align due to token normalizations, such as "(" to "-LRB-".
      CoreMap alignedSentence =  NumberSequenceClassifier.alignSentence(sentence); 
      // uncomment the next line for verbose dumping of tokens....
      // System.err.println("SENTENCE: " + ((ArrayCoreMap) sentence).toShorterString());
      List<CoreMap> timeExpressionsForSentence = 
        timexExtractor.extractTimeExpressionCoreMaps(alignedSentence, docDate, timeIndex);
      if (timeExpressionsForSentence != null) {
        allTimeExpressions.addAll(timeExpressionsForSentence);
        sentence.set(TimeAnnotations.TimexAnnotations.class, timeExpressionsForSentence);
        for (CoreMap timeExpression:timeExpressionsForSentence) {
          timeExpression.set(CoreAnnotations.SentenceIndexAnnotation.class, sentence.get(CoreAnnotations.SentenceIndexAnnotation.class));
        }
      }
      List<CoreMap> numbers = alignedSentence.get(CoreAnnotations.NumerizedTokensAnnotation.class);
      if(numbers != null){
        sentence.set(CoreAnnotations.NumerizedTokensAnnotation.class, numbers);
        allNumerics.addAll(numbers);
      }
    }
    annotation.set(CoreAnnotations.NumerizedTokensAnnotation.class, allNumerics);
  } else {
    allTimeExpressions = annotateSingleSentence(annotation, docDate, timeIndex);
  }
  annotation.set(TimeAnnotations.TimexAnnotations.class, allTimeExpressions);
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:45,代码来源:TimeAnnotator.java

示例10: annotate

import edu.stanford.nlp.time.TimeAnnotations; //导入依赖的package包/类
public void annotate(CoreMap document) throws IOException {
  // write input file in GUTime format
  Element inputXML = toInputXML(document);
  File inputFile = File.createTempFile("gutime", ".input");

  //Document doc = new Document(inputXML);
  PrintWriter inputWriter = new PrintWriter(inputFile);
  inputWriter.println(XMLUtils.nodeToString(inputXML, false));
 // new XMLOutputter().output(inputXML, inputWriter);
  inputWriter.close();

  boolean useFirstDate = 
    (!document.has(CoreAnnotations.CalendarAnnotation.class) && !document.has(CoreAnnotations.DocDateAnnotation.class));
  
  ArrayList<String> args = new ArrayList<String>();
  args.add("perl");
  args.add("-I" + this.gutimePath.getPath());
  args.add(new File(this.gutimePath, "TimeTag.pl").getPath());
  if (useFirstDate)
    args.add("-FDNW");
  args.add(inputFile.getPath());
  // run GUTime on the input file
  ProcessBuilder process = new ProcessBuilder(args);

  StringWriter outputWriter = new StringWriter();
  SystemUtils.run(process, outputWriter, null);
  String output = outputWriter.getBuffer().toString();
  Pattern docClose = Pattern.compile("</DOC>.*", Pattern.DOTALL);
  output = docClose.matcher(output).replaceAll("</DOC>");

  // parse the GUTime output
  Element outputXML;
  try {
    outputXML = XMLUtils.parseElement(output);
  } catch (Exception ex) {
    throw new RuntimeException(String.format("error:\n%s\ninput:\n%s\noutput:\n%s",
    		ex, IOUtils.slurpFile(inputFile), output), ex);
  }
  /*
  try {
    outputXML = new SAXBuilder().build(new StringReader(output)).getRootElement();
  } catch (JDOMException e) {
    throw new RuntimeException(String.format("error:\n%s\ninput:\n%s\noutput:\n%s",
    		e, IOUtils.slurpFile(inputFile), output));
  } */
  inputFile.delete();
  
  // get Timex annotations
  List<CoreMap> timexAnns = toTimexCoreMaps(outputXML, document);
  document.set(TimeAnnotations.TimexAnnotations.class, timexAnns);
  if (outputResults) {
    System.out.println(timexAnns);
  }
  
  // align Timex annotations to sentences
  int timexIndex = 0;
  for (CoreMap sentence: document.get(CoreAnnotations.SentencesAnnotation.class)) {
  	int sentBegin = beginOffset(sentence);
  	int sentEnd = endOffset(sentence);
  	
  	// skip times before the sentence
  	while (timexIndex < timexAnns.size() && beginOffset(timexAnns.get(timexIndex)) < sentBegin) {
  		++timexIndex;
  	}
  	
  	// determine times within the sentence
  	int sublistBegin = timexIndex;
  	int sublistEnd = timexIndex;
  	while (timexIndex < timexAnns.size() &&
  			   sentBegin <= beginOffset(timexAnns.get(timexIndex)) &&
  			   endOffset(timexAnns.get(timexIndex)) <= sentEnd) {
  		++sublistEnd;
  		++timexIndex;
  	}
  	
  	// set the sentence timexes
  	sentence.set(TimeAnnotations.TimexAnnotations.class, timexAnns.subList(sublistBegin, sublistEnd));
  }
}
 
开发者ID:benblamey,项目名称:stanford-nlp,代码行数:80,代码来源:GUTimeAnnotator.java


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