|
16 | 16 |
|
17 | 17 | package org.metafacture.metafix;
|
18 | 18 |
|
19 |
| -import org.metafacture.formatting.ObjectTemplate; |
20 | 19 | import org.metafacture.framework.FluxCommand;
|
21 |
| -import org.metafacture.framework.ObjectReceiver; |
22 |
| -import org.metafacture.framework.Sender; |
23 | 20 | import org.metafacture.framework.StreamReceiver;
|
24 | 21 | import org.metafacture.framework.annotations.Description;
|
25 | 22 | import org.metafacture.framework.annotations.In;
|
26 | 23 | import org.metafacture.framework.annotations.Out;
|
27 |
| -import org.metafacture.framework.helpers.DefaultStreamPipe; |
28 |
| -import org.metafacture.mangling.DuplicateObjectFilter; |
29 |
| -import org.metafacture.mangling.StreamFlattener; |
30 | 24 | import org.metafacture.triples.AbstractTripleSort.Compare;
|
31 |
| -import org.metafacture.triples.AbstractTripleSort.Order; |
32 |
| -import org.metafacture.triples.StreamToTriples; |
33 |
| -import org.metafacture.triples.TripleCount; |
34 |
| -import org.metafacture.triples.TripleSort; |
35 |
| - |
36 |
| -import java.io.FileNotFoundException; |
37 | 25 |
|
38 | 26 | /**
|
39 |
| - * Provide a user-friendly way to list all paths available for processing in fix. |
| 27 | + * Provide a user-friendly way to list all paths available for processing in fix (see also {@link MetafixListValues}). |
40 | 28 | *
|
41 | 29 | * @author Fabian Steeg
|
42 | 30 | */
|
|
46 | 34 | @In(StreamReceiver.class)
|
47 | 35 | @Out(String.class)
|
48 | 36 | @FluxCommand("fix-list-paths")
|
49 |
| -public class MetafixListPaths extends DefaultStreamPipe<ObjectReceiver<String>> { |
50 |
| - |
51 |
| - private Metafix fix; |
52 |
| - private boolean count = true; |
53 |
| - private boolean index; |
| 37 | +public class MetafixListPaths extends MetafixStreamAnalyzer { |
54 | 38 |
|
55 | 39 | public MetafixListPaths() {
|
56 |
| - try { |
57 |
| - fix = new Metafix("nothing()"); |
58 |
| - fix.setRepeatedFieldsToEntities(true); |
59 |
| - } |
60 |
| - catch (final FileNotFoundException e) { |
61 |
| - e.printStackTrace(); |
62 |
| - } |
63 |
| - } |
64 |
| - |
65 |
| - @Override |
66 |
| - protected void onSetReceiver() { |
67 |
| - fix.setEntityMemberName(index ? "%d" : "*"); |
68 |
| - final StreamToTriples triples = fix |
69 |
| - .setReceiver(new StreamFlattener()) |
70 |
| - .setReceiver(new StreamToTriples()); |
71 |
| - (count ? counted(triples) : unique(triples)) |
72 |
| - .setReceiver(getReceiver()); |
73 |
| - } |
74 |
| - |
75 |
| - private Sender<ObjectReceiver<String>> counted(final StreamToTriples triples) { |
76 |
| - return triples |
77 |
| - .setReceiver(tripleCount()) |
78 |
| - .setReceiver(tripleSort()) |
79 |
| - .setReceiver(new ObjectTemplate<>("${s}\t ${o}")); |
80 |
| - } |
81 |
| - |
82 |
| - private Sender<ObjectReceiver<String>> unique(final StreamToTriples triples) { |
83 |
| - return triples |
84 |
| - .setReceiver(new ObjectTemplate<>("${p}")) |
85 |
| - .setReceiver(new DuplicateObjectFilter<>()); |
86 |
| - } |
87 |
| - |
88 |
| - private TripleCount tripleCount() { |
89 |
| - final TripleCount tripleCount = new TripleCount(); |
90 |
| - tripleCount.setCountBy(Compare.PREDICATE); |
91 |
| - return tripleCount; |
92 |
| - } |
93 |
| - |
94 |
| - private TripleSort tripleSort() { |
95 |
| - final TripleSort tripleSort = new TripleSort(); |
96 |
| - tripleSort.setNumeric(true); |
97 |
| - tripleSort.setBy(Compare.OBJECT); |
98 |
| - tripleSort.setOrder(Order.DECREASING); |
99 |
| - return tripleSort; |
100 |
| - } |
101 |
| - |
102 |
| - @Override |
103 |
| - public void startRecord(final String identifier) { |
104 |
| - fix.startRecord(identifier); |
105 |
| - } |
106 |
| - |
107 |
| - @Override |
108 |
| - public void endRecord() { |
109 |
| - fix.endRecord(); |
110 |
| - } |
111 |
| - |
112 |
| - @Override |
113 |
| - public void startEntity(final String name) { |
114 |
| - fix.startEntity(name); |
115 |
| - } |
116 |
| - |
117 |
| - @Override |
118 |
| - public void endEntity() { |
119 |
| - fix.endEntity(); |
120 |
| - } |
121 |
| - |
122 |
| - @Override |
123 |
| - public void literal(final String name, final String value) { |
124 |
| - fix.literal(name, value); |
125 |
| - } |
126 |
| - |
127 |
| - @Override |
128 |
| - protected void onCloseStream() { |
129 |
| - fix.closeStream(); |
130 |
| - } |
131 |
| - |
132 |
| - @Override |
133 |
| - protected void onResetStream() { |
134 |
| - fix.resetStream(); |
135 |
| - } |
136 |
| - |
137 |
| - public void setCount(final boolean count) { |
138 |
| - this.count = count; |
139 |
| - } |
140 |
| - |
141 |
| - public boolean getCount() { |
142 |
| - return this.count; |
| 40 | + super("nothing()", Compare.PREDICATE, "${s}\t ${o}", "${p}"); |
| 41 | + setIndex(false); |
143 | 42 | }
|
144 | 43 |
|
145 | 44 | public void setIndex(final boolean index) {
|
146 |
| - this.index = index; |
| 45 | + super.getFix().setEntityMemberName(index ? Metafix.DEFAULT_ENTITY_MEMBER_NAME : "*"); |
147 | 46 | }
|
148 | 47 |
|
149 | 48 | public boolean getIndex() {
|
150 |
| - return this.index; |
| 49 | + return super.getFix().getEntityMemberName().equals(Metafix.DEFAULT_ENTITY_MEMBER_NAME); |
151 | 50 | }
|
152 | 51 | }
|
0 commit comments