@Test public void returnsEmptyWhenNotEvent() throws UIMAException { EventFactory factory = new EventFactory(JCasFactory.createJCas()); assertFalse(factory.create(crossSenteneMention).isPresent()); assertFalse(factory.create(relationMention).isPresent()); assertFalse(factory.create(textMention).isPresent()); }
@SuppressWarnings("unchecked") public Optional<Event> create(Mention mention) { if (mention instanceof EventMention) { EventMention eventMention = (EventMention) mention; Event e = new Event(jCas); e.setBegin(eventMention.startOffset()); e.setEnd(eventMention.endOffset()); e.setValue(eventMention.text()); List<String> labels = JavaConverters.seqAsJavaList(eventMention.labels()); e.setEventType(new StringArray(jCas, labels.size())); for (int i = 0; i < labels.size(); i++) { e.setEventType(i, labels.get(i)); } int startOffset = eventMention.trigger().startOffset(); int endOffset = eventMention.trigger().endOffset(); Optional<WordToken> token = checkFor(WordToken.class, startOffset, endOffset); if (token.isPresent()) { e.setTokens(new FSArray(jCas, 1)); e.setTokens(0, token.get()); } else { e.setTokens(new FSArray(jCas, 0)); } Multimap<String, Entity> arguments = ArrayListMultimap.create(); JavaConverters.mapAsJavaMap(eventMention.arguments()) .forEach( (k, v) -> JavaConverters.seqAsJavaList(v) .forEach( m -> checkFor(Entity.class, m.startOffset(), m.endOffset()) .ifPresent(entity -> arguments.put(k, entity)))); e.setArguments(new StringArray(jCas, arguments.size())); e.setEntities(new FSArray(jCas, arguments.size())); Entry<String, Entity>[] entries = arguments.entries().toArray(new Entry[arguments.size()]); for (int i = 0; i < entries.length; i++) { Entry<String, Entity> entry = entries[i]; e.setArguments(i, entry.getKey()); e.setEntities(i, entry.getValue()); } e.addToIndexes(); return Optional.of(e); } return Optional.empty(); }
EventFactory { @SuppressWarnings("unchecked") public Optional<Event> create(Mention mention) { if (mention instanceof EventMention) { EventMention eventMention = (EventMention) mention; Event e = new Event(jCas); e.setBegin(eventMention.startOffset()); e.setEnd(eventMention.endOffset()); e.setValue(eventMention.text()); List<String> labels = JavaConverters.seqAsJavaList(eventMention.labels()); e.setEventType(new StringArray(jCas, labels.size())); for (int i = 0; i < labels.size(); i++) { e.setEventType(i, labels.get(i)); } int startOffset = eventMention.trigger().startOffset(); int endOffset = eventMention.trigger().endOffset(); Optional<WordToken> token = checkFor(WordToken.class, startOffset, endOffset); if (token.isPresent()) { e.setTokens(new FSArray(jCas, 1)); e.setTokens(0, token.get()); } else { e.setTokens(new FSArray(jCas, 0)); } Multimap<String, Entity> arguments = ArrayListMultimap.create(); JavaConverters.mapAsJavaMap(eventMention.arguments()) .forEach( (k, v) -> JavaConverters.seqAsJavaList(v) .forEach( m -> checkFor(Entity.class, m.startOffset(), m.endOffset()) .ifPresent(entity -> arguments.put(k, entity)))); e.setArguments(new StringArray(jCas, arguments.size())); e.setEntities(new FSArray(jCas, arguments.size())); Entry<String, Entity>[] entries = arguments.entries().toArray(new Entry[arguments.size()]); for (int i = 0; i < entries.length; i++) { Entry<String, Entity> entry = entries[i]; e.setArguments(i, entry.getKey()); e.setEntities(i, entry.getValue()); } e.addToIndexes(); return Optional.of(e); } return Optional.empty(); } }
EventFactory { @SuppressWarnings("unchecked") public Optional<Event> create(Mention mention) { if (mention instanceof EventMention) { EventMention eventMention = (EventMention) mention; Event e = new Event(jCas); e.setBegin(eventMention.startOffset()); e.setEnd(eventMention.endOffset()); e.setValue(eventMention.text()); List<String> labels = JavaConverters.seqAsJavaList(eventMention.labels()); e.setEventType(new StringArray(jCas, labels.size())); for (int i = 0; i < labels.size(); i++) { e.setEventType(i, labels.get(i)); } int startOffset = eventMention.trigger().startOffset(); int endOffset = eventMention.trigger().endOffset(); Optional<WordToken> token = checkFor(WordToken.class, startOffset, endOffset); if (token.isPresent()) { e.setTokens(new FSArray(jCas, 1)); e.setTokens(0, token.get()); } else { e.setTokens(new FSArray(jCas, 0)); } Multimap<String, Entity> arguments = ArrayListMultimap.create(); JavaConverters.mapAsJavaMap(eventMention.arguments()) .forEach( (k, v) -> JavaConverters.seqAsJavaList(v) .forEach( m -> checkFor(Entity.class, m.startOffset(), m.endOffset()) .ifPresent(entity -> arguments.put(k, entity)))); e.setArguments(new StringArray(jCas, arguments.size())); e.setEntities(new FSArray(jCas, arguments.size())); Entry<String, Entity>[] entries = arguments.entries().toArray(new Entry[arguments.size()]); for (int i = 0; i < entries.length; i++) { Entry<String, Entity> entry = entries[i]; e.setArguments(i, entry.getKey()); e.setEntities(i, entry.getValue()); } e.addToIndexes(); return Optional.of(e); } return Optional.empty(); } EventFactory(JCas jCas); }
EventFactory { @SuppressWarnings("unchecked") public Optional<Event> create(Mention mention) { if (mention instanceof EventMention) { EventMention eventMention = (EventMention) mention; Event e = new Event(jCas); e.setBegin(eventMention.startOffset()); e.setEnd(eventMention.endOffset()); e.setValue(eventMention.text()); List<String> labels = JavaConverters.seqAsJavaList(eventMention.labels()); e.setEventType(new StringArray(jCas, labels.size())); for (int i = 0; i < labels.size(); i++) { e.setEventType(i, labels.get(i)); } int startOffset = eventMention.trigger().startOffset(); int endOffset = eventMention.trigger().endOffset(); Optional<WordToken> token = checkFor(WordToken.class, startOffset, endOffset); if (token.isPresent()) { e.setTokens(new FSArray(jCas, 1)); e.setTokens(0, token.get()); } else { e.setTokens(new FSArray(jCas, 0)); } Multimap<String, Entity> arguments = ArrayListMultimap.create(); JavaConverters.mapAsJavaMap(eventMention.arguments()) .forEach( (k, v) -> JavaConverters.seqAsJavaList(v) .forEach( m -> checkFor(Entity.class, m.startOffset(), m.endOffset()) .ifPresent(entity -> arguments.put(k, entity)))); e.setArguments(new StringArray(jCas, arguments.size())); e.setEntities(new FSArray(jCas, arguments.size())); Entry<String, Entity>[] entries = arguments.entries().toArray(new Entry[arguments.size()]); for (int i = 0; i < entries.length; i++) { Entry<String, Entity> entry = entries[i]; e.setArguments(i, entry.getKey()); e.setEntities(i, entry.getValue()); } e.addToIndexes(); return Optional.of(e); } return Optional.empty(); } EventFactory(JCas jCas); @SuppressWarnings("unchecked") Optional<Event> create(Mention mention); void create(Seq<Mention> mentions); }
EventFactory { @SuppressWarnings("unchecked") public Optional<Event> create(Mention mention) { if (mention instanceof EventMention) { EventMention eventMention = (EventMention) mention; Event e = new Event(jCas); e.setBegin(eventMention.startOffset()); e.setEnd(eventMention.endOffset()); e.setValue(eventMention.text()); List<String> labels = JavaConverters.seqAsJavaList(eventMention.labels()); e.setEventType(new StringArray(jCas, labels.size())); for (int i = 0; i < labels.size(); i++) { e.setEventType(i, labels.get(i)); } int startOffset = eventMention.trigger().startOffset(); int endOffset = eventMention.trigger().endOffset(); Optional<WordToken> token = checkFor(WordToken.class, startOffset, endOffset); if (token.isPresent()) { e.setTokens(new FSArray(jCas, 1)); e.setTokens(0, token.get()); } else { e.setTokens(new FSArray(jCas, 0)); } Multimap<String, Entity> arguments = ArrayListMultimap.create(); JavaConverters.mapAsJavaMap(eventMention.arguments()) .forEach( (k, v) -> JavaConverters.seqAsJavaList(v) .forEach( m -> checkFor(Entity.class, m.startOffset(), m.endOffset()) .ifPresent(entity -> arguments.put(k, entity)))); e.setArguments(new StringArray(jCas, arguments.size())); e.setEntities(new FSArray(jCas, arguments.size())); Entry<String, Entity>[] entries = arguments.entries().toArray(new Entry[arguments.size()]); for (int i = 0; i < entries.length; i++) { Entry<String, Entity> entry = entries[i]; e.setArguments(i, entry.getKey()); e.setEntities(i, entry.getValue()); } e.addToIndexes(); return Optional.of(e); } return Optional.empty(); } EventFactory(JCas jCas); @SuppressWarnings("unchecked") Optional<Event> create(Mention mention); void create(Seq<Mention> mentions);  }