analyseWriter/src/MEPTL/VerificationHistorique.java

302 lines
14 KiB
Java

package MEPTL;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Dictionary;
import java.util.Hashtable;
import cXML.Run;
import cXML.node;
import calcul.formatDateWriter;
public class VerificationHistorique {
/**
* Vérirication des historiques
* @param verification
* @param a
* @return le node verif
* @throws ParseException
* @throws CloneNotSupportedException
*/
public static node verificationHistorique(node verification, Run a) throws ParseException, CloneNotSupportedException {
node verif = new node();
verif.setNomElt("verification");
verif.setAttributs(verification.getAttributs());
verif.getAttributs().put("number_match", String.valueOf(commandes.number_match));
verif.getAttributs().put("mini_number_modification", String.valueOf(commandes.mini_number_modification));
verif.getAttributs().put("nombres_modifications_simultané_maxi", String.valueOf(commandes.nombres_modifications_simultané_maxi));
ArrayList<node> LesFichiers = verification.retourneLesEnfantsByName("fichier", new ArrayList<node>());
System.out.println();
System.out.println("***** DEBUT VERIFICATION DES HISTORIQUES DES MODIFICATION ****");
System.out.println();
commandes.message.append("\n\n***** DEBUT VERIFICATION DES HISTORIQUES DES MODIFICATION ****\n");
for(int i = 0 ; i < LesFichiers.size() ; i++) {
node nodStudent = new node();
nodStudent.setNomElt("fichier");
nodStudent.setAttributs(LesFichiers.get(i).getAttributs());
//String nameStudent1 = LesFichiers.get(i).getAttributs().get("dossier");
ArrayList<node> HitoriqueDuFichier = LesFichiers.get(i).retourneEnfantsByName("text:changed-region", new ArrayList<node>());
int nombreModifications = HitoriqueDuFichier.size();
nodStudent.getAttributs().put("nombre_modification", String.valueOf(nombreModifications));
int compteurnombreCorrespondance = 0 ;
int compteurnombreCorrespondancesSuivi = 0;
int compteurnombreCorrespondancesconsecutive = 0;
System.out.println(LesFichiers.get(i).getAttributs().get("dossier") + " - number of modifications : " + nombreModifications);
commandes.message.append("\n"+LesFichiers.get(i).getAttributs().get("dossier") + " - number of modifications : " + nombreModifications);
@SuppressWarnings("unchecked")
ArrayList<node> LesFichiers2 = (ArrayList<node>) LesFichiers.clone();
LesFichiers2.remove(i);
Dictionary<String, Integer> lesdates = new Hashtable<String, Integer>();
Date DateMini = null; //Première date de modification
ArrayList<String> listeModification = new ArrayList<String>();
// Parcours toutes les modifications dans l'historique
for(int j = 0 ; j < HitoriqueDuFichier.size(); j++) {
node nodDate = null;
node nodDateCreator = null;
String dcdate1 ="";
@SuppressWarnings("unused")
String dccreator ="";
String typeModification = "";
String xmlid = "";
nodDate = HitoriqueDuFichier.get(j).retourneFirstEnfantsByName("dc:date");
nodDateCreator = HitoriqueDuFichier.get(j).retourneFirstEnfantsByName("dc:creator");
typeModification = HitoriqueDuFichier.get(j).getNodes().get(0).getNomElt();
xmlid = HitoriqueDuFichier.get(j).getAttributs().get("xml:id");
if(!typeModification.equals("text:UnknownChange")) { //&&!typeModification.equals("text:format-change")
if(nodDate!=null) {
dcdate1 = nodDate.getContenu().get(0);
}
if(nodDate!=null) {
dccreator = nodDateCreator.getContenu().get(0);
}
Date DcDate1 = formatDateWriter.DateLibreOffice(dcdate1);
//Le copié et collé dans les fichiers
if(!xmlid.isEmpty()) {
if(!listeModification.contains(xmlid)) {
listeModification.add(xmlid);
ArrayList<node> TousIdentiques = LesFichiers.get(i).retourneEnfantsByNameAndValueAttribut("text:changed-region", "xml:id",xmlid,new ArrayList<node>());
int NbrParagrapheModifier = 0;
for(int n=0 ; n < TousIdentiques.size(); n++) {
NbrParagrapheModifier = NbrParagrapheModifier + TousIdentiques.get(n).retourneEnfantsByName("text:p",new ArrayList<node>()).size();
NbrParagrapheModifier = NbrParagrapheModifier + TousIdentiques.get(n).retourneEnfantsByName("text:h",new ArrayList<node>()).size();
NbrParagrapheModifier = NbrParagrapheModifier + TousIdentiques.get(n).retourneEnfantsByName("draw:frame",new ArrayList<node>()).size();
NbrParagrapheModifier = NbrParagrapheModifier + TousIdentiques.get(n).retourneEnfantsByName("text:list-item",new ArrayList<node>()).size();
NbrParagrapheModifier = NbrParagrapheModifier + TousIdentiques.get(n).retourneEnfantsByName("text:table-of-content",new ArrayList<node>()).size();
NbrParagrapheModifier = NbrParagrapheModifier + TousIdentiques.get(n).retourneEnfantsByName("text:index-title",new ArrayList<node>()).size();
}
if(NbrParagrapheModifier <= 0) {
ArrayList<node> Applati = a.Applatir(LesFichiers.get(i).clone(), new ArrayList<node>());
node A = a.retourneFirstNodeByNameAttributValue(Applati, "text:change-start", "text:change-id", xmlid);
node B = a.retourneFirstNodeByNameAttributValue(Applati, "text:change-end", "text:change-id", xmlid);
int index1 = Applati.indexOf(A);
int index2 = Applati.indexOf(B);
for(int k = index1+1; k<index2; k++) {
if(Applati.get(k).getNomElt().contains("text:table-of-content")) NbrParagrapheModifier++;
if(Applati.get(k).getNomElt().contains("text:p")) {
if(!Applati.get(k).retourneLesContenusEnfants("").isBlank()) {
NbrParagrapheModifier++;
}
}
if(Applati.get(k).getNomElt().contains("text:h")) {
if(!Applati.get(k).retourneLesContenusEnfants("").isBlank()) {
NbrParagrapheModifier++;
}
}
if(Applati.get(k).getNomElt().contains("draw:frame")) NbrParagrapheModifier++;
if(Applati.get(k).getNomElt().contains("text:list")) NbrParagrapheModifier++;
if(Applati.get(k).getNomElt().contains("text:list-item")) NbrParagrapheModifier++;
}
}
node modificationsMemeDate = new node();
modificationsMemeDate.setNomElt("memeinstant");
modificationsMemeDate.getAttributs().put("date", dcdate1);
modificationsMemeDate.getAttributs().put("nombres_modifications_simultané", String.valueOf(NbrParagrapheModifier));
if(commandes.nombres_modifications_simultané_maxi<NbrParagrapheModifier) {
modificationsMemeDate.getAttributs().put("copier_coller", "true");
nodStudent.getAttributs().put("copier_coller", "true");
}else {
modificationsMemeDate.getAttributs().put("copier_coller", "false");
}
modificationsMemeDate.getAttributs().put("xml:id", xmlid);
modificationsMemeDate.getAttributs().put("type_modification", typeModification);
nodStudent.getNodes().add(modificationsMemeDate);
}
}
if(DateMini==null) DateMini = DcDate1; // Amorçage de la date premère date de modification
if(DateMini!=null && DateMini.after(DcDate1)) DateMini = DcDate1; //recherche la première date de modification
if(lesdates.get(dcdate1)==null) {
lesdates.put(dcdate1, 1);
}else {
int compteur = lesdates.get(dcdate1) + 1;
lesdates.put(dcdate1, compteur);
}
node N1 = HitoriqueDuFichier.get(j).getNodes().get(0);
if(commandes.analyse_exclure_name_creator) {
String author = N1.retourneFirstEnfantsByName("dc:creator").getContenu().toString().toLowerCase();
if(author.equalsIgnoreCase(commandes.analyse_auteur_exclure_historique)) {
continue;
}
}
// Rechercher les correspondances
for(int i2 = 0 ; i2 < LesFichiers2.size(); i2++) {
String nameStudent2 = LesFichiers2.get(i2).getAttributs().get("dossier");
ArrayList<node> HitoriqueDuFichier2 = LesFichiers2.get(i2).retourneEnfantsByName("text:changed-region", new ArrayList<node>());
for(int j2 = 0 ; j2 <HitoriqueDuFichier2.size(); j2++ ) {
String dcdate2 = HitoriqueDuFichier2.get(j2).retourneFirstEnfantsByName("dc:date").getContenu().get(0);
String dccreator2 = HitoriqueDuFichier2.get(j2).retourneFirstEnfantsByName("dc:creator").getContenu().get(0);
node N2 = HitoriqueDuFichier2.get(j2).retourneFirstEnfantsByName(N1.getNomElt());
if(Run.equalNode(N1, N2)) { //Verification des deux nodes de l'historique identiques
if(nodStudent.retourneFirstNodeByNameAndAttributValueExactStrict("correspondance", "date", dcdate2)==null) {
//affinage du match
compteurnombreCorrespondance++;
if(compteurnombreCorrespondancesSuivi==0) {
compteurnombreCorrespondancesSuivi++;
}else {
ArrayList<node> correspondances = nodStudent.retourneEnfantsByName("correspondance", new ArrayList<node>());
node c = correspondances.get(correspondances.size()-1);
if(c.getAttributs().get("Avec_etudiant").equals(nameStudent2)&&c.getAttributs().get("dc:creator").equals(dccreator2)) {
compteurnombreCorrespondancesSuivi++;
if(compteurnombreCorrespondancesconsecutive+1>compteurnombreCorrespondancesconsecutive) compteurnombreCorrespondancesconsecutive++;
}else {
compteurnombreCorrespondancesSuivi=0;
}
}
node correspondance = new node();
correspondance.getNodes().add(N2);
correspondance.setNomElt("correspondance");
correspondance.getAttributs().put("date", dcdate1); // formatDateWriter.DateLibreOffice(DateMini)
correspondance.getAttributs().put("type",N1.getNomElt());
correspondance.getAttributs().put("Avec_etudiant", nameStudent2);
correspondance.getAttributs().put("dc:creator", dccreator2);
nodStudent.getNodes().add(correspondance);
commandes.message.append("\n\t** Trouve une correspondance ** " + dcdate1);
break;
}
}
}
}
}
}
if(compteurnombreCorrespondancesconsecutive>0)compteurnombreCorrespondancesconsecutive++; //C'est histoire des arbres et des intervalles entre les arbres. Il faut ajouter plus 1 au nombre de correspondances consecutives.
nodStudent.getAttributs().put("nombre_correspondance", String.valueOf(compteurnombreCorrespondance));
nodStudent.getAttributs().put("nombre_modifications_date_unique", String.valueOf(lesdates.size()));
nodStudent.getAttributs().put("nombre_correspondances_consecutives", String.valueOf(compteurnombreCorrespondancesconsecutive));
if(DateMini!=null) {
nodStudent.getAttributs().put("first_modification_date", formatDateWriter.DateLibreOffice(DateMini));
}else {
nodStudent.getAttributs().put("first_modification_date", "0000-01-01T00:00:00");
}
verif.getNodes().add(nodStudent);
System.out.println("\tDate de modification date unique " + String.valueOf(lesdates.size()));
commandes.message.append("\n\tDate de modification date unique " + String.valueOf(lesdates.size()));
}
// Ci-dessous le code pour vérifier la première date de modification dans le fichier.
// Recherche dans le node verif
int lastIndex = verif.getNodes().size();
for(int i = 0 ; i < lastIndex;i++) {
String D1 = verif.getNodes().get(i).getAttributs().get("first_modification_date");
boolean trouve =false;
for(int j = 0; j < lastIndex; j++) {
if(i!=j) {
String D2 = verif.getNodes().get(j).getAttributs().get("first_modification_date");
if(!D1.equals("null") && D1.equals(D2)) {
if(verif.getNodes().get(i).getAttributs().get("")==null) {
verif.getNodes().get(i).getAttributs().put("first_modification_identique", verif.getNodes().get(j).getAttributs().get("dossier"));
}else {
verif.getNodes().get(i).getAttributs().put("first_modification_identique_2", verif.getNodes().get(j).getAttributs().get("dossier"));
}
if(verif.getNodes().get(j).getAttributs().get("")==null) {
verif.getNodes().get(j).getAttributs().put("first_modification_identique", verif.getNodes().get(i).getAttributs().get("dossier"));
}else {
verif.getNodes().get(j).getAttributs().put("first_modification_identique_2", verif.getNodes().get(i).getAttributs().get("dossier"));
}
trouve=true;
}
}
}
if(!trouve) {
verif.getNodes().get(i).getAttributs().put("first_modification_identique","null");
}else {
verif.getNodes().get(i).getAttributs().put("plagiat", "probable");
}
//Verification la première date de modification postérieure à la date du contrôle.
if(commandes.analyse_controleDateModificationMini) {
Date dateFirstModifStudent = formatDateWriter.DateLibreOffice(D1);
if(commandes.analyse_modificationDateMini.after(dateFirstModifStudent)) {
verif.getNodes().get(i).getAttributs().put("first_date_modification_anterieur_date_du_controle","true");
}else {
verif.getNodes().get(i).getAttributs().put("first_date_modification_anterieur_date_du_controle","false");
}
}else {
verif.getNodes().get(i).getAttributs().put("first_date_modification_anterieur_date_du_controle","false");
}
}
System.out.println();
System.out.println("** FIN DE LA VERIFIACTION **");
System.out.println();
commandes.message.append("\n** FIN DE LA VERIFICATION **\n");
return verif;
}
}