protected void fillDates(YElement yElement, List<YExportable> referedElements, Map<String, List<StringWithAttributes>> ret) { // date element if (!yElement.getDates().isEmpty()) { ret.put(E_DATE, new ArrayList<StringWithAttributes>()); } for (YDate yDate : yElement.getDates()) { String yDateStr; String y = String.format("%02d", yDate.getYear()); String m = String.format("%02d", yDate.getMonth()); String d = String.format("%02d", yDate.getDay()); if (y != null && m != null && d != null) { yDateStr = y + "-" + m + "-" + d; } else if (y != null && m != null) { yDateStr = y + "-" + m; } else if (y != null) { yDateStr = y; } else { yDateStr = yDate.getText(); } StringWithAttributes dat = new StringWithAttributes(yDateStr); dat.addAttribute("dateType", yDate.getType()); ret.get(E_DATE).add(dat); // root.addContent(date); } }
@Override protected boolean enhanceMetadata(MatchResult result, YElement metadata) { YDate date = new YDate().setType(dateType); date.setDay(Integer.parseInt(result.group(2))); for (int i = 0; i < 12; i++) { if (result.group(i + 3) != null) { date.setMonth(i + 1); break; } } date.setYear(Integer.parseInt(result.group(15))); date.setText(result.group(1)); metadata.addDate(date); return true; }
@Override protected boolean enhanceMetadata(MatchResult result, YElement metadata) { for (int i = 1; i <= result.groupCount(); i++) { String year = result.group(i); try { int y = Integer.parseInt(year); if (y >= 1900 && y < 2020) { metadata.addDate(new YDate().setType(YConstants.DT_PUBLISHED).setYear(y).setText(year)); return true; } } catch (NumberFormatException e) {} } return false; } }
/** * Selects most apropriate (English if available) description. * * @param descriptions * list of available descriptions * @return best found description or null if list is empty */ protected static String selectBestDate(List<YDate> dates) { if (dates == null || dates.size() == 0) { return null; } StringBuilder text = new StringBuilder(); for (YDate date : dates) { text.append(date.getType() + ":"+date.getYear()+YElementToZentralBlattConverter.SUGGESTED_MULTIVALUE_FIELD_SEPARATOR); } return text.toString(); }
protected Integer getYear(List<YDate> dates) { for (YDate date : dates) { return date.getYear(); } return null; }
public static YDate parseDate(String date, String type) { if (StringUtils.isBlank(date)) { return null; } try { DateTime dateTime = ISODateTimeFormat.dateParser().parseDateTime(date); return new YDate(type, dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(), date); } catch (IllegalArgumentException e) { LOGGER.warn("Couldn't parse date", date); return null; } }
protected void convertDate(YElement yElement, BibEntry bibEntry) { YDate date = yElement.getDate(YConstants.DT_PUBLISHED); if (date != null) { if (bibEntry.getFirstFieldValue(BibEntry.FIELD_YEAR) == null) { bibEntry.setField(BibEntry.FIELD_YEAR, String.valueOf(date.getYear())); } bibEntry.setField(BibEntry.FIELD_MONTH, String.valueOf(date.getMonth())); date.getYear(); } }
private Map<String, YDate> processYDates(final List<YDate> yDates) { Map<String, YDate> dates = new HashMap<>(); if (yDates != null) { for (final YDate yDate : yDates) { dates.put(yDate.getType(), yDate); } } return dates; }
@Override void compare(YElement expected, YElement actual, EvalResult result) { List<YDate> expDates = expected.getDates(); Map<String, YDate> actDatesMap = new HashMap<String, YDate>(); for (YDate date : actual.getDates()) { String type = date.getType(); actDatesMap.put(type, date); } for (YDate date : expDates) { String type = date.getType(); if (actDatesMap.containsKey(type)) { if (date.equals(actDatesMap.get(type))) { result.append("Date - " + type, ResultStatus.RECOGNIZED, 1); } else { result.append("Date - " + type, ResultStatus.FAILED, 1); } actDatesMap.remove(type); } else { result.append("Date - " + type, ResultStatus.FAILED, 1); } } for (String type : actDatesMap.keySet()) { result.append("Date - " + type, ResultStatus.REDUNDANT, 1); } } },
protected void fillDates(HtmlMetaHeaders metadata, YElement yElement) { for (YDate yDate : yElement.getDates()) { metadata.addMetadataName(DC_NAMESPACE + SEPARATOR + DublinCoreStrings.E_DATE, yDate.getText()); } }
YDate pubdate=createDateFromDateLikeElement(pd, DateTypes.DT_PUBLISHED); if ("epub".equalsIgnoreCase(pd.getAttributeValue("pub-type"))) { pubdate.setType(DateTypes.DT_ONLINE);
public DateTime parseDate(final YDate yDate) throws InvalidDateException { DateTime parsedDate; try { parsedDate = new DateTime(yDate.getYear(), yDate.getMonth() > 0 ? yDate.getMonth() : 1, yDate.getDay() > 0 ? yDate.getDay() : 1, 0, 0, DateTimeZone.UTC); } catch (IllegalFieldValueException e) { throw new InvalidDateException("Incorrect values in YDates.", e); } if (yDate.getDay() == 0) { parsedDate = parsedDate.dayOfMonth().withMinimumValue(); } if (yDate.getMonth() == 0) { parsedDate = parsedDate.dayOfYear().withMinimumValue(); } return parsedDate; }
/** * Selects most appropriate (Publication's if available) data. */ protected static String selectBestDate(List<YDate> dates) { if (dates == null || dates.size() == 0) { return null; } int py = dates.get(0).getYear(); for (YDate date: dates) { //Search for English version if (date.getType().equals(YConstants.DT_PUBLISHED)) { py = date.getYear(); } } if (py > 1000) { return new Integer(py).toString(); } else { return null; } }
protected YDate convert(PublicationDate publicationDate) { int year = publicationDate.getYear(); int month = publicationDate.getMonth() != null ? publicationDate.getMonth() : 1; int day = publicationDate.getDay() != null ? publicationDate.getDay() : 1; switch (publicationDate.getMediaType()) { case ONLINE: return new YDate(DateTypes.DT_PUBLISHED, year, month, day, StringUtils.EMPTY); case PRINT: return new YDate(DateTypes.DT_ISSUED, year, month, day, StringUtils.EMPTY); default: } return null; }