Skip to content

Commit 32597ca

Browse files
committed
Mysterious whitespace changes which should not occur any more :-(
1 parent f220f9e commit 32597ca

File tree

5 files changed

+411
-411
lines changed

5 files changed

+411
-411
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
rdf http://www.w3.org/1999/02/22-rdf-syntax-ns#
2-
edm http://www.europeana.eu/schemas/edm/
3-
dcterms http://purl.org/dc/terms/
4-
dc http://purl.org/dc/elements/1.1/
5-
skos http://www.w3.org/2004/02/skos/core#
6-
oai http://www.openarchives.org/OAI/2.0/
1+
rdf http://www.w3.org/1999/02/22-rdf-syntax-ns#
2+
edm http://www.europeana.eu/schemas/edm/
3+
dcterms http://purl.org/dc/terms/
4+
dc http://purl.org/dc/elements/1.1/
5+
skos http://www.w3.org/2004/02/skos/core#
6+
oai http://www.openarchives.org/OAI/2.0/
77
ore http://www.openarchives.org/ore/terms/

examples/sort/sort-gnd.flux

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
default fileName = FLUX_DIR + "gnd-sample.pica";
2-
3-
fileName|
4-
open-file|
5-
as-lines|
6-
decode-pica|
7-
morph(FLUX_DIR + "gnd-pref-label.xml")|
8-
stream-to-triples|
9-
sort-triples(sortBy="object")|
10-
template("${s}\t${o}")|
1+
default fileName = FLUX_DIR + "gnd-sample.pica";
2+
3+
fileName|
4+
open-file|
5+
as-lines|
6+
decode-pica|
7+
morph(FLUX_DIR + "gnd-pref-label.xml")|
8+
stream-to-triples|
9+
sort-triples(sortBy="object")|
10+
template("${s}\t${o}")|
1111
write("stdout");

src/main/java/org/culturegraph/mf/stream/converter/ObjectTemplate.java

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,59 +13,59 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.culturegraph.mf.stream.converter;
17-
18-
import java.util.HashMap;
19-
import java.util.Map;
20-
import java.util.regex.Matcher;
21-
import java.util.regex.Pattern;
22-
23-
import org.culturegraph.mf.framework.DefaultObjectPipe;
24-
import org.culturegraph.mf.framework.ObjectReceiver;
25-
import org.culturegraph.mf.framework.annotations.Description;
26-
import org.culturegraph.mf.framework.annotations.In;
27-
import org.culturegraph.mf.framework.annotations.Out;
28-
import org.culturegraph.mf.types.Triple;
29-
import org.culturegraph.mf.util.StringUtil;
30-
31-
32-
/**
33-
* Builds a {@link String} from a template and an {@link Object}. ${obj} marks
34-
* the place where the object is to be inserted.
35-
*
36-
* @param <T>
37-
* object type
38-
*
39-
* @author Markus Geipel
40-
*
41-
*/
42-
@Description("Builds a String from a template and an Object. Provide template in brackets. ${o} marks the place where the object is to be inserted. " +
43-
"If the object in an instance of Triple ${s}, ${p} and ${o} are used instead")
44-
@In(Object.class)
45-
@Out(String.class)
46-
public final class ObjectTemplate<T> extends DefaultObjectPipe<T, ObjectReceiver<String>> {
47-
48-
//TODO: make replace more efficient
49-
private static final Pattern OBJ_PATTERN = Pattern.compile("${o}", Pattern.LITERAL);
50-
private final Map<String, String> vars = new HashMap<String, String>();
51-
private final String template;
52-
53-
public ObjectTemplate(final String template) {
54-
super();
55-
this.template = template;
56-
}
57-
58-
@Override
59-
public void process(final T obj) {
60-
if(obj instanceof Triple){
61-
final Triple triple = (Triple)obj;
62-
vars.put("s", triple.getSubject());
63-
vars.put("p", triple.getPredicate());
64-
vars.put("o", triple.getObject());
65-
getReceiver().process(StringUtil.format(template, vars));
66-
}else{
67-
final Matcher matcher = OBJ_PATTERN.matcher(template);
68-
getReceiver().process(matcher.replaceAll(obj.toString()));
69-
}
70-
}
71-
}
16+
package org.culturegraph.mf.stream.converter;
17+
18+
import java.util.HashMap;
19+
import java.util.Map;
20+
import java.util.regex.Matcher;
21+
import java.util.regex.Pattern;
22+
23+
import org.culturegraph.mf.framework.DefaultObjectPipe;
24+
import org.culturegraph.mf.framework.ObjectReceiver;
25+
import org.culturegraph.mf.framework.annotations.Description;
26+
import org.culturegraph.mf.framework.annotations.In;
27+
import org.culturegraph.mf.framework.annotations.Out;
28+
import org.culturegraph.mf.types.Triple;
29+
import org.culturegraph.mf.util.StringUtil;
30+
31+
32+
/**
33+
* Builds a {@link String} from a template and an {@link Object}. ${obj} marks
34+
* the place where the object is to be inserted.
35+
*
36+
* @param <T>
37+
* object type
38+
*
39+
* @author Markus Geipel
40+
*
41+
*/
42+
@Description("Builds a String from a template and an Object. Provide template in brackets. ${o} marks the place where the object is to be inserted. " +
43+
"If the object in an instance of Triple ${s}, ${p} and ${o} are used instead")
44+
@In(Object.class)
45+
@Out(String.class)
46+
public final class ObjectTemplate<T> extends DefaultObjectPipe<T, ObjectReceiver<String>> {
47+
48+
//TODO: make replace more efficient
49+
private static final Pattern OBJ_PATTERN = Pattern.compile("${o}", Pattern.LITERAL);
50+
private final Map<String, String> vars = new HashMap<String, String>();
51+
private final String template;
52+
53+
public ObjectTemplate(final String template) {
54+
super();
55+
this.template = template;
56+
}
57+
58+
@Override
59+
public void process(final T obj) {
60+
if(obj instanceof Triple){
61+
final Triple triple = (Triple)obj;
62+
vars.put("s", triple.getSubject());
63+
vars.put("p", triple.getPredicate());
64+
vars.put("o", triple.getObject());
65+
getReceiver().process(StringUtil.format(template, vars));
66+
}else{
67+
final Matcher matcher = OBJ_PATTERN.matcher(template);
68+
getReceiver().process(matcher.replaceAll(obj.toString()));
69+
}
70+
}
71+
}

src/main/java/org/culturegraph/mf/stream/pipe/OreAggregationAdder.java

Lines changed: 107 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.culturegraph.mf.stream.pipe;
17-
16+
package org.culturegraph.mf.stream.pipe;
17+
1818
import java.util.Deque;
1919
import java.util.LinkedList;
2020
import java.util.List;
@@ -29,108 +29,108 @@
2929
import org.culturegraph.mf.framework.annotations.Out;
3030
import org.culturegraph.mf.types.ListMap;
3131
import org.culturegraph.mf.util.ResourceUtil;
32-
33-
34-
35-
/**
36-
* adds ore:Aggregation to an Europeana Data Model stream
37-
*
38-
* @author Markus Michael Geipel
39-
*
40-
*/
41-
@Description("adds ore:Aggregation to an Europeana Data Model stream. The aggregation id is set by emitting literal('aggregation_id', id)")
42-
@In(StreamReceiver.class)
43-
@Out(StreamReceiver.class)
44-
public final class OreAggregationAdder extends DefaultStreamPipe<StreamReceiver> {
45-
46-
private static final String RDF_ABOUT = "~rdf:about";
47-
private static final ListMap<String, String> AGGREGATED_ENTITIES = new ListMap<String, String>();
48-
private static final String ORE_AGGREGATION_PROPERTIES = "ore-aggregation.properties";
49-
private static final String ORE_AGGREGATION = "ore:Aggregation";
50-
private static final String AGGREGATION_ID = "aggregation_id";
51-
private static final String RDF_REFERENCE = "~rdf:reference";
52-
private static final Pattern SPLIT_PATTERN = Pattern.compile("\\s*,\\s*");
53-
private final Deque<String> entityStack = new LinkedList<String>();
54-
private final ListMap<String, String> aggregation = new ListMap<String, String>();
55-
private String aggregationId;
56-
57-
static {
58-
final Properties properties = ResourceUtil.loadProperties(ORE_AGGREGATION_PROPERTIES);
59-
for (Entry<Object, Object> entry : properties.entrySet()) {
60-
final String[] parts = SPLIT_PATTERN.split(entry.getValue().toString());
61-
final String name = entry.getKey().toString();
62-
for (String value : parts) {
63-
AGGREGATED_ENTITIES.add(name, value);
64-
}
65-
}
66-
}
67-
68-
@Override
69-
public void startRecord(final String identifier) {
70-
entityStack.clear();
71-
aggregationId = identifier;
72-
getReceiver().startRecord(identifier);
73-
}
74-
75-
@Override
76-
public void endRecord() {
77-
writeAggregation();
78-
aggregation.clear();
79-
getReceiver().endRecord();
80-
}
81-
82-
private void writeAggregation() {
83-
if (!aggregation.isEmpty()) {
84-
final StreamReceiver receiver = getReceiver();
85-
receiver.startEntity(ORE_AGGREGATION);
86-
receiver.literal(RDF_ABOUT, aggregationId);
87-
for (Entry<String, List<String>> entry : aggregation.entrySet()) {
88-
final String key = entry.getKey();
89-
if (AGGREGATED_ENTITIES.containsKey(key)) {
90-
91-
for (String entity : AGGREGATED_ENTITIES.get(key)) {
92-
for (String value : entry.getValue()) {
93-
receiver.startEntity(entity);
94-
receiver.literal(RDF_REFERENCE, value);
95-
receiver.endEntity();
96-
}
97-
}
98-
} else {
99-
for (String value : entry.getValue()) {
100-
receiver.literal(key, value);
101-
}
102-
}
103-
}
104-
receiver.endEntity();
105-
}
106-
}
107-
108-
@Override
109-
public void startEntity(final String name) {
110-
entityStack.push(name);
111-
getReceiver().startEntity(name);
112-
}
113-
114-
@Override
115-
public void endEntity() {
116-
entityStack.pop();
117-
getReceiver().endEntity();
118-
}
119-
120-
@Override
121-
public void literal(final String name, final String value) {
122-
if (entityStack.isEmpty()) {
123-
if (AGGREGATION_ID.equals(name)) {
124-
aggregationId = value;
125-
} else {
126-
aggregation.add(name, value);
127-
}
128-
return;
129-
}
130-
131-
if (entityStack.size()==1 && RDF_ABOUT.equals(name) && AGGREGATED_ENTITIES.containsKey(entityStack.peek())) {
132-
aggregation.add(entityStack.peek(), value);
133-
}
134-
getReceiver().literal(name, value);
135-
}
136-
}
32+
33+
34+
35+
/**
36+
* adds ore:Aggregation to an Europeana Data Model stream
37+
*
38+
* @author Markus Michael Geipel
39+
*
40+
*/
41+
@Description("adds ore:Aggregation to an Europeana Data Model stream. The aggregation id is set by emitting literal('aggregation_id', id)")
42+
@In(StreamReceiver.class)
43+
@Out(StreamReceiver.class)
44+
public final class OreAggregationAdder extends DefaultStreamPipe<StreamReceiver> {
45+
46+
private static final String RDF_ABOUT = "~rdf:about";
47+
private static final ListMap<String, String> AGGREGATED_ENTITIES = new ListMap<String, String>();
48+
private static final String ORE_AGGREGATION_PROPERTIES = "ore-aggregation.properties";
49+
private static final String ORE_AGGREGATION = "ore:Aggregation";
50+
private static final String AGGREGATION_ID = "aggregation_id";
51+
private static final String RDF_REFERENCE = "~rdf:reference";
52+
private static final Pattern SPLIT_PATTERN = Pattern.compile("\\s*,\\s*");
53+
private final Deque<String> entityStack = new LinkedList<String>();
54+
private final ListMap<String, String> aggregation = new ListMap<String, String>();
55+
private String aggregationId;
56+
57+
static {
58+
final Properties properties = ResourceUtil.loadProperties(ORE_AGGREGATION_PROPERTIES);
59+
for (Entry<Object, Object> entry : properties.entrySet()) {
60+
final String[] parts = SPLIT_PATTERN.split(entry.getValue().toString());
61+
final String name = entry.getKey().toString();
62+
for (String value : parts) {
63+
AGGREGATED_ENTITIES.add(name, value);
64+
}
65+
}
66+
}
67+
68+
@Override
69+
public void startRecord(final String identifier) {
70+
entityStack.clear();
71+
aggregationId = identifier;
72+
getReceiver().startRecord(identifier);
73+
}
74+
75+
@Override
76+
public void endRecord() {
77+
writeAggregation();
78+
aggregation.clear();
79+
getReceiver().endRecord();
80+
}
81+
82+
private void writeAggregation() {
83+
if (!aggregation.isEmpty()) {
84+
final StreamReceiver receiver = getReceiver();
85+
receiver.startEntity(ORE_AGGREGATION);
86+
receiver.literal(RDF_ABOUT, aggregationId);
87+
for (Entry<String, List<String>> entry : aggregation.entrySet()) {
88+
final String key = entry.getKey();
89+
if (AGGREGATED_ENTITIES.containsKey(key)) {
90+
91+
for (String entity : AGGREGATED_ENTITIES.get(key)) {
92+
for (String value : entry.getValue()) {
93+
receiver.startEntity(entity);
94+
receiver.literal(RDF_REFERENCE, value);
95+
receiver.endEntity();
96+
}
97+
}
98+
} else {
99+
for (String value : entry.getValue()) {
100+
receiver.literal(key, value);
101+
}
102+
}
103+
}
104+
receiver.endEntity();
105+
}
106+
}
107+
108+
@Override
109+
public void startEntity(final String name) {
110+
entityStack.push(name);
111+
getReceiver().startEntity(name);
112+
}
113+
114+
@Override
115+
public void endEntity() {
116+
entityStack.pop();
117+
getReceiver().endEntity();
118+
}
119+
120+
@Override
121+
public void literal(final String name, final String value) {
122+
if (entityStack.isEmpty()) {
123+
if (AGGREGATION_ID.equals(name)) {
124+
aggregationId = value;
125+
} else {
126+
aggregation.add(name, value);
127+
}
128+
return;
129+
}
130+
131+
if (entityStack.size()==1 && RDF_ABOUT.equals(name) && AGGREGATED_ENTITIES.containsKey(entityStack.peek())) {
132+
aggregation.add(entityStack.peek(), value);
133+
}
134+
getReceiver().literal(name, value);
135+
}
136+
}

0 commit comments

Comments
 (0)