Ajout de l'analyse d'un avis. Il reste à revoir le programme de

l'interface de manière à utiliser les classes aui existent déja pour ne
pas avoir un gros tas de code dans "inter"
This commit is contained in:
Qpelu 2025-04-03 09:30:20 +02:00
parent 4102a5bacf
commit bbf4a525da
3 changed files with 33 additions and 24 deletions

View File

@ -6,59 +6,64 @@ public class Avis {
private int film; private int film;
private String url; private String url;
public Avis(int f, String u, String com, int pos) {
public Avis(int f,String u, String com, int pos ) {
commentaire = com; commentaire = com;
positif = pos; positif = pos;
film = f; film = f;
url =u; url = u;
} }
public static int Analyse(Avis a, Dictionnaire dico) {
String[] motsCommentaire = a.getCommentaire().split("\\W+");
int total = 0;
for (String m : motsCommentaire) {
m = m.toLowerCase();
m = Dictionnaire.normaliserMot(m);
if (Dictionnaire.isStopWord(m)) continue;
if (!dico.getDico().containsKey(m)) continue;
total += dico.getDico().get(m).getSentiment();
}
return total;
}
public String getCommentaire() { public String getCommentaire() {
return commentaire; return commentaire;
} }
public int getPositif() { public int getPositif() {
return positif; return positif;
} }
public int getFilm() { public int getFilm() {
return film; return film;
} }
public void setCommentaire(String commentaire) { public void setCommentaire(String commentaire) {
this.commentaire = commentaire; this.commentaire = commentaire;
} }
public void setPositif(int positif) { public void setPositif(int positif) {
this.positif = positif; this.positif = positif;
} }
public void setFilm(int film) { public void setFilm(int film) {
this.film = film; this.film = film;
} }
public String toString() { public String toString() {
return "Avis{commentaire='" + commentaire + "', positif=" + positif + ", film=" + film + "}"; return "Avis{commentaire='" + commentaire + "', positif=" + positif + ", film=" + film + "}";
} }
public String getUrl() {
return url;
}
public String getUrl() { public void setUrl(String url) {
return url; this.url = url;
} }
public void setUrl(String url) {
this.url = url;
}
} }

View File

@ -44,7 +44,7 @@ public class Dictionnaire {
} }
} }
private boolean isStopWord(String mot) { public static boolean isStopWord(String mot) {
for (String stopword : STOPWORDS) { for (String stopword : STOPWORDS) {
if (mot.equals(stopword)) { if (mot.equals(stopword)) {
return true; return true;
@ -53,7 +53,7 @@ public class Dictionnaire {
return false; return false;
} }
private String normaliserMot(String mot) { static String normaliserMot(String mot) {
String motSansAccents = Normalizer.normalize(mot, Normalizer.Form.NFD); String motSansAccents = Normalizer.normalize(mot, Normalizer.Form.NFD);
motSansAccents = motSansAccents.replaceAll("[^\\p{ASCII}]", ""); motSansAccents = motSansAccents.replaceAll("[^\\p{ASCII}]", "");
return motSansAccents; return motSansAccents;
@ -71,7 +71,7 @@ public class Dictionnaire {
} }
} }
public Map<String, Mot> getMots() { public Map<String, Mot> getDico() {
return dico; return dico;
} }
} }

View File

@ -10,6 +10,10 @@ public class Main {
Dictionnaire dictionnaire = new Dictionnaire(); Dictionnaire dictionnaire = new Dictionnaire();
Avis a = new Avis(0, "szzn", "salut je suis un gros con", 0);
Avis.Analyse(a, dictionnaire);
dictionnaire.apprentissageSentiment(listeAvis.getListeAvis()); dictionnaire.apprentissageSentiment(listeAvis.getListeAvis());