Search in sources :

Example 11 with Datable

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~"));
}
Also used : Datable(nl.knaw.huygens.timbuctoo.model.Datable) Test(org.junit.Test)

Example 12 with Datable

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~"));
}
Also used : Datable(nl.knaw.huygens.timbuctoo.model.Datable) Test(org.junit.Test)

Example 13 with Datable

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);
    }
}
Also used : DateRangeFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue) ParseException(java.text.ParseException) Range(com.google.common.collect.Range) Date(java.util.Date) Datable(nl.knaw.huygens.timbuctoo.model.Datable)

Example 14 with Datable

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);
    }
}
Also used : StringUtils(org.apache.commons.lang.StringUtils) Logger(org.slf4j.Logger) Date(java.util.Date) Range(com.google.common.collect.Range) DatableRangeFacetGetter(nl.knaw.huygens.timbuctoo.search.description.facet.helpers.DatableRangeFacetGetter) LoggerFactory(org.slf4j.LoggerFactory) SimpleDateFormat(java.text.SimpleDateFormat) org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Objects(java.util.Objects) Strings(com.google.common.base.Strings) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) List(java.util.List) DateRangeFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue) Datable(nl.knaw.huygens.timbuctoo.model.Datable) Optional(java.util.Optional) ParseException(java.text.ParseException) P(org.apache.tinkerpop.gremlin.process.traversal.P) RelatedPropertyValueGetter(nl.knaw.huygens.timbuctoo.search.description.facet.helpers.RelatedPropertyValueGetter) DateRangeFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue) FacetValue(nl.knaw.huygens.timbuctoo.search.FacetValue) DateRangeFacetValue(nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue) ParseException(java.text.ParseException) Range(com.google.common.collect.Range) Date(java.util.Date) Datable(nl.knaw.huygens.timbuctoo.model.Datable)

Example 15 with Datable

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");
}
Also used : Datable(nl.knaw.huygens.timbuctoo.model.Datable) Facet(nl.knaw.huygens.timbuctoo.search.description.facet.Facet)

Aggregations

Datable (nl.knaw.huygens.timbuctoo.model.Datable)32 Test (org.junit.Test)29 Range (com.google.common.collect.Range)2 ParseException (java.text.ParseException)2 Date (java.util.Date)2 DateRangeFacetValue (nl.knaw.huygens.timbuctoo.server.mediatypes.v2.search.DateRangeFacetValue)2 Strings (com.google.common.base.Strings)1 SimpleDateFormat (java.text.SimpleDateFormat)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 FacetValue (nl.knaw.huygens.timbuctoo.search.FacetValue)1 Facet (nl.knaw.huygens.timbuctoo.search.description.facet.Facet)1 DatableRangeFacetGetter (nl.knaw.huygens.timbuctoo.search.description.facet.helpers.DatableRangeFacetGetter)1 RelatedPropertyValueGetter (nl.knaw.huygens.timbuctoo.search.description.facet.helpers.RelatedPropertyValueGetter)1 StringUtils (org.apache.commons.lang.StringUtils)1 P (org.apache.tinkerpop.gremlin.process.traversal.P)1 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)1 org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__ (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__)1 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)1