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, group_limit=limit) else: results = responses.lookup_paginated(path, offset=offset, limit=limit) return jsonify(results)
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)
def browse_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', 50, 0, 1000) results = responses.lookup_paginated(path, offset=offset, limit=limit) pageStart = offset + 1 pageEnd = offset + max(1, min(limit, len(results['edges']))) sources = [] for edge in results['edges']: sources.extend(edge['sources']) return flask.render_template( 'edge_list.html', results=results, sources=sources, pageStart=pageStart, pageEnd=pageEnd )
def browse_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', 50, 0, 1000) results = responses.lookup_paginated(path, offset=offset, limit=limit) pageStart = offset + 1 pageEnd = offset + max(1, min(limit, len(results['edges']))) sources = [] for edge in results['edges']: sources.extend(edge['sources']) return flask.render_template('edge_list.html', results=results, sources=sources, pageStart=pageStart, pageEnd=pageEnd)
def test_lookup_paginated(): 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'] eq_(orig_context, ["http://api.conceptnet.io/" + CONTEXT_PATH]) 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] eq_(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')) eq_( 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')] eq_(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'))