Exemplo n.º 1
0
def hasParseError_rdflib(q, parse_path=True):
    """
    if has parse error, return true.

    input:
        q, the same as GetSPO_rdflib, one row from DataFrame with key: query
    output:
        boolean
    """
    try:
        # from ipdb import set_trace; set_trace()
        pq = parser.parseQuery(q['query'])

        if parse_path:
            # using function in rdflib to absolutize/resolve prefixes
            # may cause prefix error
            prologue = translatePrologue(pq[0], None)
            # using function in rdflib to simplify filter
            inner_traverse(pq[1], inner_simplifyFilters)
            pq[1] = traverse(pq[1],
                             visitPost=functools.partial(translatePName,
                                                         prologue=prologue))
            # using function in rdflib to translate path
            if 'where' in pq[1].keys():
                pq[1]['where'] = traverse(pq[1]['where'],
                                          visitPost=translatePath)

        return False

    except:
        #from ipdb import set_trace; set_trace()
        return True
Exemplo n.º 2
0
def GetSPOfromQuery(q, getBlankNode=False):
    pq = parser.parseQuery(q)
    form = GetQueryForm(pq)

    # using function in rdflib to absolutize/resolve prefixes
    prologue = translatePrologue(pq[0], None)
    pq[1] = traverse(pq[1],
                     visitPost=functools.partial(translatePName,
                                                 prologue=prologue))

    # using function in rdflib to simplify filter
    inner_traverse(pq[1], inner_simplifyFilters)

    # using function in rdflib to translate path
    if 'where' in pq[1].keys():
        pq[1]['where'] = traverse(pq[1]['where'], visitPost=translatePath)

    if form == 'DescribeQuery':
        triples, graph, bind, values, service, filter_info, describe_var = proQueryForm(
            pq)
    else:
        triples, graph, bind, values, service, filter_info = proQueryForm(pq)

    so = GetSOFromTriple(triples, getBlankNode=getBlankNode)
    p = GetPFromTriple(triples, getBlankNode=getBlankNode)

    if form == 'DescribeQuery':
        so = so + describe_var
    return list(set(so + p))
Exemplo n.º 3
0
def parseStr(query):
    pq = parser.parseQuery(query)

    # using function in rdflib to absolutize/resolve prefixes
    # may cause prefix error
    prologue = translatePrologue(pq[0], None)
    # using function in rdflib to simplify filter
    inner_traverse(pq[1], inner_simplifyFilters)
    pq[1] = traverse(pq[1],
                     visitPost=functools.partial(translatePName,
                                                 prologue=prologue))
    # using function in rdflib to translate path
    if 'where' in pq[1].keys():
        pq[1]['where'] = traverse(pq[1]['where'], visitPost=translatePath)
    return pq
Exemplo n.º 4
0
def GetInfo(query):
    pq = parser.parseQuery(query)
    prologue = translatePrologue(pq[0], None)
    pq[1] = traverse(pq[1],
                     visitPost=functools.partial(translatePName,
                                                 prologue=prologue))

    # using function in rdflib to simplify filter
    inner_traverse(pq[1], inner_simplifyFilters)

    # using function in rdflib to translate path
    if 'where' in pq[1].keys():
        pq[1]['where'] = traverse(pq[1]['where'], visitPost=translatePath)

    info = proQueryForm(pq, additional=False)
    return info