Skip to content

Commit 1ebb071

Browse files
fixes
1 parent 49e044f commit 1ebb071

File tree

4 files changed

+111
-6
lines changed

4 files changed

+111
-6
lines changed

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

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,27 @@ public static class CommonAncestor extends AncestorRelation {
143143
registerRelation(TYPE, () -> COMMON_ANCESTOR);
144144
}
145145

146+
public CommonAncestor() {
147+
}
148+
149+
public CommonAncestor(boolean optional, boolean follow) {
150+
this.optional = optional;
151+
this.follow = follow;
152+
}
153+
146154
@Override
147155
public int getType() {
148156
return TYPE;
149157
}
150158

151159
@Override
152160
public Relation invert() {
153-
return COMMON_ANCESTOR;
161+
return new CommonAncestor(optional, follow);
162+
}
163+
164+
@Override
165+
public Relation setOptionalAndFollow(boolean optional, boolean follow) {
166+
return new CommonAncestor(optional, follow);
154167
}
155168

156169
@Override
@@ -175,14 +188,27 @@ public static class IsDescendantOf extends AncestorRelation {
175188
registerRelation(TYPE, () -> IS_DESCENDANT_OF);
176189
}
177190

191+
public IsDescendantOf() {
192+
}
193+
194+
public IsDescendantOf(boolean optional, boolean follow) {
195+
this.optional = optional;
196+
this.follow = follow;
197+
}
198+
178199
@Override
179200
public int getType() {
180201
return TYPE;
181202
}
182203

183204
@Override
184205
public Relation invert() {
185-
return IS_ANCESTOR_OF;
206+
return new IsAncestorOf(optional, follow);
207+
}
208+
209+
@Override
210+
public Relation setOptionalAndFollow(boolean optional, boolean follow) {
211+
return new IsDescendantOf(optional, follow);
186212
}
187213

188214
@Override
@@ -207,14 +233,27 @@ public static class IsAncestorOf extends AncestorRelation {
207233
registerRelation(TYPE, () -> IS_ANCESTOR_OF);
208234
}
209235

236+
public IsAncestorOf() {
237+
}
238+
239+
public IsAncestorOf(boolean optional, boolean follow) {
240+
this.optional = optional;
241+
this.follow = follow;
242+
}
243+
210244
@Override
211245
public int getType() {
212246
return TYPE;
213247
}
214248

215249
@Override
216250
public Relation invert() {
217-
return IS_DESCENDANT_OF;
251+
return new IsDescendantOf(optional, follow);
252+
}
253+
254+
@Override
255+
public Relation setOptionalAndFollow(boolean optional, boolean follow) {
256+
return new IsAncestorOf(optional, follow);
218257
}
219258

220259
@Override
@@ -239,14 +278,27 @@ public static class NotDescendantOf extends AncestorRelation {
239278
registerRelation(TYPE, () -> NOT_DESCENDANT_OF);
240279
}
241280

281+
public NotDescendantOf() {
282+
}
283+
284+
public NotDescendantOf(boolean optional, boolean follow) {
285+
this.optional = optional;
286+
this.follow = follow;
287+
}
288+
242289
@Override
243290
public int getType() {
244291
return TYPE;
245292
}
246293

247294
@Override
248295
public Relation invert() {
249-
return NOT_ANCESTOR_OF;
296+
return new NotAncestorOf(optional, follow);
297+
}
298+
299+
@Override
300+
public Relation setOptionalAndFollow(boolean optional, boolean follow) {
301+
return new NotDescendantOf(optional, follow);
250302
}
251303

252304
@Override
@@ -274,14 +326,27 @@ public static class NotAncestorOf extends AncestorRelation {
274326
registerRelation(TYPE, () -> NOT_ANCESTOR_OF);
275327
}
276328

329+
public NotAncestorOf() {
330+
}
331+
332+
public NotAncestorOf(boolean optional, boolean follow) {
333+
this.optional = optional;
334+
this.follow = follow;
335+
}
336+
277337
@Override
278338
public int getType() {
279339
return TYPE;
280340
}
281341

282342
@Override
283343
public Relation invert() {
284-
return NOT_DESCENDANT_OF;
344+
return new NotDescendantOf(optional, follow);
345+
}
346+
347+
@Override
348+
public Relation setOptionalAndFollow(boolean optional, boolean follow) {
349+
return new NotAncestorOf(optional, follow);
285350
}
286351

287352
@Override

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ public MultiRelation() {
2828
}
2929

3030

31+
public MultiRelation(boolean optional, boolean follow, List<Relation> relations) {
32+
super(optional, follow);
33+
this.relations = relations;
34+
}
35+
3136
public MultiRelation(Relation... rels) {
3237
relations = Arrays.asList(rels);
3338
}
@@ -67,7 +72,13 @@ public Relation invert() {
6772
for(Relation rel: relations) {
6873
invRels.add(rel.invert());
6974
}
70-
return new MultiRelation(invRels);
75+
return new MultiRelation(optional, follow, invRels);
76+
}
77+
78+
79+
@Override
80+
public Relation setOptionalAndFollow(boolean optional, boolean follow) {
81+
return new MultiRelation(optional, follow, relations);
7182
}
7283

7384

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ public Relation invert() {
142142
return new Equals(toSlot, fromSlot, optional, follow);
143143
}
144144

145+
@Override
146+
public Relation setOptionalAndFollow(boolean optional, boolean follow) {
147+
return new Equals(fromSlot, toSlot, optional, follow);
148+
}
149+
145150
@Override
146151
public boolean test(Position a, Position b) {
147152
return a == b;
@@ -208,6 +213,11 @@ public Relation invert() {
208213
return new GreaterThan(toSlot, fromSlot, orEquals, optional, follow, maxLength);
209214
}
210215

216+
@Override
217+
public Relation setOptionalAndFollow(boolean optional, boolean follow) {
218+
return new LessThan(fromSlot, toSlot, orEquals, optional, follow, maxLength);
219+
}
220+
211221
@Override
212222
public boolean isExact() {
213223
return false;
@@ -290,6 +300,11 @@ public Relation invert() {
290300
return new LessThan(toSlot, fromSlot, orEquals, optional, follow, maxLength);
291301
}
292302

303+
@Override
304+
public Relation setOptionalAndFollow(boolean optional, boolean follow) {
305+
return new GreaterThan(fromSlot, toSlot, orEquals, optional, follow, maxLength);
306+
}
307+
293308
@Override
294309
public boolean isExact() {
295310
return false;

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public interface RelationFactory {
8080

8181
public abstract void linksOutputs(Set<Integer> outputs);
8282

83+
public abstract Relation setOptionalAndFollow(boolean optional, boolean follow);
84+
8385

8486
public Relation() {
8587
}
@@ -222,6 +224,13 @@ public static class Any extends Relation {
222224
registerRelation(ID, () -> Relation.ANY);
223225
}
224226

227+
public Any() {
228+
}
229+
230+
public Any(boolean optional, boolean follow) {
231+
super(optional, follow);
232+
}
233+
225234
@Override
226235
public int getType() {
227236
return ID;
@@ -265,6 +274,11 @@ public boolean convertible() {
265274
return true;
266275
}
267276

277+
@Override
278+
public Relation setOptionalAndFollow(boolean optional, boolean follow) {
279+
return new Any(optional, follow);
280+
}
281+
268282
@Override
269283
public void registerRequiredSlots(Neuron input) {
270284
}

0 commit comments

Comments
 (0)