This commit is contained in:
commit
184c5f765c
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/Qpelu/Documents/Eclypse/poi-bin-5.2.3-20220909/poi-bin-5.2.3/lib/commons-codec-1.15.jar"/>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/Qpelu/Documents/Eclypse/poi-bin-5.2.3-20220909/poi-bin-5.2.3/lib/commons-collections4-4.4.jar"/>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/Qpelu/Documents/Eclypse/poi-bin-5.2.3-20220909/poi-bin-5.2.3/lib/commons-io-2.11.0.jar"/>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/Qpelu/Documents/Eclypse/poi-bin-5.2.3-20220909/poi-bin-5.2.3/lib/commons-math3-3.6.1.jar"/>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/Qpelu/Documents/Eclypse/poi-bin-5.2.3-20220909/poi-bin-5.2.3/lib/log4j-api-2.18.0.jar"/>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/Qpelu/Documents/Eclypse/poi-bin-5.2.3-20220909/poi-bin-5.2.3/lib/SparseBitSet-1.2.jar"/>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/Qpelu/Documents/Eclypse/poi-bin-5.2.3-20220909/poi-bin-5.2.3/poi-5.2.3.jar"/>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/Qpelu/Documents/Eclypse/poi-bin-5.2.3-20220909/poi-bin-5.2.3/poi-examples-5.2.3.jar"/>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/Qpelu/Documents/Eclypse/poi-bin-5.2.3-20220909/poi-bin-5.2.3/poi-excelant-5.2.3.jar"/>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/Qpelu/Documents/Eclypse/poi-bin-5.2.3-20220909/poi-bin-5.2.3/poi-javadoc-5.2.3.jar"/>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/Qpelu/Documents/Eclypse/poi-bin-5.2.3-20220909/poi-bin-5.2.3/poi-ooxml-5.2.3.jar"/>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/Qpelu/Documents/Eclypse/poi-bin-5.2.3-20220909/poi-bin-5.2.3/poi-ooxml-full-5.2.3.jar"/>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/Qpelu/Documents/Eclypse/poi-bin-5.2.3-20220909/poi-bin-5.2.3/poi-ooxml-lite-5.2.3.jar"/>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/Qpelu/Documents/Eclypse/poi-bin-5.2.3-20220909/poi-bin-5.2.3/poi-scratchpad-5.2.3.jar"/>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/Qpelu/Documents/Eclypse/poi-bin-5.2.3-20220909/poi-bin-5.2.3/ooxml-lib/commons-compress-1.21.jar"/>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/Qpelu/Documents/Eclypse/poi-bin-5.2.3-20220909/poi-bin-5.2.3/ooxml-lib/commons-logging-1.2.jar"/>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/Qpelu/Documents/Eclypse/poi-bin-5.2.3-20220909/poi-bin-5.2.3/ooxml-lib/curvesapi-1.07.jar"/>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/Qpelu/Documents/Eclypse/poi-bin-5.2.3-20220909/poi-bin-5.2.3/ooxml-lib/jakarta.activation-2.0.1.jar"/>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/Qpelu/Documents/Eclypse/poi-bin-5.2.3-20220909/poi-bin-5.2.3/ooxml-lib/jakarta.xml.bind-api-3.0.1.jar"/>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/Qpelu/Documents/Eclypse/poi-bin-5.2.3-20220909/poi-bin-5.2.3/ooxml-lib/slf4j-api-1.7.36.jar"/>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/Qpelu/Documents/Eclypse/poi-bin-5.2.3-20220909/poi-bin-5.2.3/ooxml-lib/xmlbeans-5.1.1.jar"/>
|
||||||
|
<classpathentry kind="lib" path="C:/Users/Qpelu/Downloads/log4j-core-2.9.1.jar"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
/bin/
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>IA_TP_développement_logiciel</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
encoding/<project>=UTF-8
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=21
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=21
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
package Main;
|
||||||
|
|
||||||
|
public class Avis {
|
||||||
|
private String commentaire;
|
||||||
|
private int positif;
|
||||||
|
private int film;
|
||||||
|
|
||||||
|
|
||||||
|
public Avis(String com, int pos, int f) {
|
||||||
|
commentaire = com;
|
||||||
|
positif = pos;
|
||||||
|
film = f;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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 + "}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,94 @@
|
||||||
|
package Main;
|
||||||
|
|
||||||
|
import java.text.Normalizer;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class Dictionnaire {
|
||||||
|
private Map<String, Mot> dico;
|
||||||
|
|
||||||
|
public Dictionnaire() {
|
||||||
|
dico = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static final String[] STOPWORDS = {
|
||||||
|
"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
|
||||||
|
|
||||||
|
for (String mot : motsCommentaire) {
|
||||||
|
mot = mot.toLowerCase(); // Convertir en minuscule pour éviter les doublons
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
Mot motInfo = dico.get(mot);
|
||||||
|
|
||||||
|
// Incrémenter les apparitions
|
||||||
|
motInfo.incrementerApparitionsTotal();
|
||||||
|
if (positivite > 0) { // Si l'avis est très positif
|
||||||
|
motInfo.incrementerApparitionsPositives();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calcul du pourcentage de positivité pour chaque mot
|
||||||
|
for (Mot mot : dico.values()) {
|
||||||
|
double pourcentagePositivite = 0;
|
||||||
|
if (mot.getApparitionsTotal() > 0) {
|
||||||
|
pourcentagePositivite = (double) mot.getApparitionsPositives() / mot.getApparitionsTotal() * 100;
|
||||||
|
}
|
||||||
|
System.out.println(mot.getNom() + " : Positivité = " + pourcentagePositivite + "%");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vérifie si un mot est un stopword
|
||||||
|
private boolean isStopWord(String mot) {
|
||||||
|
for (String stopword : STOPWORDS) {
|
||||||
|
if (mot.equals(stopword)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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
|
||||||
|
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();
|
||||||
|
Mot motInfo = entry.getValue();
|
||||||
|
double pourcentagePositivite = 0;
|
||||||
|
if (motInfo.getApparitionsTotal() > 0) {
|
||||||
|
pourcentagePositivite = (double) motInfo.getApparitionsPositives() / motInfo.getApparitionsTotal() * 100;
|
||||||
|
}
|
||||||
|
System.out.println(mot + " : Positivité = " + pourcentagePositivite + "%");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Récupérer la liste des mots
|
||||||
|
public Map<String, Mot> getMots() {
|
||||||
|
return dico;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,85 @@
|
||||||
|
package Main;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.*;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ListeAvis {
|
||||||
|
private List<Avis> listeAvis;
|
||||||
|
private int colCommentaire;
|
||||||
|
private int colPositivite;
|
||||||
|
private int colFilm;
|
||||||
|
|
||||||
|
// Constructeur qui charge le fichier Excel
|
||||||
|
public ListeAvis(String aPath) {
|
||||||
|
listeAvis = new ArrayList<>();
|
||||||
|
colCommentaire = 2;
|
||||||
|
colPositivite = 3;
|
||||||
|
colFilm = 4;
|
||||||
|
lireExcel(aPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fonction qui lit le fichier Excel et charge les avis
|
||||||
|
private void lireExcel(String filePath) {
|
||||||
|
try (FileInputStream fis = new FileInputStream(new File(filePath));
|
||||||
|
Workbook workbook = new XSSFWorkbook(fis)) {
|
||||||
|
|
||||||
|
Sheet sheet = workbook.getSheetAt(0); // On prend la première feuille
|
||||||
|
System.out.println("Fichier Excel chargé avec succès!");
|
||||||
|
|
||||||
|
for (Row row : sheet) {
|
||||||
|
if (row.getRowNum() == 0) continue; // Ignorer la première ligne (en-têtes)
|
||||||
|
|
||||||
|
// Extraction des données
|
||||||
|
String commentaire = getCellValue(row.getCell(colCommentaire));
|
||||||
|
int positivite = getIntCellValue(row.getCell(colPositivite));
|
||||||
|
int film = getIntCellValue(row.getCell(colFilm));
|
||||||
|
|
||||||
|
// Ajout de l'avis à la liste
|
||||||
|
listeAvis.add(new Avis(commentaire, positivite, film));
|
||||||
|
|
||||||
|
// Affichage pour débogage
|
||||||
|
System.out.println("Commentaire: " + commentaire);
|
||||||
|
System.out.println("Positivité: " + positivite);
|
||||||
|
System.out.println("Film: " + film);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fonction pour récupérer la valeur d'une cellule sous forme de String
|
||||||
|
private String getCellValue(Cell cell) {
|
||||||
|
if (cell == null) return "";
|
||||||
|
if (cell.getCellType() == CellType.STRING) {
|
||||||
|
return cell.getStringCellValue();
|
||||||
|
} else if (cell.getCellType() == CellType.NUMERIC) {
|
||||||
|
return String.valueOf((int) cell.getNumericCellValue());
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fonction pour récupérer la valeur d'une cellule sous forme d'entier
|
||||||
|
private int getIntCellValue(Cell cell) {
|
||||||
|
if (cell == null || cell.getCellType() != CellType.NUMERIC) return 0;
|
||||||
|
return (int) cell.getNumericCellValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<Avis> getListeAvis() {
|
||||||
|
return listeAvis;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void afficherAvis() {
|
||||||
|
for (Avis avis : listeAvis) {
|
||||||
|
System.out.println("Commentaire: " + avis.getCommentaire());
|
||||||
|
System.out.println("Positivité: " + avis.getPositif());
|
||||||
|
System.out.println("Film: " + avis.getFilm());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
package Main;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
String cheminFichierExcel = "C:\\Users\\Qpelu\\Downloads\\test_avis.xlsx";
|
||||||
|
ListeAvis listeAvis = new ListeAvis(cheminFichierExcel);
|
||||||
|
|
||||||
|
|
||||||
|
Dictionnaire dictionnaire = new Dictionnaire();
|
||||||
|
|
||||||
|
|
||||||
|
dictionnaire.apprentissageSentiment(listeAvis.getListeAvis());
|
||||||
|
|
||||||
|
|
||||||
|
dictionnaire.afficherMotsAnalyzes();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
package Main;
|
||||||
|
|
||||||
|
public class Mot {
|
||||||
|
private String nom;
|
||||||
|
private int sentiment;
|
||||||
|
private int apparitionsTotal;
|
||||||
|
private int apparitionsPositives;
|
||||||
|
|
||||||
|
public Mot(String nom, int sentiment) {
|
||||||
|
this.nom = nom;
|
||||||
|
this.sentiment = sentiment;
|
||||||
|
this.apparitionsTotal = 0;
|
||||||
|
this.apparitionsPositives = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNom() {
|
||||||
|
return nom;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSentiment() {
|
||||||
|
return sentiment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSentiment(double sentiment) {
|
||||||
|
this.sentiment = (int) (sentiment * 100); // Enregistrer le sentiment comme un pourcentage
|
||||||
|
}
|
||||||
|
|
||||||
|
public void incrementerApparitionsTotal() {
|
||||||
|
this.apparitionsTotal++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void incrementerApparitionsPositives() {
|
||||||
|
this.apparitionsPositives++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getApparitionsTotal() {
|
||||||
|
return apparitionsTotal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getApparitionsPositives() {
|
||||||
|
return apparitionsPositives;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Mot{nom='" + nom + "', sentiment=" + sentiment + ", apparitionsTotal=" + apparitionsTotal + ", apparitionsPositives=" + apparitionsPositives + "}";
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue