analyseWriter/src/evaluer/evaluation.java

1078 lines
35 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package evaluer;
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<String, String> traduction = new Hashtable<String, String>();
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 "<b>translation</b>" du fichier d'analyse.<br>
* Les noms des éléments sont placés dans un dictionnaire la key et la valeur est le code HTML.</br>
*
* @param translation Le node "<b>translation</b>" qui se trouve dans le node "<b>setting</b>" 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 = "</span><span class=\""+ translation.getAttributs().get("classtext") +"\">";
String className = "";
if(translation.getAttributs().get("class")!=null) if(!translation.getAttributs().get("class").isEmpty()) className = "<div class=\"" + translation.getAttributs().get("class") + "\">";
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="<p><a href=\"" + translation.getNodes().get(i).getAttributs().get("link") + "\" target=\"_blank\">Lien</a></p>";
if(translation.getNodes().get(i).getAttributs().get("color")!=null) if(!translation.getNodes().get(i).getAttributs().get("color").isEmpty()) color="<span style=\"color:" + translation.getNodes().get(i).getAttributs().get("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 + "</span>" + classText + contenu + link + "</span></div>" ;
if(T) codeHTML = className + HTML.imgInterogation() + color + translate + "</span>" + classText + contenu + link + "</span></div>" ;
}else {
if(!T) codeHTML = className + translate + "</span>" + classText + contenu + link + "</span></div>" ;
if(T) codeHTML = className + HTML.imgInterogation() + translate + "</span>" + classText + contenu + link + "</span></div>" ;
}
}else {
if(!color.isEmpty()) {
if(!T) codeHTML = className + color + translate + "</span>"+ classText + contenu + "</span></div>" ;
if(T) codeHTML = className + HTML.imgInterogation() + color + translate + "</span>"+ classText + contenu + "</span></div>" ;
}else {
if(!T) codeHTML = className + translate + classText + contenu + "</span></div>" ;
if(T) codeHTML = className + HTML.imgInterogation() + translate + classText + contenu + "</span></div>" ;
}
}
}else {
if(!link.isEmpty()) {
if(!color.isEmpty()) {
if(!T) codeHTML = color + translate+ "</span>" + link;
if(T) codeHTML = color + HTML.imgInterogation() + translate+ "</span>" + link;
}else {
if(!T) codeHTML = translate + link;
if(T) codeHTML = HTML.imgInterogation() + translate + link;
}
}else {
if(!color.isEmpty()) {
if(!T) codeHTML = color + translate+ "</span>";
if(T) codeHTML = color + HTML.imgInterogation() + translate+ "</span>";
}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<br>
* en fonction des 8 fonctions ‽ † ¢ → ¦ ↕ ↑ † ×<br>
*
* @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.</br>
* @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("<p>** ERREUR sur la ventillation des points : " + B + " **</p>");
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("<p>** ERREUR sur l'intervalle : " + B + " **</p>");
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("<p>** ERREUR de conversion en double de : " + String.valueOf(Text[0]) + " ou " + String.valueOf(Text[1]) +" **</p>");
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("<p>** ERREUR sur l'intervalle : " + Intervale + " **</p>");
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("<p>** ERREUR de conversion en double de : " + String.valueOf(Text[0]) + " **</p>");
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("<p>** ERREUR sur l'intervalle : " + Intervale + " **</p>");
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("<p>** ERREUR de conversion en double de : " + String.valueOf(Text[1]) + " **</p>");
System.out.println(e.toString());
}
return b1;
}
/**
* Traitement des bordures<br>
* <ol>
* <li>Avec ou sans intervalle sur l'épaisseur des traits</li>
* <li>Avec 3 styles de traits solid, dashed, double</li>
* <li>Avec traitement de la couleur</li>
* </ol>
* @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((tailleA<tailleB+IT) && (tailleA>tailleB-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<br>
* @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((tailleA<tailleB+IT) && (tailleA>tailleB-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((tailleA<tailleB+IT) && (tailleA>tailleB-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("<p>** ERREUR la couleur du sujet n'est pas correct " + Sujet + " **</p>");
commandes.message.append("<p>** La couleur sera automatiquement mis à noir #000000**</p>");
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;i<TextB.length;i++) {
TextB[i] = NetTexte(TextB[i]);
if(A.equals(TextB[i])) return "Correct : ";
if(A.contains(TextB[i])) return "Correct : ";
if(similitudeString(A, TextB[i],commandes.tolerance_text)) return "Correct : ";
}
return "Erreur : ";
}
/**
* Traitement Exact
* @param A
* @param B
* @return
*/
private static String TraitementOUExact(String A, String B) {
if(A==null && !B.contains("null")) return "Erreur : ";
if(A==null && B.contains("null")) return "Correct : ";
String TextB[] = B.split("¦");
for(int i=0;i<TextB.length;i++) {
if(!TextB[i].contains("")) {
if(A.equals(TextB[i])) return "Correct : ";
}else {
if (TraitementIntervalle(A,TextB[i]).equals("Correct : ")) return "Correct : ";
}
}
return "Erreur : ";
}
/**
*
* @param A
* @param Sujet
* @return
*/
private static String TraitementOUExactSansEspace(String A, String Sujet) {
if(A==null && !Sujet.contains("null")) return "Erreur : ";
if(A==null && Sujet.contains("null")) return "Correct : ";
A = A.replace(" ", "");
String TextB[] = Sujet.split("");
for(int i=0;i<TextB.length;i++) {
if(!TextB[i].contains("")) {
if(A.equals(TextB[i].replace(" ", ""))) return "Correct : ";
}else {
if (TraitementIntervalle(A,TextB[i].replace(" ", "")).equals("Correct : ")) return "Correct : ";
}
}
return "Erreur : ";
}
/**
* Fonction ET contient le texte du node Sujet
* @param A
* @param Sujet
* @return
*/
private static String TraitementETContient(String A, String Sujet) {
String TextB[] = Sujet.split("×");
boolean Correct = false;
for(int i=0;i<TextB.length;i++) {
if(!TextB[i].isEmpty()) {
if(A.trim().contains(TextB[i].trim())) {
Correct = true;
}else {
return "Erreur : ";
}
}
}
if(Correct) return "Correct : ";
return "Erreur : ";
}
/**
*
* @param A
* @param Sujet
* @return
*/
private static String TraitementDistanceDeLevenstein(String A, String Sujet) {
if(cXML.StringSimilarity.similarity(A, Sujet)>commandes.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<TextB.length;i++) {
if(TextB[i].contains("×")) {
if(TraitementETContient( A, TextB[i]).equals("Correct : ")) return "Correct : ";
}else {
if(A.trim().contains(TextB[i].trim())) return "Correct : ";
}
}
return "Erreur : ";
}
/**
* Traitement des condition OU en supprimant les chiffres
* @param A
* @param B
* @return
*/
private static String TraitementOUSupprimeChiffreEtsansCase(String A, String B) {
if(A==null) A="none";
if(A.isEmpty()) A="none";
// rechercher un digite une ou plusieur fois en fin.
Pattern p = Pattern.compile("[0-9]");
// création du moteur associé à la regex sur la chaîne A
Matcher m = p.matcher(A);
// remplacement de toutes les occurrences par ""
A= m.replaceAll("");
A=A.toLowerCase();
m = p.matcher(B);
B = m.replaceAll("");
B= B.toLowerCase();
A = NetTexte(A);
String TextB[] = B.split("");
for(int i=0;i<TextB.length;i++) {
TextB[i] = NetTexte(TextB[i]);
if(A.equals(TextB[i].toLowerCase())) return "Correct : ";
}
return "Erreur : ";
}
/**
* Sans les point et le code ‽.</br>
* @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 ¢.</br>
* @param B
* @return
*/
public static String withoutCode(String B) {
B=B.replace("¢", "");
return B;
}
/**
* Sans le code ‽, ¢ et les points.</br>
* @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<br>
* 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<br>
* Bascule le texte en minuscule.<br>
* @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("&apos;", "");
A = A.replace("&quot", "");
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();
}
return A;
}
/**
* Netoyage des chiffres placés à la fin du texte.<br>
* Cette méthode est utilisée pour supprimer les numéros de page dans les index (table de matières par exemple).<br>
* @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.</br>
* @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<node> AjouteDansALesNodesB(ArrayList<node> A,ArrayList<node> B){
for(int i=0; i<B.size();i++) {
A.add(B.get(i));
}
return A;
}
/**
* Initialisation des points
*/
public static void initiliseLesPoints() {
pointsClass=0;
pointEnJeu=0;
pointTotal=0;
}
/**
* Compare deux chaînes de caractères avec un seuil de similitude (79% par défaut).<br>
* 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.<br>
* 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.<br>
* Les Chaînes de caractères doivent avoir au moins 6 caractères, après néttoyage du texte avec la méthode NetTexte().<br>
* Sinon le seuil de tolérance est de 99.99%.<br>
* <ul>
* <li>Lorsque la longueur de la chaîne de caractères est inférieure à 50 caractères alors compare par groupe de 2 caractères.</li>
* <li>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.</li>
* <li>Lorsque la longueur de la chaîne de caractères est supérieure à 200 caractères alors compare par groupe de 4 caractères.</li>
* </ul>
* <br>
* @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<tolerance_text) return false;
return true;
}
/**
* Remplace les _20_ par un espace
* Remplace les _26_ par un &
* @param A
* @return
*/
public static String remplaceCaracteresCodageAttribut(String A) {
if(A!=null) {
A = A.replace("_20_", " ");
A = A.replace("_26_", "&");
}
return A;
}
public static int getPointsClass() {
return pointsClass;
}
public static int getPointTotal() {
return pointTotal;
}
public static int getPointEnJeu() {
return pointEnJeu;
}
public static double getProportionCorrect() {
return (double) pointsClass/pointTotal;
}
public static void setPointsClass(int ptsClass) {
pointsClass = ptsClass;
}
public static void setPointTotal(int ptTotal) {
pointTotal = ptTotal;
}
public static void setPointEnJeu(int ptEnJeu) {
pointEnJeu = ptEnJeu;
}
public static void IncrementPointTotal(Integer pt) {
pointEnJeu = pt;
pointTotal=pointTotal+ pt;
}
public static void decrementPointEnJeuDuTotal() {
pointTotal=pointTotal-pointEnJeu;
}
private static void IncrementPointClass(Integer pt) {
pointsClass=pointsClass+ pt;
}
}