-
Notifications
You must be signed in to change notification settings - Fork 5
/
DocPropertiesSwitcher.java
123 lines (105 loc) · 4.53 KB
/
DocPropertiesSwitcher.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package org.genericsystem.ir.app.gui.utils;
import org.genericsystem.cv.classifier.newmodel.SimpleModel.DocClassType.DocClassInstance;
import org.genericsystem.cv.classifier.newmodel.SimpleModel.ImgType.ImgInstance;
import org.genericsystem.reactor.Context;
import org.genericsystem.reactor.Tag;
import org.genericsystem.reactor.context.TagSwitcher;
import io.reactivex.Observable;
@SuppressWarnings({ "unchecked", "rawtypes" })
public class DocPropertiesSwitcher {
// private static final String ZONES_FILE_BASE_PATH = DistributedVerticle.BASE_PATH + "/classes/";
public static class DOC_CLASS_EMPTY implements TagSwitcher {
@Override
public Observable<Boolean> apply(Context context, Tag tag) {
return isDocClassEmpty(context, false);
}
}
public static class DOC_CLASS_NOT_EMPTY implements TagSwitcher {
@Override
public Observable<Boolean> apply(Context context, Tag tag) {
return isDocClassEmpty(context, true);
}
}
// public static class SUPERVISION_AVAILABLE implements TagSwitcher {
// @Override
// public Observable<Boolean> apply(Context context, Tag tag) {
// return isSupervisionAvailable(context, false);
// }
// }
//
// public static class SUPERVISION_NOT_AVAILABLE implements TagSwitcher {
// @Override
// public Observable<Boolean> apply(Context context, Tag tag) {
// return isSupervisionAvailable(context, true);
// }
// }
public static class DOC_DEZONED implements TagSwitcher {
@Override
public Observable<Boolean> apply(Context context, Tag tag) {
return isImgDezoned(context, false);
}
}
public static class DOC_NOT_DEZONED implements TagSwitcher {
@Override
public Observable<Boolean> apply(Context context, Tag tag) {
return isImgDezoned(context, true);
}
}
public static class DOC_OCRD implements TagSwitcher {
@Override
public Observable<Boolean> apply(Context context, Tag tag) {
return isDocOcrd(context, false);
}
}
public static class DOC_NOT_OCRD implements TagSwitcher {
@Override
public Observable<Boolean> apply(Context context, Tag tag) {
return isDocOcrd(context, true);
}
}
// public static class DOC_SUPERVISED implements TagSwitcher {
// @Override
// public Observable<Boolean> apply(Context context, Tag tag) {
// return isDocSupervised(context, false);
// }
// }
//
// public static class DOC_NOT_SUPERVISED implements TagSwitcher {
// @Override
// public Observable<Boolean> apply(Context context, Tag tag) {
// return isDocSupervised(context, true);
// }
// }
public static Observable<Boolean> isDocClassEmpty(Context context, boolean reverse) {
DocClassInstance currentDocClass = (DocClassInstance) context.getGeneric();
Observable<Boolean> binding = currentDocClass.getAllDocInstances().setOnChanged().map(docs -> docs.isEmpty());
return reverse ? binding.map(bool -> !bool) : binding;
}
// public static Observable<Boolean> isSupervisionAvailable(Context context, boolean reverse) {
// DocClassInstance currentDocClass = (DocClassInstance) context.getGeneric();
// Observable<Boolean> binding = getBooleanBinding(currentDocClass.getValue().toString());
// return reverse ? binding.map(bool -> !bool) : binding;
// }
public static Observable<Boolean> isImgDezoned(Context context, boolean reverse) {
ImgInstance imgInstance = (ImgInstance) context.getGeneric();
Observable<Boolean> binding = getBooleanBinding(imgInstance);
return reverse ? binding.map(bool -> !bool) : binding;
}
private static Observable<Boolean> getBooleanBinding(ImgInstance imgInstance) {
return imgInstance.getZoneInstances().setOnChanged().map(zones -> !zones.isEmpty());
}
public static Observable<Boolean> isDocOcrd(Context context, boolean reverse) {
ImgInstance currentImg = (ImgInstance) context.getGeneric();
Observable<Boolean> obs = currentImg.getConsolidatedZoneInstances().setOnChanged().map(zone -> !zone.isEmpty());
return reverse ? obs.map(bool -> !bool) : obs;
}
// public static Observable<Boolean> isDocSupervised(Context context, boolean reverse) {
// // TODO: will a document be considered as not supervised if a field needs to be left empty?
// DocInstance currentDoc = (DocInstance) context.getGeneric();
// Root root = currentDoc.getRoot();
// ZoneText zoneText = root.find(ZoneText.class);
// Observable<Boolean> obs = currentDoc.getHolders(zoneText).filter(zt -> "reality".equals(((ZoneTextInstance) zt).getImgFilter().getValue())).setOnChanged()
// .map(zoneTextInstances -> !zoneTextInstances.isEmpty() && !zoneTextInstances.stream().anyMatch(g -> "".equals(g.getValue().toString())));
// return reverse ? obs.map(bool -> !bool) : obs;
// }
}