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;

        String command = mc.toString(stack.getFirst());
        stack = stack.getRest();

        int exitCode;
        String normalOutput;
        String errorOutput;

        Runtime r = Runtime.getRuntime();

        try {
            Process p = r.exec(command);
            exitCode = p.waitFor();
            normalOutput = readInputStream(p.getInputStream(), OUTPUT_MAXLEN);
            errorOutput = readInputStream(p.getErrorStream(), OUTPUT_MAXLEN);
        } catch (IOException e) {
            throw new RippleException(e);
        } catch (InterruptedException e) {
            throw new RippleException(e);
        }

        solutions.put(
                stack.push(mc.valueOf(exitCode))
                        .push(mc.valueOf(normalOutput))
                        .push(mc.valueOf(errorOutput)));
    }
View Full Code Here


                      final ModelConnection mc) throws RippleException {

        RippleValue l;

        l = arg.getFirst();
        final RippleList rest = arg.getRest();

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

        mc.toList(l, listSink);
    }
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((int) Math.floor(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;

        String query = mc.toString(stack.getFirst());
        stack = stack.getRest();

        CloseableIteration<? extends BindingSet, QueryEvaluationException> results
                = mc.evaluate(query);

        try {
            try {
                while (results.hasNext()) {
                    KeyValueValue kv = new SPARQLValue(results.next());

                    try {
                        solutions.put(stack.push(kv));
                    } catch (RippleException e) {
                        // Soft fail
                        e.logError();
                    }
                }
View Full Code Here

    }

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

        RippleValue rtrue = stack.getFirst();
        stack = stack.getRest();
        RippleValue rfalse = stack.getFirst();
        stack = stack.getRest();

        Operator inner = new Operator(new IntersectInner());
        solutions.put(
                stack.push(rtrue).push(Operator.OP).push(mc.valueOf(true)).push(inner));
        solutions.put(
                stack.push(rfalse).push(Operator.OP).push(mc.valueOf(false)).push(inner));
    }
View Full Code Here

        }

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

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

            result = mc.valueOf(10).pow(x);

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

            boolean b = mc.toBoolean(arg.getFirst());

            if (b) {
                StackMapping a = new WhileApplicator(program, criterion);
                RippleList stack = originalStack.push(program).push(new Operator(a));
                solutions.put(stack);
            } else {
                solutions.put(originalStack);
            }
        }
View Full Code Here

* @author Joshua Shinavier (http://fortytwo.net)
*/
public class RandomTest extends RippleTestCase {
    public void testSingleSolution() throws Exception {
        Collection<RippleList> results;
        RippleList l;
        RippleValue v;
        double d;
        Set<Double> values = new HashSet<Double>();

        for (int i = 0; i < 1000; i++) {
            results = reduce("random.");
            assertEquals(1, results.size());
            l = results.iterator().next();
            assertEquals(1, l.length());
            v = l.getFirst();
            assertTrue(v instanceof NumericValue);
            d = ((NumericValue) v).doubleValue();
            assertTrue(0 <= d);
            assertTrue(1 > d);
            Double dobj = new Double(d);
View Full Code Here

            this.ops = ops;
            this.mc = mc;
        }

        public void put(final RippleList arg) throws RippleException {
            RippleList stack = arg;

            RippleList cur = ops;
            while (!cur.isNil()) {
                stack = stack.push(cur.getFirst());
                cur = cur.getRest();
            }

            reduce(stack, mc);
        }
View Full Code Here

    }

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

        RippleValue l;

        l = stack.getFirst();
        stack = stack.getRest();
        final int i = mc.toNumericValue(stack.getFirst()).intValue();
        final RippleList rest = stack.getRest();

        Sink<RippleList> listSink = new Sink<RippleList>() {
            public void put(RippleList list) throws RippleException {
                if (i < 1) {
                    throw new RippleException("list index out of bounds" +
                            " (keep in mind that 'at' begins counting at 1): " + i);
                }

                for (int j = 1; j < i; j++) {
                    list = list.getRest();
                    if (list.isNil()) {
                        throw new RippleException("list index out of bounds: " + i);
                    }
                }

                solutions.put(
                        rest.push(list.getFirst()));
            }
        };

        mc.toList(l, listSink);
    }
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.