1 package de.uni_hamburg.corpora.validation;
11 import java.util.ArrayList;
12 import java.io.IOException;
13 import java.net.URISyntaxException;
15 import java.sql.Timestamp;
16 import java.util.Collection;
17 import java.util.Collections;
18 import java.util.TreeSet;
19 import java.util.List;
21 import javax.xml.parsers.ParserConfigurationException;
22 import javax.xml.transform.TransformerException;
23 import javax.xml.xpath.XPathExpressionException;
24 import org.exmaralda.partitureditor.jexmaralda.JexmaraldaException;
25 import org.exmaralda.partitureditor.jexmaralda.Tier;
26 import org.xml.sax.SAXException;
48 throws SAXException, IOException, ParserConfigurationException, URISyntaxException, TransformerException, XPathExpressionException, JexmaraldaException, ClassNotFoundException {
52 Collection<URL> resulturls;
53 ArrayList<Tier> tiers =
new ArrayList<>();
54 ArrayList<BasicTranscriptionData> btds =
new ArrayList<>();
56 String overviewTable =
"";
57 String communicationsTable =
"";
59 for (URL resulturl : resulturls) {
66 for (
int i = 0; i < btexb.
getEXMARaLDAbt().getBody().getNumberOfTiers(); i++) {
71 stats.
addCritical(
function, cd,
"The linked basic transcription " + resulturl +
" cannot be opened.");
74 List<String> stringtiers =
new ArrayList<String>();
75 for (Tier tier : tiers) {
77 stringtiers.add(tier.getCategory() +
" (type: " + tier.getType() +
")");
79 Set<String> hash_Set =
new TreeSet<String>(stringtiers);
83 if (!tiers.isEmpty()) {
86 String h1 =
"<h1> Tier Overview over Whole Corpus (" + resulturls.size() +
" exbs) </h1>";
87 String header =
"<table id=\"\" class=\"compact\">\n" 90 +
" <th class=\"compact\">Category-Type-DisplayName</th>\n" 91 +
" <th class=\"compact\">Number of Tiers</th>\n" 105 for (String s : hash_Set) {
106 content = content +
"<tr><td class=\"compact\">" + s +
"</td><td class=\"compact\">" + Collections.frequency(stringtiers, s) +
"</td></tr>";
108 String footer =
" </tbody>\n" 111 overviewTable = h1 + header + content + footer;
114 stats.
addWarning(
function, cd,
"No tiers found in the linked exbs. ");
118 if (!btds.isEmpty()) {
119 String h1 =
"<h1> Tiers in each exb </h1>";
120 communicationsTable = h1;
122 String header =
"<table id=\"\" class=\"compact\">\n" 124 +
"<th class=\"compact\"> Exb Filename </th>";
125 for (String s : hash_Set) {
126 header = header +
"<th class=\"compact\">" + s +
"</th>";
128 header = header +
"</tr>" 134 content = content +
"<tr><td class=\"compact\">" + btd.getFilename() +
"</td>";
135 for (String s : hash_Set) {
137 String[] catType = s.split(
"type: ");
138 String category = catType[0].substring(0, catType[0].length() - 2);
139 String type = catType[1].substring(0, catType[1].length() - 1);
140 String[] ids = btd.getEXMARaLDAbt().getBody().getTiersOfType(type);
142 boolean existence =
false;
143 if (ids.length > 0) {
144 for (String
id : ids) {
145 if (category.equals(btd.getEXMARaLDAbt().getBody().getTierWithID(
id).getCategory())) {
146 noOfEvents += btd.getEXMARaLDAbt().getBody().getTierWithID(
id).getNumberOfEvents();
151 if (noOfEvents > 0) {
152 content = content +
"<td class=\"compact\">" + noOfEvents +
"</td>";
154 content = content +
"<td class=\"compact\">0</td>";
157 content = content +
"<td class=\"compact\"></td>";
160 content = content +
"<td class=\"compact\"></td>";
163 content = content +
"</tr>";
166 String footer =
" </tr>\n" 169 communicationsTable = h1 + header + content + footer;
171 stats.
addWarning(
function, cd,
"No linked exbs found in the coma file. ");
173 String htmlend =
" </body>\n</html>";
175 String timestamp =
"";
176 timestamp +=
" <div id='timestamp'>Generated: ";
177 Timestamp time =
new Timestamp(System.currentTimeMillis());
178 timestamp += time +
"</div>\n";
179 String result = htmltemplate + timestamp + overviewTable + communicationsTable + htmlend;
182 URL overviewurl =
new URL(cd.getParentURL(),
"curation/tier_overview.html");
183 cio.
write(result, overviewurl);
185 stats.
addCorrect(
function, cd,
"created tier overview at " + overviewurl);
198 Class cl = Class.forName(
"de.uni_hamburg.corpora.ComaData");
200 }
catch (ClassNotFoundException ex) {
212 String description =
"This class creates a sort- and filterable html overview in table form " 213 +
" of all tiers existing in the exbs linked in the coma file to make error " 214 +
"checking and harmonizing easier. ";
219 public Report function(
Corpus c, Boolean fix)
throws SAXException, IOException, ParserConfigurationException, URISyntaxException, TransformerException, XPathExpressionException, JexmaraldaException, ClassNotFoundException {
221 cd = c.getComaData();
222 stats =
function(cd, fix);
BasicTranscription getEXMARaLDAbt()
CorpusData readFileURL(URL url, Collection< Class<?extends CorpusData >> clcds)
Collection< Class<?extends CorpusData > > getIsUsableFor()
void addCritical(String description)
static String InputStream2String(InputStream is)
void addWarning(String statId, String description)
void addCorrect(String statId, String description)
Collection< URL > getAllBasicTranscriptionURLs()
ComaTierOverviewCreator()
void addException(Throwable e, String description)
void write(CorpusData cd, URL url)