示例#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 findTemplateTest()
        {
            listTemplate.AddRange(new ITemplate[] { moqWordObject1.Object, moqWordObject2.Object, moqWordObject3.Object, moqWordObject4.Object });
            string log = "";
            var    res = sAnal.findTemplate(listTemplate.ToArray(), out log);

            //good
            Assert.IsTrue(res.Contains(new PersonObject("דוד בן גוריון")));
            Assert.IsTrue(res.Contains(new ConceptObject("מגילת העצמאות")));
            Assert.IsTrue(res.Contains(new EventObject("הכרזת העצמאות")));
            Assert.IsTrue(res.Contains(new OrganizationObject("ההגנה")));
            Assert.IsTrue(res.Count() == 4);
        }
示例#3
0
        public void findTemplateIntegrationTest()
        {
            listTemplate.AddRange(new ITemplate[] { WordObject1, WordObject2, WordObject3, WordObject4 });
            string log = "";
            var    res = sAnal.findTemplate(listTemplate.ToArray(), out log);

            //good
            Assert.IsTrue(res.Contains(new OrganizationObject("ערבי")));
            Assert.IsTrue(res.Contains(new LocationObject("ירושלים")));
            Assert.IsTrue(res.Contains(new ConceptObject("פליטים")));
            Assert.IsTrue(res.Contains(new OrganizationObject("ירדן")));
            Assert.IsTrue(res.Count() == 4);
        }