Example #1
0
        /// <summary>
        /// Semantic Size of the SENTENCE
        /// </summary>
        public async Task <decimal> SSOTS(StructuredSentence sentence)
        {
            var terms      = sentence.Terms.Distinct(new TermComparer()).ToList();
            var otherTerms = terms.ToList();

            var Re = 0m;

            foreach (var from in terms)
            {
                otherTerms.Remove(from);

                foreach (var to in otherTerms)
                {
                    Re += await SDIS(from.Id, to.Id, sentence);
                }
            }

            if (Re == 0)
            {
                return(0);
            }

            //var R = 1m / Re;

            return(Re);
        }
Example #2
0
        /// <summary>
        /// Semantic Distance In Sentence
        /// </summary>
        public async Task <decimal> SDIS(long from, long to, StructuredSentence sentence)
        {
            var L = await SDIO(from, to);

            var Ns = new Dictionary <long, long>()
            {
                { 0, 0 }, // речення
            };

            if (sentence.Terms.Any(v => v.Id == from) && sentence.Terms.Any(v => v.Id == to))
            {
                Ns[0] += sentence.Terms.Count(v => v.Id == from) * sentence.Terms.Count(v => v.Id == to);
            }

            var Re = ((Ns[0] * 1m) / (L + 0m));

            //var R = 1m / Re;

            return(Re);
        }
Example #3
0
        /// <summary>
        /// Return text splited to paragraphs, sentences and with terms
        /// </summary>
        public async Task <StructuredText> GetStructuredText(string text)
        {
            var response = new StructuredText
            {
                OriginalText = text,
                Paragraphs   = new List <StructuredParagraph>(),
                Terms        = new List <Term>()
            };

            var paragraphsSeperators = new Regex(@"[\n]");
            var sentenceSeperators   = new Regex(@"[.!?]");

            var paragraphsTexts = paragraphsSeperators.Split(text).ToList();

            // Поділ на речення, абзаци і тд
            foreach (var paragraphText in paragraphsTexts)
            {
                var paragraph = new StructuredParagraph
                {
                    OriginalText = paragraphText,
                    Sentences    = new List <StructuredSentence>(),
                    Terms        = new List <Term>()
                };

                var sentenceTexts = sentenceSeperators.Split(paragraphText);

                foreach (var sentenceText in sentenceTexts)
                {
                    var sentence = new StructuredSentence
                    {
                        OriginalText = sentenceText,
                        Terms        = new List <Term>()
                    };

                    paragraph.Sentences.Add(sentence);
                }

                response.Paragraphs.Add(paragraph);
            }

            //Отримання всіх термінів
            using (var session = _db.GetSession())
            {
                var result = await session.RunAsync(_transactions.GetTerms());

                var sentences = response.Paragraphs.SelectMany(v => v.Sentences).ToList();
                while (await result.FetchAsync())
                {
                    var item = new Term(result.Current[0] as INode);

                    foreach (var sentance in sentences)
                    {
                        if (IsUsing(item, sentance.OriginalText))
                        {
                            sentance.Terms.Add(item);
                        }
                    }
                }
            }

            foreach (var item in response.Paragraphs)
            {
                item.Terms = item.Sentences.SelectMany(v => v.Terms).ToList();
            }

            response.Terms = response.Paragraphs.SelectMany(v => v.Terms).ToList();

            return(response);
        }