コード例 #1
0
ファイル: Program.cs プロジェクト: chargen/sport-topic-marker
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Invalid number of arguments, first argument should be path to dataset");
                Console.WriteLine("Second argument is action - teach means that database will be upgraded - process means that provided article will be labeled");
                return;
            }

            string pathToDataset = args[0];
            string action        = args[1];

            LabeledArticleDatabase database = LabeledArticleDatabase.LoadFromFile(pathToDataset);

            NLPProcessor processor    = new NLPProcessor();
            Marker       marker       = new Marker(processor, @"C:\Users\jantk_000\Documents\GitHub\sport-topic-marker\Model\");
            var          articleCount = database.Articles.Count;

            if ("teach".Equals(action))
            {
                for (int i = 0; i < articleCount; i++)
                {
                    Console.WriteLine("Processing article {0}/{1}", i + 1, articleCount);
                    LabeledArticle article = database.Articles[i];
                    marker.ExtendDatabaseWithArticle(article);
                }

                for (int j = 0; j < 1; j++)
                {
                    for (int i = 0; i < articleCount; i++)
                    {
                        Console.WriteLine("Teaching network with article {0}/{1}", i + 1, articleCount);
                        marker.TrainClassifierWithArticle(database.Articles[i]);
                    }

                    for (int i = 0; i < articleCount; i++)
                    {
                        LabeledArticle labeled = marker.LabelArticle(database.Articles[i].Article);
                        Console.WriteLine("Article marked as: {0} should be: {1}", labeled.Category,
                                          database.Articles[i].Category);
                    }
                }

                marker.Save();
            }
            else if ("process".Equals(action))
            {
                marker.Load();

                for (int i = 0; i < articleCount; i++)
                {
                    LabeledArticle labeled = marker.LabelArticle(database.Articles[i].Article);
                    Console.WriteLine("Article marked as: {0} should be: {1}", labeled.Category, database.Articles[i].Category);
                }
            }

            Console.ReadLine();
        }
コード例 #2
0
 public MainViewModel()
 {
     _database          = LabeledArticleDatabase.LoadFromFile(DataSetPath);
     Train              = new AsynchronousCommand(TrainAction, () => !Train.IsExecuting);
     ResetTrainedStatus = new Command(ResetStatusAction);
     Test            = new AsynchronousCommand(TestAction, () => !Test.IsExecuting && !string.IsNullOrWhiteSpace(TestingArticle));
     EnhanceDatabase = new Command(EnhanceDatabaseAction, () => !string.IsNullOrWhiteSpace(TestingArticle));
     TrainingStatus  = "Not started yet";
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: chargen/sport-topic-marker
        static void Main(string[] args)
        {
            Console.WriteLine("Dataset maker");

            if (args.Length < 1)
            {
                Console.WriteLine("Invalid number of arguments, first argument should be path to dataset");
                return;
            }

            string pathToDataset = args[0];

            LabeledArticleDatabase database = LabeledArticleDatabase.LoadFromFile(pathToDataset);

            Console.WriteLine("Currently dataset holds {0} articles", database.Articles.Count);

            while (true)
            {
                Console.WriteLine("Press 'A' to add new article");
                Console.WriteLine("Press 'ESC' to quit");
                ConsoleKeyInfo key = Console.ReadKey();
                if (key.Key == ConsoleKey.A)
                {
                    StringBuilder article = new StringBuilder();
                    Console.WriteLine("Please enter article. Type '---' after end of article.");
                    while (true)
                    {
                        string line = Console.ReadLine();
                        if ("---".Equals(line))
                        {
                            break;
                        }
                        article.AppendLine(line);
                    }
                    bool isAboutSport;
                    Console.WriteLine("Is this article about sport (Y/N)?");
                    while (true)
                    {
                        ConsoleKeyInfo keyPressed = Console.ReadKey();
                        if (keyPressed.Key == ConsoleKey.Y)
                        {
                            isAboutSport = true;
                            break;
                        }
                        if (keyPressed.Key == ConsoleKey.N)
                        {
                            isAboutSport = false;
                            break;
                        }
                    }

                    if (isAboutSport)
                    {
                        SportCategory category;
                        Console.WriteLine("What sport ?");
                        while (true)
                        {
                            string sport = Console.ReadLine();
                            bool   ok    = Enum.TryParse(sport, out category);
                            if (ok)
                            {
                                break;
                            }
                            Console.WriteLine("Invalid sport - choose one from:");
                            string[] names = Enum.GetNames(typeof(SportCategory));
                            foreach (string name in names)
                            {
                                Console.WriteLine(name);
                            }
                        }
                        database.Articles.Add(new LabeledArticle(article.ToString(), category));
                    }
                    else
                    {
                        database.Articles.Add(new LabeledArticle(article.ToString(), SportCategory.NoSport));
                    }
                }
                if (key.Key == ConsoleKey.Escape)
                {
                    break;
                }
            }

            database.Save(pathToDataset);
        }