Package net.fortytwo.ripple.model

Examples of net.fortytwo.ripple.model.RippleList


        public void apply(final RippleList arg,
                          final Sink<RippleList> solutions,
                          final ModelConnection mc) throws RippleException {

            RippleList stack = arg;
            StackMapping d = new WhileDecider(stack, program, criterion);

            solutions.put(stack.push(criterion).push(new Operator(d)));
        }
View Full Code Here


    }

    public void apply(final RippleList arg,
                      final Sink<RippleList> solutions,
                      final ModelConnection mc) throws RippleException {
        RippleList stack = arg;

        NumericValue a, result;

        a = mc.toNumericValue(stack.getFirst());
        stack = stack.getRest();

        result = mc.valueOf(Math.cosh(a.doubleValue()));

        solutions.put(
                stack.push(result));
    }
View Full Code Here

    public void apply(final RippleList arg,
                      final Sink<RippleList> solutions,
                      final ModelConnection mc) throws RippleException {

        RippleList stack = arg;
        RippleValue first = stack.getFirst();
        final RippleList rest = stack.getRest();

        Sink<Operator> opSink = new Sink<Operator>() {
            public void put(final Operator op) throws RippleException {
                solutions.put(rest.push(
                        new StackMappingWrapper(new OptionalQuantifier(op), mc)));
            }
        };

        Operator.createOperator(first, opSink, mc);
View Full Code Here

    }

    public void apply(final RippleList arg,
                      final Sink<RippleList> solutions,
                      final ModelConnection mc) throws RippleException {
        RippleList stack = arg;

        NumericValue a, b, result;

        b = mc.toNumericValue(stack.getFirst());
        stack = stack.getRest();
        a = mc.toNumericValue(stack.getFirst());
        stack = stack.getRest();

        result = a.sub(b);

        solutions.put(
                stack.push(result));
    }
View Full Code Here

                      final ModelConnection mc) throws RippleException {
        // FIXME: cheat to temporarily disable asynchronous query answering
        boolean a = Ripple.asynchronousQueries();
        Ripple.enableAsynchronousQueries(false);
        try {
            RippleList stack = arg;
            int steps = mc.toNumericValue(stack.getFirst()).intValue();
            stack = stack.getRest();

            //System.out.println("ranking on: " + stack);
            new RankingEvaluator(steps).apply(stack, solutions, mc);
        } finally {
            Ripple.enableAsynchronousQueries(a);
View Full Code Here

    public void apply(final RippleList arg,
                      final Sink<RippleList> solutions,
                      final ModelConnection mc) throws RippleException {
        RippleValue y, x;
        RippleList stack = arg;

        y = stack.getFirst();
        stack = stack.getRest();
        x = stack.getFirst();
        stack = stack.getRest();

        solutions.put(
                stack.push(x).push(x).push(y));
    }
View Full Code Here

    }

    public void apply(final RippleList arg,
                      final Sink<RippleList> solutions,
                      final ModelConnection mc) throws RippleException {
        RippleList stack = arg;

        NumericValue a, b, result;

        b = mc.toNumericValue(stack.getFirst());
        stack = stack.getRest();
        a = mc.toNumericValue(stack.getFirst());
        stack = stack.getRest();

        // Note: division by zero simply does not yield a result.
        if (!b.isZero()) {
            result = a.div(b);

            solutions.put(
                    stack.push(result));
        }
    }
View Full Code Here

    }

    public void apply(final RippleList arg,
                      final Sink<RippleList> solutions,
                      final ModelConnection mc) throws RippleException {
        RippleList stack = arg;

        final RippleValue mappingVal = stack.getFirst();
        stack = stack.getRest();
        RippleValue listVal = stack.getFirst();
        final RippleList rest = stack.getRest();

        // Note: it is simply assumed that these mappings have a production of
        // exactly one item.
        final Collector<Operator> operators = new Collector<Operator>();
        Operator.createOperator(mappingVal, operators, mc);

        Sink<RippleList> listSink = new Sink<RippleList>() {
            public void put(final RippleList list) throws RippleException {
                if (list.isNil()) {
                    solutions.put(rest.push(list));
                }

                // TODO: this is probably a little more complicated than it needs to be
                else {
                    RippleList inverted = list.invert();
                    RippleValue f = inverted.getFirst();

                    for (Operator operator : operators) {
                        StackMapping inner = new InnerMapping(mc.list(), inverted.getRest(), operator);
                        solutions.put(rest.push(f).push(mappingVal).push(Operator.OP).push(new Operator(inner)));
                    }
                }
            }
        };
View Full Code Here

        // Handle circular lists (in the unlikely event that some implementation allows them) sanely.
        // TODO: handle list containment cycles (e.g. list containing a list containing the original list) as well.
        // These are actually more likely than circular lists.
        Set<RDFValue> alreadyInterned = new HashSet<RDFValue>();

        RippleList cur = list;
        RDFValue id = cur.toRDF(this);
        while (!cur.isNil()) {
            if (alreadyInterned.contains(id)) {
                break;
            } else {
                alreadyInterned.add(id);
            }

            RDFValue firstRdf = cur.getFirst().toRDF(this);

            if (null == firstRdf) {
                System.err.println("list item has no RDF identity: " + cur.getFirst());
                return false;
            }

            if (cur.getFirst() instanceof RippleList) {
                internalize((RippleList) cur.getFirst());
            }

            RippleList rest = cur.getRest();
            RDFValue restRdf = rest.toRDF(this);

            buffer.put(
                    valueFactory.createStatement((Resource) id.sesameValue(), RDF.TYPE, RDF.LIST));
            buffer.put(
                    valueFactory.createStatement((Resource) id.sesameValue(), RDF.FIRST, firstRdf.sesameValue()));
View Full Code Here

    }

    public void apply(final RippleList arg,
                      final Sink<RippleList> solutions,
                      final ModelConnection mc) throws RippleException {
        RippleList stack = arg;

        double a;

        a = mc.toNumericValue(stack.getFirst()).doubleValue();
        stack = stack.getRest();

        // Apply the function only if it is defined for the given argument.
        if (a >= 0) {
            double d = Math.sqrt(a);

            // Yield both square roots.
            try {
                solutions.put(
                        stack.push(mc.valueOf(d)));
                if (d > 0) {
                    solutions.put(
                            stack.push(mc.valueOf(0.0 - d)));
                }
            } catch (RippleException e) {
                // Soft fail
                e.logError();
            }
View Full Code Here

TOP

Related Classes of net.fortytwo.ripple.model.RippleList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.