Skip to content

Commit 8c3b1ff

Browse files
authored
Merge pull request #16 from ubbdst/feature/replace-uri
Feature/replace uri
2 parents 5748ea4 + 98254ed commit 8c3b1ff

File tree

8 files changed

+238
-101
lines changed

8 files changed

+238
-101
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>org.elasticsearch.plugin.river.ubb</groupId>
55
<artifactId>ubb-rdf-river-plugin</artifactId>
6-
<version>1.7.7</version>
6+
<version>1.7.9</version>
77

88
<packaging>jar</packaging>
99

src/main/java/org/elasticsearch/river/ubb/RDFRiver.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ private void buildHarvester(RiverSettings settings) {
109109
rdfSettings.get("tdbLocation"), ""))
110110
.rdfQueryPath(XContentMapValues.nodeStringValue(
111111
rdfSettings.get("queryPath"), ""))
112+
.replaceResourceURI(XContentMapValues.nodeStringValue(
113+
rdfSettings.get("replaceResourceURI"), ""))
112114
.rdfNumberOfBulkActions(XContentMapValues.nodeLongValue(
113115
rdfSettings.get("bulkActions"),
114116
Defaults.DEFAULT_NUMBER_OF_BULK_ACTIONS))
@@ -193,6 +195,13 @@ private void buildHarvester(RiverSettings settings) {
193195
if (rdfSettings.containsKey("whiteMap")) {
194196
harvester.rdfWhiteMap(getStrObjMapFromSettings(rdfSettings, "whiteMap"));
195197
}
198+
if (rdfSettings.containsKey("indexTextFrom")) {
199+
harvester.textField(XContentMapValues.nodeStringValue(rdfSettings.get("indexTextFrom"), ""));
200+
}
201+
if (rdfSettings.containsKey("embedResourceUsingProperty")) {
202+
harvester.embedResource(XContentMapValues.nodeStringValue(
203+
rdfSettings.get("embedResourceUsingProperty"), ""));
204+
}
196205
if (settings.settings().containsKey("index")) {
197206
Map<String, Object> indexSettings = extractSettings(settings, "index");
198207
harvester.index(XContentMapValues.nodeStringValue(indexSettings.get("index"),

src/main/java/org/elasticsearch/river/ubb/settings/Defaults.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public final class Defaults {
3939
"\"http://www.w3.org/1999/02/22-rdf-syntax-ns#about\"" + "]";
4040
public final static String DEFAULT_RESOURCE_URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#about";
4141
public final static String DEFAULT_LIST_TYPE = "white";
42-
public final static Boolean DEFAULT_ADD_LANGUAGE = true;
42+
public final static Boolean DEFAULT_ADD_LANGUAGE = false;
4343
public final static String DEFAULT_LANGUAGE = "no";
4444
public final static Boolean DEFAULT_ADD_URI = true;
4545
public final static Boolean DEFAULT_UPDATE_DOCUMENTS = false;

src/main/java/org/elasticsearch/river/ubb/settings/RiverUtils.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.elasticsearch.river.ubb.settings;
22

3+
import org.elasticsearch.common.Strings;
4+
import org.elasticsearch.common.lang3.StringUtils;
5+
36
import java.text.DecimalFormat;
47
import java.util.regex.Pattern;
58

@@ -86,16 +89,16 @@ public static boolean isNullOrEmpty(CharSequence s) {
8689
*/
8790
public static String getTimeString(long timeInMilliSeconds) {
8891
//Time in seconds
89-
double timeInSeconds = timeInMilliSeconds/1000.0;
92+
double timeInSeconds = timeInMilliSeconds / 1000.0;
9093
//Format to 2 decimal places
9194
DecimalFormat df = new DecimalFormat(".##");
9295
//In minutes
9396
if (timeInSeconds >= 60 && timeInSeconds < 60 * 60) {
94-
return df.format(timeInSeconds/60 )+ " minutes";
97+
return df.format(timeInSeconds / 60) + " minutes";
9598
}
9699
//In hours
97100
if (timeInSeconds >= 60 * 60 && timeInSeconds < 24 * 3600) {
98-
return df.format(timeInSeconds/3600) + " hours";
101+
return df.format(timeInSeconds / 3600) + " hours";
99102
}
100103
//default unit
101104
return df.format(timeInSeconds) + " seconds";
@@ -126,4 +129,24 @@ public static String removeIllegalXMLChar(String text) {
126129
invalidXMLChars.matcher(text).replaceAll("");
127130
return text;
128131
}
132+
133+
/**
134+
* Replaces one resource URI based on the list of comma separated fragments
135+
*
136+
* @param resourceUri a resource URI to be replaced
137+
* @param fragmentsCommaSeparated a list of two comma separated fragments. If more than 2 fragments are found,
138+
* only the first 2 will be considered.
139+
*/
140+
public static String replaceResourceURI(String resourceUri, String fragmentsCommaSeparated) {
141+
if (Strings.hasText(resourceUri)) {
142+
String[] frags = Strings.splitStringByCommaToArray(fragmentsCommaSeparated);
143+
if (frags != null && frags.length >= 2) { // only if we have something to replace
144+
return Strings.replace(resourceUri,
145+
StringUtils.deleteWhitespace(frags[0]),
146+
StringUtils.deleteWhitespace(frags[1]));
147+
}
148+
}
149+
return resourceUri;
150+
}
151+
129152
}

src/main/java/org/elasticsearch/river/ubb/support/FlatContextTransformer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public Map<String, String> transform(JsonElement context) {
9494
* Main method for easy debugging
9595
*/
9696
public static void main(String[] args) {
97-
String s = FileManager.read("http://data.ub.uib.no/momayo/context.json", 20);
97+
String s = FileManager.readAsUTF8("http://data.ub.uib.no/momayo/context.json", 20);
9898
Map<String, String> props = ContextFactory.flatContext().transform(s);
9999
System.out.println(new GsonBuilder()
100100
.setPrettyPrinting()

0 commit comments

Comments
 (0)