def browse_concept(uri): req_args = flask.request.args concept = '/c/%s' % uri pieces = split_uri(concept) if len(pieces) <= 2: return browse_node('c', pieces[1]) limit = get_int(req_args, 'limit', 20, 0, 1000) filters = {} for key in VALID_KEYS: if key != 'node' and key in req_args: filters[key] = req_args[key] results = responses.lookup_grouped_by_feature(concept, filters, group_limit=limit) sources = [] if 'error' in results: return flask.render_template('error.html', error=results['error']) for feature in results['features']: rel = feature['feature']['rel'] if rel in REL_HEADINGS['en']: label_choices = REL_HEADINGS['en'][rel] else: label_choices = ['%s {0}' % rel, '{0} %s' % rel] if feature['symmetric'] or 'end' in feature['feature']: feat_label = label_choices[0] else: feat_label = label_choices[1] feature['label'] = feat_label.format(results['label']) for edge in feature['edges']: sources.extend(edge['sources']) return flask.render_template( 'node_by_feature.html', term=results, features=results['features'], sources=sources )
def test_lookup_grouped(): response = lookup_grouped_by_feature('/c/en/test') ld = flat_map(response) # Look at the details of the related node "quiz", which should be the same # as they were for the non-grouped query 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]]'}] ) # We got a bunch of features test = ld[api('/c/en/test')] assert len(test[vocab('features')]) > 5
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_concept(uri): req_args = flask.request.args concept = '/c/%s' % uri pieces = split_uri(concept) if len(pieces) <= 2: return browse_node('c', pieces[1]) limit = get_int(req_args, 'limit', 20, 0, 1000) # Offset is not used when grouping by features offset = get_int(req_args, 'offset', 0, 0, 10000) filters = {} for key in VALID_KEYS: if key != 'node' and key in req_args: filters[key] = req_args[key] if filters: filters['node'] = concept limit = get_int(req_args, 'limit', 100, 0, 1000) return edge_list_query(filters, offset=offset, limit=limit) else: results = responses.lookup_grouped_by_feature(concept, filters, feature_limit=limit) sources = [] if 'error' in results: return flask.render_template('error.html', error=results['error']) for feature in results['features']: rel = feature['feature']['rel'] if rel in REL_HEADINGS['en']: label_choices = REL_HEADINGS['en'][rel] else: label_choices = ['%s {0}' % rel, '{0} %s' % rel] if feature['symmetric'] or 'end' in feature['feature']: feat_label = label_choices[0] else: feat_label = label_choices[1] feature['label'] = feat_label.format(results['label']) for edge in feature['edges']: sources.extend(edge['sources']) return flask.render_template('node_by_feature.html', term=results, features=results['features'], sources=sources)