private void AddClick(object sender, EventArgs e) { // avoid add same word bool wordExist = _englishEnglishWords.Any(w => w.Word.Equals(WordTextBox.Text)); if (!wordExist) { // create object var englishWord = new EnglishWord() { Word = WordTextBox.Text, Meaning = MeaningTextBox.Text }; // Place object is pending insert state _context.EnglishWords.InsertOnSubmit(englishWord); // Commit changes to DB _context.SubmitChanges(); // Sync object with observable collection _englishEnglishWords.Add(englishWord); WordTextBox.Text = string.Empty; MeaningTextBox.Text = string.Empty; } }
public ActionResult Post([FromBody] EnglishWord item) { item.UpdateTime = DateTime.Now; _unitOfWork.EnglishWords.Add(item); _unitOfWork.Complete(); return(Ok(item.Id)); }
private string StemTerm(string term) { string massagedTerm = term.Trim().ToLower(); if (String.IsNullOrEmpty(massagedTerm)) { return(null); } switch (_language) { case ConfigHandler.Language.English: EnglishWord englishWord = new EnglishWord(massagedTerm); return(englishWord.Stem); case ConfigHandler.Language.German: GermanStemmer germanStemmer = new GermanStemmer(); return(germanStemmer.Stem(massagedTerm)); case ConfigHandler.Language.Russian: RussianStemmer russianStemmer = new RussianStemmer(); return(russianStemmer.Stem(massagedTerm)); case ConfigHandler.Language.French: FrenchStemmer frenchStemmer = new FrenchStemmer(); return(frenchStemmer.Stem(massagedTerm)); default: return(massagedTerm); } }
public ViewModelData() { englishWord = new EnglishWord(); aWord = new UAWord(); SaveData = new Command(Save); Collection = new ObservableCollection <UAWord>(); }
public async Task <bool> AddPairAsync(RussianWord russianWord, EnglishWord englishWord) { if (russianWord == null) { throw new ArgumentNullException(nameof(russianWord), "Parameter russianWord can't be null"); } if (englishWord == null) { throw new ArgumentNullException(nameof(englishWord), "Parameter englishWord can't be null"); } bool isWordContained = await _unitOfWork.RussianWordRepository.FirstOrDefaultAsync(russianWord) != null; if (!isWordContained) { russianWord.EnglishRussianWords = new List <EnglishRussianWord>() { new() { English = englishWord, Russian = russianWord } }; await _unitOfWork.RussianWordRepository.AddAsync(russianWord); await _unitOfWork.CommitAsync(); return(true); } else { return(false); } }
public override int GetHashCode() { unchecked { var hash = 17; hash = hash * 23 + EnglishWord.GetHashCode(); hash = hash * 23 + this.ToString().GetHashCode(); return(hash); } }
public static EnglishWord[] ConvertToEng(ICollection<string> items) { EnglishWord[] RetItems = new EnglishWord[items.Count]; int k = 0; foreach (string item in items) { RetItems[k] = new EnglishWord() { Content = item }; k++; } return RetItems; }
public static string[] Topics(string[] documents, int occuranceSize) { List <TopicItems> topics = new List <TopicItems>(); bool flag = false; foreach (string doc in documents) { Match match = Regex.Match(doc, @"(?<=#)\w+"); while (match.Success) { EnglishWord a_word = new EnglishWord(match.Value); if (topics.Count > 0) { foreach (TopicItems item in topics) { if (item.topicString == a_word.Stem) { item.count++; flag = true; } } if (flag == true) { flag = false; } else { topics.Add(new TopicItems(a_word.Stem, 1)); } } else { topics.Add(new TopicItems(a_word.Stem, 1)); } match = match.NextMatch(); } } List <string> selectedTopics = new List <string>(); topics.ForEach((item) => { if (item.count >= occuranceSize) { selectedTopics.Add(item.topicString); } }); return(selectedTopics.ToArray()); }
public async Task <IHttpActionResult> AddEnglishWord(EnglishWord word) { var resultData = await _englishWordRepository.AddWord(word); if (resultData == false) { return(InternalServerError()); } else { return(Ok()); } }
public ActionResult Put(int id, [FromBody] EnglishWord item) { if (id != item.Id) { return(StatusCode(400)); } var l = _unitOfWork.EnglishWords.Get(id); l.Standard = item.Standard; l.Word = item.Word; l.UpdateTime = DateTime.Now; _unitOfWork.Complete(); return(Ok()); }
public void LoadWords() { Console.WriteLine("И д е т з а г р у з к а . . ."); HttpWebRequest WRequest = (HttpWebRequest)WebRequest.Create("https://studyenglishwords.com/top-english-words"); HttpWebResponse WResponse = (HttpWebResponse)WRequest.GetResponse(); Stream BaseStream = WResponse.GetResponseStream(); StreamReader StreamForReading = new StreamReader(BaseStream); bool IsBlockOfWord = false; string LineForReading; int Counter = 0; while ((LineForReading = StreamForReading.ReadLine()) != null) { string EnglishWord; if (LineForReading.Contains("wordBox")) { IsBlockOfWord = true; EnglishWord = LineForReading.Replace("<td class=\"wordBox\"><a href=\"/words/", String.Empty); EnglishWord = EnglishWord.Remove(EnglishWord.IndexOf('"')); EnglishWord = EnglishWord.Replace(" ", String.Empty); _wordsWithoutTranslation[Counter, 0] = EnglishWord; } if (IsBlockOfWord && LineForReading.Contains("\"percent\"")) { string LineWithPercent = LineForReading; LineWithPercent = LineWithPercent.Replace("<td class=\"percent\">", String.Empty); LineWithPercent = LineWithPercent.Remove(LineWithPercent.IndexOf('%')); LineWithPercent = LineWithPercent.Replace(" ", String.Empty); LineWithPercent = LineWithPercent.Replace(".", ","); IsBlockOfWord = false; _wordsWithoutTranslation[Counter, 1] = LineWithPercent; Counter++; } } StreamForReading.Close(); BaseStream.Close(); FilterDictionary(); SortDictionary(); }
private int AddEngWord(string enWord) { var engWordFromDb = _context.EnglishWords .FirstOrDefault(r => r.EnWord.Equals(enWord, StringComparison.OrdinalIgnoreCase)); if (engWordFromDb == null) { enWord = enWord.Trim(); var englishWord = new EnglishWord { EnWord = enWord.ToLower() }; _context.EnglishWords.Add(englishWord); _context.SaveChanges(); return(englishWord.Id); } return(engWordFromDb.Id); }
//TODO CANCELLATION TOKEN //TODO maybe create method that fails should throw an exception? public async Task <bool> AddAsync(EnglishWord item) { if (item == null) { throw new ArgumentNullException(nameof(item), "Parameter item can't be null"); } bool isWordContained = await _unitOfWork.EnglishWordRepository.FirstOrDefaultAsync(item) != null; if (!isWordContained) { await _unitOfWork.EnglishWordRepository.AddAsync(item); await _unitOfWork.CommitAsync(); return(true); } else { return(false); } }
public FrequencyDocument TransformText(string text) { string[] tokens = Tokenize(text); var document = new FrequencyDocument { Classification = "-", Tokens = new Dictionary <string, double>() }; foreach (var token in tokens) { if (token == String.Empty) { continue; } string stripped = Regex.Replace(token, "[^a-zA-Z0-9]", ""); if (!StopWords.stopWordsList.Contains(stripped.ToLower())) { var english = new EnglishWord(stripped); string stemedToken = english.Stem; if (document.Tokens.Keys.Contains(token)) { document.Tokens[token]++; } else { document.Tokens.Add(token, 1); } } } return(document); }
private string[] Transform(string text) { var output = new List <string>(); string[] tokens = Tokenize(text); foreach (var token in tokens) { if (token == String.Empty) { continue; } string stripped = Regex.Replace(token, "[^a-zA-Z0-9]", ""); if (!StopWords.stopWordsList.Contains(stripped.ToLower())) { var english = new EnglishWord(stripped); output.Add(english.Stem); } } return(output.ToArray()); }
/// <summary> /// Parses and tokenizes a list of documents, returning a vocabulary of words. /// </summary> /// <param name="docs">string[]</param> /// <param name="stemmedDocs">List of List of string</param> /// <returns>Vocabulary (list of strings)</returns> private static List <string> GetVocabulary(string[] docs, out List <List <string> > stemmedDocs, int vocabularyThreshold) { Dictionary <string, int> wordCountList = new Dictionary <string, int>(); stemmedDocs = new List <List <string> >(); int docIndex = 0; initialLanguagePattern(); foreach (var doc in docs) { List <string> stemmedDoc = new List <string>(); docIndex++; if (docIndex % 100 == 0) { System.Console.WriteLine("Processing " + docIndex + "/" + docs.Length); } string[] parts2 = Tokenize(doc); List <string> words = new List <string>(); foreach (string part in parts2) { // Strip non-alphanumeric characters. string stripped = Regex.Replace(part, "[^a-zA-Z0-9]", ""); if (!StopWords.stopWordsList.Contains(stripped.ToLower())) { try { var english = new EnglishWord(stripped); string stem = english.Stem; words.Add(stem); if (stem.Length > 0) { // Build the word count list. if (wordCountList.ContainsKey(stem)) { wordCountList[stem]++; } else { wordCountList.Add(stem, 0); } stemmedDoc.Add(stem); } } catch { } } } stemmedDocs.Add(DeleteUnUsePOSTag(stemmedDoc)); } // Get the top words. var vocabList = wordCountList.Where(w => w.Value >= vocabularyThreshold); foreach (var item in vocabList) { vocabulary.Add(item.Key); //System.IO.File.AppendAllText("J:\\ToltecSoft.WebCrawler\\ToltecSoft.WebCrawler\\wordList.txt", item.Key + "," + Environment.NewLine); } return(vocabulary); }
public void SaveEngItem(ref EnglishWord word) { db.Englishword.Add(word); }
/// <summary> /// Parses and tokenizes a list of documents, returning a vocabulary of words. /// </summary> /// <param name="docs">string[]</param> /// <param name="stemmedDocs">List of List of string</param> /// <returns>Vocabulary (list of strings)</returns> private static List <string> GetVocabulary(string[] docs, out List <List <string> > stemmedDocs, int vocabularyThreshold) { List <string> vocabulary = new List <string>(); Dictionary <string, int> wordCountList = new Dictionary <string, int>(); stemmedDocs = new List <List <string> >(); int docIndex = 0; foreach (var doc in docs) { List <string> stemmedDoc = new List <string>(); docIndex++; if (docIndex % 100 == 0) { Console.WriteLine("Processing " + docIndex + "/" + docs.Length); } if (doc != null) { try { string[] parts2 = Tokenize(doc); List <string> words = new List <string>(); foreach (string part in parts2) { // Strip non-alphanumeric characters. string stripped = Regex.Replace(part, "[^a-zA-Z0-9]", ""); if (!StopWords.stopWordsList.Contains(stripped.ToLower())) { try { var english = new EnglishWord(stripped); string stem = english.Stem; words.Add(stem); if (stem.Length > 0) { // Build the word count list. if (wordCountList.ContainsKey(stem)) { wordCountList[stem]++; } else { wordCountList.Add(stem, 0); } stemmedDoc.Add(stem); } } catch { } } } } catch (Exception e) { /*MessageBox.Show(e.ToString());*/ } stemmedDocs.Add(stemmedDoc); } } // Get the top words. var vocabList = wordCountList.Where(w => w.Value >= vocabularyThreshold); foreach (var item in vocabList) { vocabulary.Add(item.Key); } return(vocabulary); }
public void SetUpConnection(EnglishWord word, UAWord uAWord) { word.uaword.Add(uAWord); db.SaveChanges(); db.Database.CloseConnection(); }
public static string TopicsDecider(string[] documents) { List <TopicItems> topics = new List <TopicItems>(); bool flag = false; foreach (string doc in documents) { Match match = Regex.Match(doc, @"(?<=#)\w+"); while (match.Success) { EnglishWord a_word = new EnglishWord(match.Value); if (topics.Count > 0) { foreach (TopicItems item in topics) { if (item.topicString == a_word.Stem) { item.count++; flag = true; } } if (flag == true) { flag = false; } else { topics.Add(new TopicItems(a_word.Stem, 1)); } } else { topics.Add(new TopicItems(a_word.Stem, 1)); } match = match.NextMatch(); } } double max = 0; string topic_it = null; topics.ForEach((item) => { if (item.count >= max) { max = item.count; topic_it = item.topicString; } }); if (topic_it == null) { return(null); } else { return(topic_it); } }
public int CompareTo(Word obj) { if (obj == null) { throw new NullReferenceException(); } if (Date.CompareTo(obj.Date) == 0 && EnglishExample.CompareTo(obj.EnglishExample) == 0 && EnglishWord.CompareTo(obj.EnglishWord) == 0 && TodaysWord.CompareTo(obj.TodaysWord) == 0 && TodaysExample.CompareTo(obj.TodaysExample) == 0 && WordLanguage.CompareTo(obj.WordLanguage) == 0 && PartOfSpeech.CompareTo(obj.PartOfSpeech) == 0) { return(0); } if (Date.CompareTo(obj.Date) != 0) { return(Date.CompareTo(obj.Date)); } else { if (EnglishExample.CompareTo(obj.EnglishExample) != 0) { return(EnglishExample.CompareTo(obj.EnglishExample)); } else { if (EnglishWord.CompareTo(obj.EnglishWord) != 0) { return(EnglishWord.CompareTo(obj.EnglishWord)); } else { if (WordLanguage.CompareTo(obj.WordLanguage) != 0) { return(WordLanguage.CompareTo(obj.WordLanguage)); } else { if (TodaysWord.CompareTo(obj.TodaysWord) != 0) { return(TodaysWord.CompareTo(obj.TodaysWord)); } else { if (TodaysExample.CompareTo(obj.TodaysExample) != 0) { return(TodaysExample.CompareTo(obj.TodaysExample)); } else { return(PartOfSpeech.CompareTo(obj.PartOfSpeech)); } } } } } } }
private static void AddNewWordToDB(string input) { string inputEnglishWord; string inputbBulgarianWord; VocabolaryDBContext context = new VocabolaryDBContext(); if (input.Contains("English")) { inputEnglishWord = GetInputForEnglishWord(); inputbBulgarianWord = GetInputForBulgarianWord(); } else { inputbBulgarianWord = GetInputForBulgarianWord(); inputEnglishWord = GetInputForEnglishWord(); } int?idEnglishWord = null; int?idBulgarianWord = null; try { idEnglishWord = context.EnglishWords.FirstOrDefault(w => w.Word == inputEnglishWord).EnglishWordId; idBulgarianWord = context.BulgarianWords.FirstOrDefault(w => w.Word == inputbBulgarianWord).BulgarianWordId; } catch (NullReferenceException ex) { //one or both words dosnt contain i DB } if (context.BulgarianWordsEnglishWords.Find(idEnglishWord, idBulgarianWord) != null) { Console.WriteLine("Words already exists!"); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); return; } EnglishWord englishWord; BulgarianWord bulgarianWord; if (idEnglishWord is null) { englishWord = new EnglishWord { Word = inputEnglishWord, Points = 1 }; } else { englishWord = context.EnglishWords.Find(idEnglishWord); } if (idBulgarianWord is null) { bulgarianWord = new BulgarianWord { Word = inputbBulgarianWord, Points = 1 }; } else { bulgarianWord = context.BulgarianWords.Find(idBulgarianWord); } context.Add(new BulgarianWordEnglishWord { EnglishWord = englishWord, BulgarianWord = bulgarianWord, }); context.SaveChanges(); //var englishWords = context.BulgarianWords.Where(w => w.Word == bulgarianWord).Select(w => w.EnglishWords).ToHashSet(); //var bulgarianWords = context.EnglishWords.Where(w => w.Word == englishWord).Select(w => w.BulgarianWords).ToHashSet(); }
// Parses and tokenizes a list of documents, returning a vocabulary of words public List <string> GetVocabulary(List <string> docs, out List <List <string> > stemmedDocs, int vocabularyThreshold) { List <string> vocabulary = new List <string>(); Dictionary <string, int> wordCountList = new Dictionary <string, int>(); stemmedDocs = new List <List <string> >(); foreach (var doc in docs) { List <string> stemmedDoc = new List <string>(); string[] parts2 = Tokenize(doc); List <string> words = new List <string>(); foreach (string part in parts2) { // Strip non-alphanumeric characters string stripped = Regex.Replace(part, "[^a-zA-Z0-9]", ""); if (!StopWords.stopWordsList.Contains(stripped.ToLower())) { try { var english = new EnglishWord(stripped); string stem = english.Stem; words.Add(stem); if (stem.Length > 0) { // Build the word count list if (wordCountList.ContainsKey(stem)) { wordCountList[stem]++; } else { wordCountList.Add(stem, 0); } stemmedDoc.Add(stem); } } catch (Exception e) { Console.WriteLine("Tokenizer exception source: {0}", e.Message); } } } stemmedDocs.Add(stemmedDoc); } // Get the top words var vocabList = wordCountList.Where(w => w.Value >= vocabularyThreshold); foreach (var item in vocabList) { vocabulary.Add(item.Key); } return(vocabulary); }