use of nl.knaw.huygens.timbuctoo.model.Datable in project timbuctoo by HuygensING.
the class DatableTest method convertYear_a.
@Test
public void convertYear_a() {
Assert.assertTrue(EdtfPattern.YEAR_A.matches("2010~"));
Assert.assertFalse(EdtfPattern.YEAR_A.matches("2010"));
Assert.assertFalse(EdtfPattern.YEAR_A.matches("2010-02-13~"));
testDatable("2010-01-01:12", "2010-12-31:12", Datable.Certainty.MEDIUM, new Datable("2010~"));
}
use of nl.knaw.huygens.timbuctoo.model.Datable in project timbuctoo by HuygensING.
the class DatableTest method convertYear_month_a.
@Test
public void convertYear_month_a() {
Assert.assertTrue(EdtfPattern.YEAR_MONTH_A.matches("2001-01~"));
Assert.assertFalse(EdtfPattern.YEAR_MONTH_A.matches("2010"));
Assert.assertFalse(EdtfPattern.YEAR_MONTH_A.matches("2???-02-13"));
testDatable("1000-05-01:12", "1000-05-31:12", Datable.Certainty.MEDIUM, new Datable("1000-05~"));
}
use of nl.knaw.huygens.timbuctoo.model.Datable in project timbuctoo by HuygensING.
the class DatableRangeFacetDescription method filter.
@Override
@SuppressWarnings("unchecked")
public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets) {
final Optional<DateRangeFacetValue> facet = FacetParsingHelp.getValue(facetName, facets);
if (!facet.isPresent()) {
return;
}
String lowerLimitString = facet.get().getLowerLimit() + "";
String upperLimitString = facet.get().getUpperLimit() + "";
try {
Range<Date> range = Range.closed(FILTER_FORMAT.parse(lowerLimitString), FILTER_FORMAT.parse(upperLimitString));
graphTraversal.where(__.has(propertyName, P.test((o1, o2) -> {
Datable datable = getDatable("" + o1);
if (!datable.isValid()) {
return false;
}
Range<Date> range1 = (Range<Date>) o2;
return range1.contains(datable.getFromDate()) || range1.contains(datable.getToDate());
}, range)));
} catch (ParseException e) {
LOG.error("Cannot parse date", e);
}
}
use of nl.knaw.huygens.timbuctoo.model.Datable in project timbuctoo by HuygensING.
the class RelatedDatableRangeFacetDescription method filter.
@Override
@SuppressWarnings("unchecked")
public void filter(GraphTraversal<Vertex, Vertex> graphTraversal, List<FacetValue> facets) {
Optional<FacetValue> first = facets.stream().filter(facetValue -> Objects.equals(facetValue.getName(), facetName)).findFirst();
if (!first.isPresent()) {
return;
}
FacetValue facetValue = first.get();
if (!(facetValue instanceof DateRangeFacetValue)) {
return;
}
// pad the strings to make them parsable
String lowerLimitString = Strings.padStart("" + ((DateRangeFacetValue) facetValue).getLowerLimit(), 8, '0').substring(0, 4);
String upperLimitString = Strings.padStart("" + ((DateRangeFacetValue) facetValue).getUpperLimit(), 8, '0').substring(0, 4);
try {
Range<Date> range = Range.closed(FILTER_FORMAT.parse(lowerLimitString), FILTER_FORMAT.parse(upperLimitString));
graphTraversal.where(__.bothE(relations).otherV().has(propertyName, P.test((o1, o2) -> {
Datable datable = getDatable("" + o1);
if (!datable.isValid()) {
return false;
}
Range<Date> range1 = (Range<Date>) o2;
return range1.contains(datable.getFromDate()) || range1.contains(datable.getToDate());
}, range)));
} catch (ParseException e) {
LOG.error("Cannot parse date", e);
}
}
use of nl.knaw.huygens.timbuctoo.model.Datable in project timbuctoo by HuygensING.
the class DatableRangeFacetGetter method getFacet.
@Override
public Facet getFacet(String facetName, Map<String, Set<Vertex>> values) {
long lowerLimit = 0;
long upperLimit = 0;
for (String key : values.keySet()) {
Datable datable = getDatable(key);
if (datable.isValid()) {
long fromDate = Long.valueOf(FORMAT.format(datable.getFromDate()));
long toDate = Long.valueOf(FORMAT.format(datable.getToDate()));
if (toDate > upperLimit) {
upperLimit = toDate;
}
if (lowerLimit == 0 || fromDate < lowerLimit) {
lowerLimit = fromDate;
}
}
}
return new Facet(facetName, Lists.newArrayList(new Facet.RangeOption(lowerLimit, upperLimit)), "RANGE");
}
Aggregations