Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 1.8.1 #316

Merged
merged 10 commits into from
Jun 11, 2024
21 changes: 21 additions & 0 deletions docs/user_manual/configuration_file/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,27 @@ Optional properties can be set to segment the requested dataset.
* The graph of the endpoint can be specified directly ofter the `ENDPOINT` tag using the `GRAPH` tag.
* The limits of the query can be set with the `MINOFFSET` and `MAXOFFSET` tags directly after the `PAGESIZE` tag. The resulting query will ask about the statements in the interval [`MINOFFSET`, `MAXOFFSET`]. Note that `MINOFFSET` must be smaller than `MAXOFFSET`! If both `SOURCE` and `TARGET` are restricted, a warning is generated.

Please note that LIMES does not allow namespace IRIs to be used in the `PROPERTY`, `RESTRICTION`, and `OPTIONAL_PROPERTY` tag. Please use namespace prefixes and reference the namespace IRI using a prefix. Example: Do not use
```
<SOURCE>
...
<PROPERTY>http://xmlns.com/foaf/0.1#name</PROPERTY>
...
</SOURCE>
```
instead use the following
```
<PREFIX>
<NAMESPACE>http://xmlns.com/foaf/0.1/</NAMESPACE>
<LABEL>foaf</LABEL>
</PREFIX>
<SOURCE>
...
<PROPERTY>foaf:name</PROPERTY>
...
</SOURCE>
```

### Preprocessing Functions
#### Simple

Expand Down
3 changes: 2 additions & 1 deletion docs/user_manual/running_limes.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ The Prefixes component consists of two parts:

The Data source and data target consists of the two similar components, which include three input fields:
* *Sparql endpoint/Local file*: One of two options can be chosen. Sparql endpoint means that the user will select the endpont from the list. Local file means that the file should be provided as an endpoint.
* *Endpoint*: A dropdown list of available endpoints. Moreover, the user can try to search for the endpoint, typing it in the input field or write your own endpoint. After clicking on the endpoint from the list or writing it by hand and press the Enter, the user will get the list of restriction classes according to this endpoint.
* *Endpoint*: A dropdown list of available endpoints. Moreover, the user can try to search for the endpoint, typing it in the input field or write your own endpoint. After clicking on the endpoint from the list or writing it by hand and press the Enter, the user will get the list of restriction classes according to this endpoint.
If you upload files for the data source and target, and upload a configuration file after that, then you must upload the data source and target file again as the file path of them gets overwritten by the value of the later uploaded configuration file.
becker-al marked this conversation as resolved.
Show resolved Hide resolved
* *Restriction*: Contains of three parameters splitted by space (?s rdf:type some:Type). The third parameter will be changed automatically after changing the restriction class.
* *Restriction class*: A dropdown list of restriction classes according to the endpoint. You can start typing the name of the class and the list will be filtered automatically. After choosing the restriction class, you will get all the properties related to this class.

Expand Down
2 changes: 1 addition & 1 deletion limes-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<groupId>org.aksw.limes</groupId>
<artifactId>limes-full</artifactId>
<version>1.8.0-SNAPSHOT</version>
<version>1.8.1-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ public Configuration read(Model configurationModel) {
configuration.setOutputFormat(output.toString());
}

// 10. Check for invalid config because of URIs without prefixes
if(configuration.getSourceInfo() != null){
replaceURIsWithPrefixes(configuration.getSourceInfo());
}
if(configuration.getTargetInfo() != null){
replaceURIsWithPrefixes(configuration.getTargetInfo());
}


return configuration;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,15 @@ public InputSource resolveEntity(String publicId, String systemId) throws SAXExc
children = list.item(0).getChildNodes();
configuration.setOutputFormat(getText(list.item(0)));
}

// 10. Check for invalid config because of URIs without prefixes
if(configuration.getSourceInfo() != null){
replaceURIsWithPrefixes(configuration.getSourceInfo());
}
if(configuration.getTargetInfo() != null){
replaceURIsWithPrefixes(configuration.getTargetInfo());
}

}
} catch (Exception e) {
logger.warn(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public class PreprocessingFunctionFactory {
public static final String REMOVE_NON_ALPHANUMERIC = "regularalphabet";
public static final String URI_AS_STRING = "uriasstring";
public static final String SPLIT = "split";
public static final String TO_WKT_POINT = "toWktPoint";
public static final String TO_WKT_POINT = "towktpoint"; //toWktPoint

public static PreprocessingFunctionType getPreprocessingType(String expression){
switch(expression.trim()){
switch(expression.trim().toLowerCase()){
case(CLEAN_IRI):
return PreprocessingFunctionType.CLEAN_IRI;
case(CLEAN_NUMBER):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ else if (q[ql].contains("^")) {
if (kb.getRestrictions().size() > 0) {
query = query + "}";
}

logger.info("Query issued is \n" + query);
return query;
}
Expand Down
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()));
}

}
2 changes: 1 addition & 1 deletion limes-debian-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>org.aksw.limes</groupId>
<artifactId>limes-full</artifactId>
<version>1.8.0-SNAPSHOT</version>
<version>1.8.1-SNAPSHOT</version>
</parent>

<artifactId>limes-debian-cli</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

<groupId>org.aksw.limes</groupId>
<artifactId>limes-full</artifactId>
<version>1.8.0-SNAPSHOT</version>
<version>1.8.1-SNAPSHOT</version>
<name>LIMES</name>
<description>LIMES – Link Discovery Framework for Metric Spaces.</description>
<url>https://aksw.org/Projects/LIMES</url>
Expand Down
Loading