public static Temporal createTemporal(JCas jCas, int begin, int end, String value) { Temporal d2 = new Temporal(jCas); d2.setValue(value); d2.setBegin(begin); d2.setEnd(end); d2.addToIndexes(); return d2; }
String precision = temporal.getPrecision(); String id = temporal.getExternalId(); Map<String, Object> json = new HashMap<>(); json.put(FIELD_DOC_ID, docId); json.put(FIELD_EXTERNAL_ID, id); json.put(FIELD_BEGIN, temporal.getBegin()); json.put(FIELD_END, temporal.getEnd()); json.put(FIELD_VALUE, temporal.getValue()); json.put(FIELD_TEMPORAL_TYPE, temporal.getTemporalType()); json.put(FIELD_CONFIDENCE, temporal.getConfidence()); String scope = temporal.getScope(); if (TemporalUtils.SCOPE_RANGE.equals(scope)) { json.put( FIELD_DATE_RANGE, ImmutableMap.of( FIELD_GTE, temporal.getTimestampStart(), FIELD_LTE, temporal.getTimestampStop())); } else { json.put(FIELD_DATE, temporal.getTimestampStart());
@Test public void testTimeRange() throws Exception { jCas.setDocumentText("It was July, and all was quiet"); Temporal t = new Temporal(jCas, 7, 11); t.setTimestampStart(LocalDateTime.of(2016, 7, 1, 0, 0, 0).toEpochSecond(ZoneOffset.UTC)); t.setTimestampStop(LocalDateTime.of(2016, 8, 1, 0, 0, 0).toEpochSecond(ZoneOffset.UTC)); t.setScope("RANGE"); t.setTemporalType("DATE"); t.setValue("July"); t.addToIndexes(); processJCas( NormalizeTemporal.PARAM_DATE_FORMAT, "HH:mm", NormalizeTemporal.PARAM_TEMPORAL_TYPE, "TIME"); assertEquals(1, JCasUtil.select(jCas, Temporal.class).size()); Temporal tTest = JCasUtil.selectByIndex(jCas, Temporal.class, 0); assertEquals("July", tTest.getValue()); assertFalse(tTest.getIsNormalised()); }
/** * @generated * @param jcas JCas to which this Feature Structure belongs * @param begin offset to the begin spot in the SofA * @param end offset to the end spot in the SofA */ public Temporal(JCas jcas, int begin, int end) { super(jcas); setBegin(begin); setEnd(end); readObject(); }
private void correctTimestamps(final Map<String, Object> map, final Temporal e) { // Remove whatever is there... map.remove("timestampStart"); map.remove("timestampStop"); // If it appears at all valid, then convert from seconds to millis if (e.getTimestampStart() != 0 && e.getTimestampStop() != 0) { map.put("timestampStart", e.getTimestampStart() * 1000); map.put("timestampStop", e.getTimestampStop() * 1000); } }
@Test public void testYears() throws Exception { jCas.setDocumentText( "Woolworths was a retail chain from 1909-2008. We had very hot summers in 2009-11. 1969 was wet, as was the year '16."); processJCas(); assertEquals(2, JCasUtil.select(jCas, Temporal.class).size()); Temporal ts1 = JCasUtil.selectByIndex(jCas, Temporal.class, 0); assertEquals("1909-2008", ts1.getCoveredText()); assertEquals(-1924992000L, ts1.getTimestampStart()); assertEquals(1230768000L, ts1.getTimestampStop()); Temporal ts2 = JCasUtil.selectByIndex(jCas, Temporal.class, 1); assertEquals("2009-11", ts2.getCoveredText()); assertEquals(1230768000L, ts2.getTimestampStart()); assertEquals(1325376000L, ts2.getTimestampStop()); }
e5.setPrecision("EXACT"); e5.setTemporalType("DATE"); e5.setTimestampStart(1000); e5.setTimestampStop(1100); docId, BALEEN_DOC_ID, toId(e5.getExternalId()), e5.getExternalId(), toId("ent2"), "ent2", e5.getBegin(), e5.getEnd(), e5.getType().getShortName(), e5.getValue()); m5.getProperties().put("precision", e5.getPrecision()); m5.getProperties().put("temporalType", e5.getTemporalType()); m5.getProperties().put("timestampStart", e5.getTimestampStart()); m5.getProperties().put("timestampStop", e5.getTimestampStop()); docId, BALEEN_DOC_ID, toId(e5.getExternalId()), e5.getExternalId(), e5.getTypeName(), e5.getValue());
String text = "26 November 1992"; jCas.setDocumentText(text); Temporal temporal = new Temporal(jCas, 0, text.length()); temporal.setPrecision(TemporalUtils.PRECISION_EXACT); temporal.setScope(TemporalUtils.SCOPE_SINGLE); temporal.setBegin(0); temporal.setEnd(text.length()); temporal.setTemporalType("Date"); temporal.setValue(text); temporal.setConfidence(1.0); temporal.setTimestampStart(12345L); temporal.addToIndexes(jCas);
@Test public void test2() throws Exception { jCas.setDocumentText("Report Title: An example report\nDTG: 04 1558D Sep 10"); processJCas(); Temporal dt = JCasUtil.selectByIndex(jCas, Temporal.class, 0); assertNotNull(dt); assertEquals("04 1558D Sep 10", dt.getCoveredText()); assertEquals("04 1558D Sep 10", dt.getValue()); assertEquals("EXACT", dt.getPrecision()); assertEquals("SINGLE", dt.getScope()); assertEquals("DATETIME", dt.getTemporalType()); LocalDateTime date = LocalDateTime.of(2010, Month.SEPTEMBER, 4, 11, 58); assertEquals(date.toInstant(ZoneOffset.UTC).getEpochSecond(), dt.getTimestampStart()); assertEquals( date.plusMinutes(1).toInstant(ZoneOffset.UTC).getEpochSecond(), dt.getTimestampStop()); }
Temporal dt1 = new Temporal(jCas); dt1.setValue("1 January 2010"); dt1.setBegin(16); dt1.setEnd(30); dt1.setTimestampStart(jan2010); dt1.setTimestampStop(jan2010); dt1.addToIndexes(); Temporal dt2 = new Temporal(jCas); dt2.setValue("1 January 1930"); dt2.setBegin(60); dt2.setEnd(74); dt2.setTimestampStart(jan1930); dt2.setTimestampStop(jan1930); dt2.addToIndexes(); Temporal dt3 = new Temporal(jCas); dt3.setValue("1 January 1930 to 1 January 2010"); dt3.setTimestampStart(jan1930); dt3.setTimestampStop(jan2010); dt3.addToIndexes(); Temporal dt4 = new Temporal(jCas); dt4.setValue("Some date"); dt4.addToIndexes(); assertEquals("1 January 2010", dt.getValue());
final Temporal temporal = new Temporal(jCas); temporal.setPrecision(TemporalUtils.PRECISION_EXACT); temporal.setScope(TemporalUtils.SCOPE_SINGLE); temporal.setTimestampStart(sentDate.getTime()); temporal.setTimestampStop(sentDate.getTime()); addToHeaderBlock(sentDate.toString(), offset, sb, temporal);
@Test public void testNoTimestamp() throws Exception { jCas.setDocumentText("It was midnight, and all was quiet"); Temporal t = new Temporal(jCas, 7, 15); t.setScope("SINGLE"); t.setTemporalType("TIME"); t.setValue("midnight"); t.addToIndexes(); processJCas( NormalizeTemporal.PARAM_DATE_FORMAT, "HH:mm", NormalizeTemporal.PARAM_TEMPORAL_TYPE, "TIME"); assertEquals(1, JCasUtil.select(jCas, Temporal.class).size()); Temporal tTest = JCasUtil.selectByIndex(jCas, Temporal.class, 0); assertEquals("midnight", tTest.getValue()); assertFalse(tTest.getIsNormalised()); } }
assertEquals("3-10 October 2016", ts1.getCoveredText()); assertEquals(1475452800L, ts1.getTimestampStart()); assertEquals(1476144000L, ts1.getTimestampStop()); assertEquals("27th September - Monday 3 Oct 16", ts2.getCoveredText()); assertEquals(1474934400L, ts2.getTimestampStart()); assertEquals(1475539200L, ts2.getTimestampStop()); assertEquals("21st December 2016 and 2 January 17", ts3.getCoveredText()); assertEquals(1482278400L, ts3.getTimestampStart()); assertEquals(1483401600L, ts3.getTimestampStop()); assertEquals("2/3 January '17", ts4.getCoveredText()); assertEquals(1483315200L, ts4.getTimestampStart()); assertEquals(1483488000L, ts4.getTimestampStop()); assertEquals("2nd and 5th January 2017", ts5.getCoveredText()); assertEquals("2nd January 2017", ts5.getValue()); assertEquals(1483315200L, ts5.getTimestampStart()); assertEquals(1483401600L, ts5.getTimestampStop()); assertEquals("5th January 2017", ts6.getCoveredText()); assertEquals(1483574400L, ts6.getTimestampStart()); assertEquals(1483660800L, ts6.getTimestampStop());
@Test public void test4() throws UIMAException { createPOS(); Person person = new Person(jCas, 0, 2); // He person.addToIndexes(); Money money = new Money(jCas, 59, 71); // $1.8 billion money.addToIndexes(); Temporal date = new Temporal(jCas, 75, 84); // September date.addToIndexes(); processJCas(NPVNP.PARAM_ONLY_EXISTING, true); assertEquals(0, JCasUtil.select(jCas, Relation.class).size()); }
return Optional.of(new Quantity(jCas)); case "Temporal": return Optional.of(new Temporal(jCas)); case "Url": return Optional.of(new Url(jCas));
public void timeRegexCountAndValueCheck(Double expectedCount, String... expectedValues) throws Exception { // Check the correct number of references is extracted assertEquals(expectedCount, Double.valueOf(JCasUtil.select(jCas, Temporal.class).size())); // Loop the matches and check their values for (int i = 0; i < expectedValues.length; i++) { String expectedVal = expectedValues[i]; // Get the value Temporal t1 = JCasUtil.selectByIndex(jCas, Temporal.class, i); assertNotNull(t1); // Check that the covered text is what we're expecting assertEquals(expectedVal, t1.getCoveredText()); // Check that the value and the covered text are the same assertEquals(t1.getValue(), t1.getCoveredText()); } }
@Test public void test() throws Exception { jCas.setDocumentText("47 people were seen at 1507725753."); processJCas(EpochTime.PARAM_EARLIEST, "1500000000"); assertEquals(1, JCasUtil.select(jCas, Temporal.class).size()); Temporal t = JCasUtil.selectByIndex(jCas, Temporal.class, 0); assertEquals("1507725753", t.getCoveredText()); assertEquals(1507725753, t.getTimestampStart()); assertEquals(1507725754, t.getTimestampStop()); } }
String text = "26 November 1992"; jCas.setDocumentText(text); Temporal temporal = new Temporal(jCas, 0, text.length()); temporal.setPrecision(TemporalUtils.PRECISION_EXACT); temporal.setScope(TemporalUtils.SCOPE_RANGE); temporal.setBegin(0); temporal.setEnd(text.length()); temporal.setTemporalType("Date"); temporal.setValue(text); temporal.setTimestampStart(12345L); temporal.setTimestampStop(54321L); temporal.addToIndexes(jCas);
@Test public void test3() throws Exception { jCas.setDocumentText("Report Title: An example report\nDTG: 04 1558D*SEP 10"); processJCas(); Temporal dt = JCasUtil.selectByIndex(jCas, Temporal.class, 0); assertNotNull(dt); assertEquals("04 1558D*SEP 10", dt.getCoveredText()); assertEquals("04 1558D*SEP 10", dt.getValue()); assertEquals("EXACT", dt.getPrecision()); assertEquals("SINGLE", dt.getScope()); assertEquals("DATETIME", dt.getTemporalType()); LocalDateTime date = LocalDateTime.of(2010, Month.SEPTEMBER, 4, 11, 28); assertEquals(date.toInstant(ZoneOffset.UTC).getEpochSecond(), dt.getTimestampStart()); assertEquals( date.plusMinutes(1).toInstant(ZoneOffset.UTC).getEpochSecond(), dt.getTimestampStop()); }
final Temporal temporal = new Temporal(jCas); temporal.setPrecision(TemporalUtils.PRECISION_EXACT); temporal.setScope(TemporalUtils.SCOPE_SINGLE); temporal.setTimestampStart(sentDate.getTime()); temporal.setTimestampStop(sentDate.getTime()); addToHeaderBlock(sentDate.toString(), offset, sb, temporal);