public static ReferenceTarget createReferenceTarget(JCas jCas) { ReferenceTarget rt = new ReferenceTarget(jCas); rt.addToIndexes(); return rt; }
/** * @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 ReferenceTarget(JCas jcas, int begin, int end) { super(jcas); setBegin(begin); setEnd(end); readObject(); }
private void setLinking(JCas jCas, EntityInformation<T> entityInformation, String linking) { removeFromJCasIndex(entityInformation.getReferenceTarget()); ReferenceTarget referenceTarget = new ReferenceTarget(jCas); referenceTarget.setLinking(linking); for (Entity e : entityInformation.getMentions()) { e.setReferent(referenceTarget); } addToJCasIndex(referenceTarget); addToJCasIndex(entityInformation.getMentions()); }
private void processEntities(JCas jCas, Integer docKey) throws SQLException { // Insert entities Map<ReferenceTarget, List<Entity>> coreferenceEntities = new HashMap<>(); for (Entity ent : JCasUtil.select(jCas, Entity.class)) { ReferenceTarget rt = ent.getReferent(); if (rt == null) { rt = new ReferenceTarget(jCas); } List<Entity> entities = coreferenceEntities.getOrDefault(rt, new ArrayList<>()); entities.add(ent); coreferenceEntities.put(rt, entities); } for (List<Entity> entities : coreferenceEntities.values()) { processCoreferencedEntities(docKey, entities); } }
public JCasSerializationTester() throws UIMAException { out = JCasFactory.createJCas(); in = JCasFactory.createJCas(); in.setDocumentText("This is a test"); final DocumentAnnotation inDA = (DocumentAnnotation) in.getDocumentAnnotationFs(); inDA.setDocumentClassification("CLASS"); final Location l = new Location(in); l.setBegin(10); l.setEnd(12); l.setGeoJson(GEO_JSON); l.setValue("Dinagat Islands"); l.setConfidence(0.9d); l.addToIndexes(in); final ReferenceTarget rt = new ReferenceTarget(in); rt.setBegin(0); rt.setEnd(1); rt.addToIndexes(in); final Person p = new Person(in); p.setBegin(2); p.setEnd(8); p.setGender("Male"); p.setValue("Peter"); p.setConfidence(0.5d); p.setReferent(rt); p.addToIndexes(in); }
@Test public void testExtractReferenceTargets() throws AnalysisEngineProcessException, ResourceInitializationException { String text = "Chris went to London and he saw Big Ben there."; // there - london jCas.setDocumentText(text); Person chris = new Person(jCas); chris.setBegin(text.indexOf("Chris")); chris.setEnd(chris.getBegin() + "Chris".length()); chris.addToIndexes(); ReferenceTarget target = new ReferenceTarget(jCas); target.addToIndexes(); Location london = new Location(jCas); london.setBegin(text.indexOf("London")); london.setEnd(london.getBegin() + "London".length()); london.setReferent(target); london.addToIndexes(); Location there = new Location(jCas); there.setBegin(text.indexOf("there")); there.setEnd(there.getBegin() + "there".length()); there.setReferent(target); there.addToIndexes(); processJCas(); processJCasWithSieve(0); // We should have a reference target and it should be different to the previous, as its been // recreated. Collection<ReferenceTarget> targets = JCasUtil.select(jCas, ReferenceTarget.class); assertEquals(1, targets.size()); assertTrue(targets.iterator().next().getInternalId() != target.getInternalId()); }
pId.addToIndexes(jCas); ReferenceTarget target = new ReferenceTarget(jCas); target.setLinking("testLinking"); target.addToIndexes(jCas);
private String generateSpanStart(Entity e) { String value = e.getValue() == null ? "" : e.getValue().replaceAll("\"", "'"); String referent = e.getReferent() == null ? "" : Long.toString(e.getReferent().getInternalId()); return String.format( "<span class=\"baleen %s\" id=\"%s\" value=\"%s\" data-referent=\"%s\">", e.getClass().getSimpleName(), e.getExternalId(), value, referent); }
@SuppressWarnings("unchecked") @Test public void testReferenceTargets() throws AnalysisEngineProcessException { jCas.setDocumentText("Bill went to London. William came back."); String link = "http://test"; Person p = Annotations.createPerson(jCas, 0, 4, "Bill"); Person q = Annotations.createPerson(jCas, 21, 28, NAME_2); ReferenceTarget referenceTarget = Annotations.createReferenceTarget(jCas, p, q); referenceTarget.setLinking(link); ae.process(jCas); assertEquals(1, documents.count()); assertEquals(1, entities.count()); Document a = entities.find().first(); assertEquals(2, ((List<Object>) a.get(Mongo.FIELD_ENTITIES)).size()); assertEquals(2, ((List<Object>) a.get(Mongo.FIELD_ENTITIES)).size()); assertEquals(link, a.getString(Mongo.FIELD_LINKING)); assertEquals( ConsumerUtils.getExternalId(ImmutableList.of(p, q)), a.getString(fields.getExternalId())); }
.append(FIELD_DOCUMENT_ID, documentId) .append(fields.getExternalId(), ConsumerUtils.getExternalId(e.getValue())) .append(FIELD_LINKING, referenceTarget.getLinking()) .append( FIELD_ENTITIES,
/** * Creates the referent map - map of referent target to mentions. * * @param <T> the generic type * @param jCas the j cas * @param mentions the mentions to map * @param filterEmptyReference true to filter empty references, false to add a stand in reference * @return the multimap */ public static <T extends Base> Multimap<ReferenceTarget, T> createReferentMap( final JCas jCas, final Collection<T> mentions, final boolean filterEmptyReference) { final Multimap<ReferenceTarget, T> targets = HashMultimap.create(); mentions .stream() .filter(p -> !filterEmptyReference || p.getReferent() != null) .forEach( e -> { final ReferenceTarget referent = Optional.ofNullable(e.getReferent()).orElse(new ReferenceTarget(jCas)); targets.put(referent, e); }); return targets; }
final ReferenceTarget rt1 = new ReferenceTarget(jCas); rt1.setBegin(12); rt1.setEnd(13); rt1.addToIndexes(); final ReferenceTarget rt2 = new ReferenceTarget(jCas); rt1.setBegin(12); rt1.setEnd(13); rt1.addToIndexes(); toId(e1.getExternalId()), e1.getExternalId(), toId(rt1.getExternalId()), rt1.getExternalId(), e1.getBegin(), e1.getEnd(), toId(e2.getExternalId()), e2.getExternalId(), toId(rt1.getExternalId()), rt1.getExternalId(), e2.getBegin(), e2.getEnd(), toId(e3.getExternalId()), e3.getExternalId(), toId(rt2.getExternalId()), rt2.getExternalId(), e3.getBegin(),
list.add(Long.toString(e.getReferent().getInternalId())); } else { list.add("");
String refId = ConsumerUtils.getExternalId(e.getValue()); if (!traversal.V(coerce(refId)).hasNext()) { String linking = e.getKey().getLinking() == null ? "" : e.getKey().getLinking(); traversal .addV(REFERENCE_TARGET)
@SafeVarargs public static <T extends Entity> ReferenceTarget createReferenceTarget(JCas jCas, T... entities) { ReferenceTarget rt = new ReferenceTarget(jCas); rt.addToIndexes(); Arrays.stream(entities).forEach(e -> e.setReferent(rt)); return rt; }
/** * Creates the referent map - map of referent target to mentions. * * @param <T> the generic type * @param jCas the j cas * @param mentions the mentions to map * @param filterEmptyReference true to filter empty references, false to add a stand in reference * @return the multimap */ public static <T extends Base> Multimap<ReferenceTarget, T> createReferentMap( final JCas jCas, final Collection<T> mentions, final boolean filterEmptyReference) { final Multimap<ReferenceTarget, T> targets = HashMultimap.create(); mentions .stream() .filter(p -> !filterEmptyReference || p.getReferent() != null) .forEach( e -> { final ReferenceTarget referent = Optional.ofNullable(e.getReferent()).orElse(new ReferenceTarget(jCas)); targets.put(referent, e); }); return targets; }
private void setLinking(JCas jCas, EntityInformation<T> entityInformation, String linking) { removeFromJCasIndex(entityInformation.getReferenceTarget()); ReferenceTarget referenceTarget = new ReferenceTarget(jCas); referenceTarget.setLinking(linking); for (Entity e : entityInformation.getMentions()) { e.setReferent(referenceTarget); } addToJCasIndex(referenceTarget); addToJCasIndex(entityInformation.getMentions()); }
/** * @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 ReferenceTarget(JCas jcas, int begin, int end) { super(jcas); setBegin(begin); setEnd(end); readObject(); }
@Test public void testPreciseConstructAcronym() throws AnalysisEngineProcessException, ResourceInitializationException { String text = "The British Broadcasting Corporation or the BBC if you prefer shows television programmes."; // British Broadcasting Corporation - BBC jCas.setDocumentText(text); // We need these in otherwise we just get one long setence from the mention detector Organisation beeb = new Organisation(jCas); beeb.setBegin(text.indexOf("British Broadcasting Corporation")); beeb.setEnd(beeb.getBegin() + "British Broadcasting Corporation".length()); beeb.addToIndexes(); Organisation bbc = new Organisation(jCas); bbc.setBegin(text.indexOf("BBC")); bbc.setEnd(bbc.getBegin() + "BBC".length()); bbc.addToIndexes(); processJCas(); processJCasWithSieve(4); List<ReferenceTarget> targets = new ArrayList<>(JCasUtil.select(jCas, ReferenceTarget.class)); assertEquals(1, targets.size()); List<Organisation> orgs = new ArrayList<Organisation>(JCasUtil.select(jCas, Organisation.class)); assertEquals(2, orgs.size()); assertNotNull(orgs.get(0).getReferent()); assertEquals( orgs.get(0).getReferent().getInternalId(), orgs.get(1).getReferent().getInternalId()); }
String refId = ConsumerUtils.getExternalId(e.getValue()); if (!traversal.V(coerce(refId)).hasNext()) { String linking = e.getKey().getLinking() == null ? "" : e.getKey().getLinking(); traversal .addV(REFERENCE_TARGET)