@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()); }
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; }
/** * 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; } }
/** * @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 Entity(JCas jcas, int begin, int end) { super(jcas); setBegin(begin); setEnd(end); readObject(); }
/** * Gets the entity value, or if the value has not been set then gets the covered text * * @return the entity value */ public String getValue() { if (!Strings.isNullOrEmpty(entity.getValue())) return entity.getValue(); return entity.getCoveredText(); }
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; }
.append("entityId", entity.getExternalId()) .append(FIELD_TYPE, entity.getType().getShortName()) .append(FIELD_SUBTYPE, entity.getSubType()) .append(FIELD_VALUE, entity.getValue()) .append(FIELD_BEGIN, entity.getBegin()) .append(FIELD_END, entity.getEnd());
@Test public void testInteger() { Entity e = new Entity(jCas); e.setBegin(0); e.addToIndexes(); Feature feature = e.getType().getFeatureByBaseName("begin"); NewFeatureUtils.setPrimitive(e, feature, 1); assertEquals(1, e.getIntValue(feature)); }
@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)); }
@Override protected String print(Entity t) { final StringBuilder sb = new StringBuilder(); writeLine(sb, "Value", t.getValue()); writeLine(sb, "Type", t.getTypeName()); writeLine(sb, "Span", String.format("%d -> %d", t.getBegin(), t.getEnd())); return sb.toString(); } }
@Test public void testDouble() { Entity e = new Entity(jCas); e.setConfidence(0.5); e.addToIndexes(); Feature feature = e.getType().getFeatureByBaseName("confidence"); NewFeatureUtils.setPrimitive(e, feature, 1.0); assertEquals(1.0, e.getDoubleValue(feature), 0.0); }
sentence = sentences.iterator().next(); } else { getMonitor().error("Entity without sentence {}", e.getCoveredText()); return new String[0]; list.add(e.getExternalId()); if (e.getReferent() != null) { list.add(Long.toString(e.getReferent().getInternalId())); } else { list.add(""); list.add(e.getType().getShortName()); list.add(normalize(e.getValue())); if (x.getInternalId() != e.getInternalId()) { list.add(normalize(x.getValue())); list.add(x.getType().getShortName()); entityCount++; if (collection == null || collection.isEmpty()) { nonEntityNonStopWords.add(t); } else if (!collection.stream().anyMatch(x -> e.getInternalId() == x.getInternalId())) {
@Test public void testLong() { Entity e = new Entity(jCas); e.setInternalId(12345); e.addToIndexes(); Feature feature = e.getType().getFeatureByBaseName("internalId"); NewFeatureUtils.setPrimitive(e, feature, 54321); assertEquals(54321, e.getLongValue(feature)); }
@Test public void testSame() throws AnalysisEngineProcessException, ResourceInitializationException { final Entity a = new Entity(jCas); a.setValue("a"); a.addToIndexes(); final Entity b = new Entity(jCas); b.setValue("b"); b.addToIndexes(); final Entity c = new Entity(jCas); c.setValue("c"); c.addToIndexes();
cow.setBegin(4); cow.setEnd(7); cow.addToIndexes(jCas); moon.setBegin(23); moon.setEnd(27); moon.addToIndexes(jCas);
private Optional<Entity> findEntity( Multimap<Offset, Entity> entityIndex, int begin, int end, String value) { return entityIndex .get(new Offset(begin, end)) .stream() .filter(e -> value.equals(e.getValue())) .findFirst(); }
/** * 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)); } } }
@Test public void testOverlaps() { final Entity a = new Entity(jCas); a.setBegin(0); a.setEnd(10); final Entity b = new Entity(jCas); b.setBegin(8); b.setEnd(15); final Entity c = new Entity(jCas); c.setBegin(20); c.setEnd(30); assertTrue(ComparableEntitySpanUtils.overlaps(a, b)); assertTrue(ComparableEntitySpanUtils.overlaps(b, a)); assertFalse(ComparableEntitySpanUtils.overlaps(a, c)); assertFalse(ComparableEntitySpanUtils.overlaps(c, a)); } }
@Test public void testFloat() { Entity e = new Entity(jCas); e.setIsNormalised(false); e.addToIndexes(); Feature feature = e.getType().getFeatureByBaseName("isNormalised"); NewFeatureUtils.setPrimitive(e, feature, true); assertTrue(e.getBooleanValue(feature)); }