Search in sources :

Example 1 with CQLRelation

use of org.z3950.zing.cql.CQLRelation in project okapi by folio-org.

the class CQLUtilTest method reduce.

private String reduce(String input) {
    CQLParser parser = new CQLParser(CQLParser.V1POINT2);
    try {
        CQLRelation rel = new CQLRelation("=");
        CQLTermNode source = new CQLTermNode("source", rel, "kb");
        CQLNode top = parser.parse(input);
        Comparator<CQLTermNode> f = (CQLTermNode n1, CQLTermNode n2) -> n1.getIndex().equals(n2.getIndex()) ? 0 : -1;
        CQLNode res = CQLUtil.reducer(top, source, f);
        if (res == null) {
            return "null";
        } else {
            return res.toCQL();
        }
    } catch (Exception ex) {
        return "Error: " + ex.getMessage();
    }
}
Also used : CQLTermNode(org.z3950.zing.cql.CQLTermNode) CQLParser(org.z3950.zing.cql.CQLParser) CQLRelation(org.z3950.zing.cql.CQLRelation) CQLNode(org.z3950.zing.cql.CQLNode)

Example 2 with CQLRelation

use of org.z3950.zing.cql.CQLRelation in project okapi by folio-org.

the class CQLUtilTest method eval.

private boolean eval(String input) {
    CQLParser parser = new CQLParser(CQLParser.V1POINT2);
    try {
        CQLRelation rel = new CQLRelation("=");
        CQLTermNode source = new CQLTermNode("source", rel, "kb");
        CQLNode top = parser.parse(input);
        Comparator<CQLTermNode> f = (CQLTermNode n1, CQLTermNode n2) -> {
            if (n1.getIndex().equals(n2.getIndex()) && !n1.getTerm().equals(n2.getTerm())) {
                return -1;
            }
            return 0;
        };
        return CQLUtil.eval(top, source, f);
    } catch (Exception ex) {
        return false;
    }
}
Also used : CQLTermNode(org.z3950.zing.cql.CQLTermNode) CQLParser(org.z3950.zing.cql.CQLParser) CQLRelation(org.z3950.zing.cql.CQLRelation) CQLNode(org.z3950.zing.cql.CQLNode)

Aggregations

CQLNode (org.z3950.zing.cql.CQLNode)2 CQLParser (org.z3950.zing.cql.CQLParser)2 CQLRelation (org.z3950.zing.cql.CQLRelation)2 CQLTermNode (org.z3950.zing.cql.CQLTermNode)2