Пример #1
0
        public static PlaceInformation GetPlaceInformation(string input, string location, string typeInput)
        {
            PlaceInformation placeInformation = new PlaceInformation();

            placeInformation.Location = location.Trim();

            placeInformation.Title = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(input.ToLower());

            string content = RestAPICaller.CallApiGetParagraphs(location.Trim() + "-" + input.Trim() + "-" + typeInput.Trim());

            content = TextProcessing.PreprocessParagraphsContent(content);
            placeInformation.Content = content.Trim();

            Place place = GooglePlacesAPI.GetPlaceDetails(input);

            if (place != null)
            {
                placeInformation.Rating = place.Result.Rating;
            }

            string[] sentences = Regex.Split(placeInformation.Content, @"(?<=[\.!\?])\s+");
            placeInformation.Sentiment = Paralleldots.GetSentiment(JArray.FromObject(sentences));

            return(placeInformation);
        }
Пример #2
0
        static void Main(string[] args)
        {
            var tp = new TextProcessing();

            tp.Run();
            // new Blue().SayFavoriteFood(Red.FavoriteFood);
        }
Пример #3
0
        static void TestAll(string[] args)
        {
            // data
            DataStructures.RunInstanceNull(args);
            SparseVector.RunInstanceNull(args);
            SparseMatrix.RunInstanceNull(args);
            Stateful.RunInstanceNull(args);
            Cloning.RunInstanceNull(args);
            Serialization.RunInstanceNull(args);

            // model
            Bow.RunInstanceNull(args);
            BinarySvm.RunInstanceNull(args);

            // clustering
            KMeans.RunInstanceNull(args);

            // validation
            NFold.RunInstanceNull(args);
            NFoldClass.RunInstanceNull(args);

            // other
            Searching.RunInstanceNull(args);
            TextProcessing.RunInstanceNull(args);
        }
Пример #4
0
    //...
    private void GetOcrFromService()
    {
        //...
        TextProcessing value = OcrService.Get();

        OcrTextVM = value;
    }
Пример #5
0
        private void InputDirectorySearchButton_Click(object sender, EventArgs e)
        {
            // Opens a dialog to get the file location of the target file
            if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                // Console.WriteLine(openFileDialog1.FileName);
                InputFilePath = openFileDialog1.FileName;
                InputDirectoryTextBox.Text = InputFilePath;


                TextProcessing txt = new TextProcessing();

                //txt.GetStringsFromFile(InputFilePath);

                List <string> DocumentLines = txt.GetLinesFromFile(InputFilePath);
                //string[] lines = documentText.Split('\n');

                this.Articles = txt.GetArticlesFromLines(DocumentLines);

                this.Articles = txt.ProcessWordsFromArticleText(this.Articles);

                OutputListBox.Items.Clear(); // Clear listbox before adding stuff

                for (int i = 0; i < Articles.Count; i++)
                {
                    OutputListBox.Items.Add(Articles[i].Header);
                    //Console.WriteLine(Articles[i].Body);
                }
            }
        }
Пример #6
0
        public async Task RecognizeSpeechAsync(int startTextFromIndex)
        {
            // Creates an instance of a speech config with specified subscription key and service region.
            // Replace with your own subscription key and service region (e.g., "westus").
            var config = SpeechConfig.FromSubscription("74b9da07361f4ee5b42ba0f5c432084d", "westus");

            config.SpeechRecognitionLanguage = "pt-BR";
            config.SetProfanity(ProfanityOption.Raw);

            // Creates a speech recognizer.
            using (var recognizer = new SpeechRecognizer(config))
            {
                Console.WriteLine("Say something...");

                // Starts speech recognition, and returns after a single utterance is recognized. The end of a
                // single utterance is determined by listening for silence at the end or until a maximum of 15
                // seconds of audio is processed.  The task returns the recognition text as result.
                // Note: Since RecognizeOnceAsync() returns only a single utterance, it is suitable only for single
                // shot recognition like command or query.
                // For long-running multi-utterance recognition, use StartContinuousRecognitionAsync() instead.
                recognizer.Recognized += async(e, r) =>
                {
                    //Console.WriteLine("Recognized:::" + r.Result.Text);
                    if (r.Result.Text.Length < startTextFromIndex)
                    {
                        startTextFromIndex = 0;
                    }
                    string speechProcessed = await TextProcessing.GetTextProcessed(r.Result.Text, startTextFromIndex);

                    Console.WriteLine("Text Processed:::" + speechProcessed);
                    startTextFromIndex = r.Result.Text.Length;
                    await TryToTranslate(speechProcessed);
                };
                var result = await recognizer.RecognizeOnceAsync();

                // Checks result.
                if (result.Reason == ResultReason.RecognizedSpeech)
                {
                    Console.WriteLine($"We recognized: {result.Text}");
                    //startTextFromIndex = 0;
                }
                else if (result.Reason == ResultReason.NoMatch)
                {
                    Console.WriteLine($"NOMATCH: Speech could not be recognized.");
                }
                else if (result.Reason == ResultReason.Canceled)
                {
                    var cancellation = CancellationDetails.FromResult(result);
                    Console.WriteLine($"CANCELED: Reason={cancellation.Reason}");

                    if (cancellation.Reason == CancellationReason.Error)
                    {
                        Console.WriteLine($"CANCELED: ErrorCode={cancellation.ErrorCode}");
                        Console.WriteLine($"CANCELED: ErrorDetails={cancellation.ErrorDetails}");
                        Console.WriteLine($"CANCELED: Did you update the subscription info?");
                    }
                }
            }
        }
Пример #7
0
        static void Main(string[] args)
        {
            DBDictionary <TextProcessing> DBIO = new DBDictionary <TextProcessing>();


            if (args.Length != 0)
            {
                if (args[0] == ConfigurationManager.AppSettings["CreateDictionary"])
                {
                    DBIO.Create();
                    Console.WriteLine("Словарь создан.");
                    Environment.Exit(0);
                }

                if (args[0] == ConfigurationManager.AppSettings["UpdateDictionary"])
                {
                    TextProcessing w = new TextProcessing();
                    Console.WriteLine("Укажите путь к файлу:");
                    string path = Console.ReadLine();
                    DBIO.Update(w, path);
                    Console.WriteLine("Обновление завершено.");
                }

                if (args[0] == ConfigurationManager.AppSettings["DeleteDictionary"])
                {
                    DBIO.Delete();
                    Console.WriteLine("Удаление завершено.");
                    Environment.Exit(0);
                }
            }

            ConsoleKeyInfo cki;
            string         searchWord = string.Empty;

            do
            {
                cki = Console.ReadKey();
                if (cki.Key == ConsoleKey.Escape)
                {
                    break;
                }
                searchWord = Console.ReadLine();
                if (cki.Key >= ConsoleKey.A && cki.Key <= ConsoleKey.Z)
                {
                    searchWord = cki.KeyChar + searchWord;
                }
                if (searchWord == "")
                {
                    break;
                }
                searchWord.ToLower();
                var result = DBIO.Search(searchWord);
                foreach (Words w in result)
                {
                    Console.WriteLine($"{w.Word}");
                }
            }while (true);;
        }
Пример #8
0
 private void btnSaveToFile_Click(object sender, EventArgs e)
 {
     try
     {
         synthesizer.SaveToFile(TextProcessing.ToUPSReps(txtUrdu.Text.Trim()), Directory.GetCurrentDirectory() + "\\Output Wav\\file.wav");
     }
     catch (Exception ex)
     {
         playing = false;
         MessageBox.Show(ex.Message);
     }
 }
Пример #9
0
 private void btnSpeak_Click(object sender, EventArgs e)
 {
     try
     {
         synthesizer.SpeakStart(TextProcessing.ToUPSReps(txtUrdu.Text.Trim()));
         playing = true;
     }
     catch (Exception ex)
     {
         playing = false;
         MessageBox.Show(ex.Message);
     }
 }
        protected override int GetOperatorPosition(string value)
        {
            IEnumerable <int> splitPoints = TextProcessing.GetScopedSplitPoints(value, OperatorToken, TextProcessing.DefaultLeftScopers, TextProcessing.DefaultRightScopers);

            foreach (int index in splitPoints.Reverse())
            {
                if (IsValidBinaryOperator(value, index))
                {
                    return(index);
                }
            }

            return(-1);
        }
