-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #316 from dice-group/dev
Release 1.8.1
- Loading branch information
Showing
11 changed files
with
260 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,9 @@ | |
package org.aksw.limes.core.io.config.reader; | ||
|
||
import org.aksw.limes.core.io.config.Configuration; | ||
import org.aksw.limes.core.io.config.KBInfo; | ||
|
||
import java.util.*; | ||
|
||
/** | ||
* @author Mohamed Sherif ([email protected]) | ||
|
@@ -48,5 +51,78 @@ public void setConfiguration(Configuration configuration) { | |
this.configuration = configuration; | ||
} | ||
|
||
/** | ||
* This method replaces any URIs used in the kbInfo with their prefixes | ||
* @param info | ||
*/ | ||
public static void replaceURIsWithPrefixes(KBInfo info) { | ||
Map<String, String> prefixes = info.getPrefixes(); | ||
HashMap<String, String> rev = new HashMap<>(); | ||
for(Map.Entry<String, String> entry : prefixes.entrySet()) { | ||
rev.put(entry.getValue(), entry.getKey()); | ||
} | ||
info.setProperties(replaceURIsWithPrefixes(info.getProperties(), rev)); | ||
info.setOptionalProperties(replaceURIsWithPrefixes(info.getOptionalProperties(), rev)); | ||
info.setRestrictions(replaceURIsWithPrefixes(info.getRestrictions(), rev)); | ||
info.setFunctions(replaceURIsWithPrefixes(info.getFunctions(), rev)); | ||
} | ||
|
||
private static ArrayList<String> replaceURIsWithPrefixes(Collection<String> props, HashMap<String, String> rev) { | ||
ArrayList<String> replacements = new ArrayList<>(); | ||
for (String property : props) { | ||
String originalProp = property; | ||
for (Map.Entry<String, String> prefixEntry : rev.entrySet()) { | ||
if(property.contains(prefixEntry.getKey())){ | ||
property = property.replace(prefixEntry.getKey(), prefixEntry.getValue() + ":"); | ||
} | ||
} | ||
replacements.add(property); | ||
|
||
if(property.contains("://")){ | ||
throw new IllegalArgumentException("LIMES does not support using URIs in the properties, optionalProperties, restrictions, or functions in the configuration file. " + | ||
"Please define a prefix and use the prefix for the following URI: " + originalProp); | ||
} | ||
} | ||
return replacements; | ||
} | ||
|
||
private static LinkedHashMap<String, Map<String, String>> replaceURIsWithPrefixes(Map<String, Map<String, String>> funcs, HashMap<String, String> rev) { | ||
LinkedHashMap<String, Map<String, String>> replacements = new LinkedHashMap<>(); | ||
for (Map.Entry<String, Map<String, String>> entry : funcs.entrySet()) { | ||
String property = entry.getKey(); | ||
String originalProp = property; | ||
|
||
//Replace key of function | ||
for (Map.Entry<String, String> prefixEntry : rev.entrySet()) { | ||
if(property.contains(prefixEntry.getKey())){ | ||
property = property.replace(prefixEntry.getKey(), prefixEntry.getValue() + ":"); | ||
} | ||
} | ||
if(property.contains("://")){ | ||
throw new IllegalArgumentException("LIMES does not support using namespace IRIs in the properties, optionalProperties, restrictions, or functions in the configuration file. " + | ||
"Please define a prefix and use the prefix for the namespace of the following IRI: " + originalProp); | ||
} | ||
|
||
//Replace value map | ||
Map<String, String> intermediateReplacement = new HashMap<>(); | ||
for (Map.Entry<String, String> stringEntry : entry.getValue().entrySet()) { | ||
String subKey = stringEntry.getKey(); | ||
String origSubKey = subKey; | ||
for (Map.Entry<String, String> prefixEntry : rev.entrySet()) { | ||
subKey = subKey.replace(prefixEntry.getKey(), prefixEntry.getValue() + ":"); | ||
} | ||
intermediateReplacement.put(subKey, stringEntry.getValue()); | ||
if(subKey.contains("://")){ | ||
throw new IllegalArgumentException("LIMES does not support using namespace IRIs in the properties, optionalProperties, restrictions, or functions in the configuration file. " + | ||
"Please define a prefix and use the prefix for the namespace of the following IRI: " + origSubKey); | ||
} | ||
|
||
} | ||
|
||
replacements.put(property, intermediateReplacement); | ||
} | ||
return replacements; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
...core/src/test/java/org/aksw/limes/core/io/config/reader/xml/AConfigurationReaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
package org.aksw.limes.core.io.config.reader.xml; | ||
|
||
import org.aksw.limes.core.io.config.Configuration; | ||
import org.aksw.limes.core.io.config.KBInfo; | ||
import org.aksw.limes.core.io.config.reader.AConfigurationReader; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.assertThrows; | ||
|
||
import java.util.*; | ||
|
||
public class AConfigurationReaderTest { | ||
Map<String, String> prefixes; | ||
LinkedHashMap<String, Map<String, String>> functions; | ||
KBInfo sourceInfo, targetInfo; | ||
Configuration testConf; | ||
|
||
@Before | ||
public void init() { | ||
prefixes = new HashMap<>(); | ||
prefixes.put("geos", "http://www.opengis.net/ont/geosparql#"); | ||
prefixes.put("lgdo", "http://linkedgeodata.org/ontology/"); | ||
prefixes.put("geom", "http://geovocab.org/geometry#"); | ||
prefixes.put("rdfs", "http://www.w3.org/2000/01/rdf-schema#"); | ||
prefixes.put("limes", "http://limes.sf.net/ontology/"); | ||
|
||
functions = new LinkedHashMap<>(); | ||
Map<String, String> f = new LinkedHashMap<>(); | ||
f.put("polygon", null); | ||
functions.put("geom:geometry/geos:asWKT", f); | ||
|
||
sourceInfo = new KBInfo( | ||
"linkedgeodata", //String id | ||
"http://linkedgeodata.org/sparql", //String endpoint | ||
null, //String graph | ||
"?x", //String var | ||
new ArrayList<>(Arrays.asList("geom:geometry/geos:asWKT")), //List<String> properties | ||
new ArrayList<>(), //List<String> optionalProperties | ||
new ArrayList<>(Arrays.asList("?x a lgdo:RelayBox")), //ArrayList<String> restrictions | ||
functions, //LinkedHashMap<String, Map<String, String>> functions | ||
prefixes, //Map<String, String> prefixes | ||
2000, //int pageSize | ||
"sparql", //String type | ||
-1, //int minOffset | ||
-1 //int maxoffset | ||
); | ||
|
||
targetInfo = new KBInfo( | ||
"linkedgeodata", //String id | ||
"http://linkedgeodata.org/sparql", //String endpoint | ||
null, //String graph | ||
"?y", //String var | ||
new ArrayList<>(Arrays.asList("geom:geometry/geos:asWKT")), //List<String> properties | ||
new ArrayList<>(), //List<String> optionalProperties | ||
new ArrayList<>(Arrays.asList("?y a lgdo:RelayBox")), //ArrayList<String> restrictions | ||
functions, //LinkedHashMap<String, Map<String, String>> functions | ||
prefixes, //Map<String, String> prefixes | ||
2000, //int pageSize | ||
"sparql", //String type | ||
-1, //int minOffset | ||
-1 //int maxoffset | ||
); | ||
|
||
testConf = new Configuration(); | ||
testConf.setPrefixes(prefixes); | ||
testConf.setSourceInfo(sourceInfo); | ||
testConf.setTargetInfo(targetInfo); | ||
|
||
} | ||
|
||
@Test | ||
public void testReplaceWithPrefixProp() { | ||
testConf.getSourceInfo().addProperty("http://www.opengis.net/ont/geosparql#test"); | ||
AConfigurationReader.replaceURIsWithPrefixes(testConf.getSourceInfo()); | ||
assertTrue(testConf.getSourceInfo().getProperties().contains("geos:test")); | ||
} | ||
|
||
@Test | ||
public void testReplaceWithPrefixOptionalProp() { | ||
testConf.getSourceInfo().addOptionalProperty("http://www.opengis.net/ont/geosparql#test"); | ||
AConfigurationReader.replaceURIsWithPrefixes(testConf.getSourceInfo()); | ||
assertTrue(testConf.getSourceInfo().getOptionalProperties().contains("geos:test")); | ||
} | ||
|
||
@Test | ||
public void testReplaceWithPrefixRestriction() { | ||
testConf.getSourceInfo().addRestriction("http://www.opengis.net/ont/geosparql#test"); | ||
AConfigurationReader.replaceURIsWithPrefixes(testConf.getSourceInfo()); | ||
assertTrue(testConf.getSourceInfo().getRestrictions().contains("geos:test")); | ||
} | ||
|
||
@Test | ||
public void testReplaceWithPrefixFunc() { | ||
LinkedHashMap<String, Map<String, String>> x = testConf.getSourceInfo().getFunctions(); | ||
HashMap<String, String> y = new HashMap<>(); | ||
y.put("http://www.opengis.net/ont/geosparql#test", "toLower"); | ||
x.put("http://www.opengis.net/ont/geosparql#test", y); | ||
testConf.getSourceInfo().setFunctions(x); | ||
AConfigurationReader.replaceURIsWithPrefixes(testConf.getSourceInfo()); | ||
assertTrue(testConf.getSourceInfo().getFunctions().containsKey("geos:test")); | ||
} | ||
|
||
@Test | ||
public void testReplaceWithPrefixPropError() { | ||
testConf.getPrefixes().remove("geos"); | ||
testConf.getSourceInfo().addProperty("http://www.opengis.net/ont/geosparql#test"); | ||
assertThrows(IllegalArgumentException.class, () -> AConfigurationReader.replaceURIsWithPrefixes(testConf.getSourceInfo())); | ||
} | ||
|
||
@Test | ||
public void testReplaceWithPrefixOptionalPropError() { | ||
testConf.getPrefixes().remove("geos"); | ||
testConf.getSourceInfo().addOptionalProperty("http://www.opengis.net/ont/geosparql#test"); | ||
assertThrows(IllegalArgumentException.class, () -> AConfigurationReader.replaceURIsWithPrefixes(testConf.getSourceInfo())); | ||
} | ||
|
||
@Test | ||
public void testReplaceWithPrefixRestrictionError() { | ||
testConf.getPrefixes().remove("geos"); | ||
testConf.getSourceInfo().addRestriction("http://www.opengis.net/ont/geosparql#test"); | ||
assertThrows(IllegalArgumentException.class, () -> AConfigurationReader.replaceURIsWithPrefixes(testConf.getSourceInfo())); | ||
} | ||
|
||
@Test | ||
public void testReplaceWithPrefixFuncError() { | ||
testConf.getPrefixes().remove("geos"); | ||
LinkedHashMap<String, Map<String, String>> x = testConf.getSourceInfo().getFunctions(); | ||
HashMap<String, String> y = new HashMap<>(); | ||
y.put("http://www.opengis.net/ont/geosparql#test", "toLower"); | ||
x.put("http://www.opengis.net/ont/geosparql#test", y); | ||
testConf.getSourceInfo().setFunctions(x); | ||
assertThrows(IllegalArgumentException.class, () -> AConfigurationReader.replaceURIsWithPrefixes(testConf.getSourceInfo())); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters