private <T extends Entity> T addToHeaderBlock( final String v, final int offset, final StringBuilder sb, final T annotation) { final int begin = sb.length() + offset; sb.append(v); final int end = sb.length() + offset; sb.append("\n"); annotation.setBegin(begin); annotation.setEnd(end); annotation.setConfidence(1); annotation.setValue(v); annotation.addToIndexes(); return annotation; }
private <T extends Entity> T addToHeaderBlock( final String v, final int offset, final StringBuilder sb, final T annotation) { final int begin = sb.length() + offset; sb.append(v); final int end = sb.length() + offset; sb.append("\n"); annotation.setBegin(begin); annotation.setEnd(end); annotation.setConfidence(1); annotation.setValue(v); annotation.addToIndexes(); return annotation; }
/** * Copy entity. * * @param jCas the j cas * @param begin the begin * @param end the end * @param entity the entity * @return the entity */ public static Entity copyEntity(JCas jCas, int begin, int end, Entity entity) { // TODO: This could be better, but would suggest if better is need try { final Entity instance = entity.getClass().getConstructor(JCas.class).newInstance(jCas); instance.setBegin(begin); instance.setEnd(end); instance.setReferent(entity.getReferent()); instance.setValue(entity.getValue()); return instance; } catch (final Exception e) { LOGGER.warn("Unable to copy entity", e); return null; } }
/** * Copy entity. * * @param jCas the j cas * @param begin the begin * @param end the end * @param entity the entity * @return the entity */ public static Entity copyEntity(JCas jCas, int begin, int end, Entity entity) { // TODO: This could be better, but would suggest if better is need try { final Entity instance = entity.getClass().getConstructor(JCas.class).newInstance(jCas); instance.setBegin(begin); instance.setEnd(end); instance.setReferent(entity.getReferent()); instance.setValue(entity.getValue()); return instance; } catch (final Exception e) { LOGGER.warn("Unable to copy entity", e); return null; } }
/** * Add an annotation to the JCas index, notifying UimaMonitor of the fact we have done so * * @param annot Annotation(s) to add */ public void add(Collection<? extends Annotation> annotations) { for (Annotation annot : annotations) { annot.addToIndexes(); monitor.entityAdded(annot.getType().getName()); if (annot instanceof Entity) { Entity entity = (Entity) annot; // Add in a value if it doesn't have one if (Strings.isNullOrEmpty(entity.getValue())) { entity.setValue(annot.getCoveredText()); } addToHistory(annot.getCAS(), HistoryEvents.createAdded((Recordable) annot, referrer)); } } }
/** * Add an annotation to the JCas index, notifying UimaMonitor of the fact we have done so * * @param annot Annotation(s) to add */ public void add(Collection<? extends Annotation> annotations) { for (Annotation annot : annotations) { annot.addToIndexes(); monitor.entityAdded(annot.getType().getName()); if (annot instanceof Entity) { Entity entity = (Entity) annot; // Add in a value if it doesn't have one if (Strings.isNullOrEmpty(entity.getValue())) { entity.setValue(annot.getCoveredText()); } addToHistory(annot.getCAS(), HistoryEvents.createAdded((Recordable) annot, referrer)); } } }
public static Entity createEntity(JCas jCas, int begin, int end, String value) { Entity e = new Entity(jCas); e.setBegin(begin); e.setEnd(end); if (value != null) { e.setValue(e.getCoveredText()); } e.addToIndexes(); return e; }
@Test public void testCopyEntity() { final Entity e = new Entity(jCas); e.setBegin(0); e.setBegin(5); e.setValue("value"); e.addToIndexes(); final Entity copyEntity = ComparableEntitySpanUtils.copyEntity(jCas, 10, 20, e); copyEntity.addToIndexes(); final List<Entity> select = new ArrayList<>(JCasUtil.select(jCas, Entity.class)); assertEquals(2, select.size()); assertSame(e, select.get(0)); assertEquals("value", select.get(1).getValue()); assertEquals(10, select.get(1).getBegin()); assertEquals(20, select.get(1).getEnd()); }
a.setBegin(e.getBegin()); a.setEnd(e.getEnd()); a.setValue(e.getValue()); a.setConfidence(e.getConfidence());
a.setBegin(e.getBegin()); a.setEnd(e.getEnd()); a.setValue(e.getValue()); a.setConfidence(e.getConfidence());
@Test public void testString() { Entity e = new Entity(jCas); e.setValue("entity"); e.addToIndexes(); Feature feature = e.getType().getFeatureByBaseName("value"); NewFeatureUtils.setPrimitive(e, feature, "newValue"); assertEquals("newValue", e.getStringValue(feature)); }
@Test public void testString() { Entity e = new Entity(jCas); e.setValue("Test Value"); e.addToIndexes(); Feature f = e.getType().getFeatureByBaseName("value"); Object o = FeatureUtils.featureToObject(f, e); assertTrue(o instanceof String); assertEquals("Test Value", (String) o); }
@Test public void testCompare() throws UIMAException { final JCas jCas = JCasSingleton.getJCasInstance(); final Entity e = new Entity(jCas); final Entity e2 = new Entity(jCas); ComparableEntitySpan span = new ComparableEntitySpan(e, 5, 10); assertEquals(-1, span.compareTo(new ComparableEntitySpan(e2, 11, 15))); assertEquals(1, span.compareTo(new ComparableEntitySpan(e2, 0, 4))); assertEquals(-1, span.compareTo(new ComparableEntitySpan(e2, 5, 15))); assertEquals(1, span.compareTo(new ComparableEntitySpan(e2, 5, 7))); assertEquals(0, span.compareTo(new ComparableEntitySpan(e2, 5, 10))); e.setValue("Hello"); assertEquals(1, span.compareTo(new ComparableEntitySpan(e2, 5, 10))); e.setValue(null); e2.setValue("Hello"); assertEquals(-1, span.compareTo(new ComparableEntitySpan(e2, 5, 10))); e.setValue("Howdy"); assertEquals("Howdy".compareTo("Hello"), span.compareTo(new ComparableEntitySpan(e2, 5, 10))); } }
protected void createEntitiesDocument2() { jCas.reset(); jCas.setDocumentText( "Paula went to London on 12th February 2017. In Paris, she met a UID male."); Annotations.createPerson(jCas, 0, 5, "Paula"); Annotations.createLocation(jCas, 47, 53, "Paris", null); Temporal d = Annotations.createTemporal(jCas, 24, 42, ""); d.setConfidence(1.0); Entity e = new Entity(jCas); e.setBegin(14); e.setEnd(20); e.setValue("London"); e.addToIndexes(); }
e.setValue("Howdy"); assertEquals("Howdy", span.getValue());