예제 #1
0
        public virtual List <WorldObject> Analize(string text, string systemQuestionText)
        {
            ObjectCache cache      = MemoryCache.Default;
            var         cachedItem = cache.Get(text + systemQuestionText) as WorldObject[];

            if (cachedItem == null || cachedItem.Length == 0 || true)
            {
                // var context = new TextContext();
                var textAnlz = Ma.meniAnalize(text, systemQuestionText != null);
                List <WorldObject>       input    = new List <WorldObject>();
                List <WorldObject>       sentence = new List <WorldObject>();
                List <WorldObject>       last     = new List <WorldObject>();
                List <List <ITemplate> > sentences;
                List <ITemplate>         context = new List <ITemplate>();


                if (systemQuestionText != null && textAnlz.FindAll(x => x.FindAll(y => y.isA(WordType.gufWord)).Count > 0).Count > 0)
                {
                    //add mising data to entity DB
                    var contextAnlz = Ma.meniAnalize(systemQuestionText, true);

                    //create context
                    if (contextAnlz.Any())
                    {
                        sentences = sa.findGufContext(textAnlz, contextAnlz[0].Cast <ITemplate>().ToList());
                    }
                    else
                    {
                        sentences = sa.findGufContext(textAnlz, null);
                    }
                }
                else
                {
                    sentences = sa.findGufContext(textAnlz, context);
                }

                string logTemp;

                foreach (var s in sentences)
                {
                    sentence = sa.findTemplate(s.ToArray(), out logTemp);
                    last     = sentence;
                    input.AddRange(sentence);
                }
                var exp = new CacheItemPolicy();
                exp.SlidingExpiration = (new TimeSpan(1, 0, 0, 1));
                cache.Set(text + systemQuestionText, input.ToArray(), exp);
                return(input);
            }
            else
            {
                return(new List <WorldObject>(cachedItem));
            }
        }
        public void findGufContextTest()
        {
            listTemplate.AddRange(new ITemplate[] { moqWordObject1.Object, moqWordObject2.Object, moqWordObject3.Object, moqWordObject4.Object });
            var guftemplate = new WordObject[] { moqWordGufObjectShe.Object, moqWordGufObjectHe.Object, moqWordGufObjectIt.Object, moqWordGufObjectThey.Object };



            string log            = "";
            var    listListObject = new List <List <WordObject> >();

            listListObject.Add(guftemplate.ToList());
            var res    = sAnal.findGufContext(listListObject, listTemplate);
            var single = res.Single().Cast <WordObject>();


            //good
            Assert.IsTrue(single.Where(x => x == moqWordObject1.Object).Count() == 1);
            Assert.IsTrue(single.Where(x => x == moqWordObject2.Object).Count() == 1);
            Assert.IsTrue(single.Where(x => x == moqWordObject3.Object).Count() == 1);
            Assert.IsTrue(single.Where(x => x == moqWordObject4.Object).Count() == 1);
            Assert.IsTrue(single.Count() == 4);

            listTemplate.Clear();
            //bad
            res    = sAnal.findGufContext(listListObject, listTemplate);
            single = res.Single().Cast <WordObject>();

            Assert.IsFalse(single.Where(x => x == moqWordObject1.Object).Count() == 1);
            Assert.IsFalse(single.Where(x => x == moqWordObject2.Object).Count() == 1);
            Assert.IsFalse(single.Where(x => x == moqWordObject3.Object).Count() == 1);
            Assert.IsFalse(single.Where(x => x == moqWordObject4.Object).Count() == 1);
            Assert.IsTrue(single.Count() == 4);

            //ugly
            res    = sAnal.findGufContext(listListObject, null);
            single = res.Single().Cast <WordObject>();

            Assert.IsFalse(single.Where(x => x == moqWordObject1.Object).Count() == 1);
            Assert.IsFalse(single.Where(x => x == moqWordObject2.Object).Count() == 1);
            Assert.IsFalse(single.Where(x => x == moqWordObject3.Object).Count() == 1);
            Assert.IsFalse(single.Where(x => x == moqWordObject4.Object).Count() == 1);
            Assert.IsTrue(single.Count() == 4);
        }