コード例 #1
0
ファイル: view.py プロジェクト: ashwinsekar18/grano-reconcile
def suggest_property(slug):
    project = object_or_404(Project.by_slug(slug))
    authz.require(authz.project_read(project))

    prefix = '%%%s%%' % request.args.get('prefix', '')
    q = db.session.query(Attribute)
    q = q.join(Schema)
    q = q.filter(Schema.obj=='entity')
    q = q.filter(Schema.project==project)
    q = q.filter(or_(Attribute.label.ilike(prefix), Attribute.name.ilike(prefix)))
    q = q.limit(get_limit(default=5))

    matches = []
    for attribute in q:
        matches.append({
            'name': attribute.label,
            'n:type': {
                'id': '/properties/property',
                'name': 'Property'
            },
            'id': attribute.name
        })
    return jsonify({
        "code" : "/api/status/ok",
        "status" : "200 OK",
        "prefix" : request.args.get('prefix', ''),
        "result" : matches
        })
コード例 #2
0
ファイル: view.py プロジェクト: pudo-attic/grano-reconcile
def reconcile_op(project, query):
    log.info("Reconciling in %s: %r", project.slug, query)

    schemata = []
    if "type" in query:
        schemata = query.get("type")
        if isinstance(schemata, basestring):
            schemata = [schemata]
        schemata = [s.rsplit("/", 1)[-1] for s in schemata]

    properties = []
    if "properties" in query:
        for p in query.get("properties"):
            properties.append((p.get("pid"), p.get("v")))

    matches = find_matches(project, request.account, query.get("query", ""), schemata=schemata, properties=properties)
    matches = matches.limit(get_limit(default=5))

    results = []
    for match in matches:
        data = {
            "name": match["entity"]["name"].value,
            "score": match["score"],
            "type": [],
            "id": match["entity"].id,
            "uri": url_for("entities_api.view", id=match["entity"].id, _external=True),
            "match": match["score"] == 100,
        }
        for schema in match["entity"].schemata:
            if schema.hidden:
                continue
            data["type"].append({"id": "/" + project.slug + "/" + schema.name, "name": schema.label})
        results.append(data)

    return {"result": results, "num": len(results)}
コード例 #3
0
def suggest_type(slug):
    project = object_or_404(Project.by_slug(slug))
    authz.require(authz.project_read(project))

    prefix = '%%%s%%' % request.args.get('prefix', '')
    log.info("Suggesting types in %s: %r", project.slug, prefix)

    q = db.session.query(Schema)
    q = q.filter(Schema.obj == 'entity')
    q = q.filter(Schema.hidden == False) # noqa
    q = q.filter(Schema.project == project)
    q = q.filter(or_(Schema.label.ilike(prefix), Schema.name.ilike(prefix)))
    q = q.limit(get_limit(default=5))

    matches = []
    for schema in q:
        matches.append({
            'name': schema.label,
            'id': '/%s/%s' % (slug, schema.name)
        })
    return jsonify({
        "code": "/api/status/ok",
        "status": "200 OK",
        "prefix": request.args.get('prefix', ''),
        "result": matches
    })
コード例 #4
0
ファイル: view.py プロジェクト: pudo-attic/grano-reconcile
def suggest_property(slug):
    project = object_or_404(Project.by_slug(slug))
    authz.require(authz.project_read(project))

    prefix = "%%%s%%" % request.args.get("prefix", "")
    log.info("Suggesting property names in %s: %r", project.slug, prefix)

    q = db.session.query(Attribute)
    q = q.join(Schema)
    q = q.filter(Schema.obj == "entity")
    q = q.filter(Schema.project == project)
    q = q.filter(or_(Attribute.label.ilike(prefix), Attribute.name.ilike(prefix)))
    q = q.limit(get_limit(default=5))

    matches = []
    for attribute in q:
        matches.append(
            {
                "name": attribute.label,
                "n:type": {"id": "/properties/property", "name": "Property"},
                "id": attribute.name,
            }
        )
    return jsonify(
        {"code": "/api/status/ok", "status": "200 OK", "prefix": request.args.get("prefix", ""), "result": matches}
    )
