Ejemplo n.º 1
0
        public void onClassificationFinish(object classificationRes, string name)
        {
            Classifier.ClassificationResult classificationResult = classificationRes as Classifier.ClassificationResult;
            SetViewEnabled(true);
            //LabelWait.Content = "";
            if (classificationResult.DocumentClassificationRestult != null)
            {
                LabelClassifiedAs.Content = "classified as:";

                ClassifiedPdfModel newModel = new ClassifiedPdfModel();

                foreach (var documentClassResult in classificationResult.DocumentClassificationRestult)
                {
                    ClassifiedItem newItem = new ClassifiedItem();
                    newItem.Category = documentClassResult.First as string;
                    newItem.Compatibility = documentClassResult.Second.ToString();

                    //  abstract classification result
                    if (classificationResult.AbstractClassificationRestult != null)
                    {
                        Double abstractCompatibilty;
                        if (classificationResult.AbstractClassificationRestult.TryGetValue(documentClassResult.First, out abstractCompatibilty))
                        {
                            newItem.CompatibilityAbstract = abstractCompatibilty.ToString();
                        }
                    }

                    newModel.AddClassificationData( newItem );
                    //ListBoxClassificationResult.Items.Add(i + ". " + classResult.First + "\t\t\t\t" + classResult.Second);
                }

                classifiedDocuments.AddPdfModel( pdfsDirectoryTextBox.Text, name, newModel );
                ListBoxClassificationResult.DataContext = newModel;
            }
            else
            {
                LabelClassifiedAs.Content = "classification failed";
            }
        }
Ejemplo n.º 2
0
        void DoWorkClassifyAll( object sender, DoWorkEventArgs e )
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            string directory = e.Argument as string;
            var dirInfo = new DirectoryInfo( directory );
            FileInfo[] infos = dirInfo.GetFiles( "*.pdf" );

            var numPDFs = infos.Length;
            int progress = 0;

            foreach ( var fileInfo in infos )
            {
                string fullPath = classifiedDocuments.MakePath( directory, fileInfo.Name );
                string extension = System.IO.Path.GetExtension( fullPath );

                if ( extension == ".pdf" )
                {
                    org.pdfclown.files.File file = new org.pdfclown.files.File( fullPath );
                    document = file.Document;
                    if ( document == null )
                        continue;

                    try
                    {
                        string abstractFileName = fullPath.Replace(".pdf", ".abstract");
                        string abstractFileContent = System.IO.File.ReadAllText(abstractFileName);
                        abstractContent = abstractFileContent;
                    }
                    catch (Exception exception)
                    {
                        abstractContent = null;
                        Utility.Log("file " + fullPath + " loaded without an abstract...");
                    }

                    Utility.Log("Classifing " + fullPath);

                    var classificationResult = classifier.Classify( document, abstractContent );
                    if (classificationResult.DocumentClassificationRestult != null)
                    {
                        ClassifiedPdfModel newModel = new ClassifiedPdfModel();

                        foreach ( var documentClassResult in classificationResult.DocumentClassificationRestult )
                        {
                            ClassifiedItem newItem = new ClassifiedItem();
                            newItem.Category = documentClassResult.First as string;
                            newItem.Compatibility = documentClassResult.Second.ToString();

                            //  abstract classification result
                            if (classificationResult.AbstractClassificationRestult != null)
                            {
                                Double abstractCompatibilty;
                                if (classificationResult.AbstractClassificationRestult.TryGetValue(documentClassResult.First, out abstractCompatibilty))
                                {
                                    newItem.CompatibilityAbstract = abstractCompatibilty.ToString();
                                }
                            }

                            newModel.AddClassificationData( newItem );
                        }

                        classifiedDocuments.AddPdfModel( directory, fileInfo.Name, newModel );
                    }

                    worker.ReportProgress( (int)( 100 * progress++ / (double)numPDFs ) );
                }
            }
        }
 public void AddClassificationData( ClassifiedItem newItem )
 {
     Items.Add( newItem );
 }