示例#1
0
def index(type_name):
    """ Index all entities of a given type. """
    type_ = Type.by_name(type_name)
    if type_ is None:
        print "No such type: %s" % type_name
    else:
        type_.index()
示例#2
0
文件: web.py 项目: pombredanne/helmut
def entity(type, key, format=None):
    type_ = Type.by_name(type)
    if type_ is None:
        abort(404)
    entity = type_.by_key(key)
    if entity is None:
        abort(404)
    del entity['__id__']
    url = url_for('entity', type=type, key=key, _external=True)
    format = request_format(format)
    if format == 'json':
        entity['_url'] = url
        return jsonify(entity)
    #if 'redirect_url' in entity:
    #    return redirect(entity.get('redirect_url'),
    #                    code=303)
    return render_template('view.tmpl', entity=entity, url=url)
示例#3
0
文件: web.py 项目: pombredanne/helmut
def reconcile():
    """ 
    Reconciliation API, emulates Google Refine API. See: 
    http://code.google.com/p/google-refine/wiki/ReconciliationServiceApi
    """
    # TODO: Add propert support for types and namespacing.
    data = request.args.copy()
    data.update(request.form.copy())
    if 'query' in data:
        # single 
        q = data.get('query')
        if q.startswith('{'):
            try:
                q = json.loads(q)
            except ValueError:
                abort(400)
        return jsonify(_query(q))
    elif 'queries' in data:
        # multiple requests in one query
        qs = data.get('queries')
        try:
            qs = json.loads(qs)
        except ValueError:
            abort(400)
        queries = {}
        for k, q in qs.items():
            queries[k] = _query(q)
        return jsonify(queries)
    else:
        urlp = url_for('index', _external=True).strip('/') + '{{id}}'
        types = [{'name': t.name, 'id': '/' + t.name} for t in Type.types()]
        meta = {
                'name': app.config['TITLE'],
                'identifierSpace': 'http://rdf.freebase.com/ns/type.object.id',
                'schemaSpace': 'http://rdf.freebase.com/ns/type.object.id',
                'view': {'url': urlp},
                'preview': {
                    'url': urlp + '?preview=true', 
                    'width': 400,
                    'height': 300
                    },
                'defaultTypes': types
                }
        return jsonify(meta)