-
Notifications
You must be signed in to change notification settings - Fork 0
/
Agent_2.java
178 lines (139 loc) · 5.51 KB
/
Agent_2.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package ru.dvo.iacp.is.iacpaas.mas.agents;
import java.util.ArrayList;
import ru.dvo.iacp.is.iacpaas.common.exceptions.PlatformException;
import ru.dvo.iacp.is.iacpaas.mas.IRunningAuthority;
import ru.dvo.iacp.is.iacpaas.storage.IConcept;
import ru.dvo.iacp.is.iacpaas.storage.IInforesource;
import ru.dvo.iacp.is.iacpaas.storage.exceptions.StorageException;
import ru.dvo.iacp.is.iacpaas.storage.generator.IConceptGenerator;
import ru.dvo.iacp.is.iacpaas.storage.generator.IInforesourceGenerator;
public final class AgentFiltrImpl extends AgentFiltr {
private static final String ÑONTRAIND = "ïðîòèâîïîêàçàíèÿ";
private static final String LOWER_AGE = "íèæíèé âîçðàñò";
private static final String ROOT = "îáúÿñíåíèåËå÷åíèÿ";
private static final String INFO_HISTORY = "èíôî èç ÈÁ";
private static final String RECOMMENDED = "ðåêîìåíäóåìûå";
private static final String DEFLECTABLE = "îòêëîíÿåìûå";
private static final String DIAGNOSIS = "äèàãíîç";
private static final String DRUG = "ËÑ";
private static final String FEATURE = "îñîáåííîñòü";
private static final String AGE = "âîçðàñò";
private AgentFiltrImpl link = this;
private IInforesource inforesource;
private IInforesourceGenerator generator;
public AgentFiltrImpl(IRunningAuthority runningAuthority, IInforesource agentInforesource) {
super(runningAuthority, agentInforesource);
}
public class FarmList {
private IConcept[] allConceptsFarmList;
private IConcept[] children;
private IConcept getDrug(String name) throws StorageException {
for (int i = 0; i < children.length; i++) {
if (name.equals(children[i].getName())) {
return children[i];
}
}
return null;
}
public String[] getContraind(String name) throws StorageException {
IConcept drug = getDrug(name);
if ((drug != null) && (drug.hasRelation(ÑONTRAIND))) {
IConcept[] child = drug.gotoByMeta(ÑONTRAIND).getChildren();
ArrayList<String> list = new ArrayList<String>();
for (int i = 0; i < child.length; i++) {
String value = drug.gotoByMeta(ÑONTRAIND).getChildren()[i].getValue();
list.add(value);
}
return list.toArray(new String[list.size()]);
}
return null;
}
public double getAge(String name) throws StorageException {
IConcept drug = getDrug(name);
if ((drug != null) && (drug.hasRelation(LOWER_AGE)) && (drug.getName().equals(name))) {
double age = drug.gotoByMeta(LOWER_AGE).getValue();
return age;
}
return 0;
}
public FarmList() throws StorageException {
IInforesource[] inputs = runningAuthority.getInputs();
IInforesource infoFarmList = inputs[0];
if(infoFarmList == null) {
info("Inputs inforesource not found");
return;
}
allConceptsFarmList = infoFarmList.getAllConcepts();
children = allConceptsFarmList[0].nextSetByMeta(DRUG); //ÔàðìÑïðàâî÷íèê
}
}
public class Buffer {
private IConceptGenerator root;
private IConceptGenerator deflectable;
private IConceptGenerator warning;
private IConcept[] recommended;
private double age;
private String diagnosis;
private String[] feature;
private FarmList farmList = new FarmList();
private void setInfoPerson() throws StorageException {
IConceptGenerator mapHistory = (IConceptGenerator) root.gotoByMeta(INFO_HISTORY);
ArrayList<String> list = new ArrayList<String>();
diagnosis = mapHistory.gotoByMeta(DIAGNOSIS).getValue();
age = mapHistory.gotoByMeta(AGE).getValue();
IConcept[] isFeature = mapHistory.nextSetByMeta(FEATURE);
for (int i = 0; i < isFeature.length; i++) {
String value = isFeature[i].getValue();
list.add(value);
}
feature = list.toArray(new String[list.size()]);
}
private void filterAge() throws StorageException {
recommended = root.gotoByMeta(RECOMMENDED).getChildren();
deflectable = (IConceptGenerator) root.gotoByMeta(DEFLECTABLE);
double ageDrug = 0;
for (int i = 0; i < recommended.length; i++) {
ageDrug = farmList.getAge(recommended[i].getName());
if (!(ageDrug <= age)) {
IConceptGenerator deflectableDrug = deflectable.generateWithName(DRUG, recommended[i].getName());
deflectableDrug.generateWithValue(ÑONTRAIND, "Íåïîäõîäÿùèé âîçðàñò");
recommended[i].delete(link);
}
}
}
private void filterFeature() throws StorageException {
recommended = root.gotoByMeta(RECOMMENDED).getChildren();
label: for (int i = 0; i < recommended.length; i++) {
String[] contraind = farmList.getContraind(recommended[i].getName());
if (contraind == null) {
continue;
}
for (int j = 0; j < contraind.length; j++) {
for (int k = 0; k < feature.length; k++) {
if (contraind[j].equals(feature[k])) {
IConceptGenerator deflectableDrug = deflectable.generateWithName(DRUG, recommended[i].getName());
deflectableDrug.generateWithValue(ÑONTRAIND, feature[k]);
recommended[i].delete(link);
continue label;
}
}
}
}
}
public Buffer() throws StorageException {
root = (IConceptGenerator) generator.generateFromAxiom().gotoByMeta(ROOT);
setInfoPerson();
filterAge();
filterFeature();
}
}
public void runProduction(ru.dvo.iacp.is.iacpaas.mas.messages.TaskMessage msg, TaskMessageResultCreator rc) throws PlatformException {
try {
inforesource = msg.getAgentTestReportInforesource();
generator = inforesource.getGenerator(this);
Buffer buffer = new Buffer();
} catch (Exception e) {
info(e.getMessage());
}
}
}