Search in sources :

Example 21 with RString

use of water.util.RString in project h2o-2 by h2oai.

the class KMeans2 method link.

// Make a link that lands on this page
public static String link(Key k, String content) {
    RString rs = new RString("<a href='KMeans2.query?source=%$key'>%content</a>");
    rs.replace("key", k.toString());
    rs.replace("content", content);
    return rs.toString();
}
Also used : RString(water.util.RString)

Example 22 with RString

use of water.util.RString in project h2o-2 by h2oai.

the class RStringTest method testReplacement2.

@Test
public void testReplacement2() {
    RString r = new RString(s2);
    r.replace("text", "TEXT");
    assertEquals("ReplacementInTEXTValue", r.toString());
}
Also used : RString(water.util.RString) Test(org.junit.Test)

Example 23 with RString

use of water.util.RString in project h2o-2 by h2oai.

the class RStringTest method testReplacement.

@Test
public void testReplacement() {
    RString r1 = new RString(s1);
    r1.replace("all", " +");
    assertEquals("hello  + and +%2B and ", r1.toString());
    r1.replace("go", "why");
    assertEquals("hello  + and +%2B and why", r1.toString());
}
Also used : RString(water.util.RString) Test(org.junit.Test)

Example 24 with RString

use of water.util.RString in project h2o-2 by h2oai.

the class Parse method link.

public static String link(String k, String content) {
    RString rs = new RString("<a href='Parse.query?%key_param=%$key'>%content</a>");
    rs.replace("key_param", SOURCE_KEY);
    rs.replace("key", k.toString());
    rs.replace("content", content);
    return rs.toString();
}
Also used : RString(water.util.RString)

Example 25 with RString

use of water.util.RString in project h2o-2 by h2oai.

the class RequestQueries method buildQuery.

/** Returns the request query form produced from the given input arguments.
   */
protected String buildQuery(Properties parms, RequestType type) {
    if (parms.isEmpty())
        type = RequestType.query;
    RString result = new RString(_queryHtml);
    result.replace("REQ_NAME", this.getClass().getSimpleName());
    StringBuilder query = new StringBuilder();
    query.append("<form onsubmit='return false;'>");
    RString script = new RString(_queryJs);
    script.replace("REQUEST_NAME", getClass().getSimpleName());
    for (Argument arg : _arguments) {
        try {
            arg.check(RequestQueries.this, parms.getProperty(arg._name, ""));
            queryArgumentValueSet(arg, parms);
        } catch (IllegalArgumentException e) {
            // in query mode only display error for arguments present
            if ((type != RequestType.query) || !parms.getProperty(arg._name, "").isEmpty())
                query.append("<div class='alert alert-error'>" + e.getMessage() + "</div>");
        }
        if (arg._hideInQuery)
            continue;
        if (!arg.disabled()) {
            RString x = script.restartGroup("REQUEST_ELEMENT");
            x.replace("ELEMENT_NAME", arg._name);
            // we'll act "as if" the field was never filled in.
            if (arg._prerequisites != null) {
                StringBuilder sb = new StringBuilder("if( ");
                ArrayList<RequestArguments.Argument> preqs = arg._prerequisites;
                for (RequestArguments.Argument dep : preqs) sb.append("specArg!=='").append(dep._name).append("' && ");
                sb.append("true ) ");
                x.replace("ELEMENT_PREQ", sb);
            }
            x.append();
            x = script.restartGroup("ELEMENT_VALUE");
            x.replace("ELEMENT_NAME", arg._name);
            x.replace("BODY", "function query_value_" + arg._name + "() { " + arg.jsValue() + "} ");
            x.append();
        }
        if (arg.refreshOnChange()) {
            RString x = script.restartGroup("ELEMENT_ONCHANGE");
            x.replace("BODY", arg.jsRefresh("query_refresh"));
            x.append();
        }
        RString x = script.restartGroup("ELEMENT_ADDONS");
        x.replace("BODY", arg.jsAddons());
        x.append();
    }
    for (Argument arg : _arguments) {
        if (arg._hideInQuery)
            continue;
        query.append(arg.query());
    }
    query.append("</form>");
    result.replace("QUERY", query.toString());
    result.replace("SCRIPT", script.toString());
    return result.toString();
}
Also used : RString(water.util.RString)

Aggregations

RString (water.util.RString)30 Frame (water.fvec.Frame)3 Test (org.junit.Test)2 AutoBuffer (water.AutoBuffer)1 PrettyPrint (water.PrettyPrint)1