Пример #11
0
        public void GenerateQuestions(string topic)
        {
            topic = topic.Replace(" ", "_");
            var outputJsonPath = DirectoryManager.GetOutputJsonPath(topic);

            var tpr        = new TextProcessing();
            var resultList = tpr.GetSentencesInformationFromJson(outputJsonPath);

            var questionList = new List <TopicQuestion>();

            foreach (var sentence in resultList)
            {
                var dependencies = GetSentenceDependency(sentence);

                var words = GetSentenceWords(sentence);

                var sentenceInfo = new SentenceInformationDto(sentence.SentenceText, dependencies, words);
                if (MustContinue(sentence, sentenceInfo))
                {
                    continue;
                }
                GeneratedQuestion generatedQuestion;
                try
                {
                    generatedQuestion = QuestionGenerator.Generate(sentenceInfo);
                }
                catch
                {
                    continue;
                }
                if (string.IsNullOrEmpty(generatedQuestion?.Question))
                {
                    continue;
                }
                var cleanQuestion = QuestionCleaner.RemovePunctuationFromEnd(generatedQuestion.Question);

                cleanQuestion = $"{cleanQuestion}?";
                var question = new TopicQuestion
                {
                    Topic           = topic,
                    InitialSentence = sentence.SentenceText,
                    Question        = cleanQuestion,
                    Answer          = generatedQuestion.Answer
                };
                questionList.Add(question);
            }
            DirectoryManager.WriteQuestionsToFile(questionList, topic);
        }
Пример #12
0
 /// <summary>
 /// 检查config文件是否存在,不存在则创建
 /// </summary>
 private void init()
 {
     if (!File.Exists("Config.xml"))
     {
         SqlData sd = new SqlData();
         sd.connStr  = TextProcessing.SuperEncrypt("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}; Jet OLEDB:Database Password ={1}", "zjsxzsta", "zjsxzstb");
         sd.honeybee = TextProcessing.SuperEncrypt("", "zjsxzsta", "zjsxzstb");
         string erro = "";
         //判断写入单表xml是否成功
         if (!XmlTest <SqlData> .Serialize(sd, "Config.xml", ref erro))
         {
             MessageBox.Show(erro);
         }
         //FilesClasses.InitXml();
     }
 }
        private void indexing_button_Click(object sender, EventArgs e)
        {
            if (Docbutton.BackColor == DefaultBackColor)
            {
                MessageBox.Show("Choose Documents ...");
            }
            else
            {
                if (indexing_button.BackColor == DefaultBackColor)
                {
                    indexing_button.BackColor = Color.BurlyWood;
                    ArrayList DocPaths = new ArrayList();
                    //DocPaths.Add(@"D:\Work\Goals\Master\Software\InformationRetrievalSystem\Database\doc0.txt");

                    DocPaths.Add(@"D:\Work\Goals\Master\Software\InformationRetrievalSystem\Database\doc1.txt");
                    DocPaths.Add(@"D:\Work\Goals\Master\Software\InformationRetrievalSystem\Database\doc2.txt");
                    DocPaths.Add(@"D:\Work\Goals\Master\Software\InformationRetrievalSystem\Database\doc3.txt");
                    DocPaths.Add(@"D:\Work\Goals\Master\Software\InformationRetrievalSystem\Database\doc4.txt");
                    DocPaths.Add(@"D:\Work\Goals\Master\Software\InformationRetrievalSystem\Database\doc5.txt");
                    DocPaths.Add(@"D:\Work\Goals\Master\Software\InformationRetrievalSystem\Database\doc6.txt");
                    DocPaths.Add(@"D:\Work\Goals\Master\Software\InformationRetrievalSystem\Database\doc7.txt");
                    DocPaths.Add(@"D:\Work\Goals\Master\Software\InformationRetrievalSystem\Database\doc8.txt");
                    DocPaths.Add(@"D:\Work\Goals\Master\Software\InformationRetrievalSystem\Database\doc9.txt");
                    DocPaths.Add(@"D:\Work\Goals\Master\Software\InformationRetrievalSystem\Database\doc10.txt");
                    //DocPaths.Add(@"D:\Work\Goals\Master\Software\InformationRetrievalSystem\Database\doc11.txt");
                    //DocPaths.Add(@"D:\Work\Goals\Master\Software\InformationRetrievalSystem\Database\doc12.txt");
                    //DocPaths.Add(@"D:\Work\Goals\Master\Software\InformationRetrievalSystem\Database\doc13.txt");
                    //DocPaths.Add(@"D:\Work\Goals\Master\Software\InformationRetrievalSystem\Database\doc14.txt");
                    //DocPaths.Add(@"D:\Work\Goals\Master\Software\InformationRetrievalSystem\Database\doc15.txt");
                    //DocPaths.Add(@"D:\Work\Goals\Master\Software\InformationRetrievalSystem\Database\doc16.txt");
                    //DocPaths.Add(@"D:\Work\Goals\Master\Software\InformationRetrievalSystem\Database\doc17.txt");
                    //DocPaths.Add(@"D:\Work\Goals\Master\Software\InformationRetrievalSystem\Database\doc18.txt");
                    //DocPaths.Add(@"D:\Work\Goals\Master\Software\InformationRetrievalSystem\Database\doc19.txt");
                    //DocPaths.Add(@"D:\Work\Goals\Master\Software\InformationRetrievalSystem\Database\doc20.txt");

                    TextProcessing TP = new TextProcessing(checkBox2.Checked, Stopwords_button.BackColor == Color.BurlyWood, noun_button.BackColor == Color.BurlyWood, stemming_button.BackColor == Color.BurlyWood, true);
                    //TextProcessing TP = new TextProcessing();
                    //you may path file with special format to prevent any one else from treating it.
                    InvertedFile IF = new InvertedFile(TP.Docs_Text_Processing(DocPaths.GetEnumerator()), checkBox5.Checked);
                    IF.createIndex();
                }
                else
                {
                    indexing_button.BackColor = DefaultBackColor;
                }
            }
        }
