Beispiel #1
0
def reconcile_op(query, collection=None):
    """Reconcile operation for a single query."""
    log.info("Reconcile: %r", query)
    args = {"limit": query.get("limit", "5")}
    if collection is not None:
        args["filter:collection_id"] = collection.get("id")
    parser = SearchQueryParser(args, request.authz)
    schema = query.get("type") or Entity.LEGAL_ENTITY
    proxy = model.make_entity(schema)
    proxy.add("name", query.get("query"))
    for p in query.get("properties", []):
        proxy.add(p.get("pid"), p.get("v"), quiet=True)

    query = MatchQuery(parser, entity=proxy)
    matches = list(entity_matches(query.search()))
    return {"result": matches, "num": len(matches)}
Beispiel #2
0
def reconcile_op(query, collection=None):
    """Reconcile operation for a single query."""
    log.info("Reconcile: %r", query)
    args = {'limit': query.get('limit', '5')}
    if collection is not None:
        args['filter:collection_id'] = collection.get('id')
    parser = SearchQueryParser(args, request.authz)
    schema = query.get('type') or Entity.THING
    proxy = model.make_entity(schema)
    proxy.add('name', query.get('query'))
    for p in query.get('properties', []):
        proxy.add(p.get('pid'), p.get('v'), quiet=True)

    query = MatchQuery(parser, entity=proxy)
    matches = list(entity_matches(query.search()))
    return {'result': matches, 'num': len(matches)}
Beispiel #3
0
def reconcile_op(query):
    """Reconcile operation for a single query."""
    parser = SearchQueryParser(
        {
            'limit': query.get('limit', '5'),
            'strict': 'false'
        }, request.authz)

    name = query.get('query', '')
    schema = query.get('type') or Entity.THING
    proxy = model.make_entity(schema)
    proxy.add('name', query.get('query', ''))
    for p in query.get('properties', []):
        proxy.add(p.get('pid'), p.get('v'), quiet=True)

    query = MatchQuery(parser, entity=proxy)
    matches = []
    for doc in query.search().get('hits').get('hits'):
        entity = unpack_result(doc)
        if entity is None:
            continue
        entity = model.get_proxy(entity)
        score = math.ceil(compare(model, proxy, entity) * 100)
        match = {
            'id': entity.id,
            'name': entity.caption,
            'score': score,
            'uri': entity_url(entity.id),
            'match': False
        }
        for type_ in get_freebase_types():
            if entity.schema.name == type_['id']:
                match['type'] = [type_]
        matches.append(match)

    log.info("Reconciled: %r -> %d matches", name, len(matches))
    return {'result': matches, 'num': len(matches)}