예제 #1
0
        public Synonyms GetSynonymsFromOpenThesaurus(string searchWord)
        {
            if (searchWord != null && searchWord != string.Empty)
            {
                // Create a request for the URL.
                WebRequest request = WebRequest.Create($"https://www.openthesaurus.de/synonyme/search?q={searchWord}&format=application/json");
                // If required by the server, set the credentials.
                request.Credentials = CredentialCache.DefaultCredentials;
                // Get the response.
                WebResponse response = request.GetResponse();
                // Display the status.
                SeqLog.WriteNewLogMessage(((HttpWebResponse)response).StatusDescription);
                // Get the stream containing content returned by the server.
                Stream dataStream = response.GetResponseStream();
                // Open the stream using a StreamReader for easy access.
                StreamReader reader = new StreamReader(dataStream);
                // Read the content.
                string responseFromServer = reader.ReadToEnd();
                // Display the content.
                SeqLog.WriteNewLogMessage(responseFromServer);
                // Clean up the streams and the response.
                reader.Close();
                response.Close();

                return(JsonConvert.DeserializeObject <Synonyms>(responseFromServer));
            }

            return(null);
        }
예제 #2
0
        public static void SplitNewTexts(string db)
        {
            var dbBuilder = new DbContextOptionsBuilder <TextContext>();

            dbBuilder.UseSqlite("Data Source=" + db);
            var textContext = new TextContext(dbBuilder.Options);
            IEnumerable <Text> textToProcess = textContext.Texts.Where(t => t.Processed == false);

            foreach (Text text in textToProcess)
            {
                //SeqLog.WriteNewLogMessage("{ID} - {Title} - {Processed}", text.ID, text.Title, text.Processed);

                // SplitSentece ist noch verbesserungswürdig.
                List <string> splitSentences = SplitSentences(text.Data);

                for (int i = 0; i < splitSentences.Count; i++)
                {
                    Sentence newSentence = new Sentence()
                    {
                        Data = splitSentences[i], TextID = text.ID, SentenceID = i
                    };

                    // Every sentence has a previous sentence, except the first one.
                    if (i > 0)
                    {
                        newSentence.PreviousID = i - 1;
                    }
                    else
                    {
                        newSentence.IsFirst = true;
                    }

                    // Every sentence has a next sentence, except the last one.
                    if (i + 1 < splitSentences.Count)
                    {
                        newSentence.NextID = i + 1;
                    }
                    else
                    {
                        newSentence.IsLast = true;
                    }

                    textContext.Add <Sentence>(newSentence);
                }

                text.Processed = true;
                SeqLog.WriteNewLogMessage("Text with Id:{ID} was splitted into senteces.", text.ID);
            }

            textContext.SaveChanges();
        }