Exemplo n.º 1
0
        /// <summary>
        /// Vovabularyを生成する
        /// </summary>
        public static async Task <Vocabulary> Create(IEnumerable <string> sentences, CancellationToken token = default)
        {
            if (sentences == null)
            {
                throw new ArgumentException("sentencesがnullになっています。");
            }

            var morphemes = new List <Morpheme>();

            foreach (var sentence in sentences)
            {
                var result = await MorphAnalyzerClient.AnalyzeAsync(sentence, token);

                foreach (var item in result)
                {
                    morphemes.Add(item);
                }
            }

            return(new Vocabulary(morphemes));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Bog Of Wordsを用いてベクトルに変換する
        /// </summary>
        public async Task <int[]> ConvertAsync(string sentence, CancellationToken token = default)
        {
            if (string.IsNullOrEmpty(sentence))
            {
                throw new ArgumentException("sentenceがNullもしくはEmptyになっています");
            }

            var morphemes = await MorphAnalyzerClient.AnalyzeAsync(sentence, token);

            var vec = new int[_vocabulary.Count];

            foreach (var morpheme in morphemes)
            {
                var index = _vocabulary.GetId(morpheme.Surface);

                if (index != -1)
                {
                    vec[index]++;
                }
            }

            return(vec);
        }