Skip to content

Commit 4d1a7c5

Browse files
author
Lukas Molzberger
committed
removed optional flag from relations
1 parent d0f70e9 commit 4d1a7c5

File tree

6 files changed

+44
-211
lines changed

6 files changed

+44
-211
lines changed

src/main/java/network/aika/neuron/relation/AncestorRelation.java

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ public static class CommonAncestor extends AncestorRelation {
131131
public CommonAncestor() {
132132
}
133133

134-
public CommonAncestor(boolean optional, boolean follow) {
135-
this.optional = optional;
134+
public CommonAncestor(boolean follow) {
136135
this.follow = follow;
137136
}
138137

@@ -143,12 +142,7 @@ public int getType() {
143142

144143
@Override
145144
public Relation invert() {
146-
return new CommonAncestor(optional, follow);
147-
}
148-
149-
@Override
150-
public Relation setOptionalAndFollow(boolean optional, boolean follow) {
151-
return new CommonAncestor(optional, follow);
145+
return new CommonAncestor(follow);
152146
}
153147

154148
@Override
@@ -180,8 +174,7 @@ public static class IsDescendantOf extends AncestorRelation {
180174
public IsDescendantOf() {
181175
}
182176

183-
public IsDescendantOf(boolean optional, boolean follow) {
184-
this.optional = optional;
177+
public IsDescendantOf(boolean follow) {
185178
this.follow = follow;
186179
}
187180

@@ -192,12 +185,7 @@ public int getType() {
192185

193186
@Override
194187
public Relation invert() {
195-
return new IsAncestorOf(optional, follow);
196-
}
197-
198-
@Override
199-
public Relation setOptionalAndFollow(boolean optional, boolean follow) {
200-
return new IsDescendantOf(optional, follow);
188+
return new IsAncestorOf(follow);
201189
}
202190

203191
@Override
@@ -229,8 +217,7 @@ public static class IsAncestorOf extends AncestorRelation {
229217
public IsAncestorOf() {
230218
}
231219

232-
public IsAncestorOf(boolean optional, boolean follow) {
233-
this.optional = optional;
220+
public IsAncestorOf(boolean follow) {
234221
this.follow = follow;
235222
}
236223

@@ -241,13 +228,9 @@ public int getType() {
241228

242229
@Override
243230
public Relation invert() {
244-
return new IsDescendantOf(optional, follow);
231+
return new IsDescendantOf(follow);
245232
}
246233

247-
@Override
248-
public Relation setOptionalAndFollow(boolean optional, boolean follow) {
249-
return new IsAncestorOf(optional, follow);
250-
}
251234

252235
@Override
253236
public boolean test(Activation act, Activation linkedAct, boolean allowUndefined) {
@@ -278,8 +261,7 @@ public static class NotDescendantOf extends AncestorRelation {
278261
public NotDescendantOf() {
279262
}
280263

281-
public NotDescendantOf(boolean optional, boolean follow) {
282-
this.optional = optional;
264+
public NotDescendantOf(boolean follow) {
283265
this.follow = follow;
284266
}
285267

@@ -290,12 +272,7 @@ public int getType() {
290272

291273
@Override
292274
public Relation invert() {
293-
return new NotAncestorOf(optional, follow);
294-
}
295-
296-
@Override
297-
public Relation setOptionalAndFollow(boolean optional, boolean follow) {
298-
return new NotDescendantOf(optional, follow);
275+
return new NotAncestorOf(follow);
299276
}
300277

301278
@Override
@@ -329,8 +306,7 @@ public static class NotAncestorOf extends AncestorRelation {
329306
public NotAncestorOf() {
330307
}
331308

332-
public NotAncestorOf(boolean optional, boolean follow) {
333-
this.optional = optional;
309+
public NotAncestorOf(boolean follow) {
334310
this.follow = follow;
335311
}
336312

@@ -341,12 +317,7 @@ public int getType() {
341317

342318
@Override
343319
public Relation invert() {
344-
return new NotDescendantOf(optional, follow);
345-
}
346-
347-
@Override
348-
public Relation setOptionalAndFollow(boolean optional, boolean follow) {
349-
return new NotAncestorOf(optional, follow);
320+
return new NotDescendantOf(follow);
350321
}
351322

352323
@Override

src/main/java/network/aika/neuron/relation/MultiRelation.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public MultiRelation() {
2828
}
2929

3030

31-
public MultiRelation(boolean optional, boolean follow, SortedSet<Relation> relations) {
32-
super(optional, follow);
31+
public MultiRelation(boolean follow, SortedSet<Relation> relations) {
32+
super(follow);
3333
this.relations = relations;
3434
}
3535

@@ -92,13 +92,7 @@ public Relation invert() {
9292
for(Relation rel: relations) {
9393
invRels.add(rel.invert());
9494
}
95-
return new MultiRelation(optional, follow, invRels);
96-
}
97-
98-
99-
@Override
100-
public Relation setOptionalAndFollow(boolean optional, boolean follow) {
101-
return new MultiRelation(optional, follow, relations);
95+
return new MultiRelation(follow, invRels);
10296
}
10397

10498

src/main/java/network/aika/neuron/relation/PositionRelation.java

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ public PositionRelation(int fromSlot, int toSlot) {
2929
this.toSlot = toSlot;
3030
}
3131

32-
public PositionRelation(int fromSlot, int toSlot, boolean optional, boolean follow) {
32+
public PositionRelation(int fromSlot, int toSlot, boolean follow) {
3333
this.fromSlot = fromSlot;
3434
this.toSlot = toSlot;
35-
this.optional = optional;
3635
this.follow = follow;
3736
}
3837

@@ -43,7 +42,7 @@ public boolean test(Activation act, Activation linkedAct, boolean allowUndefined
4342
if(allowUndefined && toPos == null) {
4443
return true;
4544
}
46-
return optional || test(act.lookupSlot(fromSlot), toPos);
45+
return test(act.lookupSlot(fromSlot), toPos);
4746
}
4847

4948

@@ -116,8 +115,8 @@ public Equals(int fromSlot, int toSlot) {
116115
super(fromSlot, toSlot);
117116
}
118117

119-
public Equals(int fromSlot, int toSlot, boolean optional, boolean follow) {
120-
super(fromSlot, toSlot, optional, follow);
118+
public Equals(int fromSlot, int toSlot, boolean follow) {
119+
super(fromSlot, toSlot, follow);
121120
}
122121

123122
@Override
@@ -127,12 +126,7 @@ public int getType() {
127126

128127
@Override
129128
public Relation invert() {
130-
return new Equals(toSlot, fromSlot, optional, follow);
131-
}
132-
133-
@Override
134-
public Relation setOptionalAndFollow(boolean optional, boolean follow) {
135-
return new Equals(fromSlot, toSlot, optional, follow);
129+
return new Equals(toSlot, fromSlot, follow);
136130
}
137131

138132
@Override
@@ -185,8 +179,8 @@ public LessThan(int fromSlot, int toSlot, boolean orEquals) {
185179
this.orEquals = orEquals;
186180
}
187181

188-
public LessThan(int fromSlot, int toSlot, boolean orEquals, boolean optional, boolean follow, int maxLength) {
189-
super(fromSlot, toSlot, optional, follow);
182+
public LessThan(int fromSlot, int toSlot, boolean orEquals, boolean follow, int maxLength) {
183+
super(fromSlot, toSlot, follow);
190184
this.orEquals = orEquals;
191185
this.maxLength = maxLength;
192186
}
@@ -198,13 +192,9 @@ public int getType() {
198192

199193
@Override
200194
public Relation invert() {
201-
return new GreaterThan(toSlot, fromSlot, orEquals, optional, follow, maxLength);
195+
return new GreaterThan(toSlot, fromSlot, orEquals, follow, maxLength);
202196
}
203197

204-
@Override
205-
public Relation setOptionalAndFollow(boolean optional, boolean follow) {
206-
return new LessThan(fromSlot, toSlot, orEquals, optional, follow, maxLength);
207-
}
208198

209199
@Override
210200
public boolean isExact() {
@@ -274,8 +264,8 @@ public GreaterThan(int fromSlot, int toSlot, boolean orEquals) {
274264
this.orEquals = orEquals;
275265
}
276266

277-
public GreaterThan(int fromSlot, int toSlot, boolean orEquals, boolean optional, boolean follow, int maxLength) {
278-
super(fromSlot, toSlot, optional, follow);
267+
public GreaterThan(int fromSlot, int toSlot, boolean orEquals, boolean follow, int maxLength) {
268+
super(fromSlot, toSlot, follow);
279269
this.orEquals = orEquals;
280270
this.maxLength = maxLength;
281271
}
@@ -287,12 +277,7 @@ public int getType() {
287277

288278
@Override
289279
public Relation invert() {
290-
return new LessThan(toSlot, fromSlot, orEquals, optional, follow, maxLength);
291-
}
292-
293-
@Override
294-
public Relation setOptionalAndFollow(boolean optional, boolean follow) {
295-
return new GreaterThan(fromSlot, toSlot, orEquals, optional, follow, maxLength);
280+
return new LessThan(toSlot, fromSlot, orEquals, follow, maxLength);
296281
}
297282

298283
@Override

src/main/java/network/aika/neuron/relation/Relation.java

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,32 @@ public abstract class Relation implements Comparable<Relation>, Writable {
3030

3131
public static Relation EQUALS = new MultiRelation(
3232
new Equals(BEGIN, BEGIN),
33-
new Equals(END, END, false, false)
33+
new Equals(END, END, false)
3434
);
3535
public static Relation BEGIN_EQUALS = new Equals(BEGIN, BEGIN);
3636
public static Relation END_EQUALS = new Equals(END, END);
3737
public static Relation BEGIN_TO_END_EQUALS = new Equals(BEGIN, END);
3838
public static Relation END_TO_BEGIN_EQUALS = new Equals(END, BEGIN);
3939
public static Relation CONTAINS = new MultiRelation(
4040
new LessThan(BEGIN, BEGIN, true),
41-
new GreaterThan(END, END, true, false, false, Integer.MAX_VALUE)
41+
new GreaterThan(END, END, true, false, Integer.MAX_VALUE)
4242
);
4343
public static Relation CONTAINED_IN = new MultiRelation(
4444
new GreaterThan(BEGIN, BEGIN, true),
45-
new LessThan(END, END, true, false, false, Integer.MAX_VALUE)
45+
new LessThan(END, END, true, false, Integer.MAX_VALUE)
4646
);
4747
public static Relation OVERLAPS = new MultiRelation(
4848
new LessThan(BEGIN, END, false),
49-
new GreaterThan(END, BEGIN, false, false, false, Integer.MAX_VALUE)
49+
new GreaterThan(END, BEGIN, false, false, Integer.MAX_VALUE)
5050
);
5151
public static Relation BEFORE = new LessThan(END, BEGIN, true);
5252
public static Relation AFTER = new GreaterThan(BEGIN, END, true);
5353

5454
public static Relation ANY = new Any();
5555

56-
protected boolean optional;
5756
protected boolean follow = true;
5857

5958

60-
public boolean isOptional() {
61-
return optional;
62-
}
63-
6459
public boolean isFollow() {
6560
return follow;
6661
}
@@ -87,22 +82,18 @@ public interface RelationFactory {
8782

8883
public abstract void mapSlots(Map<Integer, Position> slots, Activation act);
8984

90-
public abstract Relation setOptionalAndFollow(boolean optional, boolean follow);
91-
9285

9386
public Relation() {
9487
}
9588

9689

97-
public Relation(boolean optional, boolean follow) {
98-
this.optional = optional;
90+
public Relation(boolean follow) {
9991
this.follow = follow;
10092
}
10193

10294

10395
public void write(DataOutput out) throws IOException {
10496
out.writeInt(getType());
105-
out.writeBoolean(optional);
10697
out.writeBoolean(follow);
10798
}
10899

@@ -117,7 +108,6 @@ public static Relation read(DataInput in, Model m) throws IOException {
117108

118109
@Override
119110
public void readFields(DataInput in, Model m) throws IOException {
120-
optional = in.readBoolean();
121111
follow = in.readBoolean();
122112
}
123113

@@ -129,7 +119,7 @@ public void readFields(DataInput in, Model m) throws IOException {
129119

130120

131121
public boolean isConvertible() {
132-
return !optional && follow;
122+
return follow;
133123
}
134124

135125
public void link(Neuron n, int from, int to) {
@@ -261,8 +251,8 @@ public static class Any extends Relation {
261251
public Any() {
262252
}
263253

264-
public Any(boolean optional, boolean follow) {
265-
super(optional, follow);
254+
public Any(boolean follow) {
255+
super(follow);
266256
}
267257

268258
@Override
@@ -298,10 +288,5 @@ public Stream<Activation> getActivations(INeuron n, Activation linkedAct) {
298288
public boolean isConvertible() {
299289
return true;
300290
}
301-
302-
@Override
303-
public Relation setOptionalAndFollow(boolean optional, boolean follow) {
304-
return new Any(optional, follow);
305-
}
306291
}
307292
}

0 commit comments

Comments
 (0)