示例#1
0
        private List <TextClassificationResult> testClassification(string featureDirectoryPath, string resultFile)
        {
            DirectoryInfo directoryInfo  = new DirectoryInfo(featureDirectoryPath + "/TESTINGDATA");
            string        resultFilePath = string.Format("{0}/{1}", featureDirectoryPath, resultFile);
            //List<string> lstFeatures = C45TextClassify.GetListOfFeatures(featureFilePath);
            var data = C45TextClassify.GetFeatureInTable(SelectedFeatures, directoryInfo.FullName, true);

            var lstClasses = c45Tree.ClassArray;

            if (File.Exists(resultFilePath))
            {
                File.Delete(resultFilePath);
            }
            var ff = File.Create(resultFilePath);

            ff.Close();
            List <TextClassificationResult> results = new List <TextClassificationResult>();

            foreach (DataRow row in data.Rows)
            {
                var inputdata = GetInputData(row);

                var output = c45Tree.Decide(inputdata);
                var found  = "UNKNOWN";
                if (output > -1 && output < lstClasses.Count())
                {
                    found = lstClasses[output];
                }
                var expected = row["ResultClass"].ToString();
                var docPath  = row["DocumentPath"].ToString();
                File.AppendAllLines(resultFilePath, new string[] { "Doc:" + Path.GetFileName(docPath) + "Found:" + found + "| Expected: " + expected });
                var result = new TextClassificationResult()
                {
                    DocumentName  = Path.GetFileName(docPath),
                    DocumentPath  = docPath,
                    ExpectedClass = expected,
                    FoundClass    = found
                };
                results.Add(result);
            }
            return(results);
        }