Пример #14
0
        public async Task ProcessWikipediaText(string topic)
        {
            var rawResultsPath = DirectoryManager.GetRawResultsPath(topic);
            var cleanTextPath  = DirectoryManager.GetCleanResultsPath(topic);
            var outputJsonPath = DirectoryManager.GetOutputJsonPath(topic);
            var referencesPath = DirectoryManager.GetReferencesPath(topic);

            var text = File.ReadAllText(rawResultsPath);

            text = StringUtils.CleanText(text, referencesPath);

            await DirectoryManager.WriteTextToFile(text, cleanTextPath);

            var tpr = new TextProcessing();

            tpr.ProcessText(text, outputJsonPath);
        }
Пример #15
0
        private void analyseTextForUnrecognizedWords()
        {
            if (analyzing)
            {
                return;
            }
            analyzing = true;

            listUnrecognizedWords.Items.Clear();
            List <string> unrecognizedWords = TextProcessing.UnrecognizedWords(txtUrdu.Text.Trim());

            for (int i = 0; i < unrecognizedWords.Count; i++)
            {
                listUnrecognizedWords.Items.Add(unrecognizedWords[i]);
            }

            analyzing        = false;
            IconSync.Visible = false;
        }
Пример #16
0
        static void Main(string[] args)
        {
            // disable latino logger
            Logger.GetRootLogger().LocalOutputType         = Logger.OutputType.Custom;
            Logger.GetRootLogger().LocalProgressOutputType = Logger.ProgressOutputType.Custom;

            // output
            var sw = new StreamWriter("report.txt", true); // use file for output

            sw.WriteLine("************");

            //TestAll(args);

            // data
            //DataStructures.RunInstanceWr(sw, args);
            //SparseVector.RunInstanceWr(sw, args);
            //SparseMatrix.RunInstanceWr(sw, args);
            //Stateful.RunInstanceWr(sw, args);
            //Cloning.RunInstanceWr(sw, args);
            //Serialization.RunInstanceWr(sw, args);

            // model
            //Bow.RunInstanceWr(sw, args);
            //BinarySvm.RunInstanceWr(sw, args);

            // clustering
            //KMeans.RunInstanceWr(sw, args);

            // validation
            //NFold.RunInstanceWr(sw, args);
            //NFoldClass.RunInstanceWr(sw, args);
            //NFoldParallel.RunInstanceWr(sw, args);

            // other
            //Searching.RunInstanceWr(sw, args);

            // text processing
            TextProcessing.RunInstance(sw, args);
        }
