/** * Creates an empty KAFDocument element */ public KAFDocument(String lang, String version) { this.lang = lang; this.version = version; lps = new LinkedHashMap<String, List<LinguisticProcessor>>(); idManager = new IdManager(); annotationContainer = new AnnotationContainer(); }
void updateCounter(AnnotationType ann, String id) { this.insertId(id); try { Integer currentCounter = this.counters.get(ann); Integer newCounter = extractCounterFromId(id); if (currentCounter < newCounter) { this.counters.put(ann, newCounter); } } catch(IllegalStateException e) { this.inconsistentId.put(ann, true); } } }
/** Creates a Role object to load an existing role. It receives the ID as an argument. It doesn't add the role to the predicate. * @param id role's ID. * @param predicate the predicate which this role is part of * @param semRole semantic role * @param span span containing all the targets of the role * @return a new role. */ public Predicate.Role newRole(String id, Predicate predicate, String semRole, Span<Term> span) { idManager.updateCounter(AnnotationType.ROLE, id); Predicate.Role newRole = new Predicate.Role(id, semRole, span); return newRole; }
String getNextId(AnnotationType ann) { if (this.inconsistentId.get(ann)) { throw new IllegalStateException("Inconsistent " + ann + "IDs. Can't create new " + ann + " IDs."); } Integer nextCount = this.counters.get(ann) + 1; this.counters.put(ann, nextCount); String id = this.prefixes.get(ann) + Integer.toString(nextCount); this.insertId(id); return id; }
public Statement newStatement(String id, Statement.StatementTarget target) { idManager.updateCounter(AnnotationType.STATEMENT, id); Statement newStatement = new Statement(id, target); annotationContainer.add(newStatement, Layer.ATTRIBUTION, AnnotationType.STATEMENT); return newStatement; }
/** Creates an Entity object to load an existing entity. It receives the ID as an argument. The entity is added to the document object. * @param id the ID of the named entity. * @param type entity type. 8 values are posible: Person, Organization, Location, Date, Time, Money, Percent, Misc. * @param references it contains one or more span elements. A span can be used to reference the different occurrences of the same named entity in the document. If the entity is composed by multiple words, multiple target elements are used. * @return a new named entity. */ public Entity newEntity(String id, List<Span<Term>> references) { idManager.updateCounter(AnnotationType.ENTITY, id); Entity newEntity = new Entity(id, references); annotationContainer.add(newEntity, Layer.ENTITIES, AnnotationType.ENTITY); return newEntity; }
this.version = version; lps = new LinkedHashMap<String, List<LinguisticProcessor>>(); idManager = new IdManager(); annotationContainer = new AnnotationContainer();
/** Creates a new Role object. It assigns an appropriate ID to it. It uses the ID of the predicate to create a new ID for the role. It doesn't add the role to the predicate. * @param predicate the predicate which this role is part of * @param semRole semantic role * @param span span containing all the targets of the role * @return a new role. */ public Predicate.Role newRole(Predicate predicate, String semRole, Span<Term> span) { String newId = idManager.getNextId(AnnotationType.ROLE); Predicate.Role newRole = new Predicate.Role(newId, semRole, span); return newRole; }
public TLink newTLink(String id, TLinkReferable from, TLinkReferable to, String relType) { idManager.updateCounter(AnnotationType.TLINK, id); TLink newTLink = new TLink(id, from, to, relType); annotationContainer.add(newTLink, Layer.TEMPORAL_RELATIONS, AnnotationType.TLINK); return newTLink; }
/** Creates a new coreference. It assigns an appropriate ID to it. The Coref is added to the document. * @param references different mentions (list of targets) to the same entity. * @return a new coreference. */ public Coref newCoref(List<Span<Term>> mentions) { String newId = idManager.getNextId(AnnotationType.COREF); Coref newCoref = new Coref(newId, mentions); annotationContainer.add(newCoref, Layer.COREFERENCES, AnnotationType.COREF); return newCoref; }
public CLink newCLink(String id, Predicate from, Predicate to) { idManager.updateCounter(AnnotationType.CLINK, id); CLink newCLink = new CLink(id, from, to); annotationContainer.add(newCLink, Layer.CAUSAL_RELATIONS, AnnotationType.CLINK); return newCLink; }
public TLink newTLink(TLinkReferable from, TLinkReferable to, String relType) { String newId = idManager.getNextId(AnnotationType.TLINK); TLink newTLink = new TLink(newId, from, to, relType); annotationContainer.add(newTLink, Layer.TEMPORAL_RELATIONS, AnnotationType.TLINK); return newTLink; }
/** Creates a new opinion object. It receives its ID as an argument. The opinion is added to the document. * @return a new opinion. */ public Opinion newOpinion(String id) { idManager.updateCounter(AnnotationType.OPINION, id); Opinion newOpinion = new Opinion(id); annotationContainer.add(newOpinion, Layer.OPINIONS, AnnotationType.OPINION); return newOpinion; }
/** Creates a new relation between entities and/or sentiment features. It assigns an appropriate ID to it. The relation is added to the document. * @param from source of the relation * @param to target of the relation * @return a new relation */ public Relation newRelation(Relational from, Relational to) { String newId = idManager.getNextId(AnnotationType.RELATION); Relation newRelation = new Relation(newId, from, to); annotationContainer.add(newRelation, Layer.RELATIONS, AnnotationType.RELATION); return newRelation; }
/** Creates a new relation between entities and/or sentiment features. It receives its ID as an argument. The relation is added to the document. * @param id the ID of the relation * @param from source of the relation * @param to target of the relation * @return a new relation */ public Relation newRelation(String id, Relational from, Relational to) { idManager.updateCounter(AnnotationType.RELATION, id); Relation newRelation = new Relation(id, from, to); annotationContainer.add(newRelation, Layer.RELATIONS, AnnotationType.RELATION); return newRelation; }
public Terminal newTerminal(String id, Span<Term> span) { Terminal tn = new Terminal(id, span); String newEdgeId = idManager.getNextId(AnnotationType.EDGE); tn.setEdgeId(newEdgeId); return tn; }
public WF newWF(String id, int offset, int length, String form, int sent) { idManager.updateCounter(AnnotationType.WF, id); WF newWF = new WF(this.annotationContainer, id, offset, length, form, sent); annotationContainer.add(newWF, Layer.TEXT, AnnotationType.WF); return newWF; }
public CLink newCLink(Predicate from, Predicate to) { String newId = idManager.getNextId(AnnotationType.CLINK); CLink newCLink = new CLink(newId, from, to); annotationContainer.add(newCLink, Layer.CAUSAL_RELATIONS, AnnotationType.CLINK); return newCLink; }