V1.1
This commit is contained in:
parent
184c5f765c
commit
6a34deb43b
|
|
@ -17,37 +17,36 @@ public class Dictionnaire {
|
|||
"je", "un", "de", "et", "la", "le", "les", "en", "à", "c'est", "pour", "que", "des", "du", "une", "il", "elle", "nous", "vous", "ils", "elles", "ce", "cela", "mais", "est", "dans"
|
||||
};
|
||||
|
||||
// Méthode d'apprentissage du sentiment basée sur les avis
|
||||
|
||||
public void apprentissageSentiment(List<Avis> listeAvis) {
|
||||
for (Avis avis : listeAvis) {
|
||||
int positivite = avis.getPositif(); // On récupère la positivité de l'avis
|
||||
String[] motsCommentaire = avis.getCommentaire().split("\\W+"); // Séparer le commentaire en mots
|
||||
|
||||
int positivite = avis.getPositif();
|
||||
String[] motsCommentaire = avis.getCommentaire().split("\\W+");
|
||||
for (String mot : motsCommentaire) {
|
||||
mot = mot.toLowerCase(); // Convertir en minuscule pour éviter les doublons
|
||||
mot = mot.toLowerCase();
|
||||
|
||||
// Normaliser le mot pour éliminer les accents
|
||||
|
||||
mot = normaliserMot(mot);
|
||||
|
||||
// Ignorer les stopwords (mots inutiles)
|
||||
|
||||
if (isStopWord(mot)) continue;
|
||||
|
||||
// Ajouter le mot au dictionnaire s'il n'existe pas déjà
|
||||
|
||||
if (!dico.containsKey(mot)) {
|
||||
dico.put(mot, new Mot(mot, 0)); // Créer un nouveau mot avec un sentiment initial de 0
|
||||
dico.put(mot, new Mot(mot, 0));
|
||||
}
|
||||
|
||||
Mot motInfo = dico.get(mot);
|
||||
|
||||
// Incrémenter les apparitions
|
||||
|
||||
motInfo.incrementerApparitionsTotal();
|
||||
if (positivite > 0) { // Si l'avis est très positif
|
||||
if (positivite > 0) {
|
||||
motInfo.incrementerApparitionsPositives();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Calcul du pourcentage de positivité pour chaque mot
|
||||
|
||||
for (Mot mot : dico.values()) {
|
||||
double pourcentagePositivite = 0;
|
||||
if (mot.getApparitionsTotal() > 0) {
|
||||
|
|
@ -57,7 +56,7 @@ public class Dictionnaire {
|
|||
}
|
||||
}
|
||||
|
||||
// Vérifie si un mot est un stopword
|
||||
|
||||
private boolean isStopWord(String mot) {
|
||||
for (String stopword : STOPWORDS) {
|
||||
if (mot.equals(stopword)) {
|
||||
|
|
@ -67,14 +66,14 @@ public class Dictionnaire {
|
|||
return false;
|
||||
}
|
||||
|
||||
// Normaliser les mots pour enlever les accents
|
||||
|
||||
private String normaliserMot(String mot) {
|
||||
String motSansAccents = Normalizer.normalize(mot, Normalizer.Form.NFD);
|
||||
motSansAccents = motSansAccents.replaceAll("[^\\p{ASCII}]", ""); // Supprime les caractères non-ASCII
|
||||
motSansAccents = motSansAccents.replaceAll("[^\\p{ASCII}]", "");
|
||||
return motSansAccents;
|
||||
}
|
||||
|
||||
// Méthode pour afficher tous les mots analysés et leur positivité
|
||||
|
||||
public void afficherMotsAnalyzes() {
|
||||
for (Map.Entry<String, Mot> entry : dico.entrySet()) {
|
||||
String mot = entry.getKey();
|
||||
|
|
@ -87,7 +86,7 @@ public class Dictionnaire {
|
|||
}
|
||||
}
|
||||
|
||||
// Récupérer la liste des mots
|
||||
|
||||
public Map<String, Mot> getMots() {
|
||||
return dico;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public class Mot {
|
|||
}
|
||||
|
||||
public void setSentiment(double sentiment) {
|
||||
this.sentiment = (int) (sentiment * 100); // Enregistrer le sentiment comme un pourcentage
|
||||
this.sentiment = (int) (sentiment * 100);
|
||||
}
|
||||
|
||||
public void incrementerApparitionsTotal() {
|
||||
|
|
@ -41,7 +41,7 @@ public class Mot {
|
|||
return apparitionsPositives;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public String toString() {
|
||||
return "Mot{nom='" + nom + "', sentiment=" + sentiment + ", apparitionsTotal=" + apparitionsTotal + ", apparitionsPositives=" + apparitionsPositives + "}";
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue