Exemplo n.º 1
0
        public bool Startup()
        {
            if (_env == null ||
                CBRContextManager.GetCBRContext(_name) == null)
            {
                System.Console.WriteLine("environment is not set or context is null");
                return(false);
            }

            _ctx = CBRContextManager.GetCBRContext(_name);
            if (_problem == null)
            {
                System.Console.WriteLine("problem is not set");
                return(false);
            }
            _ctx.SetCurrentCase(_problem);
            #region only for test
            if (Version.DEBUG)
            {
                System.Console.WriteLine("=====context detail=====");
                System.Console.WriteLine("Reasoning Engine startup successfully!");
                System.Console.WriteLine("problem case is:");
                for (int i = 0; i < _problem.GetFeatures().Count; i++)
                {
                    Feature f = (Feature)_problem.GetFeatures()[i];
                    System.Console.WriteLine("\t" + f.GetFeatureName() + ":" + f.GetFeatureValue());
                }
                System.Console.WriteLine("context is:");
                System.Console.WriteLine("case base\t" + _ctx.GetCaseBase().ToString());
                System.Console.WriteLine("case base input\t" + _ctx.GetCaseBaseInput().ToString());
                System.Console.WriteLine("case base input type\t" + _ctx.GetCaseBaseInputType().ToString());
                System.Console.WriteLine("case base url\t" + _ctx.GetCaseBaseURL().ToString());
                System.Console.WriteLine("case restore method\t" + _ctx.GetCaseRestoreMethod().ToString());
                System.Console.WriteLine("case retrieval method\t" + _ctx.GetCaseRetrievalMethod().ToString());
                System.Console.WriteLine("case reuse method\t" + _ctx.GetCaseReuseMethod().ToString());
                System.Console.WriteLine("case reuse strategy\t" + _ctx.GetCaseReuseStrategy().ToString());
                System.Console.WriteLine("case revise method\t" + _ctx.GetCaseReviseMethod().ToString());
                System.Console.WriteLine("current case\t" + _ctx.GetCurrentCase().ToString());
                System.Console.WriteLine("similarity\t" + _ctx.GetSimilarity().ToString());
                System.Console.WriteLine("similarity threhold\t" + _ctx.GetSimilarityThrehold().ToString());
                System.Console.WriteLine("=====end of context detail=====");
            }
            #endregion
            return(true);
        }
Exemplo n.º 2
0
        public Case Reuse(ArrayList stats)
        {
            if (stats == null || stats.Count <= 0)
            {
                return(null);
            }

            if (_env == null)
            {
                throw new ContextException("environment variable is not set");
            }

            ICBRContext ctx = CBRContextManager.GetCBRContext(_env);

            if (ctx == null)
            {
                throw new ContextException("context is not set");
            }
            Case problem = ctx.GetCurrentCase();
            Case c       = ((IStat)(stats[0])).GetCBRCase();

            if (c != null && problem != null)
            {
                ArrayList features = c.GetFeatures();
                for (int i = 0; i < features.Count; i++)
                {
                    Feature f = (Feature)features[i];
                    //if the feature is the key of problem
                    if (f.GetIsKey())
                    {
                        problem.ModifyFeature(f.GetFeatureName(),
                                              f.GetFeatureType(), f.GetFeatureValue(),
                                              f.GetWeight(), f.GetIsKey(),
                                              f.GetIsIndex());
                    }
                }

                return(problem);
            }
            return(null);
        }
Exemplo n.º 3
0
        public Case Reuse(System.Collections.ArrayList stats)
        {
            if (stats == null || stats.Count <= 0)
            {
                return(null);
            }
            if (_env == null)
            {
                throw new ContextException("environment variable is not set");
            }

            ICBRContext ctx = CBRContextManager.GetCBRContext(_env);

            if (ctx == null)
            {
                throw new ContextException("ctx is not set");
            }

            Case problem = ctx.GetCurrentCase();

            if (problem == null)
            {
                throw new ContextException(
                          "interface ICBRContext's GetCurrentCase return null");
            }
            ArrayList list = problem.GetFeatures();

            for (int i = 0; i < list.Count; i++)
            {
                Feature f = (Feature)list[i];
                if (f.GetIsKey() && TypeHandle.IsNumericFeature(f))
                {
                    //compute the mean value of features
                    f.SetFeatureValue(ComputeMeanValue(stats,
                                                       f.GetFeatureName()));
                }
            }
            return(problem);
        }
Exemplo n.º 4
0
        public string ParseConditions(string src)
        {
            if (src == null ||
                src.Trim().Length <= 0)
            {
                return(null);
            }
            string      dst = src;
            ICBRContext ctx = CBRContextManager.GetCBRContext(_env);
            Case        c   = ctx.GetCurrentCase();

            ArrayList features = c.GetFeatures();

            foreach (Feature f in features)
            {
                string name = TOKEN_SHARP + f.GetFeatureName() + TOKEN_SHARP;
                if (f.GetFeatureValue() != null)
                {
                    dst = dst.Replace(name, f.GetFeatureValue().ToString());
                }
            }
            return(dst);
        }