Skip to content

Commit 640b646

Browse files
committed
Merge branch 'master' of https://github.com/metafacture/metafacture-core into fixJavadoc
2 parents 6c9bf16 + 7993b37 commit 640b646

File tree

13 files changed

+1602
-57
lines changed

13 files changed

+1602
-57
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Build](https://github.com/metafacture/metafacture-core/workflows/Build/badge.svg?branch=master)](https://github.com/metafacture/metafacture-core/actions?query=workflow%3ABuild) [![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=org.metafacture:metafacture-core&metric=alert_status)](https://sonarcloud.io/dashboard/index/org.metafacture:metafacture-core)
44

5-
Metafacture is a toolkit for processing semi-structured data with a focus on library metadata. It provides a versatile set of tools for reading, writing and transforming data. Metafacture can be used as a stand-alone application or as a Java library in other applications. The name Metafacture is a portmanteau of the words *meta* data and manu*facture*.
5+
Metafacture is a toolkit for processing semi-structured data with a focus on library metadata. It provides a versatile set of tools for reading, writing and transforming data. Metafacture can be used as a stand-alone application or as a Java library in other applications. The name Metafacture is a portmanteau of the words *meta*data and manu*facture*.
66

77
Metafacture includes a [large number of modules](https://github.com/metafacture/metafacture-documentation/blob/master/flux-commands.md) for operating on semi-structured data. These modules can be combined to build pipelines to perform complex metadata processing tasks. The pipelines can be constructed either in Java code or with the domain-specific language **Flux**. One of the core features of Metafacture is the **Metamorph** module. Metamorph is an xml-based language for specifying transformations of semi-structured data. It can be seamlessly integrated into Java code.
88

@@ -83,7 +83,8 @@ $ cd metafacture-core
8383
$ ./gradlew install
8484
```
8585

86-
The resulting distribution can be found in `metafacture-core/metafacture-runner/build/distributions/`.
86+
Besides the resulting distribution in `metafacture-core/metafacture-runner/build/distributions/` this also provides builds in your local maven repository.
87+
8788

8889
See [Code Quality and Style](https://github.com/metafacture/metafacture-core/wiki/Code-Quality-and-Style) on the wiki for further information on the sources.
8990

metafacture-runner/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ dependencies {
5555
plugins project(':metafacture-triples')
5656
plugins project(':metafacture-xml')
5757
plugins project(':metafacture-html')
58+
plugins project(':metafacture-yaml')
5859
plugins project(':metamorph')
5960

6061
// The plugins configuration needs to be on the runtime classpath:

metafacture-triples/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,10 @@ dependencies {
2424
testImplementation 'junit:junit:4.12'
2525
testImplementation 'org.mockito:mockito-core:2.5.5'
2626
}
27+
28+
test {
29+
testLogging {
30+
showStandardStreams = true
31+
exceptionFormat = 'full'
32+
}
33+
}

metafacture-triples/src/main/java/org/metafacture/triples/AbstractTripleSort.java

Lines changed: 43 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
import java.util.Comparator;
3131
import java.util.List;
3232
import java.util.PriorityQueue;
33+
import java.util.function.Function;
3334

3435
/**
3536
* @author markus geipel
3637
*
3738
*/
38-
public abstract class AbstractTripleSort extends DefaultObjectPipe<Triple, ObjectReceiver<Triple>>
39-
implements MemoryWarningSystem.Listener {
39+
public abstract class AbstractTripleSort extends DefaultObjectPipe<Triple, ObjectReceiver<Triple>> implements MemoryWarningSystem.Listener {
4040

4141
/**
4242
* Specifies the comparator. Can be one of {@link #SUBJECT}, {@link #PREDICATE},
@@ -70,10 +70,11 @@ public int order(final int indicator) {
7070
private final List<File> tempFiles = new ArrayList<>();
7171
private Compare compare = Compare.SUBJECT;
7272
private Order order = Order.INCREASING;
73+
private boolean numeric;
7374
private volatile boolean memoryLow;
7475

7576
/**
76-
* Constructs an AbstractTripleSort. Calls {@link #MemoryWarningSystem}.
77+
* Constructs an AbstractTripleSort. Calls {@link MemoryWarningSystem}.
7778
*/
7879
protected AbstractTripleSort() {
7980
MemoryWarningSystem.addListener(this);
@@ -96,6 +97,10 @@ protected final void setSortOrder(final Order newOrder) {
9697
order = newOrder;
9798
}
9899

100+
protected final void setSortNumeric(final boolean newNumeric) {
101+
numeric = newNumeric;
102+
}
103+
99104
@Override
100105
public final void process(final Triple namedValue) {
101106
if (memoryLow) {
@@ -115,47 +120,38 @@ public final void process(final Triple namedValue) {
115120
}
116121

117122
private void nextBatch() throws IOException {
118-
Collections.sort(buffer, createComparator(compare, order));
123+
Collections.sort(buffer, createComparator());
119124
final File tempFile = File.createTempFile("sort", "namedValues", null);
120125
tempFile.deleteOnExit();
121-
final ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(tempFile));
122126

123-
try {
127+
try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(tempFile))) {
124128
for (final Triple triple : buffer) {
125129
triple.write(out);
126130
}
127131
}
128-
finally {
129-
out.close();
130-
}
132+
131133
buffer.clear();
132134
tempFiles.add(tempFile);
133135
}
134136

135137
@Override
136138
public final void onCloseStream() {
137-
138139
if (tempFiles.isEmpty()) {
139-
Collections.sort(buffer, createComparator(compare, order));
140+
Collections.sort(buffer, createComparator());
141+
140142
for (final Triple triple : buffer) {
141143
sortedTriple(triple);
142144
}
145+
143146
onFinished();
144147
}
145148
else {
146-
final Comparator<Triple> comparator = createComparator(compare, order);
147-
final PriorityQueue<SortedTripleFileFacade> queue = new PriorityQueue<SortedTripleFileFacade>(11,
148-
new Comparator<SortedTripleFileFacade>() {
149-
// private final Comparator<Triple> comparator =
150-
// getComparator();
151-
152-
@Override
153-
public int compare(final SortedTripleFileFacade o1, final SortedTripleFileFacade o2) {
154-
return comparator.compare(o1.peek(), o2.peek());
155-
}
156-
});
149+
final Comparator<Triple> comparator = createComparator();
150+
final PriorityQueue<SortedTripleFileFacade> queue = new PriorityQueue<>(11, (o1, o2) -> comparator.compare(o1.peek(), o2.peek()));
151+
157152
try {
158153
nextBatch();
154+
159155
for (final File file : tempFiles) {
160156
queue.add(new SortedTripleFileFacade(file));
161157
}
@@ -171,6 +167,7 @@ public int compare(final SortedTripleFileFacade o1, final SortedTripleFileFacade
171167
queue.add(sortedFileFacade);
172168
}
173169
}
170+
174171
onFinished();
175172
}
176173
catch (final IOException e) {
@@ -182,6 +179,7 @@ public int compare(final SortedTripleFileFacade o1, final SortedTripleFileFacade
182179
}
183180
}
184181
}
182+
185183
MemoryWarningSystem.removeListener(this);
186184
}
187185

@@ -192,65 +190,56 @@ protected void onFinished() {
192190
protected abstract void sortedTriple(Triple namedValue);
193191

194192
public final Comparator<Triple> createComparator() {
195-
return createComparator(compare, order);
193+
return createComparator(compare, order, numeric);
194+
}
195+
196+
public static Comparator<Triple> createComparator(final Compare compare, final Order order) {
197+
return createComparator(compare, order, false);
196198
}
197199

198200
/**
199201
* Creates a Comparator.
200202
*
201-
* @param compareBy one of {@link #Compare}
202-
* @param order the {@link #Order}
203+
* @param compare one of {@link #Compare}
204+
* @param order the {@link #Order}
205+
* @param numeric "true" if comparison should be numeric. "false" if comparison
206+
* should be alphanumeric. Defaults to "false".
203207
* @return a Comparator of type Triple
204208
*/
205-
public static Comparator<Triple> createComparator(final Compare compareBy, final Order order) {
206-
final Comparator<Triple> comparator;
207-
switch (compareBy) {
209+
private static Comparator<Triple> createComparator(final Compare compare, final Order order, final boolean numeric) {
210+
final Function<Triple, String> tripleFunction;
211+
switch (compare) {
208212
case ALL:
209-
comparator = new Comparator<Triple>() {
210-
@Override
211-
public int compare(final Triple o1, final Triple o2) {
212-
return order.order(o1.compareTo(o2));
213-
}
214-
};
215-
break;
213+
return (o1, o2) -> order.order(o1.compareTo(o2));
216214
case OBJECT:
217-
comparator = new Comparator<Triple>() {
218-
@Override
219-
public int compare(final Triple o1, final Triple o2) {
220-
return order.order(o1.getObject().compareTo(o2.getObject()));
221-
}
222-
};
215+
tripleFunction = Triple::getObject;
223216
break;
224217
case SUBJECT:
225-
comparator = new Comparator<Triple>() {
226-
@Override
227-
public int compare(final Triple o1, final Triple o2) {
228-
return order.order(o1.getSubject().compareTo(o2.getSubject()));
229-
}
230-
};
218+
tripleFunction = Triple::getSubject;
231219
break;
232220
case PREDICATE:
233221
default:
234-
comparator = new Comparator<Triple>() {
235-
@Override
236-
public int compare(final Triple o1, final Triple o2) {
237-
return order.order(o1.getPredicate().compareTo(o2.getPredicate()));
238-
}
239-
};
222+
tripleFunction = Triple::getPredicate;
240223
break;
241224
}
242225

243-
return comparator;
226+
final Function<Triple, Integer> numericFunction = tripleFunction.andThen(Integer::valueOf);
227+
return numeric ?
228+
(o1, o2) -> order.order(numericFunction.apply(o1).compareTo(numericFunction.apply(o2))) :
229+
(o1, o2) -> order.order(tripleFunction.apply(o1).compareTo(tripleFunction.apply(o2)));
244230
}
245231

246232
@Override
247233
public final void onResetStream() {
248234
buffer.clear();
235+
249236
for (final File file : tempFiles) {
250237
if (file.exists()) {
251238
file.delete();
252239
}
253240
}
241+
254242
tempFiles.clear();
255243
}
244+
256245
}

metafacture-triples/src/main/java/org/metafacture/triples/TripleSort.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* @author markus geipel
2828
*
2929
*/
30-
@Description("Sorts triples")
30+
@Description("Sorts triples. Several options can be combined, e.g. `by=\"object\",numeric=\"true\",order=\"decreasing\"` will numerically sort the Object of the triples in decreasing order (given that all Objects are indeed of numeric type).")
3131
@In(Triple.class)
3232
@Out(Triple.class)
3333
@FluxCommand("sort-triples")
@@ -49,4 +49,8 @@ public void setOrder(final Order order) {
4949
setSortOrder(order);
5050
}
5151

52+
public void setNumeric(final boolean numeric) {
53+
setSortNumeric(numeric);
54+
}
55+
5256
}

0 commit comments

Comments
 (0)