コード例 #5
0
def suggest_property(slug):
    project = object_or_404(Project.by_slug(slug))
    authz.require(authz.project_read(project))

    prefix = '%%%s%%' % request.args.get('prefix', '')
    log.info("Suggesting property names in %s: %r", project.slug, prefix)

    q = db.session.query(Attribute)
    q = q.join(Schema)
    q = q.filter(Schema.obj == 'entity')
    q = q.filter(Schema.project == project)
    q = q.filter(or_(Attribute.label.ilike(prefix),
                     Attribute.name.ilike(prefix)))
    q = q.limit(get_limit(default=5))

    matches = []
    for attribute in q:
        matches.append({
            'name': attribute.label,
            'n:type': {
                'id': '/properties/property',
                'name': 'Property'
            },
            'id': attribute.name
        })
    return jsonify({
        "code": "/api/status/ok",
        "status": "200 OK",
        "prefix": request.args.get('prefix', ''),
        "result": matches
    })
コード例 #6
0
ファイル: pager.py プロジェクト: nimblemachine/grano
 def __init__(self, query, name=None, limit=25, pager_range=4, **kwargs):
     self.args = request.args
     self.name = name
     self.query = query
     self.kwargs = kwargs
     self.pager_range = pager_range
     self.offset = arg_int(self.arg_name("offset"), default=0)
     self.limit = get_limit(default=limit, field=self.arg_name("limit"))
コード例 #7
0
 def __init__(self, query, name=None, limit=25, pager_range=4, **kwargs):
     self.args = request.args
     self.name = name
     self.query = query
     self.kwargs = kwargs
     self.pager_range = pager_range
     self.offset = arg_int(self.arg_name('offset'), default=0)
     self.limit = get_limit(default=limit, field=self.arg_name('limit'))
コード例 #8
0
ファイル: view.py プロジェクト: pudo-attic/grano-reconcile
def suggest_entity(slug):
    """
    Suggest API, emulates Google Refine API. See:
    https://github.com/OpenRefine/OpenRefine/wiki/Reconciliation-Service-API
    """

    project = object_or_404(Project.by_slug(slug))
    authz.require(authz.project_read(project))

    prefix = "%%%s%%" % request.args.get("prefix", "")
    log.info("Suggesting entities in %s: %r", project.slug, prefix)

    q = db.session.query(Entity)
    q = q.join(Property)
    q = q.join(Project)
    q = q.filter(Property.name == "name")
    q = q.filter(Property.active == True)
    q = q.filter(Property.entity_id == Entity.id)
    q = q.filter(Property.value_string.ilike(prefix))
    q = q.filter(Project.slug == slug)

    if "type" in request.args:
        schema_name = request.args.get("type")
        if "/" in schema_name:
            _, schema_name = schema_name.rsplit("/", 1)
        q = q.join(Schema)
        q = q.filter(Schema.name == schema_name)

    q = q.distinct()
    q = q.limit(get_limit(default=5))

    matches = []
    for e in q:
        data = {
            "name": e["name"].value,
            "n:type": {},
            "type": [],
            "uri": url_for("entities_api.view", id=e.id, _external=True),
            "id": e.id,
        }

        for schema in e.schemata:
            if schema.hidden:
                continue
            data["type"].append({"id": "/" + project.slug + "/" + schema.name, "name": schema.label})

        if len(data["type"]):
            data["n:type"] = data["type"][0]

        matches.append(data)

    return jsonify(
        {"code": "/api/status/ok", "status": "200 OK", "prefix": request.args.get("prefix", ""), "result": matches}
    )
コード例 #9
0
ファイル: pager.py プロジェクト: ahurriyetoglu/grano
 def __init__(self, query, name=None, limit=25, pager_range=4,
              results_converter=lambda x: x, **kwargs):
     self.args = request.args
     self.results_converter = results_converter
     self.name = name
     self.query = query
     self.kwargs = kwargs
     self.pager_range = pager_range
     self.offset = arg_int(self.arg_name('offset'), default=0)
     self.limit = get_limit(default=limit, field=self.arg_name('limit'))
     self._results = None
コード例 #10
0
def suggest_entity(slug):
    """
    Suggest API, emulates Google Refine API. See:
    https://github.com/OpenRefine/OpenRefine/wiki/Reconciliation-Service-API
    """

    project = object_or_404(Project.by_slug(slug))
    authz.require(authz.project_read(project))

    prefix = '%%%s%%' % request.args.get('prefix', '')
    log.info("Suggesting entities in %s: %r", project.slug, prefix)

    q = db.session.query(Entity)
    q = q.join(Property)
    q = q.join(Project)
    q = q.filter(Property.name == 'name')
    q = q.filter(Property.active == True) # noqa
    q = q.filter(Property.entity_id == Entity.id)
    q = q.filter(Property.value_string.ilike(prefix))
    q = q.filter(Project.slug == slug)

    if 'type' in request.args:
        schema_name = request.args.get('type')
        if '/' in schema_name:
            _, schema_name = schema_name.rsplit('/', 1)
        q = q.join(Schema)
        q = q.filter(Schema.name == schema_name)

    q = q.distinct()
    q = q.limit(get_limit(default=5))

    matches = []
    for e in q:
        data = {
            'name': e['name'].value,
            'n:type': {
                'id': '/' + project.slug + '/' + e.schema.name,
                'name': e.schema.label
            },
            'uri': url_for('entities_api.view', id=e.id, _external=True),
            'id': e.id
        }

        data['type'] = [data.get('n:type')]
        matches.append(data)

    return jsonify({
        "code": "/api/status/ok",
        "status": "200 OK",
        "prefix": request.args.get('prefix', ''),
        "result": matches
    })
コード例 #11
0
ファイル: view.py プロジェクト: ashwinsekar18/grano-reconcile
def suggest_entity(slug):
    """ 
    Suggest API, emulates Google Refine API. See:
    https://github.com/OpenRefine/OpenRefine/wiki/Reconciliation-Service-API
    """

    project = object_or_404(Project.by_slug(slug))
    authz.require(authz.project_read(project))

    prefix = request.args.get('prefix', '') + '%'

    q = db.session.query(EntityProperty)
    q = q.join(Entity)
    q = q.join(Project)
    q = q.filter(EntityProperty.name=='name')
    q = q.filter(EntityProperty.active==True)
    q = q.filter(EntityProperty.entity_id!=None)
    q = q.filter(EntityProperty.value_string.ilike(prefix))
    q = q.filter(Project.slug==slug)

    if 'type' in request.args:
        schema_name = request.args.get('type')
        if '/' in schema_name:
            _, schema_name = schema_name.rsplit('/', 1)
        q = q.join(Schema)
        q = q.filter(Schema.name==schema_name)

    q = q.distinct()
    q = q.limit(get_limit(default=5))

    matches = []
    for eprop in q:
        matches.append({
            'name': eprop.value_string,
            'n:type': {
                'id': '/' + project.slug,
                'name': project.label
                },
            'id': eprop.entity_id
            })
    return jsonify({
        "code" : "/api/status/ok",
        "status" : "200 OK",
        "prefix" : request.args.get('prefix', ''),
        "result" : matches
        })
コード例 #12
0
def reconcile_op(project, query):
    log.info("Reconciling in %s: %r", project.slug, query)
    
    schemata = []
    if 'type' in query:
        schemata = query.get('type')
        if isinstance(schemata, basestring):
            schemata = [schemata]
        schemata = [s.rsplit('/', 1)[-1] for s in schemata]

    properties = []
    if 'properties' in query:
        for p in query.get('properties'):
            properties.append((p.get('pid'), p.get('v')))

    matches = find_matches(project, request.account,
                           query.get('query', ''),
                           schemata=schemata,
                           properties=properties)
    matches = matches.limit(get_limit(default=5))

    results = []
    for match in matches:
        data = {
            'name': match['entity']['name'].value,
            'score': match['score'],
            'type': [{
                'id': '/' + project.slug + '/' + match['entity'].schema.name,
                'name': match['entity'].schema.label
            }],
            'id': match['entity'].id,
            'uri': url_for('entities_api.view', id=match['entity'].id,
                           _external=True),
            'match': False #match['score'] == 100
        }
        results.append(data)

    return {
        'result': results,
        'num': len(results)
    }
コード例 #13
0
def table(id):
    file = object_or_404(File.by_id(id))
    authz.require(authz.project_read(file.project))
    limit = get_limit(10)
    validate_cache(keys={'id': file.id, 'limit': limit})
    return jsonify(files.as_table(file, limit))
コード例 #14
0
ファイル: files_api.py プロジェクト: jacqui/grano
def table(id):
    file = object_or_404(File.by_id(id))
    authz.require(authz.project_read(file.project))
    limit = get_limit(10)
    validate_cache(keys={'id': file.id, 'limit': limit})
    return jsonify(files.as_table(file, limit))