Beispiel #1
0
  /**
   * Helper method to set the start date while parsing a date.
   *
   * @param firstDate The string based representation of a date (number only).
   * @param date The <tt>HistoricalDate</tt> object to be updated.
   */
  private void setStartDate(String firstDate, HistoricalDate date) {
    // create a date instance
    try {
      SimpleDateFormat formatter = new SimpleDateFormat("yyyy");
      if (firstDate.length() < 3) {
        firstDate = firstDate + "00";
      } else if (date.getPrecision() == null) {
        date.setPrecision(Precision.YEAR);
      }

      Date d = formatter.parse(firstDate);
      date.setStartDate(d);
    } catch (ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Beispiel #2
0
  /**
   * Helper method to set the end date while parsing a date.
   *
   * @param firstDate The start date. Used as a basis for interpreting relative end dates such as
   *     1934/35.
   * @param endDate The string based representation of a date (number only).
   * @param separator The separator used to split date parts. This may indicate the certainty of the
   *     trailing date as distinct from the entire date, as in 1935 or possibly 36.
   * @param date The <tt>HistoricalDate</tt> object to be updated.
   */
  private void setEndDate(String firstDate, String endDate, String separator, HistoricalDate date) {
    if (endDate == null) {
      date.setEndDate(date.getStartDate());
      return;
    }

    // for dates like 1325/26, adjust the second to be a full four-year date
    if (firstDate.length() > endDate.length()) {
      int offset = firstDate.length() - endDate.length();
      endDate = firstDate.substring(0, offset) + endDate;
    }

    date.setEndDate(date.getStartDate());
    if (separator != null && (separator.indexOf("possibly") > 0)) {
      date.setEndCertainty(Certainty.POSSIBLE);
    }
  }
Beispiel #3
0
  /**
   * @param desc
   * @return
   */
  public String extractDate(String desc) {
    String result = desc;
    Matcher mat = datePattern.matcher(desc);

    if (mat.find() && (mat.start() == 0)) {
      HistoricalDate date = new HistoricalDate(mat.group(1));
      em.persist(date);
      ms.setDate(date);

      result = desc.substring(mat.end());
      if (date.getText().matches(UNKNOWN_DATE_RE)) {
        return result;
      }

      String prefix = StringUtils.trimToNull(mat.group(2));
      String firstDate = StringUtils.trimToNull(mat.group(3));
      String separator = StringUtils.trimToNull(mat.group(4));
      String lastDate = StringUtils.trimToNull(mat.group(5));
      String suffix = StringUtils.trimToNull(mat.group(6));

      if (suffix != null) {
        if (suffix.matches("c\\.?")) {
          date.setPrecision(Precision.CENTURY);
        } else {
          // Doesn't seem to happen
        }
      }

      if (prefix != null) {
        if (prefix.equalsIgnoreCase("ca.")) {
          // mark date as approximate
          date.setCertainty(Certainty.APPROXIMATE);
        } else if (prefix.equalsIgnoreCase("possibly")) {
          // mark date as uncertain
          date.setCertainty(Certainty.POSSIBLE);
        } else {
          // doesen't occur
        }
      }

      setStartDate(firstDate, date);
      setEndDate(firstDate, lastDate, separator, date);
      LOGGER.debug("           Date: " + date.getText());
    } else {
      //			System.out.println(desc);
    }

    return result;
  }