1 package de.uni_hamburg.corpora.validation;
9 import java.io.IOException;
10 import java.net.URISyntaxException;
11 import java.util.ArrayList;
12 import java.util.Collection;
13 import java.util.HashMap;
15 import javax.xml.parsers.DocumentBuilder;
16 import javax.xml.parsers.DocumentBuilderFactory;
17 import javax.xml.parsers.ParserConfigurationException;
18 import javax.xml.transform.TransformerException;
19 import javax.xml.xpath.XPathExpressionException;
20 import org.exmaralda.partitureditor.jexmaralda.JexmaraldaException;
21 import org.w3c.dom.Document;
22 import org.w3c.dom.Element;
23 import org.w3c.dom.NodeList;
24 import org.xml.sax.SAXException;
34 HashMap<String, Collection<String>> annotationsInComa;
35 ArrayList<String> annotations;
49 throws SAXException, IOException, ParserConfigurationException, URISyntaxException {
51 if (annotationsInComa != null) {
52 for (Map.Entry<String, Collection<String>> entry : annotationsInComa.entrySet()) {
53 String name = entry.getKey();
54 Collection<String> annotTypes = entry.getValue();
55 for (String annotType : annotTypes) {
56 if (!annotations.contains(annotType)) {
57 System.out.println(
"Coma file is containing annotation (" + annotType
58 +
") for " + name +
" not specified by annotation spec file!");
59 stats.
addWarning(
function, cd,
"annotation error: annotation in annotation panel (" 60 + annotType +
") in communication " + name +
" not specified!");
61 int index = cd.getURL().getFile().lastIndexOf(
"/");
62 String filePath = cd.getURL().getFile().substring(0, index) +
"/" + name +
"/" + name +
".exb";
63 exmaError.addError(
"tier-checker-with-annotation", filePath,
"",
"",
false,
"annotation error: annotation in annotation panel(" 64 + annotType +
") for communication " + name +
" not specified in the annotation specification file!");
66 stats.
addCorrect(
function, cd,
"annotation in annotation panel (" 67 + annotType +
") in communication " + name +
" was found.");
72 stats.
addNote(
function, cd,
"No annotations found in coma.");
84 throws SAXException, IOException, ParserConfigurationException, URISyntaxException, TransformerException, XPathExpressionException {
85 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
86 DocumentBuilder db = dbf.newDocumentBuilder();
88 if (cd.getURL().toString().endsWith(
".coma")) {
89 NodeList communications = doc.getElementsByTagName(
"Communication");
90 annotationsInComa =
new HashMap<String, Collection<String>>();
91 for (
int i = 0; i < communications.getLength(); i++) {
92 Element communication = (Element) communications.item(i);
93 NodeList transcriptions = communication.getElementsByTagName(
"Transcription");
94 for (
int j = 0; j < transcriptions.getLength(); j++) {
95 Element transcription = (Element) transcriptions.item(j);
97 String name = ((Element) transcription.getElementsByTagName(
"Name").item(0)).getTextContent();
98 NodeList keys = transcription.getElementsByTagName(
"Key");
99 boolean segmented =
false;
100 for (
int k = 0; k < keys.getLength(); k++) {
101 Element key = (Element) keys.item(k);
102 if (key.getAttribute(
"Name").equals(
"segmented")) {
103 String seg = key.getTextContent();
104 if (seg.equals(
"true"))
112 for (
int k = 0; k < keys.getLength(); k++) {
113 Element key = (Element) keys.item(k);
114 if (key.getAttribute(
"Name").contains(
"Annotation type:")) {
115 int colonIndex = key.getAttribute(
"Name").lastIndexOf(
':');
116 if (annotationsInComa.containsKey(name)) {
117 if (!annotationsInComa.get(name).contains(key.getAttribute(
"Name").substring(colonIndex + 2))) {
118 Collection<String> c = annotationsInComa.get(name);
119 c.add(key.getAttribute(
"Name").substring(colonIndex + 2));
120 annotationsInComa.put(name, c);
123 Collection<String> c =
new ArrayList<String>();
124 c.add(key.getAttribute(
"Name").substring(colonIndex + 2));
125 annotationsInComa.put(name, c);
133 annotations =
new ArrayList<String>();
134 NodeList tags = doc.getElementsByTagName(
"tag");
135 for (
int i = 0; i < tags.getLength(); i++) {
136 Element tag = (Element) tags.item(i);
137 annotations.add(tag.getAttribute(
"name"));
150 Class cl = Class.forName(
"de.uni_hamburg.corpora.ComaData");
151 Class clSecond = Class.forName(
"de.uni_hamburg.corpora.AnnotationSpecification");
153 IsUsableFor.add(clSecond);
154 }
catch (ClassNotFoundException ex) {
166 String description =
"This class checks out that all annotations are from" 167 +
" the annotation specification file and that there are no annotations" 168 +
" in the coma file not existing in the annotation specification file.";
173 public Report function(
Corpus c, Boolean fix)
throws SAXException, IOException, ParserConfigurationException, URISyntaxException {
175 cd = c.getComaData();
176 stats =
function(cd, fix);
void addNote(String statId, String description)
Collection< Class<?extends CorpusData > > getIsUsableFor()
void addAnnotations(CorpusData cd)
static ExmaErrorList exmaError
void addWarning(String statId, String description)
void addCorrect(String statId, String description)
static InputStream String2InputStream(String s)
void addException(Throwable e, String description)
ComaTiersDescriptionAnnotationPanelChecker()