Пример #1
0
def cmd_q(fb, qstr):
    """run a freebase query.

    if the query string starts with "{" it is treated as json.
    otherwise it is treated as o-rison.

    dump the result as json.
    
    %prog q
    """
    if qstr.startswith('{'):
        q = simplejson.loads(qstr)
    else:
        q = rison.loads('(' + qstr + ')')

    # done this way for streaming
    first = True
    for result in fb.mss.mqlreaditer(q):
        if first:
            first = False
            print '[',
        else:
            print ',',
        print simplejson.dumps(result, indent=2),
    print ']'
Пример #2
0
def cmd_q(fb, qstr):
    """run a freebase query.

    if the query string starts with "{" it is treated as json.
    otherwise it is treated as o-rison.

    dump the result as json.
    
    %prog q
    """
    if qstr.startswith('{'):
        q = simplejson.loads(qstr)
    else:
        q = rison.loads('(' + qstr + ')')

    # done this way for streaming
    first = True
    for result in fb.mss.mqlreaditer(q):
        if first:
            first = False
            print '[',
        else:
            print ',',
        print simplejson.dumps(result, indent=2),
    print ']'
Пример #3
0
def cmd_q(fb, qstr):
    """run a freebase query.

    if the query string starts with "{" it is treated as json.
    otherwise it is treated as o-rison.

    dump the result as json.
    
    %prog q
    """
    if qstr.startswith('{'):
        q = simplejson.loads(qstr)
    else:
        q = rison.loads('(' + qstr + ')')

    # results could be streamed with a little more work
    results = fb.mss.mqlreaditer(q)
    print simplejson.dumps(list(results), indent=2)
Пример #4
0
def cmd_q(fb, qstr):
    """run a freebase query.

    if the query string starts with "{" it is treated as json.
    otherwise it is treated as o-rison.

    dump the result as json.
    
    %prog q
    """
    if qstr.startswith('{'):
        q = simplejson.loads(qstr)
    else:
        q = rison.loads('(' + qstr + ')')

    # results could be streamed with a little more work
    results = fb.mss.mqlreaditer(q)
    print simplejson.dumps(list(results), indent=2)
Пример #5
0
def cmd_find(fb, qstr):
    """print all ids matching a given constraint.

    if the query string starts with "{" it is treated as json.
    otherwise it is treated as o-rison.

    %prog find
    """
    if qstr.startswith('{'):
        q = simplejson.loads(qstr)
    else:
        q = rison.loads('(' + qstr + ')')

    if 'id' not in q:
        q['id'] = None

    results = fb.mss.mqlreaditer(q)
    for r in results:
        out(r.id)
Пример #6
0
def cmd_find(fb, qstr):
    """print all ids matching a given constraint.

    if the query string starts with "{" it is treated as json.
    otherwise it is treated as o-rison.

    %prog find
    """
    if qstr.startswith('{'):
        q = simplejson.loads(qstr)
    else:
        q = rison.loads('(' + qstr + ')')

    if 'id' not in q:
        q['id'] = None

    results = fb.mss.mqlreaditer(q)
    for r in results:
        out(r.id)