Exemplo n.º 1
0
        public void AddItem()
        {
            // arrange
            List <string> featureNames = new List <string> {
                "F1", "F2", "F3"
            };
            ItemNumericalSet set = new ItemNumericalSet(featureNames);

            // act
            FeatureNumericalValue[] arr = new FeatureNumericalValue[3] {
                new FeatureNumericalValue {
                    FeatureName = "F1", FeatureValue = 1.1
                },
                new FeatureNumericalValue {
                    FeatureName = "F2", FeatureValue = 1.2
                },
                new FeatureNumericalValue {
                    FeatureName = "F3", FeatureValue = 1.3
                }
            };
            ItemNumerical item = set.AddItem(arr);

            // assert
            Assert.IsNotNull(item);
            Assert.AreEqual(true, item.HasValue("F1") & item.HasValue("F2") & item.HasValue("F3"));
            Assert.AreEqual(1.3, item.GetValue("F3"));
        }
Exemplo n.º 2
0
        public void GetSeparateValue_ItemSetFeatures4Items15_ReturnsSeparateValue()
        {
            // arrange
            FillItemSet_Features4_Items15();
            ISplitter splitter = new SplitterRss();

            // act
            FeatureNumericalValue sv = splitter.Split(_set, "F1");
            double fv = Math.Round(sv.FeatureValue, 2);

            // assert
            Assert.IsNotNull(sv);
        }
Exemplo n.º 3
0
        public static ItemNumericalSet ParseItemNumericalSet(string path, int sheetNo = 1)
        {
            FileInfo fi = new FileInfo(path);

            if (!fi.Exists)
            {
                throw new FileNotFoundException();
            }


            OfficeOpenXml.ExcelPackage xls = new OfficeOpenXml.ExcelPackage(fi);
            var sheet = xls.Workbook.Worksheets[sheetNo];

            int cols = sheet.Dimension.End.Column;
            int rows = sheet.Dimension.End.Row;

            List <string> featureNames = new List <string>();

            for (int j = 1; j <= cols; j++)
            {
                var fn = sheet.Cells[1, j].Value;
                if (fn == null)
                {
                    throw new Exception();
                }
                string str = fn.ToString();
                if (string.IsNullOrEmpty(str))
                {
                    throw new Exception();
                }
                featureNames.Add(str);
            }

            ItemNumericalSet set = new ItemNumericalSet(featureNames);

            for (int i = 2; i <= rows; i++)
            {
                FeatureNumericalValue[] arr = new FeatureNumericalValue[cols];
                for (int j = 1; j <= cols; j++)
                {
                    var v = sheet.Cells[i, j].Value;
                    arr[j - 1] = new FeatureNumericalValue {
                        FeatureName = featureNames[j - 1], FeatureValue = Convert.ToDouble(v)
                    };
                }
                set.AddItem(arr);
            }

            return(set);
        }
Exemplo n.º 4
0
        public void GetSeparateValue_ItemSetFeatures2Items5_ReturnsSeparateValue()
        {
            // arrange
            string f1 = "F1";
            string f2 = "F2";
            FeatureNumericalManager featureManager = new FeatureNumericalManager();

            featureManager.Add(new FeatureNumerical(f1));
            featureManager.Add(new FeatureNumerical(f2));
            _set = new ItemNumericalSet(featureManager);

            int[] a1 = new int[5] {
                1, 2, 3, 4, 5
            };
            float[] a2 = new float[5] {
                1f, 0.2f, 2.3f, 4.1f, 4f
            };
            for (int i = 0; i < 5; i++)
            {
                ItemNumerical item = _set.CreateItem();
                item.SetValue(f1, a1[i]);
                item.SetValue(f2, a2[i]);
                _set.AddItem(item);
            }

            ISplitter splitter = new SplitterRss();

            // act
            FeatureNumericalValue sv = splitter.Split(_set, "F1");
            double fv = Math.Round(sv.FeatureValue, 2);

            // assert
            Assert.IsNotNull(sv);
            //Assert.AreEqual(3.15, fv);
            Assert.AreEqual(1.65, fv);
        }