Пример #17
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (!File.Exists("Config.xml"))
     {
         SqlData sd = new SqlData();
         sd.connStr  = TextProcessing.SuperEncrypt(textBox1.Text, "zjsxzsta", "zjsxzstb");
         sd.honeybee = TextProcessing.SuperEncrypt(textBox2.Text, "zjsxzsta", "zjsxzstb");
         string erro = "";
         //判断写入单表xml是否成功
         if (!XmlTest <SqlData> .Serialize(sd, "Config.xml", ref erro))
         {
             MessageBox.Show(erro);
         }
         //if(FilesClasses.InitXml(textBox1.Text, textBox2.Text))
         //{
         //    textBox2.Text = "";
         //    textBox1.Text = "";
         //}
         //else
         //{
         //    MessageBox.Show("保存错误!");
         //}
     }
 }
Пример #18
0
 public void SetUp()
 {
     TP = new TextProcessing();
 }
 /// <summary>
 /// Get the position of the right-most valid operator token.
 /// </summary>
 /// <param name="value">The string to find the operator in.</param>
 /// <returns>The position of the operator. -1 if none can be found</returns>
 protected virtual int GetOperatorPosition(string value)
 {
     return(TextProcessing.GetScopedSplitPoints(value, OperatorToken, TextProcessing.DefaultLeftScopers, TextProcessing.DefaultRightScopers).Last());
 }
Пример #20
0
        static void Main(string[] args)
        {
            Text zenText;
            var  filePath = ConfigurationManager.AppSettings["FilePath"];

            using (var textFile = File.OpenText(filePath))
            {
                try
                {
                    zenText = new Text(textFile);
                }
                finally
                {
                    if (textFile != null)
                    {
                        ((IDisposable)textFile).Dispose();
                    }
                }
            }
            zenText.Display();
            Console.ReadKey();
            Console.Clear();

            var newText1 = TextProcessing.OrderByAscendingCountWordsInSentence(zenText);

            newText1.Display();
            Console.ReadKey();
            Console.Clear();

            int lengthWord = 3;
            var listWords  = TextProcessing.FindAllWordByLength(
                TextProcessing.FindAllSentenceType(zenText, SentenceType.Interrogative),
                lengthWord,
                true);

            Console.WriteLine(string.Join(", ", listWords));
            Console.ReadKey();
            Console.Clear();

            int index    = 0;
            var newText2 = TextProcessing.DeleteWordsContainingCharacterType(
                zenText,
                CharacterType.Consonant,
                index,
                TextProcessing.FindAllWordByLength(zenText, lengthWord));

            newText2.Display();
            Console.ReadKey();
            Console.Clear();

            var newText3 = TextProcessing.ReplaceWord(zenText, TextProcessing.FindAllWordByLength(zenText, lengthWord), "ERROR");

            newText3.Display();
            Console.ReadKey();
            Console.Clear();

            var objectModel = ObjectModel.CreateObjectModel();

            //ObjectModel.SaveObjectModel(objectModel, "ObjectModel", @"C:\Users\thedr\Desktop");
            Console.WriteLine(objectModel);
        }
