1 package de.uni_hamburg.corpora.validation;
9 import java.io.IOException;
10 import java.util.ArrayList;
11 import java.util.Collection;
12 import javax.xml.parsers.DocumentBuilder;
13 import javax.xml.parsers.DocumentBuilderFactory;
14 import javax.xml.parsers.ParserConfigurationException;
15 import javax.xml.transform.TransformerException;
16 import javax.xml.xpath.XPathExpressionException;
17 import org.exmaralda.partitureditor.jexmaralda.BasicTranscription;
18 import org.exmaralda.partitureditor.jexmaralda.Event;
19 import org.exmaralda.partitureditor.jexmaralda.JexmaraldaException;
20 import org.exmaralda.partitureditor.jexmaralda.Tier;
21 import org.w3c.dom.NodeList;
22 import org.xml.sax.SAXException;
33 ArrayList<String> allTagStrings;
47 throws SAXException, IOException, ParserConfigurationException, JexmaraldaException, TransformerException, XPathExpressionException {
49 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
50 DocumentBuilder db = dbf.newDocumentBuilder();
53 if (cd.getURL().toString().endsWith(
".xml")) {
54 allTagStrings =
new ArrayList<String>();
55 NodeList tags = doc.getElementsByTagName(
"tag");
56 for (
int i = 0; i < tags.getLength(); i++) {
57 org.w3c.dom.Element tag = (org.w3c.dom.Element) tags.item(i);
58 allTagStrings.add(tag.getAttribute(
"name"));
61 BasicTranscription basictranscription =
new BasicTranscription();
62 basictranscription.BasicTranscriptionFromString(cd.toSaveableString());
63 for (
int pos = 0; pos < basictranscription.getBody().getNumberOfTiers(); pos++) {
64 Tier tier = basictranscription.getBody().getTierAt(pos);
66 if (tier.getType().equals(
"a") && !tier.getCategory().equals(
"de") && !tier.getCategory().equals(
"en")
67 && !tier.getCategory().equals(
"ita") && !tier.getCategory().equals(
"fe")) {
69 for (
int pos2 = 0; pos2 < tier.getNumberOfEvents(); pos2++) {
71 Event
event = tier.getEventAt(pos2);
74 String content =
event.getDescription();
75 if (!content.isEmpty()) {
76 if (content.endsWith(
" ")) {
77 content = content.substring(0, content.length() - 1);
80 if (!(allTagStrings.contains(content))) {
81 System.out.println(
"Exb file " + cd.getURL().getFile().substring(cd.getURL().getFile().lastIndexOf(
"/") + 1) +
" is containing annotation with incompatible tag (" 82 + content +
") in its tier " + tier.getID() +
" for the event " +
event.getStart() +
" not specified by annotation spec file!");
83 stats.
addWarning(
"exb-annotation-panel-check",
"Exb file " + cd.getURL().getFile().substring(cd.getURL().getFile().lastIndexOf(
"/") + 1)
84 +
" is containing annotation with incompatible tag (" + content
85 +
") in its tier " + tier.getID() +
" for the event " +
event.getStart() +
" not specified by annotation spec file!");
86 exmaError.addError(
"exb-annotation-panel-check", cd.getURL().getFile(), tier.getID(),
event.getStart(),
false,
87 "Exb file " + cd.getURL().getFile().substring(cd.getURL().getFile().lastIndexOf(
"/") + 1) +
" is containing annotation with incompatible tag (" + content
88 +
") in its tier " + tier.getID() +
" for the event " +
event.getStart() +
" not specified by annotation spec file!");
106 Class cl = Class.forName(
"de.uni_hamburg.corpora.AnnotationSpecification");
107 Class clSecond = Class.forName(
"de.uni_hamburg.corpora.BasicTranscriptionData");
109 IsUsableFor.add(clSecond);
110 }
catch (ClassNotFoundException ex) {
122 String description =
"This class checks whether the annotations in exb " 123 +
"files comply with the annotation specification panel. ";
128 public Report function(
Corpus c, Boolean fix)
throws SAXException, IOException, ParserConfigurationException, JexmaraldaException, TransformerException, XPathExpressionException {
130 for (
CorpusData cdata : c.getBasicTranscriptionData()) {
131 stats.
merge(
function(cdata, fix));
133 for (
CorpusData adata : c.getAnnotationspecification()) {
134 stats.
merge(
function(adata, fix));
Collection< Class<?extends CorpusData > > getIsUsableFor()
ExbAnnotationPanelCheck()
static ExmaErrorList exmaError
void addWarning(String statId, String description)
static InputStream String2InputStream(String s)
void addException(Throwable e, String description)