Ejemplo n.º 1
0
        private void btnLoad_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog d = new OpenFileDialog())
            {
                d.Filter = "Arff File|*.arff";
                if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    var fileReader = new java.io.FileReader(d.FileName);
                    var instances  = new weka.core.Instances(new java.io.BufferedReader(fileReader));
                    instances.setClassIndex(instances.numAttributes() - 1);
                    fileReader.close();

                    clear_all();
                    foreach (weka.core.Instance i in instances)
                    {
                        var p = new valuePoint(i.value(0), i.value(1), (int)i.classValue());
                        if (p.x < 0 || p.x >= 1 || p.y < 0 || p.y >= 1)
                        {
                            continue;
                        }
                        point_list.Add(p);
                    }
                    draw_all_points();
                    this.pictureBox1.Invalidate();
                }
            }
        }
Ejemplo n.º 2
0
        public static Instances LoadInstances(string fileName)
        {
            lock (m_lockObject)
            {
                if (!fileName.Contains("\\"))
                {
                    fileName = string.Format("{0}\\{1}", TestParameters.BaseDir, fileName);
                }
                var       fr        = new java.io.FileReader(fileName);
                var       br        = new java.io.BufferedReader(fr);
                Instances instances = new Instances(br);
                br.close();
                fr.close();
                instances.setClassIndex(instances.numAttributes() - 1);

                return(instances);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 日本語アナライザ初期化処理
        /// </summary>
        private static void InitializeAnalyzer()
        {
            string sqliteDataSource = Directory.GetParent(Application.ExecutablePath).FullName +
                                      Properties.Settings.Default.SQLITE_DATA_SOURCE;

            AppObject.ConnectString = AppObject.GetConnectString(sqliteDataSource);

            //ユーザ辞書の設定
            AppObject.RootDirPath  = Directory.GetParent(Application.ExecutablePath).FullName;
            AppObject.RootDirPath += LuceneIndexBuilder.StoreDirName;

            //Analyzer
            java.io.Reader treader = new java.io.FileReader(AppObject.RootDirPath + @".\..\UserDictionary.txt");
            UserDictionary userDic = null;

            try {
                //ユーザ辞書
                userDic = UserDictionary.Open(treader);
            } finally {
                treader.close();
            }

            AppObject.AppAnalyzer = new JapaneseAnalyzer(userDic, //ユーザ定義辞書
                                                         JapaneseTokenizerMode.SEARCH,
                                                         JapaneseAnalyzer.GetDefaultStopSet(),
                                                         JapaneseAnalyzer.GetDefaultStopTags());
            //JapaneseTokenizerMode.EXTENDED;
            // ->拡張モードは、未知の単語のユニグラムを出力します。
            //JapaneseTokenizerMode.NORMAL;
            // ->通常のセグメンテーション:化合物の分解なし
            //JapaneseTokenizerMode.SEARCH;
            // ->検索を対象としたセグメンテーション:
            //   これには、長い名詞の複合化プロセスが含まれ、同義語としての完全な複合トークンも含まれます。

            //AppObject.AppAnalyzer = new JapaneseAnalyzer();
        }
Ejemplo n.º 4
0
        private void btnLoad_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog d = new OpenFileDialog())
            {
                d.Filter = "Arff File|*.arff";
                if (d.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    var fileReader = new java.io.FileReader(d.FileName);
                    var instances = new weka.core.Instances(new java.io.BufferedReader(fileReader));
                    instances.setClassIndex(instances.numAttributes() - 1);
                    fileReader.close();

                    clear_all();
                    foreach (weka.core.Instance i in instances)
                    {
                        var p = new valuePoint(i.value(0), i.value(1), (int)i.classValue());
                        if (p.x < 0 || p.x >= 1 || p.y < 0 || p.y >= 1)
                            continue;
                        point_list.Add(p);
                    }
                    draw_all_points();
                    this.pictureBox1.Invalidate();
                }
            }
        }
Ejemplo n.º 5
0
        public void classifyTest()
        {
            try
            {
                CSV2Arff();
                java.io.FileReader  arrfFile = new java.io.FileReader("D:/final_version/Gesture-Gis-master/GestureGis2/ComparisonFeaturefile.arff");
                weka.core.Instances insts    = new weka.core.Instances(arrfFile);
                //weka.core.Instances insts2 = new weka.core.Instances(new java.io.FileReader("D:/Gesture-Gis-master/GestureGis2/ComparisonFeaturefile.arff"));
                insts.setClassIndex(insts.numAttributes() - 1);

                //int percentSplit = 66;

                weka.classifiers.Classifier cl = new weka.classifiers.trees.J48();
                //Console.WriteLine("Performing " + percentSplit + "% split evaluation.");

                //randomize the order of the instances in the dataset.
                //weka.filters.Filter myRandom = new weka.filters.unsupervised.instance.Randomize();
                //myRandom.setInputFormat(insts);
                //insts = weka.filters.Filter.useFilter(insts, myRandom);
                int count                 = insts.numInstances();
                int trainSize             = count - 1;
                int testSize              = count - trainSize;
                weka.core.Instances train = new weka.core.Instances(insts, 0, trainSize);

                cl.buildClassifier(train);
                //weka.core.Instance current = insts2.instance(0);
                int numCorrect = 0;

                /*for (int i = trainSize; i < insts.numInstances(); i++)
                 * {
                 *  weka.core.Instance currentInst = insts.instance(i);
                 *  double predictedClass = cl.classifyInstance(currentInst);
                 *  if (predictedClass == insts.instance(i).classValue())
                 *      numCorrect++;
                 * }*/
                int index = count - 1;
                weka.core.Instance currentInst    = insts.instance(index);
                double             predictedClass = cl.classifyInstance(currentInst);
                int pre = (int)predictedClass;
                if (predictedClass == insts.instance(index).classValue())
                {
                    numCorrect++;
                }
                //insts.instance(index).classAttribute();
                //insts.attribute(11);
                string s = insts.toString();
                s = s.Substring(s.IndexOf("{") + 1);
                s = s.Substring(0, s.IndexOf("}"));
                s = s.Substring(0, s.Length);
                string[] ae = s.Split(',');

                /*ArrayList arr = new ArrayList();
                 * string path_class = @"D:\final_version\Gesture-Gis-master\GestureGis2\Classfile.txt";
                 * using (StreamReader reader = new StreamReader(path_class))
                 * {
                 *  while (!reader.EndOfStream)
                 *  {
                 *      arr.Add(reader.ReadLine());
                 *  }
                 *  reader.Close();
                 * }*/
                PredictedClassbyWeka = (string)(ae[pre]);
                arrfFile.close();

                //insts.instance(index).attribute(3);

                /*System.Diagnostics.Debug.WriteLine(numCorrect + " out of " + testSize + " correct (" +
                 *         (double)((double)numCorrect / (double)testSize * 100.0) + "%)");
                 * Console.WriteLine(numCorrect + " out of " + testSize + " correct (" +
                 *         (double)((double)numCorrect / (double)testSize * 100.0) + "%)");*/
            }
            catch (java.lang.Exception ex)
            {
                ex.printStackTrace();
            }
        }