Skip to content
Snippets Groups Projects
Commit 93fcfca1 authored by Lange, Dr. Herbert's avatar Lange, Dr. Herbert
Browse files

add function to create list of file urls from comma-separated string and update parameters

parent 2048e73d
No related branches found
No related tags found
1 merge request!6add feature to load criteria file from resource and place all criteria files...
......@@ -48,17 +48,39 @@ public class FileListChecker extends Checker implements CorpusFunction {
return uris;
}
/**
* Splits a file list on commas and converts to URIs
* @param fileList the comma-separated list
* @return the set of URIs
* @throws MalformedURLException if the file name cannot be converted into a URL
* @throws URISyntaxException if the URL cannot be converted into a URI
*/
private static Set<URI> splitFileList(String fileList) throws MalformedURLException, URISyntaxException {
Set<URI> uris = new HashSet<>();
for (String fname : fileList.split(",")) {
uris.add(new URL(fname).toURI().normalize());
}
return uris;
}
Set<URI> expectedFiles = new HashSet<>();
Set<URI> presentFiles = new HashSet<>();
public FileListChecker(Properties properties) throws FileNotFoundException, MalformedURLException, URISyntaxException {
super(false, properties);
if (properties.containsKey("expected-files-list")) {
expectedFiles = readFileList(properties.getProperty("expected-files-list"));
if (properties.containsKey("expected-files-file")) {
expectedFiles = readFileList(properties.getProperty("expected-files-file"));
}
else if (properties.containsKey("expected-files-list")) {
expectedFiles = splitFileList(properties.getProperty("expected-files-list"));
}
if (properties.containsKey("present-files-list")) {
presentFiles = readFileList(properties.getProperty("present-files-list"));
if (properties.containsKey("present-files-file")) {
presentFiles = readFileList(properties.getProperty("present-files-file"));
}
else if (properties.containsKey("present-files-list")) {
expectedFiles = splitFileList(properties.getProperty("present-files-list"));
}
}
/**
......@@ -95,6 +117,11 @@ public class FileListChecker extends Checker implements CorpusFunction {
@Override
public Report function(Corpus c, Boolean fix) throws NoSuchAlgorithmException, ClassNotFoundException, FSMException, URISyntaxException, SAXException, IOException, ParserConfigurationException, JexmaraldaException, TransformerException, XPathExpressionException, JDOMException {
if (props.containsKey("expected-files-linked")) {
LinkedFileChecker lfc = new LinkedFileChecker(props);
lfc.function(c, fix);
expectedFiles.addAll(lfc.getFileList());
}
Report report = new Report();
// Try to read corpus directory instead
if (presentFiles.isEmpty()){
......@@ -131,9 +158,13 @@ public class FileListChecker extends Checker implements CorpusFunction {
@Override
public Map<String, String> getParameters() {
Map<String,String> params = super.getParameters();
params.put("expected-files-list","A file containing names of all expected file names, one name per line");
params.put("present-files-list", "A file containing names of all file names of files present, one name per " +
params.put("expected-files-file","A file containing names of all expected file names, one name per line");
params.put("present-files-file", "A file containing names of all file names of files present, one name per " +
"line");
params.put("expected-files-list","A list containing names of all expected file names, separated by commas");
params.put("present-files-list", "A list containing names of all file names of files present, separated by " +
"commas");
params.put("expected-files-linked", "Flag to use a files linked in corpus files as expected files");
return params;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment