예제 #1
0
        public void Run(string basePath)
        {
            var task = _newsArticleProvider.GetNextArticleAsync();

            task.Wait();
            var article = task.Result;

            var alg1 = new Alg1Analizer(basePath);
            var alg2 = new Alg2Analizer(basePath);

            var analysis1      = alg1.Analize(article.Content);
            var analysis2      = alg2.Analize(article.Content);
            var googleDetected = _translateServiceClient.DetectLanguage(article.Content);

            Console.WriteLine("Article content:");
            Console.WriteLine(article.Content);
            Console.WriteLine("-----------------------------------------------");
            Console.WriteLine($"Actual lng: {article.ActualLanguage}");
            Console.WriteLine("Alg1 analysis:");
            PrintFullAnalysis(analysis1);
            Console.WriteLine("Alg2 analysis:");
            PrintFullAnalysis(analysis2);
            Console.WriteLine($"Google lng: {googleDetected}");
            Console.WriteLine("-----------------------------------------------");
        }
        public void DetectLanguage_ShortInputText_ProperLanguageDetected(string input, Language expected)
        {
            var actual = _instance.DetectLanguage(input);

            actual.Should().Be(expected);
        }
예제 #3
0
        // Porównanie efektywności algorytmów 1 i 2 dla wszystkich języków
        public void CreateComparisonOfAlgorithmEffectivenessForAllLanguages()
        {
            Dictionary <Language, int> alg1SuccessfulDetection   = new Dictionary <Language, int>();
            Dictionary <Language, int> alg2SuccessfulDetection   = new Dictionary <Language, int>();
            Dictionary <Language, int> googleSuccessfulDetection = new Dictionary <Language, int>();
            Alg1Analizer           alg1 = new Alg1Analizer(languageDictionaries);
            Alg2Analizer           alg2 = new Alg2Analizer(languageDictionaries);
            TranslateServiceClient translateServiceClient = new TranslateServiceClient();

            foreach (Language language in pathsToArticles.Keys)
            {
                int alg1SuccessfulDetectionCount   = 0;
                int alg2SuccessfulDetectionCount   = 0;
                int googleSuccessfulDetectionCount = 0;
                int numberOfArticlesToAnalyze      = 10;

                string   path  = pathsToArticles[language];
                string[] lines = System.IO.File.ReadAllLines(path);
                foreach (string url in lines)
                {
                    string content = urlsToArticles[url].Content;
                    content = content.Substring(0, content.Length / 10);

                    // Algorytm 1
                    Analysis analysis = alg1.Analize(content);
                    if (analysis.GetDiscoveredLanguage().Equals(language))
                    {
                        alg1SuccessfulDetectionCount++;
                    }

                    // Algorytm 2
                    Analysis analysis2 = alg2.Analize(content);
                    if (analysis2.GetDiscoveredLanguage().Equals(language))
                    {
                        alg2SuccessfulDetectionCount++;
                    }

                    Console.WriteLine("Google: {0}", url);

                    Language googleLanguage = translateServiceClient.DetectLanguage(content);
                    if (googleLanguage.Equals(language))
                    {
                        googleSuccessfulDetectionCount++;
                    }
                }
                alg1SuccessfulDetection.Add(language, alg1SuccessfulDetectionCount);
                alg2SuccessfulDetection.Add(language, alg2SuccessfulDetectionCount);
                googleSuccessfulDetection.Add(language, googleSuccessfulDetectionCount);
            }

            string csvPath = "../../comparisons/alg_comparison_all_lang.csv";

            if (!File.Exists(csvPath))
            {
                File.Create(csvPath).Close();
            }
            using (TextWriter writer = new StreamWriter(csvPath, false, Encoding.UTF8)) {
                writer.WriteLine("Porównanie algorytmów 1 i 2 - wszystkie języki;;;;;;;");
                writer.WriteLine(";EN;DE;FR;ES;PT;IT");
                writer.WriteLine("Alg. 1;" + alg1SuccessfulDetection[Language.English] + ";"
                                 + alg1SuccessfulDetection[Language.German] + ";"
                                 // + alg1SuccessfulDetection[Language.Polish] + ";"
                                 + alg1SuccessfulDetection[Language.French] + ";"
                                 + alg1SuccessfulDetection[Language.Spanish] + ";"
                                 + alg1SuccessfulDetection[Language.Portuguese] + ";"
                                 + alg1SuccessfulDetection[Language.Italian]);

                writer.WriteLine("Alg. 2;" + alg2SuccessfulDetection[Language.English] + ";"
                                 + alg2SuccessfulDetection[Language.German] + ";"
                                 // + alg2SuccessfulDetection[Language.Polish] + ";"
                                 + alg2SuccessfulDetection[Language.French] + ";"
                                 + alg2SuccessfulDetection[Language.Spanish] + ";"
                                 + alg2SuccessfulDetection[Language.Portuguese] + ";"
                                 + alg2SuccessfulDetection[Language.Italian]);

                writer.WriteLine("Google API;" + googleSuccessfulDetection[Language.English] + ";"
                                 + googleSuccessfulDetection[Language.German] + ";"
                                 // + alg2SuccessfulDetection[Language.Polish] + ";"
                                 + googleSuccessfulDetection[Language.French] + ";"
                                 + googleSuccessfulDetection[Language.Spanish] + ";"
                                 + googleSuccessfulDetection[Language.Portuguese] + ";"
                                 + googleSuccessfulDetection[Language.Italian]);
            }
        }