Browse Source

bouton export + bouton jul + weka

yocj 5 years ago
parent
commit
96ee2a94cf
5 changed files with 40 additions and 18 deletions
  1. 1 1
      .idea/misc.xml
  2. 10 1
      jul.iml
  3. 2 2
      src/main/Jul.java
  4. 9 4
      src/main/View.java
  5. 18 10
      src/main/Weka.java

+ 1 - 1
.idea/misc.xml

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11.0.3" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/out" />
   </component>
 </project>

+ 10 - 1
jul.iml

@@ -18,7 +18,7 @@
     </orderEntry>
     <orderEntry type="library" name="R User Library" level="project" />
     <orderEntry type="library" name="R Skeletons" level="application" />
-    <orderEntry type="module-library" exported="">
+    <orderEntry type="module-library">
       <library>
         <CLASSES>
           <root url="jar://$USER_HOME$/weka.jar!/" />
@@ -27,5 +27,14 @@
         <SOURCES />
       </library>
     </orderEntry>
+    <orderEntry type="module-library">
+      <library>
+        <CLASSES>
+          <root url="jar://C:/Program Files/Weka-3-8-4/weka.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES />
+      </library>
+    </orderEntry>
   </component>
 </module>

+ 2 - 2
src/main/Jul.java

@@ -54,11 +54,11 @@ public class Jul {
         this.chapeau = chapeau;
     }
 
-    public boolean isEstChoisi() {
+    public boolean isChoisi() {
         return choisi;
     }
 
-    public void setEstChoisi(boolean estChoisi) {
+    public void setChoisi(boolean estChoisi) {
         this.choisi = estChoisi;
     }
 }

+ 9 - 4
src/main/View.java

@@ -38,17 +38,17 @@ public class View extends JFrame {
         boutonExport.addActionListener(new ActionListener() {
             @Override
             public void actionPerformed(ActionEvent actionEvent) {
-
+                Weka.traitement(juls);
             }
         });
 
         panimg.setLayout(new GridLayout(5,4));
         for (int i=0;i<20;i++){
+            Jul j = new Jul();
             JButton button = new JButton();
             button.setBackground(Color.RED);
             button.setSize(new Dimension(200,200));
             try {
-                Jul j = new Jul();
                 juls.add(j);
                 ImageJul julImg =  new ImageJul(j);
                 Image iconeJul = julImg.genImage();
@@ -58,8 +58,13 @@ public class View extends JFrame {
                 ex.printStackTrace();
             }
             button.addActionListener(e -> {
-                Color bg = button.getBackground().equals(Color.GREEN) ? Color.RED: Color.GREEN;
-                button.setBackground(bg);
+                if (j.isChoisi()) {
+                    button.setBackground(Color.RED);
+                    j.setChoisi(false);
+                } else {
+                    button.setBackground(Color.GREEN);
+                    j.setChoisi(true);
+                }
 
             });
             panimg.add(button);

+ 18 - 10
src/main/Weka.java

@@ -1,14 +1,12 @@
 package main;
 
-import weka.core.Attribute;
-import weka.core.FastVector;
-import weka.core.Instances;
+import weka.core.*;
 
 import java.util.ArrayList;
 
 public class Weka {
 
-    public static void traitement() {
+    public static void traitement(ArrayList<Jul> juls) {
         // attributs nominaux avec leurs valeurs
         FastVector fvLunettes = new FastVector(3);
         fvLunettes.addElement("vue");
@@ -38,8 +36,8 @@ public class Weka {
         // attribut cible
 
         FastVector fvCible = new FastVector(2);
-        fvCible.addElement("oui");
-        fvCible.addElement("non");
+        fvCible.addElement("true");
+        fvCible.addElement("false");
 
         Attribute cible = new Attribute("cible", fvCible);
 
@@ -54,9 +52,19 @@ public class Weka {
 
 
         // création entrainement
-        int nElem = 0;
-        Instances isTrainingSet = new Instances("Jul", fvJulAttributes, nElem);
-
-        isTrainingSet.setClassIndex(4);
+        Instances isTrainingSet = new Instances("Jul", fvJulAttributes, juls.size());
+
+        isTrainingSet.setClassIndex(isTrainingSet.numAttributes() - 1);
+
+        for (Jul j : juls) {
+           Instance i = new DenseInstance(isTrainingSet.numAttributes());
+           i.setValue((Attribute)fvJulAttributes.elementAt(0), j.getLunettes());
+           i.setValue((Attribute)fvJulAttributes.elementAt(1), j.getMasque());
+           i.setValue((Attribute)fvJulAttributes.elementAt(2), j.getCollier());
+           i.setValue((Attribute)fvJulAttributes.elementAt(3), j.getChapeau());
+           i.setValue((Attribute)fvJulAttributes.elementAt(4), String.valueOf(j.isChoisi()));
+           System.out.println(String.valueOf(j.isChoisi()));
+           isTrainingSet.add(i);
+        }
     }
 }