corpus-services  1.0
ComaChartsGeneration.java
Go to the documentation of this file.
1 /*
2  * To change this license header, choose License Headers in Project Properties.
3  * To change this template file, choose Tools | Templates
4  * and open the template in the editor.
5  */
6 package de.uni_hamburg.corpora.validation;
7 
15 import java.io.IOException;
16 import java.net.MalformedURLException;
17 import java.net.URL;
18 import java.util.Collection;
19 import java.util.regex.Matcher;
20 import java.util.regex.Pattern;
21 import javax.xml.parsers.ParserConfigurationException;
22 import javax.xml.transform.TransformerConfigurationException;
23 import javax.xml.transform.TransformerException;
24 import javax.xml.xpath.XPathExpressionException;
25 import org.xml.sax.SAXException;
26 
34 public class ComaChartsGeneration extends Checker implements CorpusFunction {
35 
36  boolean inel = false;
37  String xslpath = "/xsl/Coma2Charts.xsl";
38 
40  //no fixing available
41  super(false);
42  }
43 
44  @Override
45  public Report function(CorpusData cd, Boolean fix) {
46  Report r = new Report();
47  String xsl;
48  try {
49 
50  // get the XSLT stylesheet as String
51  xsl = TypeConverter.InputStream2String(getClass().getResourceAsStream(xslpath));
52  // create XSLTransformer and set the parameters
53  XSLTransformer xt = new XSLTransformer();
54  //set an parameter for INEL
55  if(inel){
56  xt.setParameter("mode", "inel");
57  }
58  // perform XSLT transformation
59  String result = xt.transform(cd.toSaveableString(), xsl);
60 
61 
62  //get location to save new result
63  URL overviewurl = new URL(cd.getParentURL(), "resources/charts.html");
64  CorpusIO cio = new CorpusIO();
65  //save it
66  cio.write(result, overviewurl);
67  //everything worked
68  r.addCorrect(function, cd, "created html charts at " + overviewurl);
69 
70 
71  } catch (TransformerConfigurationException ex) {
72  r.addException(ex, function, cd, "Transformer configuration error");
73  } catch (TransformerException ex) {
74  r.addException(ex, function, cd, "Transformer error");
75  } catch (MalformedURLException ex) {
76  r.addException(ex, function, cd, "Malformed URL error");
77  } catch (IOException ex) {
78  r.addException(ex, function, cd, "Unknown input/output error");
79  } catch (ParserConfigurationException ex) {
80  r.addException(ex, function, cd, "Unknown Parser error");
81  } catch (SAXException ex) {
82  r.addException(ex, function, cd, "Unknown XML error");
83  } catch (XPathExpressionException ex) {
84  r.addException(ex, function, cd, "Unknown XPath error");
85  }
86 
87  return r;
88 
89  }
90 
91 
92  @Override
93  public Collection<Class<? extends CorpusData>> getIsUsableFor() {
94  Class cl1;
95  try {
96  cl1 = Class.forName("de.uni_hamburg.corpora.ComaData");
97  IsUsableFor.add(cl1);
98  } catch (ClassNotFoundException ex) {
99  report.addException(ex, "Usable class not found.");
100  }
101  return IsUsableFor;
102  }
103 
108  @Override
109  public String getDescription() {
110  String description = "This class creates a sort- and filterable html overview in table form "
111  + " of the content of the coma file to make error checking and harmonizing easier. ";
112  return description;
113  }
114 
115  public void setInel() {
116  inel = true;
117  }
118 
119  @Override
120  public Report function(Corpus c, Boolean fix) {
121  Report stats;
122  cd = c.getComaData();
123  stats = function(cd, fix);
124  return stats;
125  }
126 
127 }
void setParameter(String parameterName, Object parameterValue)
static String InputStream2String(InputStream is)
void addCorrect(String statId, String description)
Definition: Report.java:217
void addException(Throwable e, String description)
Definition: Report.java:287
Collection< Class<?extends CorpusData > > getIsUsableFor()