Пример #1
0
        /// <summary>
        /// Dodaje listê dokumentów na podstawie katalogu z plikami w postaci s³owo, iloœæ wyst¹pieñ.
        /// </summary>
        /// <param name="sourceDir">Katalog z plikami.</param>
        /// <param name="dictionary">Rodzaj s³ownika, który ma byæ u¿yty do tworzenia nowych dokumentów.</param>
        /// <param name="drt">Rodzaj dokumentów.</param>
        /// <param name="className">Nazwa klasy, do której maj¹ nale¿eæ wszystkie nowo dodane elementu lub null, jeœli klasa jest nieznana.</param>
        /// <param name="learningDocInfo">Obiekt zawieraj¹cy informacje o wszystkich dokumentach ucz¹cych.
        /// Je¿eli dana reprezentacja nie potrzebuje tego obiektu, parametr jest ignorowany.</param>
        public void AddDocumentsFromDir(String sourceDir, Dictionary dictionary, DocumentRepresentationType drt, String className, LearningDocInfo learningDocInfo)
        {
            CheckCorrectness(drt, dictionary.GetDictionaryType());

            Console.WriteLine("Adding dir: " + sourceDir);

            DirectoryInfo sourceDirInfo = new DirectoryInfo(sourceDir);

            foreach (FileInfo fileInfo in sourceDirInfo.GetFiles())
            {
                Console.WriteLine("Adding file: " + fileInfo.FullName);
                switch (drt)
                {
                case DocumentRepresentationType.TfIdf:
                    documentList.Add(new TfIdfDocument(fileInfo.FullName, dictionary, className, learningDocInfo));
                    break;

                case DocumentRepresentationType.Binary:
                    documentList.Add(new BinaryDocument(fileInfo.FullName, dictionary, className));
                    break;

                case DocumentRepresentationType.Own:
                    documentList.Add(new OwnDocument(fileInfo.FullName, dictionary, className));
                    break;

                default:
                    throw new Exception("Unknown DocumentRepresentationType: " + drt);
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Sprawdza czy podane parametry s¹ zgodne z parametrami dla plików zapisanych na liœcie.
 /// Jeœli nie ma zgodnoœci, to rzuca wyj¹tek.
 /// </summary>
 /// <param name="dtr">Typ dokumentu</param>
 /// <param name="dt">Typ s³ownika</param>
 private void CheckCorrectness(DocumentRepresentationType dtr, DictionaryType dt)
 {
     if (documentList.Count > 0)
     {
         Document tmpDocument = documentList[0];
         if (tmpDocument.GetDocumentRepresentationType() != dtr || tmpDocument.DictionaryType != dt)
         {
             throw new Exception("Can't add document. RepresentationType or DictionaryType differs from others in the list.");
         }
     }
 }
Пример #3
0
        /// <summary>
        /// Odczytuje sieć nuronową z podanego pliku.
        /// </summary>
        /// <param name="pathFile">Scieżka do pliku.</param>
        public void LoadRadialNetwork(String pathFile)
        {
            Stream          stream     = File.Open(pathFile, FileMode.Open);
            BinaryFormatter bFormatter = new BinaryFormatter();

            this.radialNetwork                   = (RadialNetwork)bFormatter.Deserialize(stream);
            this.dictionary                      = (Dictionary)bFormatter.Deserialize(stream);
            this.learningDocInfo                 = (LearningDocInfo)bFormatter.Deserialize(stream);
            DocumentClass.DocumentCategories     = (List <String>)bFormatter.Deserialize(stream);
            this.learnDocumentRepresentationType = (DocumentRepresentationType)bFormatter.Deserialize(stream);
            this.learnDictionaryType             = (DictionaryType)bFormatter.Deserialize(stream);
            LoadSettings(stream, bFormatter);
            stream.Close();

            this.form.LoadClassificatorEnd(ClasyficatorType.RadialNeural);
        }
        public static String ToString(DocumentRepresentationType documentRepresentationType)
        {
            switch (documentRepresentationType)
            {
            case DocumentRepresentationType.Binary:
                return("Binrna");

            case DocumentRepresentationType.Own:
                return("Tf");

            case DocumentRepresentationType.TfIdf:
                return("TfIdf");

            default:
                throw new Exception("Methode not implemented for this type.");
            }
        }
Пример #5
0
 /// <summary>
 /// Tworzy listê na podstawie katalogu z plikami w postaci s³owo, iloœæ wyst¹pieñ.
 /// </summary>
 /// <param name="sourceDir">Katalog z plikami.</param>
 /// <param name="dictionary">Rodzaj s³ownika, który ma byæ u¿yty do tworzenia nowych dokumentów.</param>
 /// <param name="drt">Rodzaj dokumentów.</param>
 /// <param name="className">Nazwa klasy, do której maj¹ nale¿eæ wszystkie nowo dodane elementu lub null, jeœli klasa jest nieznana.</param>
 /// <param name="learningDocInfo">Obiekt zawieraj¹cy informacje o wszystkich dokumentach ucz¹cych.
 /// Je¿eli dana reprezentacja nie potrzebuje tego obiektu, parametr jest ignorowany.</param>
 public DocumentList(String sourceDir, Dictionary dictionary, DocumentRepresentationType drt, String className, LearningDocInfo learningDocInfo)
 {
     documentList = new List <Document>();
     AddDocumentsFromDir(sourceDir, dictionary, drt, className, learningDocInfo);
 }
Пример #6
0
 void OnLearningWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     this.learnDocumentRepresentationType = (DocumentRepresentationType)Settings.Default.documentRepresentationType;
     this.LearnDictionaryType             = (DictionaryType)Settings.Default.dictionaryType;
     form.LearnEnd();
 }
Пример #7
0
        /// <summary>
        /// Tworzy listê zawieraj¹c¹ wszystkie dokumenty do uczenia.
        /// </summary>
        /// <param name="sourceDir">Kataloog zawieraj¹cy katalogi z poszczególnymi kategoriami.</param>
        /// <param name="dictionary">S³ownik na podstawie którego maj¹ byæ tworzone dokumenty.</param>
        /// <param name="drt">Rodzaj dokumentów.</param>
        /// <param name="learningDocInfo">Obiekt klasy learningDocInfo lub null jeœli nie jest potrzebny dla danego s³ownika i typu dokumentu.</param>
        /// <returns></returns>
        public static DocumentList CreateLearningDocumentList(String sourceDir, Dictionary dictionary, DocumentRepresentationType drt, LearningDocInfo learningDocInfo)
        {
            DocumentList  result        = new DocumentList();
            DirectoryInfo sourceDirInfo = new DirectoryInfo(sourceDir);

            foreach (DirectoryInfo dirInfo in sourceDirInfo.GetDirectories())
            {
                result.AddDocumentsFromDir(dirInfo.FullName + "\\" + PreprocessingConsts.StemmedFolder, dictionary, drt, dirInfo.Name, learningDocInfo);
            }
            return(result);
        }