예제 #1
0
        public static void PerformClassification(string tifFileName, double minConfOut, out ClassifyResult resultClassify, out string resultfilename)
        {
            List <DocumentData> docs = new List <DocumentData>();

            DocumentData doc;

            DocumentsLoader.GetAllDocuemntPRDTIFOnly(tifFileName, out doc);
            docs.Add(doc);
            ClassifyService.PrepareCandidates(docs, modelData.FieldsSelectedNames.ToArray());

            ClassifyService.getDocFeatures(doc, null, null, null, new List <int>(), false, null, true, false);

            ClassifyService.level1RunTestForLevel2(docs, modelData.FieldsSelectedNames.ToArray(), AddConsoleMessage);

            resultClassify = new ClassifyResult();

            resultClassify.Items = new ClassifyResultField[modelData.FieldsSelectedNames.ToArray().Length];

            foreach (var r in modelData.FieldsSelectedNames.ToArray().Select((x, i) => new { Value = x, Index = i }))
            {
                List <CandidateData> candidatesforField = docs[0].Candidates.OrderByDescending(a => a.AccordConfidance[r.Index]).Take(4).Where(b => b.AccordConfidance[r.Index] > minConfOut).ToList();
                resultClassify.Items[r.Index]    = new ClassifyResultField();
                resultClassify.Items[r.Index].id = r.Value;
                if (candidatesforField.Any())
                {
                    resultClassify.Items[r.Index].candidates = new ClassifyResultFieldCandidatesCandidate[candidatesforField.Count];
                    for (int i = 0; i < candidatesforField.Count; i++)
                    {
                        resultClassify.Items[r.Index].candidates[i]            = new ClassifyResultFieldCandidatesCandidate();
                        resultClassify.Items[r.Index].candidates[i].value      = candidatesforField[i].Content;
                        resultClassify.Items[r.Index].candidates[i].confidance = candidatesforField[i].AccordConfidance[r.Index].ToString();
                    }
                }
            }



            var fileName = Path.GetFileNameWithoutExtension(tifFileName);
            var dirName  = Path.GetDirectoryName(tifFileName);

            resultfilename = Path.Combine(dirName, fileName + ".xml");

            System.Xml.Serialization.XmlSerializer writer = new System.Xml.Serialization.XmlSerializer(typeof(ClassifyResult));

            using (System.IO.StreamWriter file = new System.IO.StreamWriter(resultfilename))
            {
                writer.Serialize(file, resultClassify);
            }
        }
예제 #2
0
        private void AddFolder(string folderName, string className = "")
        {
            ObservableCollection <DocumentData> tempList = new ObservableCollection <DocumentData>();

            tempList.CollectionChanged += tempList_CollectionChanged;
            DocumentsLoader.GetAllDocuemntsNew(folderName, tempList);
            foreach (var doc in tempList)
            {
                SetupData.AddPage(new PageData()
                {
                    Setup = new PageSetupData()
                    {
                        FileName = doc.ImageSource, PageNo = 1
                    }, DocData = doc
                });
            }

            SetupData.RemoveBadFields(_filterFields);

            AddConsoleMessage("Done loading Documents");
        }
        //--------------------------------------------------------------------------
        public void InsertDocuments()
        {
            OpenFileDialog documentFilesPicker = new OpenFileDialog();

            documentFilesPicker.Title            = "Select document files";
            documentFilesPicker.Multiselect      = true;
            documentFilesPicker.Filter           = "txt files (*.txt)|*.txt";
            documentFilesPicker.FilterIndex      = 1;
            documentFilesPicker.RestoreDirectory = true;

            if (documentFilesPicker.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            // start loading
            _documentsLoader =
                new DocumentsLoader(documentFilesPicker.FileNames, _businessLogic);
            if (!_documentsLoader.HasDocumentToProcess)
            {
                return;
            }

            if (!_documentsLoader.Load(_businessLogic))
            {
                System.Windows.Forms.MessageBox.Show(
                    "Failed loading ALL documents!", "Error");
                return;
            }

            _currentLoadingScreen = new LoadingScreenDialog(
                "Loading documents ...", true);
            _currentLoadingScreen.ShowDialog();

            // show report
            ReportDialog report = new ReportDialog(_documentsLoader.DocumentsStatus);

            report.ShowDialog();
        }