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:
parent
4102a5bacf
commit
bbf4a525da
|
|
@ -6,59 +6,64 @@ public class Avis {
|
|||
private int film;
|
||||
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;
|
||||
positif = pos;
|
||||
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() {
|
||||
return commentaire;
|
||||
}
|
||||
|
||||
|
||||
public int getPositif() {
|
||||
return positif;
|
||||
}
|
||||
|
||||
|
||||
public int getFilm() {
|
||||
return film;
|
||||
}
|
||||
|
||||
|
||||
public void setCommentaire(String commentaire) {
|
||||
this.commentaire = commentaire;
|
||||
}
|
||||
|
||||
|
||||
public void setPositif(int positif) {
|
||||
this.positif = positif;
|
||||
}
|
||||
|
||||
|
||||
public void setFilm(int film) {
|
||||
this.film = film;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String toString() {
|
||||
return "Avis{commentaire='" + commentaire + "', positif=" + positif + ", film=" + film + "}";
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ public class Dictionnaire {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean isStopWord(String mot) {
|
||||
public static boolean isStopWord(String mot) {
|
||||
for (String stopword : STOPWORDS) {
|
||||
if (mot.equals(stopword)) {
|
||||
return true;
|
||||
|
|
@ -53,7 +53,7 @@ public class Dictionnaire {
|
|||
return false;
|
||||
}
|
||||
|
||||
private String normaliserMot(String mot) {
|
||||
static String normaliserMot(String mot) {
|
||||
String motSansAccents = Normalizer.normalize(mot, Normalizer.Form.NFD);
|
||||
motSansAccents = motSansAccents.replaceAll("[^\\p{ASCII}]", "");
|
||||
return motSansAccents;
|
||||
|
|
@ -71,7 +71,7 @@ public class Dictionnaire {
|
|||
}
|
||||
}
|
||||
|
||||
public Map<String, Mot> getMots() {
|
||||
public Map<String, Mot> getDico() {
|
||||
return dico;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,10 @@ public class Main {
|
|||
|
||||
|
||||
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());
|
||||
|
|
|
|||
Loading…
Reference in New Issue