예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        private static string GetFullWord(string word, GrammarWordType grammarType)
        {
            string result;

            if (!_fullWordForms.TryGetFullForm(grammarType, word, out result))
            {
                result = word;
            }
            return(result);
        }
예제 #4
0
 public bool TryGetFullForm(GrammarWordType grammarWordType, string shortForm, out string fullForm)
 {
     return(_shortAndFullFormsWords[grammarWordType].TryGetValue(shortForm, out fullForm));
 }
예제 #5
0
파일: Word.cs 프로젝트: AndreyShp/StudyFun
 public Word(string text, GrammarWordType type)
 {
     Text = text;
     Type = type;
 }