package evaluer; import java.text.Normalizer; import java.util.ArrayList; import java.util.Dictionary; import java.util.Hashtable; import java.util.regex.Matcher; import java.util.regex.Pattern; import MEPTL.HTML; import MEPTL.commandes; import cXML.node; import calcul.StringSimilarity; /** * * @author pablo rodriguez * */ public class evaluation { public static Dictionary traduction = new Hashtable(); private static int pointsClass = 0; private static int pointTotal=0; private static int pointEnJeu = 0; /** * Chargement des traductions des éléments de l'exercice en utilsant le node "translation" du fichier d'analyse.
* Les noms des éléments sont placés dans un dictionnaire la key et la valeur est le code HTML.
* * @param translation Le node "translation" qui se trouve dans le node "setting" du fichier d'analyse. */ public static void chargeTraduction(node translation) { if(translation!=null) { String classText = ""; if(translation.getAttributs().get("classtext")!=null) if(!translation.getAttributs().get("classtext").isEmpty()) classText = ""; String className = ""; if(translation.getAttributs().get("class")!=null) if(!translation.getAttributs().get("class").isEmpty()) className = "
"; for(int i = 0 ; i < translation.getNodes().size();i++) { String translate = ""; String contenu =""; String link = ""; String color = ""; String codeHTML = ""; boolean T = false; if(translation.getNodes().get(i).getAttributs().get("translate")!=null) if(!translation.getNodes().get(i).getAttributs().get("translate").isEmpty()) translate=translation.getNodes().get(i).getAttributs().get("translate"); if(!translation.getNodes().get(i).getContenu().isEmpty()) contenu = translation.getNodes().get(i).getContenu().get(0).replace("-!", "<").replace("!-", ">"); if(translation.getNodes().get(i).getAttributs().get("link")!=null) if(!translation.getNodes().get(i).getAttributs().get("link").isEmpty()) link="

Lien

"; if(translation.getNodes().get(i).getAttributs().get("color")!=null) if(!translation.getNodes().get(i).getAttributs().get("color").isEmpty()) color=""; if(translation.getNodes().get(i).getAttributs().get("image")!=null) if(!translation.getNodes().get(i).getAttributs().get("image").isEmpty()) if(translation.getNodes().get(i).getAttributs().get("image").equals("true")) T=true; if(!contenu.isEmpty() && !className.isEmpty() && !classText.isEmpty()) { if(!link.isEmpty()) { if(!color.isEmpty()) { if(!T) codeHTML = className + color + translate + "" + classText + contenu + link + "
" ; if(T) codeHTML = className + HTML.imgInterogation() + color + translate + "
" + classText + contenu + link + "" ; }else { if(!T) codeHTML = className + translate + "" + classText + contenu + link + "" ; if(T) codeHTML = className + HTML.imgInterogation() + translate + "" + classText + contenu + link + "" ; } }else { if(!color.isEmpty()) { if(!T) codeHTML = className + color + translate + ""+ classText + contenu + "" ; if(T) codeHTML = className + HTML.imgInterogation() + color + translate + ""+ classText + contenu + "" ; }else { if(!T) codeHTML = className + translate + classText + contenu + "" ; if(T) codeHTML = className + HTML.imgInterogation() + translate + classText + contenu + "" ; } } }else { if(!link.isEmpty()) { if(!color.isEmpty()) { if(!T) codeHTML = color + translate+ "" + link; if(T) codeHTML = color + HTML.imgInterogation() + translate+ "" + link; }else { if(!T) codeHTML = translate + link; if(T) codeHTML = HTML.imgInterogation() + translate + link; } }else { if(!color.isEmpty()) { if(!T) codeHTML = color + translate+ ""; if(T) codeHTML = color + HTML.imgInterogation() + translate+ ""; }else { if(!T) codeHTML = translate; if(T) codeHTML = HTML.imgInterogation() + translate; } } } codeHTML = codeHTML.replace("-!", "<").replace("!-", ">"); if(!codeHTML.isEmpty()) { traduction.put(translation.getNodes().get(i).getNomElt().replace("..", " "),codeHTML); } } } } /** * Compare les chaînes de caractères A et sujet
* en fonction des 8 fonctions ‽ † ¢ → ¦ ↕ ↑ † ×
* * @param A le texte de l'étudiant. * @param Sujet le texte du sujet. * @return Une chaine de caractère contenant "Correct" ou "Erreur". */ public static String Compare(String A, String Sujet ) { // les points String pointString = "" ; pointEnJeu=0; if(Sujet!=null) if(Sujet.contains("‽")) { pointString = TraitePoint(Sujet); Sujet=Sujet.substring(0, Sujet.indexOf("‽")); } // optionnel pas d'analyse if(pointEnJeu==0) return "Optionnel"; //Méthode de comparaison avec calcul de Levenshtein if(Sujet!=null) if(Sujet.contains("╬")) { if(A==null) return "Erreur : -" + pointString; Sujet = Sujet.replace("╬", ""); if(TraitementDistanceDeLevenstein(A,Sujet).equals("Correct : ")) { IncrementPointClass(pointEnJeu); return "Correct : +" + pointString; } return "Erreur : -" + pointString; } // autre chose que null, none ou vide (analyse très simple) toutes les autres fonctions sont ignorées if(Sujet!=null) if(Sujet.contains("†")) { if(A==null) return "Erreur : -" + pointString; if(A.equals("none")) return "Erreur : -" + pointString; if(A.isEmpty()) return "Erreur : -" + pointString; IncrementPointClass(pointEnJeu); return "Correct : +" + pointString; } // fonction ET CONTIENT plusieurs textes - quelque chose mais pas vide - if(Sujet!=null) if(Sujet.contains("×") && !Sujet.contains("¢") && !Sujet.contains("→") && !Sujet.contains("#") && !Sujet.contains("¦") && !Sujet.contains("↕") && !Sujet.contains("↑") ) { if(A==null) return "Erreur : -" + pointString; if(A.equals("none")) return "Erreur : -" + pointString; if(A.isEmpty()) return "Erreur : -" + pointString; if(TraitementETContient(A,Sujet).equals("Correct : ")) { IncrementPointClass(pointEnJeu); return "Correct : +" + pointString; } return "Erreur : -" + pointString; } // fonction OU puis ET CONTIENT plusieurs textes - quelque chose mais pas vide - if(Sujet!=null) if(Sujet.contains("×") && Sujet.contains("¦") && !Sujet.contains("¦(") && !Sujet.contains("¢") && !Sujet.contains("→") && !Sujet.contains("#") && !Sujet.contains("↕") && !Sujet.contains("↑") ) { if(A==null) return "Erreur : -" + pointString; if(A.equals("none")) return "Erreur : -" + pointString; if(A.isEmpty()) return "Erreur : -" + pointString; if(TraitementOUETcontient(A,Sujet).equals("Correct : ")) { IncrementPointClass(pointEnJeu); return "Correct : +" + pointString; } return "Erreur : -" + pointString; } // nettoyage du texte avant de l'analyser et similitude // si ne contient pas d'autres fonctions cette fonction ne peut pas être combinée if(Sujet!=null) if(Sujet.contains("¢") && !Sujet.contains("→") && !Sujet.contains("#") && !Sujet.contains("¦") && !Sujet.contains("↕") && !Sujet.contains("↑") ) { if(A==null) A="null"; if(similitudeString(A, Sujet,commandes.tolerance_text)) { IncrementPointClass(pointEnJeu); return "Correct : +" + pointString; } return "Erreur : -" + pointString; } //intervalle valeur simple pas de bordure, pas de couleur, et pas d'autres fonctions if(Sujet.contains("→") && !Sujet.contains("#") && !Sujet.contains("¦") && !Sujet.contains("↕") && !Sujet.contains("↑") && !Sujet.contains("¢")) { if (TraitementIntervalle(A,Sujet).equals("Correct : ")) { IncrementPointClass(pointEnJeu); return "Correct : +" + pointString; }else { return "Erreur : -" + pointString; } } // bordure simple avec ou sans intervalles ou autres fonctions if(Sujet.contains("#") && Sujet.contains("pt") && Sujet.contains(" ") && !Sujet.contains("¦") && !Sujet.contains("↕") && !Sujet.contains("↑") && !Sujet.contains("¢") ) { if(TraitementBordure2(Sujet,A).equals("Correct : ")) { IncrementPointClass(pointEnJeu); return "Correct : +" + pointString; }else { return "Erreur : -" + pointString; } } // Ombrage la valeur est toujours doublé 0,18cm deux fois par exemple // #808080 0.18cm 0.18cmcm‼1 // La tolérance est de 0.04 Pattern p = Pattern.compile("^#[a-z0-9]{6} ([0-9]{1,}\\.[0-9]{1,}|[0-9]{1,})[a-z]{2}"); Matcher m = p.matcher(Sujet.trim()); if(m.find()) { if(TraitementOmbrage(Sujet, A).equals("Correct : ")) { IncrementPointClass(pointEnJeu); return "Correct : +" + pointString; }else { return "Erreur : -" + pointString; } } // couleur simple pas de bordure ou pas d'autres fonction if(Sujet.contains("#")&& m.find() && !Sujet.contains("pt") && !Sujet.contains(" ") && !Sujet.contains("¦") && !Sujet.contains("↕") && !Sujet.contains("↑") && !Sujet.contains("¢") ) { if(TraitementCouleur(Sujet,A).equals("Correct : ")) { IncrementPointClass(pointEnJeu); return "Correct : +" + pointString; }else { return "Erreur : -" + pointString; } } //Exact avec OU sans d'autres fonctions OU if(Sujet.contains("¦") && !Sujet.contains("↕") && !Sujet.contains("↑") && !Sujet.contains("¢")) { if(TraitementOUExact(A,Sujet).equals("Correct : ")) { IncrementPointClass(pointEnJeu); return "Correct : +" + pointString; }else { return "Erreur : -" + pointString; } } //OU Exact mais sans les espaces et sans d'autres fonctions OU if(Sujet.contains("≡") && !Sujet.contains("¦") && !Sujet.contains("↕") && !Sujet.contains("↑") && !Sujet.contains("¢")) { if(TraitementOUExactSansEspace(A,Sujet).equals("Correct : ")) { IncrementPointClass(pointEnJeu); return "Correct : +" + pointString; }else { return "Erreur : -" + pointString; } } //Opérateur OU avec nettoyage du texte if(Sujet.contains("↕") && !Sujet.contains("¦") && !Sujet.contains("↑") && !Sujet.contains("¢")) { if(TraitementOU(A,Sujet).equals("Correct : ")) { IncrementPointClass(pointEnJeu); return "Correct : +" + pointString; }else { return "Erreur : -" + pointString; } } //Opérateur ou avec nettoyage des caractères spéciaux et des chiffres if(Sujet.contains("↑") && !Sujet.contains("¦") && !Sujet.contains("↕") && !Sujet.contains("¢")) { if(TraitementOUSupprimeChiffreEtsansCase(A,Sujet).equals("Correct : ")) { IncrementPointClass(pointEnJeu); return "Correct : +" + pointString; }else { return "Erreur : -" + pointString; } } // ne contient aucune fonction if(!Sujet.contains("≡") && !Sujet.contains("¦") && !Sujet.contains("↕") && !Sujet.contains("↑") && !Sujet.contains("¢") && !Sujet.contains("†") && !Sujet.contains("→")) { if(A!=null)if(A.equals("auto")) A=null; if(Sujet!=null)if(Sujet.equals("auto")) Sujet=null; if(A!=null) if(A.equals("0cm")) A=null; if(Sujet!=null) if(Sujet.equals("0cm")) Sujet=null; if(A!=null) if(A.equals("none")) A=null; if(Sujet!=null) if(Sujet.equals("none")) Sujet=null; if(A!=null) if(A.isEmpty()) A=null; if(Sujet!=null) if(Sujet.isEmpty()) Sujet=null; if(A!=null) if(A.equals("0")) A=null; if(Sujet!=null) if(Sujet.equals("0")) Sujet=null; if(A!=null) if(A.equals("null")) A=null; if(Sujet!=null) if(Sujet.equals("null")) Sujet=null; if(A!=null) if(A.equals("false")) A=null; if(Sujet!=null) if(Sujet.equals("false")) Sujet=null; if(A!=null) if(Sujet==null) if(!pointString.isEmpty()) { return "Erreur : -" + pointString;} if(A!=null) if(Sujet==null) if(pointString.isEmpty()) {return "Erreur";} if(A==null) if(Sujet==null) if(!pointString.isEmpty()){IncrementPointClass(pointEnJeu); return "Correct : +" + pointString;} if(A==null) if(Sujet==null) if(pointString.isEmpty()) {IncrementPointClass(pointEnJeu); return "Correct";} if(A==null) if(Sujet!=null) if(!pointString.isEmpty()) return "Erreur : -" + pointString; if(A==null) if(Sujet!=null) if(pointString.isEmpty()) return "Erreur"; if(!pointString.isEmpty()) { if(A.equals(Sujet)){ IncrementPointClass(pointEnJeu); return "Correct : +" + pointString;} else { return "Erreur : -" + pointString; } }else { if(A.equals(Sujet)){ IncrementPointClass(pointEnJeu); return "Correct";} else { return "Erreur"; } } }else { return "Erreur combinaison avec † ¢ → ¦ ↕ ↑ ×"; } } /** * Traitement des points de l'attribut.
* @param B * @return */ public static String TraitePoint(String B) { int point = 0; pointEnJeu=0; String pointString =""; String C =B.substring(B.indexOf("‽")+1,B.length()); if(B!=null) if(B.contains("‽")) if(B.length()>1) if(!C.isEmpty()) { try { point = Integer.valueOf(B.substring(B.indexOf("‽")+1,B.length())); }catch (Exception e) { commandes.message.append("

** ERREUR sur la ventillation des points : " + B + " **

"); System.out.println("ERREUR sur la ventillation des points : " + B); e.getMessage(); } }else { point=0; } if(point==0) { pointString=""; } if(point>0) { pointString = Integer.valueOf(point) + " pt"; IncrementPointTotal(point); pointEnJeu= point; } return pointString; } /** * Traitement des intervalles * @return */ private static String TraitementIntervalle(String A, String B) { if(A==null) return "Erreur : "; if(A.isEmpty()) return "Erreur : "; String Text[] = B.split("→"); if(Text.length<2) { commandes.message.append("

** ERREUR sur l'intervalle : " + B + " **

"); System.out.println("** ERREUR de l'intervalle "+ B + " **"); } // Rechercher un digite une ou plusieurs fois en fin. // Pattern p = Pattern.compile("[^0-9\\.]"); //uniquement des valeur positive Pattern p = Pattern.compile("[^-?0-9\\.]"); //Avec des valeurs négatives // remplacement de toutes les occurrences par "" if(Text[0]!=null) Text[0]= p.matcher(Text[0]).replaceAll(""); if(Text[1]!=null) Text[1] = p.matcher(Text[1]).replaceAll(""); A = p.matcher(A).replaceAll(""); double b0=0.0; double b1=0.0; try{ b0 = Double.valueOf(Text[0]); b1 = Double.valueOf(Text[1]); }catch (Exception e) { commandes.message.append("

** ERREUR de conversion en double de : " + String.valueOf(Text[0]) + " ou " + String.valueOf(Text[1]) +" **

"); System.out.println(e.toString()); } if(A.isEmpty()) return "Erreur : "; double v = Double.valueOf(A); if(v<=b1 && v>=b0 ) return "Correct : "; return "Erreur : "; } /** * Retourne la valeur minimale d'un intervale. * @param Intervale * @return */ public static double TraitementIntervaleRetourneValeurMinimale(String Intervale) { String Text[] = Intervale.split("→"); // rechercher un digite une ou plusieur fois en fin. Pattern p = Pattern.compile("[^0-9\\.]"); if(Text.length<2) { commandes.message.append("

** ERREUR sur l'intervalle : " + Intervale + " **

"); System.out.println("** ERREUR de l'intervalle "+ Intervale + " **"); } // remplacement de toutes les occurrences par "" if(Text[0]!=null) Text[0]= p.matcher(Text[0]).replaceAll(""); double b0=0.0; try { b0 = Double.valueOf(Text[0]); }catch (Exception e) { commandes.message.append("

** ERREUR de conversion en double de : " + String.valueOf(Text[0]) + " **

"); System.out.println(e.toString()); } return b0; } /** * Retourne la valeur maximale d'un intervalle. * @param Intervale * @return */ public static double TraitementIntervaleRetourneValeurMaximale(String Intervale) { String Text[] = Intervale.split("→"); // rechercher un digite une ou plusieur fois en fin. Pattern p = Pattern.compile("[^0-9\\.]"); if(Text.length<2) { commandes.message.append("

** ERREUR sur l'intervalle : " + Intervale + " **

"); System.out.println("** ERREUR de l'intervalle "+ Intervale + " **"); } // remplacement de toutes les occurrences par "" if(Text[0]!=null)Text[0]= p.matcher(Text[0]).replaceAll(""); if(Text[1]!=null) Text[1]= p.matcher(Text[1]).replaceAll(""); double b1 = 0.0; try { b1 = Double.valueOf(Text[1]); }catch (Exception e) { commandes.message.append("

** ERREUR de conversion en double de : " + String.valueOf(Text[1]) + " **

"); System.out.println(e.toString()); } return b1; } /** * Traitement des bordures
*
    *
  1. Avec ou sans intervalle sur l'épaisseur des traits
  2. *
  3. Avec 3 styles de traits solid, dashed, double
  4. *
  5. Avec traitement de la couleur
  6. *
* @param Sujet * @param B * @return */ private static String TraitementBordure2(String Sujet, String B) { if(Sujet.isEmpty()) return "Erreur : "; if(B==null) return "Erreur : "; String TextB[] = B.split(" "); String TextA[] = Sujet.split(" "); if(TextB.length!=3 || TextA.length!=3) return "Erreur : "; boolean taille = false; boolean type = false; boolean couleur =false; // traitement de la taille (epaisseur du trait) if(TextA[0].contains("→")) { if(TraitementIntervalle(TextB[0], TextA[0]).equals("Correct : ")) taille = true; }else { TextA[0] = TextA[0].replace("pt","").replace("cm", "").replace("mm", "").replace("in", ""); TextB[0] = TextB[0].replace("pt","").replace("cm", "").replace("mm", "").replace("in", ""); double tailleA = Double.valueOf(TextA[0]); double tailleB = Double.valueOf(TextB[0]); double IT = 0.02; if((tailleAtailleB-IT))taille = true; } // traitement du type de trait String typeA = TextA[1]; String typeB = TextB[1]; //trait pointillé if(typeA.equals("dash-dot")) typeA="dashed"; if(typeB.equals("dash-dot")) typeB="dashed"; if(typeA.equals("dotted")) typeA="dashed"; if(typeB.equals("dotted")) typeB="dashed"; if(typeA.equals("fine-dashed")) typeA="dashed"; if(typeB.equals("fine-dashed")) typeB="dashed"; if(typeB.equals("dash-dot-dot")) typeB="dashed"; if(typeA.equals("dash-dot-dot")) typeA="dashed"; if(typeA.equals("double-thin")) typeA="double"; if(typeB.equals("double-thin")) typeB="double"; if(typeA.equals("outset")) typeA="double"; if(typeB.equals("outset")) typeB="double"; if(typeA.equals("inset")) typeA="double"; if(typeB.equals("inset")) typeB="double"; if(typeA.equals("groove")) typeA="solid"; if(typeB.equals("groove")) typeB="solid"; if(typeA.equals("ridge")) typeA="solid"; if(typeB.equals("ridge")) typeB="solid"; if(typeA.equals(typeB)) type=true; // traitement de la couleur du trait String couleurA = TextA[2]; //.replace("#", ""); String couleurB = TextB[2]; //.replace("#", ""); if(couleurA.equals(couleurB)) couleur = true; if(!couleur) { if(TraitementCouleur(couleurA, couleurB).equals("Correct : ")) { couleur =true; } } if(taille && type && couleur) return "Correct : "; return "Erreur : "; } /** * Traitement des ombrages
* @param Sujet * @param B * @return */ private static String TraitementOmbrage(String Sujet, String B) { if(Sujet.isEmpty()) return "Erreur : "; if(B==null) return "Erreur : "; String TextB[] = B.split(" "); String TextA[] = Sujet.split(" "); if(TextB.length!=3 || TextA.length!=3) return "Erreur : "; boolean taille1 = false; boolean taille2 = false; boolean couleur =false; // traitement de la taille1 (largeur ombrage) if(TextA[1].contains("→")) { if(TraitementIntervalle(TextB[1], TextA[1]).equals("Correct : ")) taille1 = true; }else { TextA[1] = TextA[1].replace("pt","").replace("cm", "").replace("mm", "").replace("in", ""); TextB[1] = TextB[1].replace("pt","").replace("cm", "").replace("mm", "").replace("in", ""); double tailleA = Double.valueOf(TextA[1]); double tailleB = Double.valueOf(TextB[1]); double IT = 0.02; if((tailleAtailleB-IT))taille1 = true; } if(TextA[2].contains("→")) { if(TraitementIntervalle(TextB[2], TextA[2]).equals("Correct : ")) taille2 = true; }else { TextA[2] = TextA[2].replace("pt","").replace("cm", "").replace("mm", "").replace("in", ""); TextB[2] = TextB[2].replace("pt","").replace("cm", "").replace("mm", "").replace("in", ""); double tailleA = Double.valueOf(TextA[2]); double tailleB = Double.valueOf(TextB[2]); double IT = 0.02; if((tailleAtailleB-IT))taille2 = true; } // traitement de la couleur du trait String couleurA = TextA[0]; //.replace("#", ""); String couleurB = TextB[0]; //.replace("#", ""); if(couleurA.equals(couleurB)) couleur = true; if(!couleur) { if(TraitementCouleur(couleurA, couleurB).equals("Correct : ")) { couleur =true; } } if(taille1 && taille2 && couleur) return "Correct : "; return "Erreur : "; } /** * Traitement de la couleur par comparaison * La tolérance sur les 3 couleurs primaires RVB est de plus ou moins 30 par défaut. * @param A * @param B * @return */ private static String TraitementCouleur(String Sujet, String B) { if(B==null) return "Erreur : "; if(B.isEmpty()) return "Erreur : "; Pattern p = Pattern.compile("#.{6}"); Matcher m = p.matcher(Sujet.trim()); if(!m.find()) { commandes.message.append("

** ERREUR la couleur du sujet n'est pas correct " + Sujet + " **

"); commandes.message.append("

** La couleur sera automatiquement mis à noir #000000**

"); Sujet="000000"; } // traitement de la couleur du trait String couleurS = Sujet.replace("#", ""); String couleurB = B.replace("#", ""); if(couleurS.equals(couleurB)) return "Correct : "; if(couleurS.length()==6 && couleurB.length()==6) { int Sred = Integer.parseInt(couleurS.substring(0, 2),16); int Sgreen = Integer.parseInt(couleurS.substring(2, 4),16); int Sblue = Integer.parseInt(couleurS.substring(4, 6),16); int Bred = Integer.parseInt(couleurB.substring(0, 2),16); int Bgreen = Integer.parseInt(couleurB.substring(2, 4),16); int Bblue = Integer.parseInt(couleurB.substring(4, 6),16); // couleur dominante avec 10 niveau // if(Sred>Sgreen+10 && Sred>Sblue+10 && Bred>Bgreen+10 && Bred>=Bblue+10) return "Correct : ";//couleur=true; //Couleur dominante rouge // if(Sgreen>Sred+10 && Sgreen>Sblue+10 && Bgreen>Bred+10 && Bgreen>Bblue+10) return "Correct : "; //couleur = true; //Couleur dominante vert // if(Sblue>Sred+10 && Sblue>Sgreen+10 && Bblue>Bred+10 && Bblue>Bgreen+10) return "Correct : "; //couleur = true; //Couleur dominante bleu // if(Sblue==Sred && Sblue==Sgreen && Bblue==Bred && Bblue==Bgreen) return "Correct : "; //couleur = true; //Couleur gris (tous les gris) if(procheCouleur(Sred,Bred,Sgreen,Bgreen,Sblue,Bblue)) return "Correct : "; //couleur = true; //Couleur gris (tous les gris) } //if(couleur) return "Correct : "; return "Erreur : "; } /** * Couleur proche avec une tolérance par défaut de 20 nuances dans l'espace colorométrique RVB. * @param R1 Rouge Sujet * @param R2 Rouge Student * @param V1 Vert Sujet * @param V2 Vert Student * @param B1 Bleu Sujet * @param B2 Bleu Student * @return */ private static Boolean procheCouleur(int R1, int R2, int V1, int V2, int B1, int B2) { int ecartR = Math.abs(R1-R2); int ecartV = Math.abs(V1-V2); int ecartB = Math.abs(B1-B2); if((ecartR <=commandes.tolerance_rouge)&&(ecartV <=commandes.tolerance_vert)&&(ecartB <=commandes.tolerance_bleu) )return true; return false; } /** * Traitement des conditions OU avec nettoyage du texte * Comparaison egale, contient , similitude * @param A * @param B * @return */ private static String TraitementOU(String A, String B) { if(A==null) A="none"; if(A.isEmpty()) A="none"; A = NetTexte(A); String TextB[] = B.split("↕"); for(int i=0;icommandes.tolerance_text) { return "Correct : "; } return "Erreur : "; } /** * Fonction OU contenant des ET contient le texte du node Sujet * @param A * @param Sujet * @return */ private static String TraitementOUETcontient(String A, String Sujet) { String TextB[] = Sujet.split("¦"); for(int i=0;i * @param B * @return */ public static String withoutPoint(String B) { if(B!=null) if(B.contains("‽")) { B=B.substring(0, B.indexOf("‽")); } return B; } /** * Sans le code ¢.
* @param B * @return */ public static String withoutCode(String B) { B=B.replace("¢", ""); return B; } /** * Sans le code ‽, ¢ et les points.
* @param B * @return */ public static String withoutCodeAndPoint(String B) { if(B!=null) { if(B.contains("‽")) B=B.substring(0, B.indexOf("‽")); if(!B.isEmpty()) B=B.replace("¢", ""); } return B; } /** * Uniquement suppression des codes ‽, ↑, ↕, ≡, ¢,╬ et les points
* pour effectuer la recherche d'un node par son contenu. * @param B un string * @return B un string */ public static String withoutCodeAndPointPourRechercheContenuExact(String B) { if(B!=null) { if(B.contains("‽")) B=B.replaceAll("‽[0-9]{0,}", ""); //B=B.substring(0, B.indexOf("‽")); if(!B.isEmpty()) if(B.contains("↑")) B=B.replace("↑", ""); if(!B.isEmpty()) if(B.contains("↕")) B=B.replace("↕", ""); if(!B.isEmpty()) if(B.contains("≡")) B=B.replace("≡", ""); if(!B.isEmpty()) if(B.contains("¢")) B=B.replace("¢", ""); if(!B.isEmpty()) if(B.contains("╬")) B=B.replace("╬", ""); if(!B.isEmpty()) B=B.replaceAll("‽[0-9]{1,}", ""); if(!B.isEmpty()) B=B.replaceAll("‼[0-9]{1,}", ""); } return B; } /** * Supprime les caracatères spéciaux, la pontuaction, tous les espaces, et les chiffres
* Bascule le texte en minuscule.
* @param A Le texte qui doit être nettoyé. * @return Le texte nettoyé. */ public static String NetTexte(String A) { if (A!=null) { A=A.toLowerCase().trim(); A = A.replace("'", ""); A = A.replace(""", ""); Pattern pt = Pattern.compile("[^a-z0-9]"); // avec les chiffres "[^a-zA-Z0-9]" Matcher match= pt.matcher(A); while(match.find()){ String s= match.group(); A=A.replaceAll("\\"+s, ""); } A=A.replaceAll("[0-9]", ""); A=A.replace(" ", ""); A=A.toLowerCase(); // Normaliser la chaîne en forme décomposée pour séparer les caractères accentués String normalized = Normalizer.normalize(A, Normalizer.Form.NFD); // Supprime les caractères accentués diacritique return normalized.replaceAll("\\p{InCombiningDiacriticalMarks}+", ""); } return A; } /** * Netoyage des chiffres placés à la fin du texte.
* Cette méthode est utilisée pour supprimer les numéros de page dans les index (table de matières par exemple).
* @param A Le texte. * @return Le texte A sans chiffre à la fin du texte. */ public static String NetChiffreALaFin(String A) { A=A.replaceAll("{1,}[0-9]", ""); return A; } /** * Retourne la chaîne sans le numéro à la fin.
* @param String A * @return String */ public static String RemoveLastNumber(String A) { Pattern p = Pattern.compile("[0-9]+$"); Matcher m = p.matcher(A); A= m.replaceAll(""); return A; } /** * * @param A * @param B * @return */ public static ArrayList AjouteDansALesNodesB(ArrayList A,ArrayList B){ for(int i=0; i * Lorsque les deux chaînes de caractères partages 90% des caractères comparés par groupe de 2 ou 3 ou 4. Alors retourne TRUE.
* Lorsque les deux chaînes de caractères partages moins de 90% des caractères comparés par groupe de 2 ou 3 ou 4. Alors retourne FALSE.
* Les Chaînes de caractères doivent avoir au moins 6 caractères, après néttoyage du texte avec la méthode NetTexte().
* Sinon le seuil de tolérance est de 99.99%.
*
    *
  • Lorsque la longueur de la chaîne de caractères est inférieure à 50 caractères alors compare par groupe de 2 caractères.
  • *
  • Lorsque la longueur de la chaîne de caractères est entre à 50 et 200 caractères alors compare par groupe de 3 caractères.
  • *
  • Lorsque la longueur de la chaîne de caractères est supérieure à 200 caractères alors compare par groupe de 4 caractères.
  • *
*
* @param A Chaîne de caracatères de l'étudiant. * @param Modele Chaîne de caractères du sujet. * @param tolerance_text Le seuil de tolérance pour la comparaison (valeur comprise entre 0 et 1). * @return TRUE ou FALSE en fonction de la comparaison et du seuil de tolérance. */ private static boolean similitudeString(String A, String Modele, Double tolerance_text) { if(tolerance_text==null) tolerance_text = 0.9 ; Modele = NetTexte(Modele); A = NetTexte(A); double Sim = StringSimilarity.similarity(A, Modele); if(Sim