Пример #21
0
        static void Main(string[] args)
        {
            DBDictionary <TextProcessing> DBIO = new DBDictionary <TextProcessing>(args[0]);

            while (true)
            {
                Console.WriteLine("Введите управляющую комаду:");
                string   info    = Console.ReadLine();
                string[] command = info.Split(' ');

                try
                {
                    if (command[0] == ConfigurationManager.AppSettings["CreateDictionary"])
                    {
                        TextProcessing w = new TextProcessing();
                        DBIO.Create();
                        DBIO.Update(w, command[1]);
                        Console.WriteLine("Словарь создан.");
                    }

                    if (command[0] == ConfigurationManager.AppSettings["UpdateDictionary"])
                    {
                        TextProcessing w = new TextProcessing();
                        DBIO.Update(w, command[1]);
                        Console.WriteLine("Обновление завершено.");
                    }
                }
                catch (IndexOutOfRangeException)
                {
                    Console.WriteLine("Отсутствует путь к файлу. Невозможно обновить базу данных.");
                }
                catch (IOException e)
                {
                    Console.WriteLine("Невозможно прочитать файл:");
                    Console.WriteLine(e.Message);
                }

                if (command[0] == ConfigurationManager.AppSettings["DeleteDictionary"])
                {
                    DBIO.Delete();
                    Console.WriteLine("Удаление завершено.");
                }

                if (command[0] == ConfigurationManager.AppSettings["StartServer"])
                {
                    break;
                }
                if (command[0] == ConfigurationManager.AppSettings["Exit"])
                {
                    Environment.Exit(0);
                }
            }

            try
            {
                TSPServer serv = new TSPServer();
                listener = serv.StartListener(args[1]);
                Console.WriteLine("Ожидание подключений...");

                while (true)
                {
                    TcpClient    client       = listener.AcceptTcpClient();
                    ClientObject clientObject = new ClientObject(client, DBIO);
                    //Создание потока для нового клиента
                    Thread clientThread = new Thread(new ThreadStart(clientObject.Autocomplete));
                    clientThread.Start();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (listener != null)
                {
                    listener.Stop();
                }
            }
        }
Пример #22
0
        private void txtUrdu_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                // CTRL + S : Speak shortcut
                if (e.Modifiers == Keys.Control && e.KeyCode == Keys.S)
                {
                    synthesizer.SpeakStart(TextProcessing.ToUPSReps(txtUrdu.Text.Trim()));
                    playing = true;
                }
                // CTRL + F : Save to file shortcut
                else if (e.Modifiers == Keys.Control && e.KeyCode == Keys.F)
                {
                    synthesizer.SaveToFile(TextProcessing.ToUPSReps(txtUrdu.Text.Trim()), Directory.GetCurrentDirectory() + "\\Output Wav\\file.wav");
                }
                // CTRL + P : Parse/analyse text shortcut
                else if (e.Modifiers == Keys.Control && e.KeyCode == Keys.P)
                {
                    IconSync.Visible = true;
                    analyser         = new Thread(new ThreadStart(analyseTextForUnrecognizedWords));
                    analyser.Start();
                }
                // CTRL + D : Diacritic suggestion pop-up
                else if (e.Modifiers == Keys.Control && e.KeyCode == Keys.D)
                {
                    listDiacriticsSuggestion.Items.Clear();

                    string selectedWord = txtUrdu.SelectedText.Trim();

                    // First try, if the selection is a WORD (simple, not with diacritics)
                    suggestedDiacritics = DataAccessLayer.SearchRecordsByWord(selectedWord);
                    if (suggestedDiacritics != null)
                    {
                        for (int i = 0; i < suggestedDiacritics.Count; i++)
                        {
                            listDiacriticsSuggestion.Items.Add(suggestedDiacritics[i].DiacriticRep);
                        }
                    }
                    // Second try, if the selection is a DIACRITICS REPRESENTATION (not simple word)
                    else
                    {
                        suggestedDiacritics = DataAccessLayer.SearchRecordsByWord(DataAccessLayer.UrduWordFromDiacriticRep(selectedWord));
                        if (suggestedDiacritics != null)
                        {
                            for (int i = 0; i < suggestedDiacritics.Count; i++)
                            {
                                listDiacriticsSuggestion.Items.Add(suggestedDiacritics[i].DiacriticRep);
                            }
                        }
                    }

                    // If there are some diacritics to select from
                    if (listDiacriticsSuggestion.Items.Count > 0)
                    {
                        listDiacriticsSuggestion.Visible       = true;
                        listDiacriticsSuggestion.SelectedIndex = 0;
                        listDiacriticsSuggestion.Focus();
                    }
                }
                else
                {
                    listDiacriticsSuggestion.Visible = false;
                }
            }
            catch (Exception ex)
            {
                playing = false;
                MessageBox.Show(ex.Message);
            }
        }