protected override DictionaryWord Read() { if (BaseReader.EndOfStream) return null; var line = BaseReader.ReadLine(); var columns = line.Split(' '); return new DictionaryWord { Id = int.Parse(columns[0]), Word = columns[1], Meanings = columns .Skip(2) .Select(x => { var values = x.Split(':'); return new DictionaryMeaning { Id = int.Parse(values[0]), Meaning = values[1], PartOfSpeech = SynsetHelper.GetPos(values[1]), Encounters = int.Parse(values[2]) }; }) .ToMeaningDictionary() }; }
protected override DictionaryWord Read() { if (BaseReader.EndOfStream) { return(null); } var line = BaseReader.ReadLine(); if (string.IsNullOrWhiteSpace(line)) { return(null); } var match = ParseRegex.Match(line); if (!match.Success) { return(null); } return(new DictionaryWord { Id = ++_wordCounter, Word = match.Groups["word"].Value, Meanings = match.Groups["meaning"].Captures .Cast <Capture>() .Select((x, i) => { var split = x.Value.Split(':'); if (split.Length == 1) { return new DictionaryMeaning { Id = i + 1, Meaning = split[0], PartOfSpeech = SynsetHelper.GetPos(split[0]) } } ; int.TryParse(split[1], out var encounters); return new DictionaryMeaning { Id = i + 1, Meaning = split[0], PartOfSpeech = SynsetHelper.GetPos(split[0]), Encounters = encounters }; }) .ToMeaningDictionary() });
private MeaningDictionary ParseEncounters(string value) { return(value .Split('|') .Where(x => !string.IsNullOrEmpty(x)) .Select(x => { var values = x.Split(':'); return new DictionaryMeaning { Id = int.Parse(values[0]), Meaning = values[1], PartOfSpeech = SynsetHelper.GetPos(values[1]), Encounters = int.Parse(values[2]) }; }) .ToMeaningDictionary()); }
internal void AddEncounter(WordDictionary dictionary, RawWordEncounter encounter) { var dictionaryWord = dictionary.GetByName(encounter.Word); var dictionaryMeaning = dictionaryWord?.Meanings.GetByName(encounter.Meaning); var meaningAnalysis = GetByName(encounter.Meaning); if (meaningAnalysis == null) { meaningAnalysis = new DictionaryMeaning { Id = dictionaryMeaning?.Id ?? -1, Meaning = encounter.Meaning, PartOfSpeech = SynsetHelper.GetPos(encounter.Meaning) }; Add(encounter.Meaning, meaningAnalysis); } meaningAnalysis.Encounters++; }
protected override RawWordEncounter Read() { if (BaseReader.EndOfStream) { return(null); } var line = BaseReader.ReadLine(); if (string.IsNullOrWhiteSpace(line)) { return new RawWordEncounter { Word = RawWordEncounter.EndOfSentence } } ; var match = ParseRegex.Match(line); if (!match.Success) { return new RawWordEncounter { Word = RawWordEncounter.EndOfSentence } } ; return(new RawWordEncounter { Word = match.Groups["word"].Value, Pos = SynsetHelper.GetPos(match.Groups["meaning"].Value), Meaning = match.Groups["meaning"].Value }); } } }