Package edu.stanford.nlp.time

Examples of edu.stanford.nlp.time.Timex


        //mention.set(CoreAnnotations.EntityNameAnnotation.class, name);
        String type = mention.get(CoreAnnotations.NamedEntityTagAnnotation.class);
        mention.set(CoreAnnotations.EntityTypeAnnotation.class, type);

        // Take first non nil as timex for the mention
        Timex timex = (Timex) CoreMapAttributeAggregator.FIRST_NON_NIL.aggregate(
            TimeAnnotations.TimexAnnotation.class, mentionTokens);
        if (timex != null) {
          mention.set(TimeAnnotations.TimexAnnotation.class, timex);
        }
      }
View Full Code Here


    if (token.containsKey(CoreAnnotations.SpeakerAnnotation.class)) {
      setSingleElement(wordInfo, "Speaker", curNS, token.get(CoreAnnotations.SpeakerAnnotation.class));
    }

    if (token.containsKey(TimeAnnotations.TimexAnnotation.class)) {
      Timex timex = token.get(TimeAnnotations.TimexAnnotation.class);
      Element timexElem = new Element("Timex", curNS);
      timexElem.addAttribute(new Attribute("tid", timex.tid()));
      timexElem.addAttribute(new Attribute("type", timex.timexType()));
      timexElem.appendChild(timex.value());
      wordInfo.appendChild(timexElem);
    }

    if (token.containsKey(CoreAnnotations.TrueCaseAnnotation.class)) {
      Element cur = new Element("TrueCase", curNS);
View Full Code Here

              l3.set("normalizedNER", token.get(CoreAnnotations.NormalizedNamedEntityTagAnnotation.class));
              l3.set("speaker", token.get(CoreAnnotations.SpeakerAnnotation.class));
              l3.set("truecase", token.get(CoreAnnotations.TrueCaseAnnotation.class));
              l3.set("truecaseText", token.get(CoreAnnotations.TrueCaseTextAnnotation.class));
              // Timex
              Timex time = token.get(TimeAnnotations.TimexAnnotation.class);
              if (time != null) {
                l3.set("timex", (Consumer<Writer>) l4 -> {
                  l4.set("tid", time.tid());
                  l4.set("type", time.timexType());
                  l4.set("value", time.value());
                  l4.set("altValue", time.altVal());
                });
              }
            }));
          }
        }));
