private void addEventsToIndexes(Set<PData> events, Map<String, Gene> proteinMap, Set<Word> triggers, JCas aJCas) { Map<String, Word> triggerMap = new HashMap<>(); Map<String, PData> eventMap = new HashMap<>(); HashMap<String, EventMention> eventAnnotations = new HashMap<String, EventMention>(); HashMap<String, EventTrigger> triggerAnnotations = new HashMap<String, EventTrigger>(); for (Word trg : triggers) { triggerMap.put(trg.TID, trg); } for (PData event : events) { eventMap.put(event.PID, event); } for (PData event : events) { try { addEventToIndexes(event, proteinMap, triggerMap, eventAnnotations, triggerAnnotations, aJCas); } catch (UnknownProteinIdException e) { String docId = "<unknown>"; FSIterator<Annotation> it = aJCas.getAnnotationIndex(Header.type).iterator(); if (it.hasNext()) { Header h = (Header) it.next(); docId = h.getDocId(); } log.debug("Exception occurred in document " + docId + ". The respective event will be skipped. Error was: ", e); } } }
private DocumentId getDocumentId(JCas aJCas) { DocumentId docId = null; try { DBProcessingMetaData dbProcessingMetaData = JCasUtil.selectSingle(aJCas, DBProcessingMetaData.class); docId = new DocumentId(dbProcessingMetaData); } catch (IllegalArgumentException e) { // it seems there is not DBProcessingMetaData we could get a complex primary key from. The document ID // will have to do. log.debug("Could not find the primary key in the DBProcessingMetaData due to exception: {}. Using the document ID as primary key.", DBProcessingMetaData.class.getSimpleName()); } if (docId == null) { AnnotationIndex<Annotation> headerIndex = aJCas.getAnnotationIndex(Header.type); FSIterator<Annotation> headerIt = headerIndex.iterator(); if (!headerIt.hasNext()) { int min = Math.min(100, aJCas.getDocumentText().length()); log.warn( "Got document without a header and without DBProcessingMetaData; cannot obtain document ID." + " This document will not be written into the database. Document text begins with: {}", aJCas.getDocumentText().substring(0, min)); ++headerlessDocuments; return null; } Header header = (Header) headerIt.next(); docId = new DocumentId(header.getDocId()); } return docId; }
String docid = "<unknown>"; try { docid = JCasUtil.selectSingle(aJCas, Header.class).getDocId(); } catch (Exception e) {
if (headerIt.hasNext()) { Header header = (Header) headerIt.next(); docId = header.getDocId(); } else { docId = "<unknown ID>";