示例#1
0
        public double Compute(ValueExpression expression, string path)
        {
            path = PathUtils.NormalizePath(path);

            var statistics = _statistics.GetStatistics(path);

            if (statistics == null)
            {
                return(0);
            }

            // find which subsets of attributes match this expression
            long sum      = 0;
            long totalSum = 0;
            var  visitor  = new PriorityVisitor(statistics.AttributeSubsets, _metadataAttributes);
            var  result   = expression.Accept(visitor);

            // count the files which contain these subsets
            for (var i = 0; i < result.Count; ++i)
            {
                if (result[i])
                {
                    sum += statistics.GetSubsetCount(i);
                }

                totalSum += statistics.GetSubsetCount(i);
            }

            Trace.Assert(sum <= totalSum);

            // compute the probability
            return(sum / (double)totalSum);
        }
        public void VisitValue()
        {
            var valueExpr =
                new ValueExpression(
                    new FuzzyVariable("MyFuzzyVariable", new NumericVariable("MyNumVariable")),
                    new FuzzyTerm("MyTerm", new MembershipFunction()));

            var sut = new ToStringVisitor();

            var result = sut.Visit(valueExpr);
            Assert.AreEqual("MyFuzzyVariable=MyTerm", result);

            result = valueExpr.Accept(sut);
            Assert.AreEqual("MyFuzzyVariable=MyTerm", result);
        }
        public void VisitValue()
        {
            var variable = new FuzzyVariable("MyFuzzyVariable", new NumericVariable("MyNumVariable"));
            var valueExpr =
                new ValueExpression(
                    variable,
                    new FuzzyTerm("MyTerm", new MembershipFunction()));

            var sut = new GetInvolvedVariables();

            var result = sut.Visit(valueExpr);
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(variable, result[0]);

            result = valueExpr.Accept(sut);
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(variable, result[0]);
        }
        public void Accept()
        {
            var term = new FuzzyTerm("Term", new MembershipFunction());
            var var = new FuzzyVariable("Variable", null, term);
            
            var mocks = new MockRepository();

            var visitor = mocks.StrictMock<IExpressionVisitor<int>>();

            var sut = new ValueExpression(var, term);

            Expect.Call(visitor.Visit(sut)).Return(42);

            mocks.ReplayAll();

            var result = sut.Accept(visitor);

            Assert.AreEqual(42, result);

            mocks.VerifyAll();
        }
示例#5
0
 public AccessedAttributesVisitor(ValueExpression expr)
 {
     expr.Accept(this);
 }