Ejemplo n.º 1
0
def genLetCondReturn(type, value):
    global count

    if len(value) == 1:
        # do something
        var = value[0].strip()
        if listSearch(var):
            var = lowrewriter.prefix_var(var) + "_RDFTerm"
        let = ""
    else:
        var = "$" + type + ` count `
        count = count + 1
        value_all = ""
        for s in value:
            if listSearch(s):
                s = lowrewriter.prefix_var(s.strip()) + "_RDFTerm"
            value_all = value_all + s

        let = "let " + var + " := _xsparql:_serialize((" + value_all + ")) \n"

    if listSearch(var):
        rdftype = var + "_NodeType"
        var = lowrewriter.prefix_var(var) + "_RDFTerm"
    else:
        rdftype = '""'

    cond = "if ( _xsparql:" + type + "( " + rdftype + ",  " + var + "  ) ) then (\n\t\t"
    suffix = ' ) else ""'

    return let, cond, var, suffix
Ejemplo n.º 2
0
def build_predicate(subject, p):

    #    debug.debug('------- build_predicate', p, len(p))

    if len(p) == 1:
        b = p[0][0]
        if len(b) >= 2 and b[0] == "{" and b[-1] == "}" and b[1:-1].find("{") == -1 and b[1:-1].find("}") == -1:
            strip = str(b).lstrip("{")
            b = strip.rstrip("}")

            #            let_p, cond_p, ret_p, suff_p = build_bnode('_validPredicate', p[0][1])
            let, cond, ret, suff = build_object(subject, b, p[0][1])
            return let, cond, " " + b + ",  " + ret + " ", suff
        elif len(b) >= 2 and (b[0] == "$" or b[0] == "?"):
            if b[0] == "?":
                b = b.lstrip("?")
                b = "$" + b

            if listSearch(b):
                var = lowrewriter.prefix_var(b) + "_RDFTerm"
            else:
                var = b

            let_p, cond_p, ret_p, suff_p = build_bnode("_validPredicate", var)
            let, cond, ret, suff = build_object(subject, ret_p.rstrip(", "), p[0][1])
            return let_p + let, cond_p + cond, ret, suff_p + suff
        else:
            if len(b) >= 2:
                if b[0] != "_" and b[1] != ":":
                    let_p, cond_p, ret_p, suff_p = build_bnode("_validPredicate", b)
                    let, cond, ret, suff = build_object(subject, ret_p.rstrip(", "), p[0][1])
                    return let_p + let, "", cond_p + cond + "  \n\t  " + ret.rstrip(", ") + "  \n " + suff_p + suff, ""
            else:
                let, cond, ret, suff = build_object(subject, b, p[0][1])
                return let, "", cond + "  \n\t " + ret.rstrip(",") + ", " + suff, ""
    elif len(p) == 0:
        return "", "", "", ""
    else:
        d = p
        if d[0] == "[":
            d.remove("[")
            let1, cond1, ret1, suff1 = build_predicate(subject, [d[0]])
            let2, cond2, ret2, suff2 = build_predicate(subject, [d[1]])
            return let1 + let2, cond1 + cond2, '"[", ' + ret1 + '"&#59;", \n\t\t' + ret2 + ' "]",\n', suff1 + suff2
        else:
            let1, cond1, ret1, suff1 = build_predicate(subject, [d[0]])
            let2, cond2, ret2, suff2 = build_predicate(subject, d[1:])
            return let1 + let2, "", "\n\t " + cond1 + ret1.rstrip(", ") + suff1 + ",  \n\t " + ret2, ""