-
Notifications
You must be signed in to change notification settings - Fork 14
/
MappingFileParser.java
60 lines (51 loc) · 2.38 KB
/
MappingFileParser.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* Copyright (C) 2020 Czech Technical University in Prague
* <p>
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
* version.
* <p>
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details. You should have received a copy of the GNU General Public License along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*/
package cz.cvut.kbss.ontodriver.owlapi.util;
import cz.cvut.kbss.jopa.owlapi.exception.MappingFileParserException;
import cz.cvut.kbss.ontodriver.config.DriverConfiguration;
import cz.cvut.kbss.ontodriver.owlapi.config.OwlapiConfigParam;
import cz.cvut.kbss.ontodriver.owlapi.config.OwlapiOntoDriverProperties;
import java.io.File;
import java.net.URI;
import java.util.Map;
public class MappingFileParser {
private final File mappingFile;
private final String delimiter;
public MappingFileParser(DriverConfiguration configuration) {
final String mappingFilePath = configuration.getProperty(OwlapiConfigParam.MAPPING_FILE_LOCATION);
assert mappingFilePath != null;
this.mappingFile = resolveMappingFile(mappingFilePath);
this.delimiter = configuration.getProperty(OwlapiConfigParam.IRI_MAPPING_DELIMITER,
OwlapiOntoDriverProperties.DEFAULT_IRI_MAPPING_DELIMITER);
}
private File resolveMappingFile(String path) {
File mapping = new File(path);
if (mapping.exists()) {
return mapping;
}
try {
mapping = new File(URI.create(path));
if (mapping.exists()) {
return mapping;
}
} catch (IllegalArgumentException e) {
throw new MappingFileParserException(
"Mapping file path " + path + " is neither a valid file path nor a valid URI.", e);
}
throw new MappingFileParserException("Mapping file " + path + " does not exist.");
}
public Map<URI, URI> getMappings() {
assert mappingFile != null;
return cz.cvut.kbss.jopa.util.MappingFileParser.getMappings(mappingFile, delimiter);
}
}