View Full Code Here

   * Create an internal Timex object from the serialized protocol buffer.
   * @param proto The serialized protocol buffer to read from.
   * @return A timex, with as much information filled in as was gleaned from the protocol buffer.
   */
  private Timex fromProto(CoreNLPProtos.Timex proto) {
    return new Timex(
        proto.hasType() ? proto.getType() : null,
        proto.hasValue() ? proto.getValue() : null,
        proto.hasAltValue() ? proto.getAltValue() : null,
        proto.hasTid() ? proto.getTid() : null,
        proto.hasText() ? proto.getText() : null,
View Full Code Here

        out.println("<th>Char Begin</th><th>Char End</th><th>Token Begin</th><th>Token End</th>");
      }
      out.println("<th>Timex3 Tag</th></tr>");
      for (CoreMap timexAnn : timexAnns) {
        out.println("<tr>");
        Timex timex = timexAnn.get(TimeAnnotations.TimexAnnotation.class);
        int begin =
                timexAnn.get(CoreAnnotations.CharacterOffsetBeginAnnotation.class);
        int end =
                timexAnn.get(CoreAnnotations.CharacterOffsetEndAnnotation.class);
        out.print("<td>" + StringEscapeUtils.escapeHtml4(query.substring(begin, end)) + "</td>");
        out.print("<td>" + ((timex.value() != null)? StringEscapeUtils.escapeHtml4(timex.value()):"") + "</td>");
        if (includeOffsets) {
          out.print("<td>" + begin + "</td>");
          out.print("<td>" + end + "</td>");
          out.print("<td>" + timexAnn.get(CoreAnnotations.TokenBeginAnnotation.class) + "</td>");
          out.print("<td>" + timexAnn.get(CoreAnnotations.TokenEndAnnotation.class) + "</td>");
        }
        out.print("<td>" + StringEscapeUtils.escapeHtml4(timex.toString()) + "</td>");
        out.println("</tr>");
      }
      out.println("</table>");
    } else {
      out.println("<em>No temporal expressions.</em>");
View Full Code Here

    } else {
      s = singleEntityToString(l);
    }

    Number numberFromSUTime = fetchNumberFromSUTime(l);
    Timex timexFromSUTime = fetchTimexFromSUTime(l);

    if (DEBUG) System.err.println("Quantifiable: working on " + s);
    String p = null;
    switch (entityType) {
      case "NUMBER": {
View Full Code Here

      if (!compatible) return compatible;
    }

    if ("TIME".equals(tag) || "SET".equals(tag) || "DATE".equals(tag) || "DURATION".equals(tag)) {
      // Check timex...
      Timex timex1 = cur.get(TimeAnnotations.TimexAnnotation.class);
      Timex timex2 = prev.get(TimeAnnotations.TimexAnnotation.class);
      String tid1 = (timex1 != null)? timex1.tid():null;
      String tid2 = (timex2 != null)? timex2.tid():null;
      boolean compatible = checkStrings(tid1,tid2);
      if (!compatible) return compatible;
    }

    return true;
View Full Code Here

  public static <E extends CoreMap> void fixupNerBeforeNormalization(List<E> list)
  {
    // Goes through tokens and tries to fix up NER annotations
    String prevNerTag = BACKGROUND_SYMBOL;
    String prevNumericType = null;
    Timex prevTimex = null;
    for (int i = 0, sz = list.size(); i < sz; i++) {
      E wi = list.get(i);
      Timex timex = wi.get(TimeAnnotations.TimexAnnotation.class);
      String numericType = wi.get(CoreAnnotations.NumericCompositeTypeAnnotation.class);

      String curWord = (wi.get(CoreAnnotations.TextAnnotation.class) != null ? wi.get(CoreAnnotations.TextAnnotation.class) : "");
      String currNerTag = wi.get(CoreAnnotations.NamedEntityTagAnnotation.class);

      if (DEBUG) { System.err.println("fixupNerBeforeNormalization: wi is " + wi); }
      // Attempts repairs to NER tags only if not marked by SUTime already
      if (timex == null && numericType == null) {
        // repairs commas in between dates...  String constant first in equals() in case key has null value....
        if ((i+1) < sz && ",".equals(wi.get(CoreAnnotations.TextAnnotation.class)) && "DATE".equals(prevNerTag)) {
          if (prevTimex == null && prevNumericType == null) {
            E nextToken = list.get(i+1);
            String nextNER = nextToken.get(CoreAnnotations.NamedEntityTagAnnotation.class);
            if (nextNER != null && nextNER.equals("DATE")) {
              wi.set(CoreAnnotations.NamedEntityTagAnnotation.class, "DATE");
            }
          }
        }

        //repairs mistagged multipliers after a numeric quantity
        if (!curWord.equals("") && (moneyMultipliers.containsKey(curWord) ||
                (getOneSubstitutionMatch(curWord, moneyMultipliers.keySet()) != null)) &&
                prevNerTag != null && (prevNerTag.equals("MONEY") || prevNerTag.equals("NUMBER"))) {
          wi.set(CoreAnnotations.NamedEntityTagAnnotation.class, prevNerTag);
        }

        //repairs four digit ranges (2002-2004) that have not been tagged as years - maybe bad? (empirically useful)
        if (curWord.contains("-")) {
          String[] sides = curWord.split("-");
          if (sides.length == 2) {
            try {
              int first = Integer.parseInt(sides[0]);
              int second = Integer.parseInt(sides[1]);
              //they're both integers, see if they're both between 1000-3000 (likely years)
              if (1000 <= first && first <= 3000 && 1000 <= second && second <= 3000) {
                wi.set(CoreAnnotations.NamedEntityTagAnnotation.class, "DATE");
                String dateStr = new ISODateInstance(new ISODateInstance(sides[0]), new ISODateInstance(sides[1])).getDateString();
                if (DEBUG) {
                  System.err.println("#5: Changing normalized NER from " +
                          wi.get(CoreAnnotations.NormalizedNamedEntityTagAnnotation.class) + " to " + dateStr + " at index " + i);
                }
                wi.set(CoreAnnotations.NormalizedNamedEntityTagAnnotation.class, dateStr);
                continue;
              }
            } catch (Exception e) {
              // they weren't numbers.
            }
          }
        }

        // Marks time units as DURATION if they are preceded by a NUMBER tag.  e.g. "two years" or "5 minutes"
        if ( timeUnitWords.contains(curWord) &&
                (currNerTag == null || !"DURATION".equals(currNerTag) ) &&
                ("NUMBER".equals(prevNerTag))) {
          wi.set(CoreAnnotations.NamedEntityTagAnnotation.class, "DURATION");
          for (int j = i-1; j > 0; j--) {
            E prev = list.get(j);
            if ("NUMBER".equals(prev.get(CoreAnnotations.NamedEntityTagAnnotation.class))) {
              prev.set(CoreAnnotations.NamedEntityTagAnnotation.class, "DURATION");
            }
          }
        }
      } else {
        // Fixup SUTime marking of twenty-second
        if ("DURATION".equals(currNerTag) && ordinalsToValues.containsKey(curWord)
                && curWord.endsWith("second") && timex.text().equals(curWord)) {
          wi.set(CoreAnnotations.NamedEntityTagAnnotation.class, "ORDINAL");
        }
      }

      prevNerTag = currNerTag;
View Full Code Here

        int end = timeExpression.get(CoreAnnotations.TokenEndAnnotation.class);
        int offset = 0;
        if(sentence != null && sentence.containsKey(CoreAnnotations.TokenBeginAnnotation.class)) {
          offset = sentence.get(CoreAnnotations.TokenBeginAnnotation.class);
        }
        Timex timex = timeExpression.get(TimeAnnotations.TimexAnnotation.class);
        if(timex != null){
          if(DEBUG){
            System.err.println("FOUND DATE/TIME \"" + timeExpression +
                "\" with offsets " + start + " " + end +
                " and value " + timex);
            System.err.println("The above CoreMap has the following fields:");
            // for(Class key: timeExpression.keySet()) System.err.println("\t" + key + ": " + timeExpression.get(key));
          }
          String label = timex.timexType();
          for(int i = start; i < end; i ++){
            CoreLabel token = tokenSequence.get(i - offset);
            if(token.get(CoreAnnotations.AnswerAnnotation.class).equals(flags.backgroundSymbol)){
              token.set(CoreAnnotations.AnswerAnnotation.class, label);
              token.set(TimeAnnotations.TimexAnnotation.class, timex);
View Full Code Here

TOP

Related Classes of edu.stanford.nlp.time.Timex

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.