16 |
16 |
* @author Bernard
|
17 |
17 |
*/
|
18 |
18 |
public class ModeleChaines {
|
19 |
|
static class Chainon {
|
20 |
|
Unite unite;
|
21 |
|
String texte;
|
22 |
|
Schema chaine = null;
|
23 |
|
int nbEltsChaine = 0;
|
24 |
|
String idChaine = "";
|
25 |
|
int noChaine = 0;
|
26 |
|
Chainon(Unite unite, String texte) {
|
27 |
|
this.unite = unite;
|
28 |
|
this.texte = texte;
|
29 |
|
}
|
30 |
|
}
|
31 |
|
private Vue vue;
|
32 |
|
private GChaines panneauGraphique;
|
33 |
|
private Unite[] listeUnites;
|
34 |
|
private boolean peutafficher = true;
|
35 |
|
private HashMap<Unite, Schema> chainesUnitesNonFiltrees =
|
36 |
|
new HashMap<Unite, Schema>();
|
37 |
|
private int[] seuilsValsNbElements = new int[0];
|
38 |
|
private HashMap<Unite, Chainon> chainonsUnites = new HashMap<Unite, Chainon>();
|
39 |
|
private HashMap<Schema, ArrayList<Unite>> unitesChaines =
|
40 |
|
new HashMap<Schema, ArrayList<Unite>>();
|
41 |
|
private HashMap<String, HashSet<String>> valsMasqueesChamp =
|
42 |
|
new HashMap<String, HashSet<String>>();
|
43 |
|
private HashSet<String> valNulleMasqueeChamp = new HashSet<String>();
|
44 |
|
private boolean[] valsMasqueesNbElements = new boolean[0];
|
45 |
|
|
46 |
|
public ModeleChaines(Vue vue, GChaines panneauGraphique) {
|
47 |
|
this.vue = vue;
|
48 |
|
this.panneauGraphique = panneauGraphique;
|
49 |
|
}
|
50 |
|
Schema getChaine(Unite unit) {
|
51 |
|
return chainonsUnites.get(unit).chaine;
|
52 |
|
}
|
53 |
|
public HashMap<Unite, Chainon> getChainonUnites(){
|
54 |
|
return chainonsUnites;
|
55 |
|
}
|
56 |
|
Unite[] getUnites() {
|
57 |
|
return listeUnites;
|
58 |
|
}
|
59 |
|
Unite[] getUnitesChaine(Schema chaine) {
|
60 |
|
ArrayList<Unite> units = unitesChaines.get(chaine);
|
61 |
|
return units.toArray(new Unite[0]);
|
62 |
|
}
|
63 |
|
boolean isMasqueeValChamp(String champ, String val) {
|
64 |
|
return valsMasqueesChamp.containsKey(champ)
|
65 |
|
&&valsMasqueesChamp.get(champ).contains(val);
|
66 |
|
}
|
67 |
|
boolean isMasqueeValNulleChamp(String champ) {
|
68 |
|
return valNulleMasqueeChamp.contains(champ);
|
69 |
|
}
|
70 |
|
boolean isMasqueeValNbElements(int i) {
|
71 |
|
return i >= valsMasqueesNbElements.length ? false : valsMasqueesNbElements[i];
|
72 |
|
}
|
73 |
|
public HashMap<String, HashSet<String>> getValsMasqueesChamp(){
|
74 |
|
return valsMasqueesChamp;
|
75 |
|
}
|
76 |
|
public HashSet<String> getValsNulleMasqueesChamp(){
|
77 |
|
return valNulleMasqueeChamp;
|
78 |
|
}
|
79 |
|
public HashMap<Unite, Schema> getchainesUnitesNonFiltrees(){
|
80 |
|
return chainesUnitesNonFiltrees;
|
81 |
|
}
|
82 |
|
public boolean[] getValsNbMasqueesChamp(){
|
83 |
|
return valsMasqueesNbElements;
|
84 |
|
}
|
85 |
|
public void setValsMasqueesChamp(HashMap<String, HashSet<String>> valsMasqueesChamp){
|
86 |
|
this.valsMasqueesChamp = valsMasqueesChamp;
|
87 |
|
}
|
88 |
|
public void setValsNulleMasqueesChamp(HashSet<String> valNulleMasqueeChamp){
|
89 |
|
this.valNulleMasqueeChamp = valNulleMasqueeChamp;
|
90 |
|
}
|
91 |
|
public void setValsNbMasqueesChamp(boolean[] valsMasqueesNbElements){
|
92 |
|
this.valsMasqueesNbElements=valsMasqueesNbElements;
|
93 |
|
}
|
94 |
|
//retourne le nombre de valeurs masquees pour le champ
|
95 |
|
public int nbvaleursmasquees(String champ){
|
96 |
|
int resultat=0;
|
97 |
|
if(champ==null){//si le champ affiché est le nombre de chainons
|
98 |
|
for(boolean val : valsMasqueesNbElements){
|
99 |
|
if(val){
|
100 |
|
resultat = resultat + 1;
|
101 |
|
}
|
102 |
|
}
|
103 |
|
}
|
104 |
|
else{
|
105 |
|
resultat = valsMasqueesChamp.get(champ).size();
|
106 |
|
}
|
107 |
|
return resultat;
|
108 |
|
}
|
109 |
|
void demasquerToutesValsChamp(String champ) {
|
110 |
|
valsMasqueesChamp.get(champ).clear();
|
111 |
|
valNulleMasqueeChamp.remove(champ);
|
112 |
|
}
|
113 |
|
void demasquerToutesValsNbElts(String champ) {
|
114 |
|
for (int i = 0; i<valsMasqueesNbElements.length; i++) {
|
115 |
|
valsMasqueesNbElements[i] = false;
|
116 |
|
}
|
117 |
|
}
|
118 |
|
void setGChaine(GChaines panneaugraphique){
|
119 |
|
this.panneauGraphique = panneaugraphique;
|
120 |
|
}
|
121 |
|
void setUnites(Unite[] donnees){
|
122 |
|
this.listeUnites = donnees;
|
123 |
|
}
|
124 |
|
void permettreaffichage(boolean autorisation){
|
125 |
|
this.peutafficher = autorisation;
|
126 |
|
}
|
127 |
|
boolean peutetreafficher(){
|
128 |
|
return this.peutafficher;
|
129 |
|
}
|
130 |
|
void masquerAutresValsChamp(String typeunite, String champ, String val) {
|
131 |
|
for(String v: vue.getValeursChamp(Unite.class, typeunite, champ))
|
132 |
|
valsMasqueesChamp.get(champ).add(v);
|
133 |
|
valsMasqueesChamp.get(champ).remove(val);
|
134 |
|
valNulleMasqueeChamp.add(champ);
|
135 |
|
}
|
136 |
|
void masquerValChamp(boolean yes, String champ, String val) {
|
137 |
|
if (yes) valsMasqueesChamp.get(champ).add(val);
|
138 |
|
else valsMasqueesChamp.get(champ).remove(val);
|
139 |
|
}
|
140 |
|
void masquerValsNonNullesChamp(String typeunite, String champ) {
|
141 |
|
for(String v: vue.getValeursChamp(Unite.class, typeunite, champ))
|
142 |
|
valsMasqueesChamp.get(champ).add(v);
|
143 |
|
valNulleMasqueeChamp.remove(champ);
|
144 |
|
}
|
145 |
|
void masquerValNulleChamp(boolean yes, String champ) {
|
146 |
|
if (yes) valNulleMasqueeChamp.add(champ);
|
147 |
|
else valNulleMasqueeChamp.remove(champ);
|
148 |
|
}
|
149 |
|
void masquerAutresValsNbElts(String champ, int i0) {
|
150 |
|
for (int i = 0; i<valsMasqueesNbElements.length; i++) {
|
151 |
|
valsMasqueesNbElements[i] = i!=i0;
|
152 |
|
}
|
153 |
|
}
|
154 |
|
void masquerValNbElements(boolean yes, int i) {
|
155 |
|
valsMasqueesNbElements[i] = yes;
|
156 |
|
}
|
157 |
|
void init(String typeChaines, String typeUnites, int[] seuils)
|
158 |
|
throws UnsupportedOperationException {
|
159 |
|
seuilsValsNbElements = seuils;
|
160 |
|
String[] champs = vue.getNomsChamps(Unite.class, typeUnites);
|
161 |
|
valsMasqueesChamp.clear();
|
162 |
|
for (String champ : champs)
|
163 |
|
valsMasqueesChamp.put(champ, new HashSet<String>());
|
164 |
|
valNulleMasqueeChamp.clear();
|
165 |
|
valsMasqueesNbElements = new boolean[seuils.length+3];
|
166 |
|
calculerChainesUnitesNonFiltrees(typeChaines, typeUnites);
|
167 |
|
calculerDonnees(typeChaines, typeUnites);
|
168 |
|
}
|
169 |
|
//struture qui n'est pas filtrées mais qui associe à une unité qui correspond au bon type d'unités
|
170 |
|
//la chaine qui la contient et qui est elle aussi du bon type de Schéma
|
171 |
|
private void calculerChainesUnitesNonFiltrees(String typeChaines,
|
172 |
|
String typeUnites) throws UnsupportedOperationException {
|
173 |
|
chainesUnitesNonFiltrees.clear();
|
174 |
|
for (Schema chaine : vue.getSchemasAVoir(typeChaines))
|
175 |
|
for (Element elt : chaine.getContenu()) {
|
176 |
|
if (elt.getClass()==Unite.class&&elt.getType().equals(typeUnites)) {
|
177 |
|
if (chainesUnitesNonFiltrees.containsKey(elt)) {
|
178 |
|
throw new UnsupportedOperationException("L'unité "+vue.getIdElement(elt)
|
179 |
|
+" appartient à deux chaînes : "+vue.getIdElement(chaine)+" et "
|
180 |
|
+vue.getIdElement(chainesUnitesNonFiltrees.get((Unite) elt)));
|
181 |
|
} else
|
182 |
|
chainesUnitesNonFiltrees.put((Unite) elt, chaine);
|
183 |
|
}
|
184 |
|
}
|
185 |
|
}
|
186 |
|
void modifMasqueVals(String typeChaines, String typeUnites) {
|
187 |
|
calculerDonnees(typeChaines, typeUnites);
|
188 |
|
}
|
189 |
|
void modifMasqueValsChampChaine(String typeChaines, String typeUnites,ArrayList noparagraphecachees,String champ
|
190 |
|
,String Valeur) {
|
191 |
|
calculerDonnees(typeChaines, typeUnites, noparagraphecachees, champ
|
192 |
|
, Valeur);
|
193 |
|
}
|
194 |
|
private void filtrerListeUnites(String typeUnites, String typeChaines) {
|
195 |
|
Unite[] unites = vue.getUnitesAVoir(typeUnites);
|
196 |
|
Schema[] chaines = vue.getSchemasAVoir(typeChaines);
|
197 |
|
unitesChaines.clear();
|
198 |
|
for (Schema chaine : chaines) unitesChaines.put(chaine, new ArrayList<Unite>());
|
199 |
|
ArrayList<Integer> indFiltrees = new ArrayList<Integer>();
|
200 |
|
String[] champs = vue.getNomsChamps(Unite.class, typeUnites);
|
201 |
|
boolean agarder;
|
202 |
|
for (int i = 0; i<unites.length; i++) {
|
203 |
|
agarder = true;
|
204 |
|
for (String champ : champs) {//pour tous les champs
|
205 |
|
String val = vue.getValeurChamp(unites[i], champ);//je recupere la valeur du champ
|
206 |
|
if (val.isEmpty()) {
|
207 |
|
if (valNulleMasqueeChamp.contains(champ)) {
|
208 |
|
agarder = false;
|
209 |
|
break;
|
210 |
|
}
|
211 |
|
} else {
|
212 |
|
if (valsMasqueesChamp.get(champ).contains(val)) {
|
213 |
|
agarder = false;
|
214 |
|
break;
|
215 |
|
}
|
216 |
|
}
|
217 |
|
}
|
218 |
|
if (agarder) {
|
219 |
|
indFiltrees.add(i);
|
220 |
|
if (chainesUnitesNonFiltrees.containsKey(unites[i])) {
|
221 |
|
Schema chaine = chainesUnitesNonFiltrees.get(unites[i]);
|
222 |
|
unitesChaines.get(chaine).add(unites[i]);
|
223 |
|
}
|
224 |
|
}
|
225 |
|
}
|
226 |
|
ArrayList<Integer> indIndFiltrees = new ArrayList<Integer>();
|
227 |
|
for(int k=0; k<indFiltrees.size(); k++) {
|
228 |
|
Unite unit = unites[indFiltrees.get(k)];
|
229 |
|
if(chainesUnitesNonFiltrees.containsKey(unit)) {
|
230 |
|
if(!isMasqueeValNbElements(calculerValNbElements(
|
231 |
|
unitesChaines.get(chainesUnitesNonFiltrees.get(unit)).size())))
|
232 |
|
indIndFiltrees.add(k);
|
233 |
|
} else {
|
234 |
|
if(!isMasqueeValNbElements(0)) indIndFiltrees.add(k);
|
235 |
|
}
|
236 |
|
}
|
237 |
|
listeUnites = new Unite[indIndFiltrees.size()];
|
238 |
|
for (int k = 0; k<listeUnites.length; k++) {
|
239 |
|
listeUnites[k] = unites[indFiltrees.get(indIndFiltrees.get(k))];
|
240 |
|
}
|
241 |
|
for (Schema chaine : chaines) {
|
242 |
|
int nb = unitesChaines.get(chaine).size();
|
243 |
|
if(nb==0||isMasqueeValNbElements(calculerValNbElements(nb)))
|
244 |
|
unitesChaines.remove(chaine);
|
245 |
|
}
|
246 |
|
}
|
247 |
|
private void calculerDonnees(String typeChaines, String typeUnites) {
|
248 |
|
filtrerListeUnites(typeUnites, typeChaines);
|
249 |
|
Chainon[] chainons = new Chainon[listeUnites.length];
|
250 |
|
for (int i = 0; i<listeUnites.length; i++) {
|
251 |
|
Unite unit = listeUnites[i];
|
252 |
|
chainons[i] = new Chainon(unit, vue.getTexteUnite(unit));
|
253 |
|
if(chainesUnitesNonFiltrees.containsKey(unit)) {
|
254 |
|
Schema chaine = chainesUnitesNonFiltrees.get(unit);
|
255 |
|
chainons[i].chaine = chaine;
|
256 |
|
chainons[i].nbEltsChaine = unitesChaines.get(chaine).size();
|
257 |
|
chainons[i].idChaine = vue.getIdElement(chaine);
|
258 |
|
}
|
259 |
|
chainonsUnites.put(listeUnites[i], chainons[i]);
|
260 |
|
}
|
261 |
|
HashMap<Schema, Integer> noChaine = new HashMap<Schema, Integer>();
|
262 |
|
int no = 0;
|
263 |
|
for (Schema chaine : vue.getSchemasAVoir(typeChaines)) {
|
264 |
|
if(unitesChaines.containsKey(chaine)) {
|
265 |
|
int nbElts = unitesChaines.get(chaine).size();
|
266 |
|
noChaine.put(chaine, nbElts>1 ? ++no : 0);
|
267 |
|
}
|
268 |
|
}
|
269 |
|
for (Unite unit : listeUnites) {
|
270 |
|
Chainon chainon = chainonsUnites.get(unit);
|
271 |
|
if (chainon.chaine!=null) chainon.noChaine = noChaine.get(chainon.chaine);
|
272 |
|
}
|
273 |
|
int[] noPar = vue.getCorpus().calculerNoParagraphe(listeUnites);
|
274 |
|
if(peutafficher){
|
275 |
|
panneauGraphique.setDonnees(chainons, noPar);
|
276 |
|
}
|
277 |
|
}
|
278 |
|
void initVide() {
|
279 |
|
listeUnites = new Unite[0];
|
280 |
|
chainesUnitesNonFiltrees.clear();
|
281 |
|
seuilsValsNbElements = new int[0];
|
282 |
|
chainonsUnites.clear();
|
283 |
|
unitesChaines.clear();
|
284 |
|
if(peutafficher){
|
285 |
|
panneauGraphique.setDonnees(new Chainon[0], new int[0]);
|
286 |
|
panneauGraphique.setCouleurs(new Color[0]);
|
287 |
|
panneauGraphique.setTaille(new int[0]);
|
288 |
|
panneauGraphique.setForme(new int[0]);
|
289 |
|
panneauGraphique.setSurTexte(new String[0]);
|
290 |
|
panneauGraphique.setSousTexte(new String[0]);
|
291 |
|
}
|
292 |
|
valNulleMasqueeChamp.clear();
|
293 |
|
valsMasqueesChamp.clear();
|
294 |
|
valsMasqueesNbElements = new boolean[0];
|
295 |
|
}
|
296 |
|
void setChampAffiche(String champ, HashMap<String, Color> couleursValeursChamp) {
|
297 |
|
if(peutafficher){
|
298 |
|
panneauGraphique.setCouleurs(colorerChamp(champ, couleursValeursChamp));
|
299 |
|
}
|
300 |
|
}
|
301 |
|
void setChampAfficheTaille(String champ, HashMap<String, Integer> TaillesValeursChamp) {
|
302 |
|
if(peutafficher){
|
303 |
|
panneauGraphique.setTaille(ReduireChamp(champ, TaillesValeursChamp));
|
304 |
|
}
|
305 |
|
}
|
306 |
|
void setChampAfficheForme(String champ, HashMap<String, Integer> FormesValeursChamp) {
|
307 |
|
if(peutafficher){
|
308 |
|
panneauGraphique.setForme(FormerChamp(champ, FormesValeursChamp));
|
309 |
|
}
|
310 |
|
}
|
311 |
|
|
312 |
|
void setChampAfficheSurTexte(String champ, HashMap<String, String> SurTexteValeursChamp) {
|
313 |
|
if(peutafficher){
|
314 |
|
panneauGraphique.setSurTexte(SurTexteChamp(champ, SurTexteValeursChamp));
|
315 |
|
}
|
316 |
|
}
|
317 |
|
void setChampAfficheSousTexte(String champ, HashMap<String, String> SousTexteValeursChamp) {
|
318 |
|
if(peutafficher){
|
319 |
|
panneauGraphique.setSousTexte(SousTexteChamp(champ, SousTexteValeursChamp));
|
320 |
|
}
|
321 |
|
}
|
322 |
|
|
323 |
|
void setChampAfficheNbElts(Color[] couleurs) {
|
324 |
|
if(peutafficher){
|
325 |
|
panneauGraphique.setCouleurs(colorerNbElts(couleurs));
|
326 |
|
}
|
327 |
|
}
|
328 |
|
|
329 |
|
|
330 |
|
|
331 |
|
void setChampAfficheTailleNbElts(int[] taille) {
|
332 |
|
if(peutafficher){
|
333 |
|
panneauGraphique.setTaille(ReduireNbElts(taille));
|
334 |
|
}
|
335 |
|
}
|
336 |
|
|
337 |
|
void setChampAfficheFormeNbElts(int[] forme) {
|
338 |
|
if(peutafficher){
|
339 |
|
panneauGraphique.setForme(FormeNbElts(forme));
|
340 |
|
}
|
341 |
|
}
|
342 |
|
|
343 |
|
void setChampAfficheSurTexteNbElts(String[] SurTexte) {
|
344 |
|
if(peutafficher){
|
345 |
|
panneauGraphique.setSurTexte(SurTexteNbElts(SurTexte));
|
346 |
|
}
|
347 |
|
}
|
348 |
|
|
349 |
|
void setChampAfficheSousTexteNbElts(String[] SousTexte) {
|
350 |
|
if(peutafficher){
|
351 |
|
panneauGraphique.setSousTexte(SousTexteNbElts(SousTexte));
|
352 |
|
}
|
353 |
|
}
|
354 |
|
|
355 |
|
private Color[] colorerNbElts(Color[] couleurs) {
|
356 |
|
Color[] couls = new Color[listeUnites.length];
|
357 |
|
for (int i = 0; i<listeUnites.length; i++) {
|
358 |
|
Chainon ch = chainonsUnites.get(listeUnites[i]);
|
359 |
|
if (ch.chaine==null) couls[i] = couleurs[0];
|
360 |
|
else {
|
361 |
|
int nbElts = ch.nbEltsChaine;
|
362 |
|
couls[i] = couleurs[calculerValNbElements(nbElts)];
|
363 |
|
}
|
364 |
|
}
|
365 |
|
return couls;
|
366 |
|
}
|
367 |
|
private int[] FormeNbElts(int[] formes) {
|
368 |
|
int[] forme = new int[listeUnites.length];
|
369 |
|
for (int i = 0; i<listeUnites.length; i++) {
|
370 |
|
Chainon ch = chainonsUnites.get(listeUnites[i]);
|
371 |
|
if (ch.chaine==null) forme[i] = formes[0];
|
372 |
|
else {
|
373 |
|
int nbElts = ch.nbEltsChaine;
|
374 |
|
forme[i] = formes[calculerValNbElements(nbElts)];
|
375 |
|
}
|
376 |
|
}
|
377 |
|
return forme;
|
378 |
|
}
|
379 |
|
|
380 |
|
private int[] ReduireNbElts(int[] tailles) {
|
381 |
|
int[] taille = new int[listeUnites.length];
|
382 |
|
for (int i = 0; i<listeUnites.length; i++) {
|
383 |
|
Chainon ch = chainonsUnites.get(listeUnites[i]);
|
384 |
|
if (ch.chaine==null) taille[i] = tailles[0];
|
385 |
|
else {
|
386 |
|
int nbElts = ch.nbEltsChaine;
|
387 |
|
taille[i] = tailles[calculerValNbElements(nbElts)];
|
388 |
|
}
|
389 |
|
}
|
390 |
|
return taille;
|
391 |
|
}
|
392 |
|
private String[] SurTexteNbElts(String[] SurTextes) {
|
393 |
|
String[] SurTexte = new String[listeUnites.length];
|
394 |
|
for (int i = 0; i<listeUnites.length; i++) {
|
395 |
|
Chainon ch = chainonsUnites.get(listeUnites[i]);
|
396 |
|
if (ch.chaine==null) SurTexte[i] = SurTextes[0];
|
397 |
|
else {
|
398 |
|
int nbElts = ch.nbEltsChaine;
|
399 |
|
SurTexte[i] = SurTextes[calculerValNbElements(nbElts)];
|
400 |
|
}
|
401 |
|
}
|
402 |
|
return SurTexte;
|
403 |
|
}
|
404 |
|
private String[] SousTexteNbElts(String[] SousTextes) {
|
405 |
|
String[] SousTexte = new String[listeUnites.length];
|
406 |
|
for (int i = 0; i<listeUnites.length; i++) {
|
407 |
|
Chainon ch = chainonsUnites.get(listeUnites[i]);
|
408 |
|
if (ch.chaine==null) SousTexte[i] = SousTextes[0];
|
409 |
|
else {
|
410 |
|
int nbElts = ch.nbEltsChaine;
|
411 |
|
SousTexte[i] = SousTextes[calculerValNbElements(nbElts)];
|
412 |
|
}
|
413 |
|
}
|
414 |
|
return SousTexte;
|
415 |
|
}
|
416 |
|
|
417 |
|
|
418 |
|
private Color[] colorerChamp(String champ, HashMap<String, Color> couleursValeursChamp) {
|
419 |
|
Color[] couls = new Color[listeUnites.length];
|
420 |
|
for (int i = 0; i<listeUnites.length; i++) {
|
421 |
|
Chainon ch = chainonsUnites.get(listeUnites[i]);
|
422 |
|
couls[i] = couleursValeursChamp.get(vue.getValeurChamp(ch.unite, champ));
|
423 |
|
}
|
424 |
|
return couls;
|
425 |
|
}
|
426 |
|
//même chose que colorer champ mais en influant la taille des chainons
|
427 |
|
private int[] ReduireChamp(String champ, HashMap<String, Integer> TaillesValeursChamp) {
|
428 |
|
int[] taille = new int[listeUnites.length];
|
429 |
|
for (int i = 0; i<listeUnites.length; i++) {
|
430 |
|
Chainon ch = chainonsUnites.get(listeUnites[i]);
|
431 |
|
taille[i] = TaillesValeursChamp.get(vue.getValeurChamp(ch.unite, champ));
|
432 |
|
}
|
433 |
|
return taille;
|
434 |
|
}
|
435 |
|
//même chose que colorer champ mais en influant la forme des chainons
|
436 |
|
private int[] FormerChamp(String champ, HashMap<String, Integer> FormesValeursChamp) {
|
437 |
|
int[] forme = new int[listeUnites.length];
|
438 |
|
for (int i = 0; i<listeUnites.length; i++) {
|
439 |
|
Chainon ch = chainonsUnites.get(listeUnites[i]);
|
440 |
|
forme[i] = FormesValeursChamp.get(vue.getValeurChamp(ch.unite, champ));
|
441 |
|
}
|
442 |
|
return forme;
|
443 |
|
}
|
444 |
|
//même chose que colorer champ mais en influant le texte au dessus des chainons
|
445 |
|
private String[] SurTexteChamp(String champ, HashMap<String, String> SurTexteValeursChamp) {
|
446 |
|
String[] SurTexte = new String[listeUnites.length];
|
447 |
|
for (int i = 0; i<listeUnites.length; i++) {
|
448 |
|
Chainon ch = chainonsUnites.get(listeUnites[i]);
|
449 |
|
SurTexte[i] = SurTexteValeursChamp.get(vue.getValeurChamp(ch.unite, champ));
|
450 |
|
}
|
451 |
|
return SurTexte;
|
452 |
|
}
|
453 |
|
//même chose que colorer champ mais en influant le texte au dessous des chainons
|
454 |
|
private String[] SousTexteChamp(String champ, HashMap<String, String> SousTexteValeursChamp) {
|
455 |
|
String[] SousTexte = new String[listeUnites.length];
|
456 |
|
for (int i = 0; i<listeUnites.length; i++) {
|
457 |
|
Chainon ch = chainonsUnites.get(listeUnites[i]);
|
458 |
|
SousTexte[i] = SousTexteValeursChamp.get(vue.getValeurChamp(ch.unite, champ));
|
459 |
|
}
|
460 |
|
return SousTexte;
|
461 |
|
}
|
462 |
|
|
463 |
|
|
464 |
|
public int calculerValNbElements(int nbElts) {
|
465 |
|
return nbElts==1 ? 1 : nbElts<=seuilsValsNbElements[0] ? 2 :
|
466 |
|
nbElts<=seuilsValsNbElements[1] ? 3 : 4;
|
467 |
|
}
|
468 |
|
|
469 |
|
|
470 |
|
|
471 |
|
//retourne un tableau contenant les numéros de paragraphe qui contiennent des unités du modele
|
472 |
|
public Integer[] listenumeroparagraphe(){
|
473 |
|
int[] noparagraphe = (vue.getCorpus()).calculerNoParagraphe(listeUnites);
|
474 |
|
ArrayList<Integer> resultat = new ArrayList();
|
475 |
|
int former = -1;
|
476 |
|
for(int i = 0 ; i < noparagraphe.length;i++){
|
477 |
|
if(former!=noparagraphe[i]){
|
478 |
|
resultat.add(noparagraphe[i]);
|
479 |
|
former = noparagraphe[i];
|
480 |
|
}
|
481 |
|
}
|
482 |
|
Integer[] resultatconversion = new Integer[resultat.size()];
|
483 |
|
return ( resultat.toArray(resultatconversion));
|
484 |
|
}
|
485 |
|
|
486 |
|
|
487 |
|
//renvoie un Hashmap quidécrit la répartition des unités en position
|
488 |
|
//au sein du texte
|
489 |
|
//@require : listesUnites est trié selon la position de debut de ses éléments
|
490 |
|
public ArrayList<int[]> dispositionunites(int nbclasses){
|
491 |
|
Unite[] unites = listeUnites;
|
492 |
|
ArrayList<int[]> locationunites = new ArrayList<int[]>(nbclasses);
|
493 |
|
int longueurtexte = vue.getCorpus().getTexte().length();
|
494 |
|
int[] listeposition = ChaineUtil.discretisation(0,longueurtexte,nbclasses + 1);
|
495 |
|
int posprev = 0;
|
496 |
|
if(nbclasses > 0){
|
497 |
|
int posactuel = 1;
|
498 |
|
int compte = 0;
|
499 |
|
int k = 0;
|
500 |
|
while(k < unites.length || posactuel < nbclasses + 1){
|
501 |
|
if(k < unites.length && unites[k].getDeb() < listeposition[posactuel]
|
502 |
|
&& unites[k].getDeb() >= listeposition[posprev]){
|
503 |
|
//si l'unite est dans cette partie du texte alors on incrémente le compteur
|
504 |
|
compte = compte + 1;
|
505 |
|
k = k + 1;
|
506 |
|
}
|
507 |
|
else{
|
508 |
|
posprev = posactuel;//on actualise la position precedente
|
509 |
|
locationunites.add(new int[]{listeposition[posprev],compte});
|
510 |
|
compte = 0;
|
511 |
|
posactuel = posactuel + 1;
|
512 |
|
}
|
513 |
|
}
|
514 |
|
}
|
515 |
|
return locationunites;
|
516 |
|
}
|
517 |
|
|
518 |
|
|
519 |
|
|
520 |
|
|
521 |
|
//renvoie un tableau contenant les fréquences de chaque valeur d'un champ de la chaine dans la liste d'unités
|
522 |
|
public HashMap<String, Float> calculerfrequencechaine(Unite[] donnees,String typeChaines
|
523 |
|
,String Champcible,HashSet<String> valeurinterdite){
|
524 |
|
String[] valsdisponibles = vue.getValeursChamp(Schema.class, typeChaines, Champcible);
|
525 |
|
HashMap<String, Float> tableaufrequence = new HashMap<String, Float>(valsdisponibles.length + 1);
|
526 |
|
String valeurchamp;
|
527 |
|
//on initialise le tableau résultat
|
528 |
|
for(String valeur : valsdisponibles){
|
529 |
|
tableaufrequence.put(valeur, 0.0f);
|
530 |
|
}
|
531 |
|
tableaufrequence.put("", 0.0f);
|
532 |
|
int compteur = 0;
|
533 |
|
//on compte le nombre d'occurences
|
534 |
|
for(Unite unit : donnees){
|
535 |
|
valeurchamp = chainesUnitesNonFiltrees.containsKey(unit) ? vue.getValeurChamp(chainesUnitesNonFiltrees.get(unit)
|
536 |
|
, Champcible) : null;
|
537 |
|
if(valeurchamp!=null && !valeurinterdite.contains(valeurchamp)){
|
538 |
|
compteur = compteur + 1;
|
539 |
|
tableaufrequence.put(valeurchamp,tableaufrequence.get(valeurchamp) + 1);
|
540 |
|
}
|
541 |
|
}
|
542 |
|
//on calcule les pourcentages
|
543 |
|
for(String valeur : valsdisponibles){
|
544 |
|
tableaufrequence.put(valeur,compteur==0 ? 0.0f : tableaufrequence.get(valeur) * 10000.0f /
|
545 |
|
compteur / 100.0f);
|
546 |
|
}
|
547 |
|
tableaufrequence.put("",compteur==0 ? 0.0f : tableaufrequence.get("") * 10000.0f /
|
548 |
|
compteur / 100.0f);
|
549 |
|
|
550 |
|
return tableaufrequence;
|
551 |
|
}
|
552 |
|
//renvoie un tableau contenant les fréquences de chaque longueur des chaines de la liste d'unités
|
553 |
|
public HashMap<String, Float> calculerfrequencenbelt(Unite[] donnees,String typeUnites
|
554 |
|
,String[] valsdisponibles){
|
555 |
|
HashMap<String, Float> tableaufrequence = new HashMap<String, Float>(valsdisponibles.length);
|
556 |
|
String valeurchamp;
|
557 |
|
//on initialise le tableau résultat
|
558 |
|
for(String valeur : valsdisponibles){
|
559 |
|
tableaufrequence.put(valeur, 0.0f);
|
560 |
|
}
|
561 |
|
int compte = 0;
|
562 |
|
//on compte le nombre d'occurences
|
563 |
|
for(Unite unit : donnees){
|
564 |
|
Schema chaine = chainesUnitesNonFiltrees.containsKey(unit) ? chainesUnitesNonFiltrees.get(unit)
|
565 |
|
: null;
|
566 |
|
int nb = chaine==null ? 0 : unitesChaines.get(chaine).size() ;
|
567 |
|
if(isMasqueeValNbElements(calculerValNbElements(nb))){
|
568 |
|
|
569 |
|
}
|
570 |
|
else if(nb==0){
|
571 |
|
valeurchamp = valsdisponibles[0];
|
572 |
|
tableaufrequence.put(valeurchamp,tableaufrequence.get(valeurchamp) + 1);
|
573 |
|
compte = compte + 1;
|
574 |
|
}
|
575 |
|
else{
|
576 |
|
valeurchamp = valsdisponibles[calculerValNbElements(nb)];
|
577 |
|
tableaufrequence.put(valeurchamp,tableaufrequence.get(valeurchamp) + 1);
|
578 |
|
compte = compte + 1;
|
579 |
|
}
|
580 |
|
}
|
581 |
|
|
582 |
|
|
583 |
|
//on calcule les pourcentages
|
584 |
|
for(String valeur : valsdisponibles){
|
585 |
|
tableaufrequence.put(valeur, tableaufrequence.get(valeur) * 10000.0f /
|
586 |
|
compte / 100.0f);
|
587 |
|
}
|
588 |
|
|
589 |
|
|
590 |
|
return tableaufrequence;
|
591 |
|
}
|
592 |
|
|
593 |
|
|
594 |
|
|
595 |
|
|
596 |
|
//on enlève les unités dont les valeurs des chaines les contenant sont masquees
|
597 |
|
public Unite[] filtrechaine(Unite[] donnees, String Champ, HashSet<String> Valeurcachees){
|
598 |
|
ArrayList<Unite> unitefiltrees = new ArrayList<Unite>();
|
599 |
|
for(Unite unit : donnees){
|
600 |
|
if(chainesUnitesNonFiltrees.containsKey(unit) && !(Valeurcachees.contains(vue.getValeurChamp(chainesUnitesNonFiltrees.get(unit),Champ)))){
|
601 |
|
unitefiltrees.add(unit);
|
602 |
|
}
|
603 |
|
}
|
604 |
|
Unite[] resultat = unitefiltrees.toArray(new Unite[0]);
|
605 |
|
return resultat;
|
606 |
|
}
|
607 |
|
//on ne garde que les unités dont les chaines les contenant possèdent la valeur "valeur" pour le champ
|
608 |
|
//"Champ"
|
609 |
|
public Unite[] filtrevaleurchaine(Unite[] donnees,String Champ,String valeur){
|
610 |
|
ArrayList<Unite> uniteduchamp = new ArrayList();
|
611 |
|
ArrayList<Unite> unitefiltrees = new ArrayList();
|
612 |
|
for(Schema chaine : unitesChaines.keySet()){
|
613 |
|
//on trie les unités dont les chaines contenant ont la bonne valeur pour le champ
|
614 |
|
if((vue.getValeurChamp(chaine, Champ)).equals(valeur)){
|
615 |
|
uniteduchamp.addAll(unitesChaines.get(chaine));
|
616 |
|
}
|
617 |
|
}
|
618 |
|
//on ne garde que les unités passée en paramètre
|
619 |
|
for(int i = 0; i < donnees.length;i++){
|
620 |
|
if(uniteduchamp.contains(donnees[i])){
|
621 |
|
unitefiltrees.add(donnees[i]);
|
622 |
|
}
|
623 |
|
}
|
624 |
|
//on met le résultat sous forme de tableau
|
625 |
|
Unite[] resultat =(Unite[]) unitefiltrees.toArray();
|
626 |
|
return resultat;
|
627 |
|
}
|
628 |
|
|
629 |
|
|
630 |
|
//renvoioe la chaine qui contient l'unité dans ModeleChaine
|
631 |
|
public Schema getSchemacontenantunite(Unite unit){
|
632 |
|
return chainesUnitesNonFiltrees.get(unit);
|
633 |
|
}
|
634 |
|
|
635 |
|
//filtre qui remplit les mêmes fonctions que le précédent mais également qui filtre suivant une liste de
|
636 |
|
//paragraphes interdits et ne garde que les unités appartenant aux chaines ayant pour le champ Champ la valeur
|
637 |
|
//Valeur
|
638 |
|
private void filtrerListeUnites(String typeUnites, String typeChaines,ArrayList noparagraphecachees,
|
639 |
|
String Champ,String Valeur){
|
640 |
|
Unite[] unites = vue.getUnitesAVoir(typeUnites);
|
641 |
|
Schema[] chaines = vue.getSchemasAVoir(typeChaines);
|
642 |
|
unitesChaines.clear();
|
643 |
|
int[] noparagraphe = (vue.getCorpus()).calculerNoParagraphe(unites);
|
644 |
|
for (Schema chaine : chaines) unitesChaines.put(chaine, new ArrayList<Unite>());
|
645 |
|
ArrayList<Integer> indFiltrees = new ArrayList<Integer>();
|
646 |
|
String[] champs = vue.getNomsChamps(Unite.class, typeUnites);
|
647 |
|
boolean agarder;
|
648 |
|
for (int i = 0; i<unites.length; i++) {
|
649 |
|
agarder = true;
|
650 |
|
for (String champ : champs) {//pour tous les champs
|
651 |
|
String val = vue.getValeurChamp(unites[i], champ);//je recupere la valeur du champ
|
652 |
|
if (val.isEmpty()) {
|
653 |
|
if (valNulleMasqueeChamp.contains(champ)) {
|
654 |
|
agarder = false;
|
655 |
|
break;
|
656 |
|
}
|
657 |
|
} else {
|
658 |
|
if (valsMasqueesChamp.get(champ).contains(val)) {
|
659 |
|
agarder = false;
|
660 |
|
break;
|
661 |
|
}
|
662 |
|
}
|
663 |
|
}
|
664 |
|
//si l'unité appartient à un paragraphe interdit
|
665 |
|
if(noparagraphecachees.contains(noparagraphe[i])){
|
666 |
|
agarder = false;
|
667 |
|
}
|
668 |
|
//si la chaine contenant l'unité a une mauvaise valeur pour le champ ou si l'unité est sans chaine
|
669 |
|
if(!chainesUnitesNonFiltrees.containsKey(unites[i]) ||
|
670 |
|
!vue.getValeurChamp(chainesUnitesNonFiltrees.get(unites[i]),Champ).equals(Valeur)){
|
671 |
|
agarder = false;
|
672 |
|
}
|
673 |
|
if (agarder) {
|
674 |
|
indFiltrees.add(i);
|
675 |
|
if (chainesUnitesNonFiltrees.containsKey(unites[i])) {
|
676 |
|
Schema chaine = chainesUnitesNonFiltrees.get(unites[i]);
|
677 |
|
unitesChaines.get(chaine).add(unites[i]);
|
678 |
|
}
|
679 |
|
}
|
680 |
|
}
|
681 |
|
ArrayList<Integer> indIndFiltrees = new ArrayList<Integer>();
|
682 |
|
for(int k=0; k<indFiltrees.size(); k++) {
|
683 |
|
Unite unit = unites[indFiltrees.get(k)];
|
684 |
|
if(chainesUnitesNonFiltrees.containsKey(unit)) {
|
685 |
|
if(!isMasqueeValNbElements(calculerValNbElements(
|
686 |
|
unitesChaines.get(chainesUnitesNonFiltrees.get(unit)).size())))
|
687 |
|
indIndFiltrees.add(k);
|
688 |
|
} else {
|
689 |
|
if(!isMasqueeValNbElements(0)) indIndFiltrees.add(k);
|
690 |
|
}
|
691 |
|
}
|
692 |
|
listeUnites = new Unite[indIndFiltrees.size()];
|
693 |
|
for (int k = 0; k<listeUnites.length; k++) {
|
694 |
|
listeUnites[k] = unites[indFiltrees.get(indIndFiltrees.get(k))];
|
695 |
|
}
|
696 |
|
for (Schema chaine : chaines) {
|
697 |
|
int nb = unitesChaines.get(chaine).size();
|
698 |
|
if(nb==0||isMasqueeValNbElements(calculerValNbElements(nb)))
|
699 |
|
unitesChaines.remove(chaine);
|
700 |
|
}
|
701 |
|
}
|
702 |
|
//permet de calculer les données pour une valeur de champ de la chaine
|
703 |
|
private void calculerDonnees(String typeChaines, String typeUnites,ArrayList noparagraphecachees,String champ
|
704 |
|
,String Valeur) {
|
705 |
|
filtrerListeUnites(typeUnites, typeChaines,noparagraphecachees, champ, Valeur);
|
706 |
|
Chainon[] chainons = new Chainon[listeUnites.length];
|
707 |
|
for (int i = 0; i<listeUnites.length; i++) {
|
708 |
|
Unite unit = listeUnites[i];
|
709 |
|
chainons[i] = new Chainon(unit, vue.getTexteUnite(unit));
|
710 |
|
if(chainesUnitesNonFiltrees.containsKey(unit)) {
|
711 |
|
Schema chaine = chainesUnitesNonFiltrees.get(unit);
|
712 |
|
chainons[i].chaine = chaine;
|
713 |
|
chainons[i].nbEltsChaine = unitesChaines.get(chaine).size();
|
714 |
|
chainons[i].idChaine = vue.getIdElement(chaine);
|
715 |
|
}
|
716 |
|
chainonsUnites.put(listeUnites[i], chainons[i]);
|
717 |
|
}
|
718 |
|
HashMap<Schema, Integer> noChaine = new HashMap<Schema, Integer>();
|
719 |
|
int no = 0;
|
720 |
|
for (Schema chaine : vue.getSchemasAVoir(typeChaines)) {
|
721 |
|
if(unitesChaines.containsKey(chaine)) {
|
722 |
|
int nbElts = unitesChaines.get(chaine).size();
|
723 |
|
noChaine.put(chaine, nbElts>1 ? ++no : 0);
|
724 |
|
}
|
725 |
|
}
|
726 |
|
for (Unite unit : listeUnites) {
|
727 |
|
Chainon chainon = chainonsUnites.get(unit);
|
728 |
|
if (chainon.chaine!=null) chainon.noChaine = noChaine.get(chainon.chaine);
|
729 |
|
}
|
730 |
|
int[] noPar = vue.getCorpus().calculerNoParagraphe(listeUnites);
|
731 |
|
if(peutafficher){
|
732 |
|
panneauGraphique.setDonnees(chainons, noPar);
|
733 |
|
}
|
734 |
|
}
|
735 |
|
|
736 |
|
|
737 |
|
|
738 |
|
|
739 |
|
|
740 |
|
|
|
19 |
|
|
20 |
static class Chainon {
|
|
21 |
|
|
22 |
Unite unite;
|
|
23 |
|
|
24 |
String texte;
|
|
25 |
|
|
26 |
Schema chaine = null;
|
|
27 |
|
|
28 |
int nbEltsChaine = 0;
|
|
29 |
|
|
30 |
String idChaine = "";
|
|
31 |
|
|
32 |
int noChaine = 0;
|
|
33 |
|
|
34 |
Chainon(Unite unite, String texte) {
|
|
35 |
this.unite = unite;
|
|
36 |
this.texte = texte;
|
|
37 |
}
|
|
38 |
}
|
|
39 |
|
|
40 |
private Vue vue;
|
|
41 |
|
|
42 |
private GChaines panneauGraphique;
|
|
43 |
|
|
44 |
private Unite[] listeUnites;
|
|
45 |
|
|
46 |
private boolean peutafficher = true;
|
|
47 |
|
|
48 |
private HashMap<Unite, Schema> chainesUnitesNonFiltrees = new HashMap<>();
|
|
49 |
|
|
50 |
private int[] seuilsValsNbElements = new int[0];
|
|
51 |
|
|
52 |
private HashMap<Unite, Chainon> chainonsUnites = new HashMap<>();
|
|
53 |
|
|
54 |
private HashMap<Schema, ArrayList<Unite>> unitesChaines = new HashMap<>();
|
|
55 |
|
|
56 |
private HashMap<String, HashSet<String>> valsMasqueesChamp = new HashMap<>();
|
|
57 |
|
|
58 |
private HashSet<String> valNulleMasqueeChamp = new HashSet<>();
|
|
59 |
|
|
60 |
private boolean[] valsMasqueesNbElements = new boolean[0];
|
|
61 |
|
|
62 |
public ModeleChaines(Vue vue, GChaines panneauGraphique) {
|
|
63 |
this.vue = vue;
|
|
64 |
this.panneauGraphique = panneauGraphique;
|
|
65 |
}
|
|
66 |
|
|
67 |
Schema getChaine(Unite unit) {
|
|
68 |
return chainonsUnites.get(unit).chaine;
|
|
69 |
}
|
|
70 |
|
|
71 |
public HashMap<Unite, Chainon> getChainonUnites() {
|
|
72 |
return chainonsUnites;
|
|
73 |
}
|
|
74 |
|
|
75 |
Unite[] getUnites() {
|
|
76 |
return listeUnites;
|
|
77 |
}
|
|
78 |
|
|
79 |
Unite[] getUnitesChaine(Schema chaine) {
|
|
80 |
ArrayList<Unite> units = unitesChaines.get(chaine);
|
|
81 |
return units.toArray(new Unite[0]);
|
|
82 |
}
|
|
83 |
|
|
84 |
boolean isMasqueeValChamp(String champ, String val) {
|
|
85 |
return valsMasqueesChamp.containsKey(champ)
|
|
86 |
&& valsMasqueesChamp.get(champ).contains(val);
|
|
87 |
}
|
|
88 |
|
|
89 |
boolean isMasqueeValNulleChamp(String champ) {
|
|
90 |
return valNulleMasqueeChamp.contains(champ);
|
|
91 |
}
|
|
92 |
|
|
93 |
boolean isMasqueeValNbElements(int i) {
|
|
94 |
return i >= valsMasqueesNbElements.length ? false : valsMasqueesNbElements[i];
|
|
95 |
}
|
|
96 |
|
|
97 |
public HashMap<String, HashSet<String>> getValsMasqueesChamp() {
|
|
98 |
return valsMasqueesChamp;
|
|
99 |
}
|
|
100 |
|
|
101 |
public HashSet<String> getValsNulleMasqueesChamp() {
|
|
102 |
return valNulleMasqueeChamp;
|
|
103 |
}
|
|
104 |
|
|
105 |
public HashMap<Unite, Schema> getchainesUnitesNonFiltrees() {
|
|
106 |
return chainesUnitesNonFiltrees;
|
|
107 |
}
|
|
108 |
|
|
109 |
public boolean[] getValsNbMasqueesChamp() {
|
|
110 |
return valsMasqueesNbElements;
|
|
111 |
}
|
|
112 |
|
|
113 |
public void setValsMasqueesChamp(HashMap<String, HashSet<String>> valsMasqueesChamp) {
|
|
114 |
this.valsMasqueesChamp = valsMasqueesChamp;
|
|
115 |
}
|
|
116 |
|
|
117 |
public void setValsNulleMasqueesChamp(HashSet<String> valNulleMasqueeChamp) {
|
|
118 |
this.valNulleMasqueeChamp = valNulleMasqueeChamp;
|
|
119 |
}
|
|
120 |
|
|
121 |
public void setValsNbMasqueesChamp(boolean[] valsMasqueesNbElements) {
|
|
122 |
this.valsMasqueesNbElements = valsMasqueesNbElements;
|
|
123 |
}
|
|
124 |
|
|
125 |
// retourne le nombre de valeurs masquees pour le champ
|
|
126 |
public int nbvaleursmasquees(String champ) {
|
|
127 |
int resultat = 0;
|
|
128 |
if (champ == null) {// si le champ affiché est le nombre de chainons
|
|
129 |
for (boolean val : valsMasqueesNbElements) {
|
|
130 |
if (val) {
|
|
131 |
resultat = resultat + 1;
|
|
132 |
}
|
|
133 |
}
|
|
134 |
}
|
|
135 |
else {
|
|
136 |
resultat = valsMasqueesChamp.get(champ).size();
|
|
137 |
}
|
|
138 |
return resultat;
|
|
139 |
}
|
|
140 |
|
|
141 |
void demasquerToutesValsChamp(String champ) {
|
|
142 |
valsMasqueesChamp.get(champ).clear();
|
|
143 |
valNulleMasqueeChamp.remove(champ);
|
|
144 |
}
|
|
145 |
|
|
146 |
void demasquerToutesValsNbElts(String champ) {
|
|
147 |
for (int i = 0; i < valsMasqueesNbElements.length; i++) {
|
|
148 |
valsMasqueesNbElements[i] = false;
|
|
149 |
}
|
|
150 |
}
|
|
151 |
|
|
152 |
void setGChaine(GChaines panneaugraphique) {
|
|
153 |
this.panneauGraphique = panneaugraphique;
|
|
154 |
}
|
|
155 |
|
|
156 |
void setUnites(Unite[] donnees) {
|
|
157 |
this.listeUnites = donnees;
|
|
158 |
}
|
|
159 |
|
|
160 |
void permettreaffichage(boolean autorisation) {
|
|
161 |
this.peutafficher = autorisation;
|
|
162 |
}
|
|
163 |
|
|
164 |
boolean peutetreafficher() {
|
|
165 |
return this.peutafficher;
|
|
166 |
}
|
|
167 |
|
|
168 |
void masquerAutresValsChamp(String typeunite, String champ, String val) {
|
|
169 |
for (String v : vue.getValeursChamp(Unite.class, typeunite, champ))
|
|
170 |
valsMasqueesChamp.get(champ).add(v);
|
|
171 |
valsMasqueesChamp.get(champ).remove(val);
|
|
172 |
valNulleMasqueeChamp.add(champ);
|
|
173 |
}
|
|
174 |
|
|
175 |
void masquerValChamp(boolean yes, String champ, String val) {
|
|
176 |
if (yes) valsMasqueesChamp.get(champ).add(val);
|
|
177 |
else valsMasqueesChamp.get(champ).remove(val);
|
|
178 |
}
|
|
179 |
|
|
180 |
void masquerValsNonNullesChamp(String typeunite, String champ) {
|
|
181 |
for (String v : vue.getValeursChamp(Unite.class, typeunite, champ))
|
|
182 |
valsMasqueesChamp.get(champ).add(v);
|
|
183 |
valNulleMasqueeChamp.remove(champ);
|
|
184 |
}
|
|
185 |
|
|
186 |
void masquerValNulleChamp(boolean yes, String champ) {
|
|
187 |
if (yes) valNulleMasqueeChamp.add(champ);
|
|
188 |
else valNulleMasqueeChamp.remove(champ);
|
|
189 |
}
|
|
190 |
|
|
191 |
void masquerAutresValsNbElts(String champ, int i0) {
|
|
192 |
for (int i = 0; i < valsMasqueesNbElements.length; i++) {
|
|
193 |
valsMasqueesNbElements[i] = i != i0;
|
|
194 |
}
|
|
195 |
}
|
|
196 |
|
|
197 |
void masquerValNbElements(boolean yes, int i) {
|
|
198 |
valsMasqueesNbElements[i] = yes;
|
|
199 |
}
|
|
200 |
|
|
201 |
void init(String typeChaines, String typeUnites, int[] seuils)
|
|
202 |
throws UnsupportedOperationException {
|
|
203 |
seuilsValsNbElements = seuils;
|
|
204 |
String[] champs = vue.getNomsChamps(Unite.class, typeUnites);
|
|
205 |
valsMasqueesChamp.clear();
|
|
206 |
for (String champ : champs)
|
|
207 |
valsMasqueesChamp.put(champ, new HashSet<String>());
|
|
208 |
valNulleMasqueeChamp.clear();
|
|
209 |
valsMasqueesNbElements = new boolean[seuils.length + 3];
|
|
210 |
calculerChainesUnitesNonFiltrees(typeChaines, typeUnites);
|
|
211 |
calculerDonnees(typeChaines, typeUnites);
|
|
212 |
}
|
|
213 |
|
|
214 |
// struture qui n'est pas filtrées mais qui associe à une unité qui correspond au bon type d'unités
|
|
215 |
// la chaine qui la contient et qui est elle aussi du bon type de Schéma
|
|
216 |
private void calculerChainesUnitesNonFiltrees(String typeChaines,
|
|
217 |
String typeUnites) throws UnsupportedOperationException {
|
|
218 |
chainesUnitesNonFiltrees.clear();
|
|
219 |
for (Schema chaine : vue.getSchemasAVoir(typeChaines))
|
|
220 |
for (Element elt : chaine.getContenu()) {
|
|
221 |
if (elt.getClass() == Unite.class && elt.getType().equals(typeUnites)) {
|
|
222 |
if (chainesUnitesNonFiltrees.containsKey(elt)) {
|
|
223 |
throw new UnsupportedOperationException("L'unité " + vue.getIdElement(elt)
|
|
224 |
+ " appartient à deux chaînes : " + vue.getIdElement(chaine) + " et "
|
|
225 |
+ vue.getIdElement(chainesUnitesNonFiltrees.get(elt)));
|
|
226 |
}
|
|
227 |
else
|
|
228 |
chainesUnitesNonFiltrees.put((Unite) elt, chaine);
|
|
229 |
}
|
|
230 |
}
|
|
231 |
}
|
|
232 |
|
|
233 |
void modifMasqueVals(String typeChaines, String typeUnites) {
|
|
234 |
calculerDonnees(typeChaines, typeUnites);
|
|
235 |
}
|
|
236 |
|
|
237 |
void modifMasqueValsChampChaine(String typeChaines, String typeUnites, ArrayList noparagraphecachees, String champ, String Valeur) {
|
|
238 |
calculerDonnees(typeChaines, typeUnites, noparagraphecachees, champ, Valeur);
|
|
239 |
}
|
|
240 |
|
|
241 |
private void filtrerListeUnites(String typeUnites, String typeChaines) {
|
|
242 |
Unite[] unites = vue.getUnitesAVoir(typeUnites);
|
|
243 |
Schema[] chaines = vue.getSchemasAVoir(typeChaines);
|
|
244 |
unitesChaines.clear();
|
|
245 |
for (Schema chaine : chaines)
|
|
246 |
unitesChaines.put(chaine, new ArrayList<Unite>());
|
|
247 |
ArrayList<Integer> indFiltrees = new ArrayList<>();
|
|
248 |
String[] champs = vue.getNomsChamps(Unite.class, typeUnites);
|
|
249 |
boolean agarder;
|
|
250 |
for (int i = 0; i < unites.length; i++) {
|
|
251 |
agarder = true;
|
|
252 |
for (String champ : champs) {// pour tous les champs
|
|
253 |
String val = vue.getValeurChamp(unites[i], champ);// je recupere la valeur du champ
|
|
254 |
if (val.isEmpty()) {
|
|
255 |
if (valNulleMasqueeChamp.contains(champ)) {
|
|
256 |
agarder = false;
|
|
257 |
break;
|
|
258 |
}
|
|
259 |
}
|
|
260 |
else {
|
|
261 |
if (valsMasqueesChamp.get(champ).contains(val)) {
|
|
262 |
agarder = false;
|
|
263 |
break;
|
|
264 |
}
|
|
265 |
}
|
|
266 |
}
|
|
267 |
if (agarder) {
|
|
268 |
indFiltrees.add(i);
|
|
269 |
if (chainesUnitesNonFiltrees.containsKey(unites[i])) {
|
|
270 |
Schema chaine = chainesUnitesNonFiltrees.get(unites[i]);
|
|
271 |
unitesChaines.get(chaine).add(unites[i]);
|
|
272 |
}
|
|
273 |
}
|
|
274 |
}
|
|
275 |
ArrayList<Integer> indIndFiltrees = new ArrayList<>();
|
|
276 |
for (int k = 0; k < indFiltrees.size(); k++) {
|
|
277 |
Unite unit = unites[indFiltrees.get(k)];
|
|
278 |
if (chainesUnitesNonFiltrees.containsKey(unit)) {
|
|
279 |
if (!isMasqueeValNbElements(calculerValNbElements(
|
|
280 |
unitesChaines.get(chainesUnitesNonFiltrees.get(unit)).size())))
|
|
281 |
indIndFiltrees.add(k);
|
|
282 |
}
|
|
283 |
else {
|
|
284 |
if (!isMasqueeValNbElements(0)) indIndFiltrees.add(k);
|
|
285 |
}
|
|
286 |
}
|
|
287 |
listeUnites = new Unite[indIndFiltrees.size()];
|
|
288 |
for (int k = 0; k < listeUnites.length; k++) {
|
|
289 |
listeUnites[k] = unites[indFiltrees.get(indIndFiltrees.get(k))];
|
|
290 |
}
|
|
291 |
for (Schema chaine : chaines) {
|
|
292 |
int nb = unitesChaines.get(chaine).size();
|
|
293 |
if (nb == 0 || isMasqueeValNbElements(calculerValNbElements(nb)))
|
|
294 |
unitesChaines.remove(chaine);
|
|
295 |
}
|
|
296 |
}
|
|
297 |
|
|
298 |
private void calculerDonnees(String typeChaines, String typeUnites) {
|
|
299 |
filtrerListeUnites(typeUnites, typeChaines);
|
|
300 |
Chainon[] chainons = new Chainon[listeUnites.length];
|
|
301 |
for (int i = 0; i < listeUnites.length; i++) {
|
|
302 |
Unite unit = listeUnites[i];
|
|
303 |
chainons[i] = new Chainon(unit, vue.getTexteUnite(unit));
|
|
304 |
if (chainesUnitesNonFiltrees.containsKey(unit)) {
|
|
305 |
Schema chaine = chainesUnitesNonFiltrees.get(unit);
|
|
306 |
chainons[i].chaine = chaine;
|
|
307 |
chainons[i].nbEltsChaine = unitesChaines.get(chaine).size();
|
|
308 |
chainons[i].idChaine = vue.getIdElement(chaine);
|
|
309 |
}
|
|
310 |
chainonsUnites.put(listeUnites[i], chainons[i]);
|
|
311 |
}
|
|
312 |
HashMap<Schema, Integer> noChaine = new HashMap<>();
|
|
313 |
int no = 0;
|
|
314 |
for (Schema chaine : vue.getSchemasAVoir(typeChaines)) {
|
|
315 |
if (unitesChaines.containsKey(chaine)) {
|
|
316 |
int nbElts = unitesChaines.get(chaine).size();
|
|
317 |
noChaine.put(chaine, nbElts > 1 ? ++no : 0);
|
|
318 |
}
|
|
319 |
}
|
|
320 |
for (Unite unit : listeUnites) {
|
|
321 |
Chainon chainon = chainonsUnites.get(unit);
|
|
322 |
if (chainon.chaine != null) chainon.noChaine = noChaine.get(chainon.chaine);
|
|
323 |
}
|
|
324 |
int[] noPar = vue.getCorpus().calculerNoParagraphe(listeUnites);
|
|
325 |
if (peutafficher) {
|
|
326 |
panneauGraphique.setDonnees(chainons, noPar);
|
|
327 |
}
|
|
328 |
}
|
|
329 |
|
|
330 |
void initVide() {
|
|
331 |
listeUnites = new Unite[0];
|
|
332 |
chainesUnitesNonFiltrees.clear();
|
|
333 |
seuilsValsNbElements = new int[0];
|
|
334 |
chainonsUnites.clear();
|
|
335 |
unitesChaines.clear();
|
|
336 |
if (peutafficher) {
|
|
337 |
panneauGraphique.setDonnees(new Chainon[0], new int[0]);
|
|
338 |
panneauGraphique.setCouleurs(new Color[0]);
|
|
339 |
panneauGraphique.setTaille(new int[0]);
|
|
340 |
panneauGraphique.setForme(new int[0]);
|
|
341 |
panneauGraphique.setSurTexte(new String[0]);
|
|
342 |
panneauGraphique.setSousTexte(new String[0]);
|
|
343 |
}
|
|
344 |
valNulleMasqueeChamp.clear();
|
|
345 |
valsMasqueesChamp.clear();
|
|
346 |
valsMasqueesNbElements = new boolean[0];
|
|
347 |
}
|
|
348 |
|
|
349 |
void setChampAffiche(String champ, HashMap<String, Color> couleursValeursChamp) {
|
|
350 |
if (peutafficher) {
|
|
351 |
panneauGraphique.setCouleurs(colorerChamp(champ, couleursValeursChamp));
|
|
352 |
}
|
|
353 |
}
|
|
354 |
|
|
355 |
void setChampAfficheTaille(String champ, HashMap<String, Integer> TaillesValeursChamp) {
|
|
356 |
if (peutafficher) {
|
|
357 |
panneauGraphique.setTaille(ReduireChamp(champ, TaillesValeursChamp));
|
|
358 |
}
|
|
359 |
}
|
|
360 |
|
|
361 |
void setChampAfficheForme(String champ, HashMap<String, Integer> FormesValeursChamp) {
|
|
362 |
if (peutafficher) {
|
|
363 |
panneauGraphique.setForme(FormerChamp(champ, FormesValeursChamp));
|
|
364 |
}
|
|
365 |
}
|
|
366 |
|
|
367 |
void setChampAfficheSurTexte(String champ, HashMap<String, String> SurTexteValeursChamp) {
|
|
368 |
if (peutafficher) {
|
|
369 |
panneauGraphique.setSurTexte(SurTexteChamp(champ, SurTexteValeursChamp));
|
|
370 |
}
|
|
371 |
}
|
|
372 |
|
|
373 |
void setChampAfficheSousTexte(String champ, HashMap<String, String> SousTexteValeursChamp) {
|
|
374 |
if (peutafficher) {
|
|
375 |
panneauGraphique.setSousTexte(SousTexteChamp(champ, SousTexteValeursChamp));
|
|
376 |
}
|
|
377 |
}
|
|
378 |
|
|
379 |
void setChampAfficheNbElts(Color[] couleurs) {
|
|
380 |
if (peutafficher) {
|
|
381 |
panneauGraphique.setCouleurs(colorerNbElts(couleurs));
|
|
382 |
}
|
|
383 |
}
|
|
384 |
|
|
385 |
|
|
386 |
|
|
387 |
void setChampAfficheTailleNbElts(int[] taille) {
|
|
388 |
if (peutafficher) {
|
|
389 |
panneauGraphique.setTaille(ReduireNbElts(taille));
|
|
390 |
}
|
|
391 |
}
|
|
392 |
|
|
393 |
void setChampAfficheFormeNbElts(int[] forme) {
|
|
394 |
if (peutafficher) {
|
|
395 |
panneauGraphique.setForme(FormeNbElts(forme));
|
|
396 |
}
|
|
397 |
}
|
|
398 |
|
|
399 |
void setChampAfficheSurTexteNbElts(String[] SurTexte) {
|
|
400 |
if (peutafficher) {
|
|
401 |
panneauGraphique.setSurTexte(SurTexteNbElts(SurTexte));
|
|
402 |
}
|
|
403 |
}
|
|
404 |
|
|
405 |
void setChampAfficheSousTexteNbElts(String[] SousTexte) {
|
|
406 |
if (peutafficher) {
|
|
407 |
panneauGraphique.setSousTexte(SousTexteNbElts(SousTexte));
|
|
408 |
}
|
|
409 |
}
|
|
410 |
|
|
411 |
private Color[] colorerNbElts(Color[] couleurs) {
|
|
412 |
Color[] couls = new Color[listeUnites.length];
|
|
413 |
for (int i = 0; i < listeUnites.length; i++) {
|
|
414 |
Chainon ch = chainonsUnites.get(listeUnites[i]);
|
|
415 |
if (ch.chaine == null) couls[i] = couleurs[0];
|
|
416 |
else {
|
|
417 |
int nbElts = ch.nbEltsChaine;
|
|
418 |
couls[i] = couleurs[calculerValNbElements(nbElts)];
|
|
419 |
}
|
|
420 |
}
|
|
421 |
return couls;
|
|
422 |
}
|
|
423 |
|
|
424 |
private int[] FormeNbElts(int[] formes) {
|
|
425 |
int[] forme = new int[listeUnites.length];
|
|
426 |
for (int i = 0; i < listeUnites.length; i++) {
|
|
427 |
Chainon ch = chainonsUnites.get(listeUnites[i]);
|
|
428 |
if (ch.chaine == null) forme[i] = formes[0];
|
|
429 |
else {
|
|
430 |
int nbElts = ch.nbEltsChaine;
|
|
431 |
forme[i] = formes[calculerValNbElements(nbElts)];
|
|
432 |
}
|
|
433 |
}
|
|
434 |
return forme;
|
|
435 |
}
|
|
436 |
|
|
437 |
private int[] ReduireNbElts(int[] tailles) {
|
|
438 |
int[] taille = new int[listeUnites.length];
|
|
439 |
for (int i = 0; i < listeUnites.length; i++) {
|
|
440 |
Chainon ch = chainonsUnites.get(listeUnites[i]);
|
|
441 |
if (ch.chaine == null) taille[i] = tailles[0];
|
|
442 |
else {
|
|
443 |
int nbElts = ch.nbEltsChaine;
|
|
444 |
taille[i] = tailles[calculerValNbElements(nbElts)];
|
|
445 |
}
|
|
446 |
}
|
|
447 |
return taille;
|
|
448 |
}
|
|
449 |
|
|
450 |
private String[] SurTexteNbElts(String[] SurTextes) {
|
|
451 |
String[] SurTexte = new String[listeUnites.length];
|
|
452 |
for (int i = 0; i < listeUnites.length; i++) {
|
|
453 |
Chainon ch = chainonsUnites.get(listeUnites[i]);
|
|
454 |
if (ch.chaine == null) SurTexte[i] = SurTextes[0];
|
|
455 |
else {
|
|
456 |
int nbElts = ch.nbEltsChaine;
|
|
457 |
SurTexte[i] = SurTextes[calculerValNbElements(nbElts)];
|
|
458 |
}
|
|
459 |
}
|
|
460 |
return SurTexte;
|
|
461 |
}
|
|
462 |
|
|
463 |
private String[] SousTexteNbElts(String[] SousTextes) {
|
|
464 |
String[] SousTexte = new String[listeUnites.length];
|
|
465 |
for (int i = 0; i < listeUnites.length; i++) {
|
|
466 |
Chainon ch = chainonsUnites.get(listeUnites[i]);
|
|
467 |
if (ch.chaine == null) SousTexte[i] = SousTextes[0];
|
|
468 |
else {
|
|
469 |
int nbElts = ch.nbEltsChaine;
|
|
470 |
SousTexte[i] = SousTextes[calculerValNbElements(nbElts)];
|
|
471 |
}
|
|
472 |
}
|
|
473 |
return SousTexte;
|
|
474 |
}
|
|
475 |
|
|
476 |
|
|
477 |
private Color[] colorerChamp(String champ, HashMap<String, Color> couleursValeursChamp) {
|
|
478 |
Color[] couls = new Color[listeUnites.length];
|
|
479 |
for (int i = 0; i < listeUnites.length; i++) {
|
|
480 |
Chainon ch = chainonsUnites.get(listeUnites[i]);
|
|
481 |
couls[i] = couleursValeursChamp.get(vue.getValeurChamp(ch.unite, champ));
|
|
482 |
}
|
|
483 |
return couls;
|
|
484 |
}
|
|
485 |
|
|
486 |
// même chose que colorer champ mais en influant la taille des chainons
|
|
487 |
private int[] ReduireChamp(String champ, HashMap<String, Integer> TaillesValeursChamp) {
|
|
488 |
int[] taille = new int[listeUnites.length];
|
|
489 |
for (int i = 0; i < listeUnites.length; i++) {
|
|
490 |
Chainon ch = chainonsUnites.get(listeUnites[i]);
|
|
491 |
taille[i] = TaillesValeursChamp.get(vue.getValeurChamp(ch.unite, champ));
|
|
492 |
}
|
|
493 |
return taille;
|
|
494 |
}
|
|
495 |
|
|
496 |
// même chose que colorer champ mais en influant la forme des chainons
|
|
497 |
private int[] FormerChamp(String champ, HashMap<String, Integer> FormesValeursChamp) {
|
|
498 |
int[] forme = new int[listeUnites.length];
|
|
499 |
for (int i = 0; i < listeUnites.length; i++) {
|
|
500 |
Chainon ch = chainonsUnites.get(listeUnites[i]);
|
|
501 |
forme[i] = FormesValeursChamp.get(vue.getValeurChamp(ch.unite, champ));
|
|
502 |
}
|
|
503 |
return forme;
|
|
504 |
}
|
|
505 |
|
|
506 |
// même chose que colorer champ mais en influant le texte au dessus des chainons
|
|
507 |
private String[] SurTexteChamp(String champ, HashMap<String, String> SurTexteValeursChamp) {
|
|
508 |
String[] SurTexte = new String[listeUnites.length];
|
|
509 |
for (int i = 0; i < listeUnites.length; i++) {
|
|
510 |
Chainon ch = chainonsUnites.get(listeUnites[i]);
|
|
511 |
SurTexte[i] = SurTexteValeursChamp.get(vue.getValeurChamp(ch.unite, champ));
|
|
512 |
}
|
|
513 |
return SurTexte;
|
|
514 |
}
|
|
515 |
|
|
516 |
// même chose que colorer champ mais en influant le texte au dessous des chainons
|
|
517 |
private String[] SousTexteChamp(String champ, HashMap<String, String> SousTexteValeursChamp) {
|
|
518 |
String[] SousTexte = new String[listeUnites.length];
|
|
519 |
for (int i = 0; i < listeUnites.length; i++) {
|
|
520 |
Chainon ch = chainonsUnites.get(listeUnites[i]);
|
|
521 |
SousTexte[i] = SousTexteValeursChamp.get(vue.getValeurChamp(ch.unite, champ));
|
|
522 |
}
|
|
523 |
return SousTexte;
|
|
524 |
}
|
|
525 |
|
|
526 |
|
|
527 |
public int calculerValNbElements(int nbElts) {
|
|
528 |
return nbElts == 1 ? 1 : nbElts <= seuilsValsNbElements[0] ? 2 : nbElts <= seuilsValsNbElements[1] ? 3 : 4;
|
|
529 |
}
|
|
530 |
|
|
531 |
|
|
532 |
|
|
533 |
// retourne un tableau contenant les numéros de paragraphe qui contiennent des unités du modele
|
|
534 |
public Integer[] listenumeroparagraphe() {
|
|
535 |
int[] noparagraphe = (vue.getCorpus()).calculerNoParagraphe(listeUnites);
|
|
536 |
ArrayList<Integer> resultat = new ArrayList<>();
|
|
537 |
int former = -1;
|
|
538 |
for (int i = 0; i < noparagraphe.length; i++) {
|
|
539 |
if (former != noparagraphe[i]) {
|
|
540 |
resultat.add(noparagraphe[i]);
|
|
541 |
former = noparagraphe[i];
|
|
542 |
}
|
|
543 |
}
|
|
544 |
Integer[] resultatconversion = new Integer[resultat.size()];
|
|
545 |
return (resultat.toArray(resultatconversion));
|
|
546 |
}
|
|
547 |
|
|
548 |
|
|
549 |
// renvoie un Hashmap quidécrit la répartition des unités en position
|
|
550 |
// au sein du texte
|
|
551 |
// @require : listesUnites est trié selon la position de debut de ses éléments
|
|
552 |
public ArrayList<int[]> dispositionunites(int nbclasses) {
|
|
553 |
Unite[] unites = listeUnites;
|
|
554 |
ArrayList<int[]> locationunites = new ArrayList<>(nbclasses);
|
|
555 |
int longueurtexte = vue.getCorpus().getTexte().length();
|
|
556 |
int[] listeposition = ChaineUtil.discretisation(0, longueurtexte, nbclasses + 1);
|
|
557 |
int posprev = 0;
|
|
558 |
if (nbclasses > 0) {
|
|
559 |
int posactuel = 1;
|
|
560 |
int compte = 0;
|
|
561 |
int k = 0;
|
|
562 |
while (k < unites.length || posactuel < nbclasses + 1) {
|
|
563 |
if (k < unites.length && unites[k].getDeb() < listeposition[posactuel]
|
|
564 |
&& unites[k].getDeb() >= listeposition[posprev]) {
|
|
565 |
// si l'unite est dans cette partie du texte alors on incrémente le compteur
|
|
566 |
compte = compte + 1;
|
|
567 |
k = k + 1;
|
|
568 |
}
|
|
569 |
else {
|
|
570 |
posprev = posactuel;// on actualise la position precedente
|
|
571 |
locationunites.add(new int[] { listeposition[posprev], compte });
|
|
572 |
compte = 0;
|
|
573 |
posactuel = posactuel + 1;
|
|
574 |
}
|
|
575 |
}
|
|
576 |
}
|
|
577 |
return locationunites;
|
|
578 |
}
|
|
579 |
|
|
580 |
|
|
581 |
|
|
582 |
|
|
583 |
// renvoie un tableau contenant les fréquences de chaque valeur d'un champ de la chaine dans la liste d'unités
|
|
584 |
public HashMap<String, Float> calculerfrequencechaine(Unite[] donnees, String typeChaines, String Champcible, HashSet<String> valeurinterdite) {
|
|
585 |
String[] valsdisponibles = vue.getValeursChamp(Schema.class, typeChaines, Champcible);
|
|
586 |
HashMap<String, Float> tableaufrequence = new HashMap<>(valsdisponibles.length + 1);
|
|
587 |
String valeurchamp;
|
|
588 |
// on initialise le tableau résultat
|
|
589 |
for (String valeur : valsdisponibles) {
|
|
590 |
tableaufrequence.put(valeur, 0.0f);
|
|
591 |
}
|
|
592 |
tableaufrequence.put("", 0.0f);
|
|
593 |
int compteur = 0;
|
|
594 |
// on compte le nombre d'occurences
|
|
595 |
for (Unite unit : donnees) {
|
|
596 |
valeurchamp = chainesUnitesNonFiltrees.containsKey(unit) ? vue.getValeurChamp(chainesUnitesNonFiltrees.get(unit), Champcible) : null;
|
|
597 |
if (valeurchamp != null && !valeurinterdite.contains(valeurchamp)) {
|
|
598 |
compteur = compteur + 1;
|
|
599 |
tableaufrequence.put(valeurchamp, tableaufrequence.get(valeurchamp) + 1);
|
|
600 |
}
|
|
601 |
}
|
|
602 |
// on calcule les pourcentages
|
|
603 |
for (String valeur : valsdisponibles) {
|
|
604 |
tableaufrequence.put(valeur, compteur == 0 ? 0.0f
|
|
605 |
: tableaufrequence.get(valeur) * 10000.0f /
|
|
606 |
compteur / 100.0f);
|
|
607 |
}
|
|
608 |
tableaufrequence.put("", compteur == 0 ? 0.0f
|
|
609 |
: tableaufrequence.get("") * 10000.0f /
|
|
610 |
compteur / 100.0f);
|
|
611 |
|
|
612 |
return tableaufrequence;
|
|
613 |
}
|
|
614 |
|
|
615 |
// renvoie un tableau contenant les fréquences de chaque longueur des chaines de la liste d'unités
|
|
616 |
public HashMap<String, Float> calculerfrequencenbelt(Unite[] donnees, String typeUnites, String[] valsdisponibles) {
|
|
617 |
HashMap<String, Float> tableaufrequence = new HashMap<>(valsdisponibles.length);
|
|
618 |
String valeurchamp;
|
|
619 |
// on initialise le tableau résultat
|
|
620 |
for (String valeur : valsdisponibles) {
|
|
621 |
tableaufrequence.put(valeur, 0.0f);
|
|
622 |
}
|
|
623 |
int compte = 0;
|
|
624 |
// on compte le nombre d'occurences
|
|
625 |
for (Unite unit : donnees) {
|
|
626 |
Schema chaine = chainesUnitesNonFiltrees.containsKey(unit) ? chainesUnitesNonFiltrees.get(unit)
|
|
627 |
: null;
|
|
628 |
int nb = chaine == null ? 0 : unitesChaines.get(chaine).size();
|
|
629 |
if (isMasqueeValNbElements(calculerValNbElements(nb))) {
|
|
630 |
|
|
631 |
}
|
|
632 |
else if (nb == 0) {
|
|
633 |
valeurchamp = valsdisponibles[0];
|
|
634 |
tableaufrequence.put(valeurchamp, tableaufrequence.get(valeurchamp) + 1);
|
|
635 |
compte = compte + 1;
|
|
636 |
}
|
|
637 |
else {
|
|
638 |
valeurchamp = valsdisponibles[calculerValNbElements(nb)];
|
|
639 |
tableaufrequence.put(valeurchamp, tableaufrequence.get(valeurchamp) + 1);
|
|
640 |
compte = compte + 1;
|
|
641 |
}
|
|
642 |
}
|
|
643 |
|
|
644 |
|
|
645 |
// on calcule les pourcentages
|
|
646 |
for (String valeur : valsdisponibles) {
|
|
647 |
tableaufrequence.put(valeur, tableaufrequence.get(valeur) * 10000.0f /
|
|
648 |
compte / 100.0f);
|
|
649 |
}
|
|
650 |
|
|
651 |
|
|
652 |
return tableaufrequence;
|
|
653 |
}
|
|
654 |
|
|
655 |
|
|
656 |
|
|
657 |
|
|
658 |
// on enlève les unités dont les valeurs des chaines les contenant sont masquees
|
|
659 |
public Unite[] filtrechaine(Unite[] donnees, String Champ, HashSet<String> Valeurcachees) {
|
|
660 |
ArrayList<Unite> unitefiltrees = new ArrayList<>();
|
|
661 |
for (Unite unit : donnees) {
|
|
662 |
if (chainesUnitesNonFiltrees.containsKey(unit) && !(Valeurcachees.contains(vue.getValeurChamp(chainesUnitesNonFiltrees.get(unit), Champ)))) {
|
|
663 |
unitefiltrees.add(unit);
|
|
664 |
}
|
|
665 |
}
|
|
666 |
Unite[] resultat = unitefiltrees.toArray(new Unite[0]);
|
|
667 |
return resultat;
|
|
668 |
}
|
|
669 |
|
|
670 |
// on ne garde que les unités dont les chaines les contenant possèdent la valeur "valeur" pour le champ
|
|
671 |
// "Champ"
|
|
672 |
public Unite[] filtrevaleurchaine(Unite[] donnees, String Champ, String valeur) {
|
|
673 |
ArrayList<Unite> uniteduchamp = new ArrayList<>();
|
|
674 |
ArrayList<Unite> unitefiltrees = new ArrayList<>();
|
|
675 |
for (Schema chaine : unitesChaines.keySet()) {
|
|
676 |
// on trie les unités dont les chaines contenant ont la bonne valeur pour le champ
|
|
677 |
if ((vue.getValeurChamp(chaine, Champ)).equals(valeur)) {
|
|
678 |
uniteduchamp.addAll(unitesChaines.get(chaine));
|
|
679 |
}
|
|
680 |
}
|
|
681 |
// on ne garde que les unités passée en paramètre
|
|
682 |
for (int i = 0; i < donnees.length; i++) {
|
|
683 |
if (uniteduchamp.contains(donnees[i])) {
|
|
684 |
unitefiltrees.add(donnees[i]);
|
|
685 |
}
|
|
686 |
}
|
|
687 |
// on met le résultat sous forme de tableau
|
|
688 |
Unite[] resultat = (Unite[]) unitefiltrees.toArray();
|
|
689 |
return resultat;
|
|
690 |
}
|
|
691 |
|
|
692 |
|
|
693 |
// renvoioe la chaine qui contient l'unité dans ModeleChaine
|
|
694 |
public Schema getSchemacontenantunite(Unite unit) {
|
|
695 |
return chainesUnitesNonFiltrees.get(unit);
|
|
696 |
}
|
|
697 |
|
|
698 |
// filtre qui remplit les mêmes fonctions que le précédent mais également qui filtre suivant une liste de
|
|
699 |
// paragraphes interdits et ne garde que les unités appartenant aux chaines ayant pour le champ Champ la valeur
|
|
700 |
// Valeur
|
|
701 |
private void filtrerListeUnites(String typeUnites, String typeChaines, ArrayList<Integer> noparagraphecachees,
|
|
702 |
String Champ, String Valeur) {
|
|
703 |
Unite[] unites = vue.getUnitesAVoir(typeUnites);
|