示例#1
0
def query_node(top, query):
    req_args = flask.request.args
    path = '/%s/%s' % (top, query.strip('/'))
    offset = get_int(req_args, 'offset', 0, 0, 100000)
    limit = get_int(req_args, 'limit', 20, 0, 1000)
    grouped = req_args.get('grouped', 'false').lower() == 'true'
    if grouped:
        limit = min(limit, 100)
        results = responses.lookup_grouped_by_feature(path, feature_limit=limit)
    elif path.startswith('/a/'):
        results = responses.lookup_single_assertion(path)
    else:
        results = responses.lookup_paginated(path, offset=offset, limit=limit)
    return jsonify(results)
示例#2
0
def query_node(top, query):
    req_args = flask.request.args
    path = '/%s/%s' % (top, query.strip('/'))
    offset = get_int(req_args, 'offset', 0, 0, 100000)
    limit = get_int(req_args, 'limit', 20, 0, 1000)
    grouped = req_args.get('grouped', 'false').lower() == 'true'
    if grouped:
        limit = min(limit, 100)
        results = responses.lookup_grouped_by_feature(path,
                                                      feature_limit=limit)
    elif path.startswith('/a/'):
        results = responses.lookup_single_assertion(path)
    else:
        results = responses.lookup_paginated(path, offset=offset, limit=limit)
    return jsonify(results)
示例#3
0
def test_lookup_paginated(run_build):
    response = lookup_paginated('/c/en/test', limit=5)

    # The original response points to a context file retrieved over HTTP.
    # Check its value before we mess with it.
    orig_context = response['@context']
    assert orig_context == [
        "http://api.conceptnet.io/ld/conceptnet5.7/context.ld.json"
    ]

    ld = flat_map(response)

    # Look at the details of the related node "quiz"
    quiz = ld[api('/c/en/quiz')]
    check_id_match(quiz['@type'], vocab('Node'))
    quiz_label = quiz[vocab('label')][0]
    assert quiz_label == {
        '@type': 'http://www.w3.org/2001/XMLSchema#string',
        '@value': 'quiz',
    }

    edge = ld[api('/a/[/r/RelatedTo/,/c/en/test/,/c/en/quiz/]')]
    check_id_match(edge['@type'], vocab('Edge'))
    check_id_match(edge[vocab('dataset')], api('/d/verbosity'))
    check_id_match(edge[vocab('start')], api('/c/en/test'))
    check_id_match(edge[vocab('end')], api('/c/en/quiz'))
    check_id_match(edge[vocab('rel')], api('/r/RelatedTo'))
    check_id_match(edge[vocab('rel')], api('/r/RelatedTo'))
    assert edge[vocab('surfaceText')] == [{
        '@type':
        'http://www.w3.org/2001/XMLSchema#string',
        '@value':
        '[[test]] is related to [[quiz]]',
    }]

    # The resource we actually asked for has more properties
    test = ld[api('/c/en/test')]
    assert len(test[vocab('edges')]) == 5

    pagination = ld[api('/c/en/test?offset=0&limit=5')]
    check_id_match(pagination['@type'],
                   vocab('pagination-PartialCollectionView'))
    check_id_match(pagination[vocab('pagination-paginatedProperty')],
                   vocab('edges'))
    check_id_match(pagination[vocab('pagination-nextPage')],
                   api('/c/en/test?offset=5&limit=5'))
示例#4
0
def browse_node(top, query):
    # TODO: can we make this work with edge_list_query?
    req_args = flask.request.args
    path = '/%s/%s' % (top, query.strip('/'))
    offset = get_int(req_args, 'offset', 0, 0, 100000)
    limit = get_int(req_args, 'limit', 100, 0, 1000)
    results = responses.lookup_paginated(path, offset=offset, limit=limit)
    sources = []
    pageStart = offset + 1
    pageEnd = offset + max(1, min(limit, len(results['edges'])))

    for edge in results['edges']:
        sources.extend(edge['sources'])
    return flask.render_template('edge_list.html',
                                 results=results,
                                 sources=sources,
                                 pageStart=pageStart,
                                 pageEnd=pageEnd)