corpus-services  1.0
ComaApostropheChecker.java
Go to the documentation of this file.
1 package de.uni_hamburg.corpora.validation;
2 
8 import java.io.IOException;
9 import java.net.URISyntaxException;
10 import java.util.Collection;
11 import javax.xml.parsers.ParserConfigurationException;
12 import javax.xml.transform.TransformerException;
13 import javax.xml.xpath.XPathExpressionException;
14 import org.xml.sax.SAXException;
15 
20 public class ComaApostropheChecker extends Checker implements CorpusFunction {
21 
22  String comaLoc = "";
23  String comaFile = "";
24  boolean apostrophe = false;
25 
27  //can fix
28  super(true);
29  }
30 
36  @Override
37  public Report function(CorpusData cd, Boolean fix) // check whether there's any illegal apostrophes '
38  throws SAXException, IOException, ParserConfigurationException, URISyntaxException, TransformerException, XPathExpressionException {
39  Report stats = new Report(); // create a new report
40  comaFile = cd.toSaveableString(); // read the coma file as a string
41  if (comaFile.contains("'")) { // if coma file contains an apostrophe ' then issue warning
42  apostrophe = true;
43  if (fix) {
44  comaFile = comaFile.replaceAll("'", "’"); //replace all 's with ´s
45  CorpusIO cio = new CorpusIO();
46  cd.updateUnformattedString(comaFile);
47  cio.write(cd, cd.getURL()); // write back to coma file with allowed apostrophes ´
48  stats.addFix(function, cd, "Corrected the apostrophes"); // fix report
49  } else {
50  System.out.println("Coma file is containing apostrophe(s) ’");
51  stats.addCritical(function, cd, "Coma file is containing apostrophe(s) ’");
52  }
53  } else {
54  stats.addCorrect(function, cd, "Coma file does not contain apostrophes");
55  }
56  return stats; // return the report with warnings
57  }
58 
64  @Override
65  public Collection<Class<? extends CorpusData>> getIsUsableFor() {
66  try {
67  Class cl = Class.forName("de.uni_hamburg.corpora.ComaData");
68  IsUsableFor.add(cl);
69  } catch (ClassNotFoundException ex) {
70  report.addException(ex, "Usable class not found.");
71  }
72  return IsUsableFor;
73  }
74 
79  @Override
80  public String getDescription() {
81  String description = "This class checks whether or not the coma file "
82  + "contains an apostrophe '. If it does then these all apostrophes"
83  + " ' are changed to apostrophes ’.";
84  return description;
85  }
86 
87  @Override
88  public Report function(Corpus c, Boolean fix) throws SAXException, IOException, ParserConfigurationException, URISyntaxException, TransformerException, XPathExpressionException {
89  Report stats;
90  cd = c.getComaData();
91  stats = function(cd, fix);
92  return stats;
93  }
94 }
void addCritical(String description)
Definition: Report.java:104
void addCorrect(String statId, String description)
Definition: Report.java:217
Collection< Class<?extends CorpusData > > getIsUsableFor()
void addException(Throwable e, String description)
Definition: Report.java:287
void write(CorpusData cd, URL url)
Definition: CorpusIO.java:66
void addFix(String statId, CorpusData cd, String description)
Definition: Report.java:155