je commence à faire le lien entre le dico et votre partie
This commit is contained in:
parent
bbf4a525da
commit
40a222510c
|
|
@ -25,6 +25,7 @@ public class Avis {
|
|||
if (!dico.getDico().containsKey(m)) continue;
|
||||
|
||||
total += dico.getDico().get(m).getSentiment();
|
||||
System.out.println(total);
|
||||
}
|
||||
|
||||
return total;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package Main;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.text.Normalizer;
|
||||
|
|
@ -14,6 +16,39 @@ public class Dictionnaire {
|
|||
public Dictionnaire() {
|
||||
dico = new HashMap<>();
|
||||
}
|
||||
|
||||
public Dictionnaire(String path) {
|
||||
dico = new HashMap<>();
|
||||
try (BufferedReader br = new BufferedReader(new FileReader(path))) {
|
||||
String ligne;
|
||||
br.readLine(); // Ignore l'en-tête
|
||||
|
||||
while ((ligne = br.readLine()) != null) {
|
||||
String[] valeurs = ligne.split(",", 4);
|
||||
|
||||
|
||||
if (valeurs.length != 4) {
|
||||
System.err.println("Ligne ignorée (format incorrect) : " + ligne);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
String nom = valeurs[0].trim();
|
||||
int sentiment = Integer.parseInt(valeurs[3].trim());
|
||||
int apparitionsTotal = Integer.parseInt(valeurs[1].trim());
|
||||
int apparitionsPositives = Integer.parseInt(valeurs[2].trim());
|
||||
Mot m = new Mot(nom, sentiment, apparitionsTotal, apparitionsPositives);
|
||||
dico.put(nom,m);
|
||||
System.out.println( m.toString());
|
||||
} catch (NumberFormatException e) {
|
||||
System.err.println("Erreur de conversion dans la ligne : " + ligne);
|
||||
}
|
||||
}
|
||||
System.out.println("Fichier CSV chargé avec succès !");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static final String[] STOPWORDS = {
|
||||
"je", "un", "de", "et", "la", "le", "les", "en", "à", "c'est", "pour", "que", "des", "du", "une",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
package Main;
|
||||
|
||||
|
||||
public class Export {
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -3,7 +3,7 @@ package Main;
|
|||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
|
||||
String cheminFichierExcel = "C:\\Users\\Qpelu\\Downloads\\big.csv";
|
||||
/* String cheminFichierExcel = "C:\\Users\\Qpelu\\Downloads\\big.csv";
|
||||
String cheminSauvegarde = "C:\\Users\\Qpelu\\Downloads\\dictionnaire.csv";
|
||||
|
||||
ListeAvis listeAvis = new ListeAvis(cheminFichierExcel);
|
||||
|
|
@ -20,5 +20,7 @@ public class Main {
|
|||
|
||||
dictionnaire.sauvegarderDictionnaireCSV(cheminSauvegarde);
|
||||
|
||||
}
|
||||
}*/Dictionnaire d =new Dictionnaire("C:\\Users\\Qpelu\\Downloads\\dictionnaire.csv");
|
||||
System.out.println(d);
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,12 @@ public class Mot {
|
|||
this.apparitionsTotal = 0;
|
||||
this.apparitionsPositives = 0;
|
||||
}
|
||||
public Mot(String nom, int sentiment, int apparitionsTotal,int apparitionsPositives) {
|
||||
this.nom = nom;
|
||||
this.sentiment = sentiment;
|
||||
this.apparitionsTotal = apparitionsTotal;
|
||||
this.apparitionsPositives = apparitionsPositives;
|
||||
}
|
||||
|
||||
public String getNom() {
|
||||
return nom;
|
||||
|
|
|
|||
|
|
@ -197,7 +197,7 @@ public class inter extends JFrame {
|
|||
/**
|
||||
* Analyse un commentaire et calcule une note sur 5
|
||||
*/
|
||||
private int analyserCommentaire(String commentaire) {
|
||||
/*private int analyserCommentaire(String commentaire) {
|
||||
if (commentaire == null || commentaire.trim().isEmpty()) {
|
||||
return 3; // Note moyenne par défaut
|
||||
}
|
||||
|
|
@ -227,12 +227,14 @@ public class inter extends JFrame {
|
|||
|
||||
// Limiter entre 1 et 5
|
||||
return Math.max(1, Math.min(5, note));
|
||||
}
|
||||
}/*
|
||||
|
||||
/**
|
||||
* Calcule la note moyenne d'un film basée sur tous ses commentaires
|
||||
*/
|
||||
private int calculerNoteMoyenne(int filmNumber) {
|
||||
|
||||
Dictionnaire dico = new Dictionnaire();
|
||||
List<String> commentaires = commentairesFilms.get(filmNumber);
|
||||
|
||||
if (commentaires == null || commentaires.isEmpty()) {
|
||||
|
|
@ -242,7 +244,9 @@ public class inter extends JFrame {
|
|||
int totalNotes = 0;
|
||||
|
||||
for (String commentaire : commentaires) {
|
||||
totalNotes += analyserCommentaire(commentaire);
|
||||
Avis com =new Avis(filmNumber,"cd",commentaire,0);
|
||||
totalNotes += Avis.Analyse(com, dico);
|
||||
System.out.println(totalNotes);
|
||||
}
|
||||
|
||||
return Math.round((float) totalNotes / commentaires.size());
|
||||
|
|
|
|||
Loading…
Reference in New Issue