@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof KAFDocument)) return false; KAFDocument naf = (KAFDocument) o; /* Language and version */ if (!this.getLang().equals(naf.getLang()) || !this.getVersion().equals(naf.getVersion())) return false; /* NAF header */ if (!this.headerEquals(naf)) return false; /* Layers and annotations */ return Utils.areEquals(this.annotationContainer, naf.annotationContainer); }
public static KAFDocument join(List<KAFDocument> nafs) { KAFDocument firstNaf = nafs.get(0); KAFDocument joinedNaf = new KAFDocument(firstNaf.getLang(), nafs.get(0).getVersion()); joinedNaf.setRawText(firstNaf.getRawText()); for (KAFDocument nafPart : nafs) { for (AnnotationType type : highLevelAnnotationTypes) { Layer layer = highLevelAnnotationType2Layer.get(type); List<Annotation> annotations = new ArrayList<Annotation>(); if (isMultiLayerAnnotationType(type)) { for (String groupId : nafPart.annotationContainer.getGroupIDs(type)) { annotations.addAll(nafPart.getAnnotations(type, groupId)); } } else { annotations = nafPart.getAnnotations(type); } for (Annotation ann : annotations) { joinedNaf.addExistingAnnotation(ann, layer, type); } } } return joinedNaf; }
public List<KAFDocument> splitInParagraphs() { List<KAFDocument> paraNafs = new ArrayList<KAFDocument>(); Integer numParagraphs = this.getNumParagraphs(); for (Integer paragraph = 1; paragraph <= numParagraphs; paragraph++) { KAFDocument naf = new KAFDocument(this.getLang(), this.getVersion()); naf.setRawText(this.getRawText()); for (AnnotationType type : highLevelAnnotationTypes) { Layer layer = highLevelAnnotationType2Layer.get(type); if (isParagraphLevelAnnotationType(type)) { List<Annotation> annotations = new ArrayList<Annotation>(); if (isMultiLayerAnnotationType(type)) { for (String groupId : annotationContainer.getGroupIDs(type)) { annotations.addAll(this.getByPara(type, groupId, paragraph)); } } else { annotations = this.getByPara(type, paragraph); } for (Annotation ann : annotations) { naf.addExistingAnnotation(ann, layer, type); } } } paraNafs.add(naf); } return paraNafs; }
public List<KAFDocument> splitInSentences() { List<KAFDocument> sentNafs = new ArrayList<KAFDocument>(); Integer numParagraphs = this.getNumParagraphs(); for (Integer paragraph = 1; paragraph <= numParagraphs; paragraph++) { List<Integer> sentences = this.getSentsByParagraph(paragraph); for (Integer sentence : sentences) { KAFDocument naf = new KAFDocument(this.getLang(), this.getVersion()); naf.setRawText(this.getRawText()); for (AnnotationType type : highLevelAnnotationTypes) { Layer layer = highLevelAnnotationType2Layer.get(type); if (isSentenceLevelAnnotationType(type)) { List<Annotation> annotations = new ArrayList<Annotation>(); if (isMultiLayerAnnotationType(type)) { for (String groupId : annotationContainer.getGroupIDs(type)) { annotations.addAll(this.getBySent(type, groupId, sentence)); } } else { annotations = this.getBySent(type, sentence); } for (Annotation ann : annotations) { naf.addExistingAnnotation(ann, layer, type); } } } sentNafs.add(naf); } } return sentNafs; }
/** * Returns a new document containing all annotations related to the given WFs */ /* Couldn't index opinion by terms. Terms are added after the Opinion object is created, and there's no way to access the annotationContainer from the Opinion.*/ public KAFDocument split(List<WF> wfs) { List<Term> terms = this.annotationContainer.getTermsByWFs(wfs); List<Dep> deps = this.annotationContainer.getDepsByTerms(terms); List<Chunk> chunks = this.annotationContainer.getChunksByTerms(terms); List<Entity> entities = this.annotationContainer.getEntitiesByTerms(terms); List<Coref> corefs = this.annotationContainer.getCorefsByTerms(terms); List<Timex3> timeExs = this.annotationContainer.getTimeExsByWFs(wfs); List<Feature> properties = this.annotationContainer.getPropertiesByTerms(terms); List<Feature> categories = this.annotationContainer.getCategoriesByTerms(terms); // List<Opinion> opinions = this.annotationContainer.getOpinionsByTerms(terms); List<Predicate> predicates = this.annotationContainer.getPredicatesByTerms(terms); List<Relational> relationals = new ArrayList<Relational>(); relationals.addAll(properties); relationals.addAll(categories); relationals.addAll(entities); List<Relation> relations = this.annotationContainer.getRelationsByRelationals(relationals); KAFDocument newKaf = new KAFDocument(this.getLang(), this.getVersion()); newKaf.addLinguisticProcessors(this.getLinguisticProcessors()); this.copyAnnotationsToKAF(newKaf, wfs, terms, deps, chunks, entities, corefs, timeExs, properties, categories, new ArrayList<Opinion>(), relations, predicates); return newKaf; }
emitMeta(nafURI, KS.VERSION, this.document.getVersion()); emitMeta(nafURI, DCTERMS.IDENTIFIER, this.document.getPublic().publicId);
this.model.add(nafURI, KS.VERSION, this.vf.createLiteral(this.document.getVersion())); this.model.add(nafURI, DCTERMS.IDENTIFIER, this.vf.createLiteral(this.document.getPublic().publicId));
Element root = new Element("NAF"); root.setAttribute("lang", kaf.getLang(), Namespace.XML_NAMESPACE); root.setAttribute("version", kaf.getVersion());
Element root = new Element("NAF"); root.setAttribute("lang", kaf.getLang(), Namespace.XML_NAMESPACE); root.setAttribute("version", kaf.getVersion());