1 package de.uni_hamburg.corpora.validation;
8 import java.io.IOException;
9 import java.net.URISyntaxException;
10 import java.security.NoSuchAlgorithmException;
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 org.w3c.dom.Document;
19 import org.w3c.dom.Element;
20 import org.w3c.dom.NodeList;
21 import org.xml.sax.SAXException;
22 import javax.xml.transform.TransformerException;
23 import javax.xml.xpath.XPathExpressionException;
24 import org.exmaralda.partitureditor.fsm.FSMException;
25 import org.exmaralda.partitureditor.jexmaralda.JexmaraldaException;
26 import org.jdom.JDOMException;
36 HashMap<String, Collection<String>> annotationsInComa;
37 ArrayList<String> annotations;
49 throws SAXException, IOException, ParserConfigurationException, URISyntaxException, TransformerException, XPathExpressionException {
50 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
51 DocumentBuilder db = dbf.newDocumentBuilder();
53 if (cd.
getURL().toString().endsWith(
".coma")) {
54 NodeList communications = doc.getElementsByTagName(
"Communication");
55 annotationsInComa =
new HashMap<String, Collection<String>>();
56 for (
int i = 0; i < communications.getLength(); i++) {
57 Element communication = (Element) communications.item(i);
58 String name = communication.getAttribute(
"Name");
59 NodeList descriptions = communication.getElementsByTagName(
"Description");
60 for (
int j = 0; j < descriptions.getLength(); j++) {
61 Element description = (Element) descriptions.item(j);
62 NodeList keys = description.getElementsByTagName(
"Key");
63 for (
int k = 0; k < keys.getLength(); k++) {
64 Element key = (Element) keys.item(k);
65 if (key.getAttribute(
"Name").contains(
"Annotation")) {
66 int spaceIndex = key.getAttribute(
"Name").lastIndexOf(
' ');
67 if (annotationsInComa.containsKey(name)) {
68 if (!annotationsInComa.get(name).contains(key.getAttribute(
"Name").substring(spaceIndex + 1))) {
69 Collection<String> c = annotationsInComa.get(name);
70 c.add(key.getAttribute(
"Name").substring(spaceIndex + 1));
71 annotationsInComa.put(name, c);
74 Collection<String> c =
new ArrayList<String>();
75 c.add(key.getAttribute(
"Name").substring(spaceIndex + 1));
76 annotationsInComa.put(name, c);
83 annotations =
new ArrayList<String>();
84 NodeList annotationSets = doc.getElementsByTagName(
"annotation-set");
85 for (
int i = 0; i < annotationSets.getLength(); i++) {
86 Element annotationSet = (Element) annotationSets.item(i);
87 annotations.add(annotationSet.getAttribute(
"exmaralda-tier-category"));
105 stats = exceptionalCheck(cd);
107 }
catch (ParserConfigurationException pce) {
108 stats.
addException(pce, comaLoc +
": Unknown parsing error");
109 }
catch (SAXException saxe) {
110 stats.
addException(saxe, comaLoc +
": Unknown parsing error");
111 }
catch (IOException ioe) {
112 stats.
addException(ioe, comaLoc +
": Unknown file reading error");
113 }
catch (URISyntaxException ex) {
114 stats.
addException(ex, comaLoc +
": Unknown file reading error");
115 }
catch (TransformerException ex) {
116 stats.
addException(ex, comaLoc +
": Unknown file reading error");
117 }
catch (XPathExpressionException ex) {
118 stats.
addException(ex, comaLoc +
": Unknown file reading error");
129 throws SAXException, IOException, ParserConfigurationException, URISyntaxException {
131 if (annotationsInComa != null){
132 for (Map.Entry<String, Collection<String>> entry : annotationsInComa.entrySet()) {
133 String name = entry.getKey();
134 Collection<String> annotTypes = entry.getValue();
135 for (String annotType : annotTypes) {
136 if (!annotations.contains(annotType)) {
137 System.out.println(
"Coma file is containing annotation (" + annotType
138 +
") for " + name +
" not specified by annotation spec file!");
139 stats.
addWarning(
"tier-checker-with-annotation",
"annotation error: annotation (" 140 + annotType +
") for " + name +
" not specified in the annotation spec file!");
141 int index = cd.
getURL().getFile().lastIndexOf(
"/");
142 String nameExtension = name.substring(name.lastIndexOf(
'_'));
144 switch (nameExtension) {
146 filePath = cd.
getURL().getFile().substring(0, index) +
"/conversation/" + name +
"/" + name +
".exb";
149 filePath = cd.
getURL().getFile().substring(0, index) +
"/narrative/" + name +
"/" + name +
".exb";
152 filePath = cd.
getURL().getFile().substring(0, index) +
"/songs/" + name +
"/" + name +
".exb";
155 filePath = cd.
getURL().getFile().substring(0, index) +
"/" + nameExtension.substring(1) +
"/" + name +
"/" + name +
".exb";
173 Class cl = Class.forName(
"de.uni_hamburg.corpora.ComaData");
174 Class clSecond = Class.forName(
"de.uni_hamburg.corpora.AnnotationSpecification");
176 IsUsableFor.add(clSecond);
177 }
catch (ClassNotFoundException ex) {
188 String description =
"This class checks out if all annotations for Nganasan" 189 +
" Corpus are from the annotation specification file and there are" 190 +
" no annotations in the coma file not present in the annotation" 191 +
" specification file.";
196 public Report function(
CorpusData cd, Boolean fix)
throws NoSuchAlgorithmException, ClassNotFoundException, FSMException, URISyntaxException, SAXException, IOException, ParserConfigurationException, JexmaraldaException, TransformerException, XPathExpressionException, JDOMException {
197 throw new UnsupportedOperationException(
"Not supported yet.");
201 public Report function(
Corpus c, Boolean fix)
throws NoSuchAlgorithmException, ClassNotFoundException, FSMException, URISyntaxException, SAXException, IOException, ParserConfigurationException, JexmaraldaException, TransformerException, XPathExpressionException, JDOMException {
202 throw new UnsupportedOperationException(
"Not supported yet.");
String toSaveableString()
NgTierCheckerWithAnnotation()
Collection< Class<?extends CorpusData > > getIsUsableFor()
void addWarning(String statId, String description)
Report check(CorpusData cd)
static InputStream String2InputStream(String s)
void addException(Throwable e, String description)
void addAnnotations(CorpusData cd)