public bool CreateOrUpdate(long sentenceId, long wordId, string originalText, int orderInSentence, GrammarWordType grammarWordType) { var parsedGrammarWordType = (int)grammarWordType; bool result = false; Adapter.ActionByContext(context => { SentenceWord sentenceWord = context.SentenceWord.FirstOrDefault( e => e.SentenceId == sentenceId && e.OrderInSentence == orderInSentence); if (sentenceWord == null) { sentenceWord = new SentenceWord { SentenceId = sentenceId, OrderInSentence = orderInSentence }; context.SentenceWord.Add(sentenceWord); } sentenceWord.WordId = wordId; sentenceWord.OriginalText = originalText; sentenceWord.GrammarType = parsedGrammarWordType; context.SaveChanges(); result = IdValidator.IsValid(sentenceWord.Id); }); return(result); }
private Word ConvertToWord(Sentence sentence, Parse parse) { int start = parse.Span.Start; int end = parse.Span.End; string text = GetPartText(parse, start, end); string dirtyType = parse.Type; GrammarWordType grammarWordType = _typeConverter.ConvertToWordType(dirtyType); var result = new Word(text, grammarWordType); string fullText = GetFullWord(text, grammarWordType); if (_nativeTextAnalyzer.NeedTryGetBaseForm(dirtyType) && !_specialWords.Contains(fullText.ToLowerInvariant())) { result.NormalForms = _nativeTextAnalyzer.GetLemmas(fullText, dirtyType.ToLowerInvariant()); } if (!string.Equals(fullText, text, StringComparison.InvariantCultureIgnoreCase)) { result.FullText = fullText; } sentence.AddWord(result); return(result); }
private static string GetFullWord(string word, GrammarWordType grammarType) { string result; if (!_fullWordForms.TryGetFullForm(grammarType, word, out result)) { result = word; } return(result); }
public bool TryGetFullForm(GrammarWordType grammarWordType, string shortForm, out string fullForm) { return(_shortAndFullFormsWords[grammarWordType].TryGetValue(shortForm, out fullForm)); }
public Word(string text, GrammarWordType type) { Text = text; Type = type; }