예제 #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)}
예제 #2
0
파일: reconcile_api.py 프로젝트: wdsn/aleph
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)}
예제 #3
0
def similar(entity_id):
    enable_cache()
    entity = get_index_entity(entity_id, request.authz.READ)
    entity = model.get_proxy(entity)
    record_audit(Audit.ACT_ENTITY, id=entity_id)
    result = MatchQuery.handle(request, entity=entity)
    return EntitySerializer.jsonify_result(result)
예제 #4
0
def similar(id):
    enable_cache()
    entity = get_index_entity(id, request.authz.READ)
    entity = model.get_proxy(entity)
    record_audit(Audit.ACT_ENTITY, id=id)
    result = MatchQuery.handle(request, entity=entity, schema=CombinedSchema)
    return jsonify(result)
예제 #5
0
def similar(entity_id):
    enable_cache()
    entity = get_index_entity(entity_id, request.authz.READ)
    tag_request(collection_id=entity.get('collection_id'))
    entity = model.get_proxy(entity)
    result = MatchQuery.handle(request, entity=entity)
    return EntitySerializer.jsonify_result(result)
예제 #6
0
파일: entities_api.py 프로젝트: pudo/aleph
def similar(entity_id):
    enable_cache()
    entity = get_index_entity(entity_id, request.authz.READ)
    tag_request(collection_id=entity.get('collection_id'))
    entity = model.get_proxy(entity)
    record_audit(Audit.ACT_ENTITY, id=entity_id)
    result = MatchQuery.handle(request, entity=entity)
    return EntitySerializer.jsonify_result(result)
예제 #7
0
def match():
    entity = parse_request(EntityUpdateSchema)
    entity = model.get_proxy(entity)
    tag_request(schema=entity.schema.name, caption=entity.caption)
    collection_ids = request.args.getlist('collection_ids')
    result = MatchQuery.handle(request, entity=entity,
                               collection_ids=collection_ids)
    return EntitySerializer.jsonify_result(result)
예제 #8
0
def match():
    entity = parse_request(EntityUpdateSchema)
    record_audit(Audit.ACT_MATCH, entity=entity)
    entity = model.get_proxy(entity)
    collection_ids = request.args.getlist('collection_ids')
    result = MatchQuery.handle(request, entity=entity,
                               collection_ids=collection_ids)
    return EntitySerializer.jsonify_result(result)
예제 #9
0
파일: entities_api.py 프로젝트: pudo/aleph
def match():
    entity = parse_request(EntityUpdateSchema)
    record_audit(Audit.ACT_MATCH, entity=entity)
    entity = model.get_proxy(entity)
    tag_request(schema=entity.schema.name, caption=entity.caption)
    collection_ids = request.args.getlist('collection_ids')
    result = MatchQuery.handle(request, entity=entity,
                               collection_ids=collection_ids)
    return EntitySerializer.jsonify_result(result)
예제 #10
0
파일: reconcile_api.py 프로젝트: pudo/aleph
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)
    }
예제 #11
0
def similar(profile_id):
    """
    ---
    get:
      summary: Get similar entities
      description: >
        Get a list of similar entities to the profile with id `profile_id`
      parameters:
      - in: path
        name: profile_id
        required: true
        schema:
          type: string
      - in: query
        name: 'filter:schema'
        schema:
          items:
            type: string
          type: array
      - in: query
        name: 'filter:schemata'
        schema:
          items:
            type: string
          type: array
      responses:
        '200':
          description: Returns a list of entities
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EntitiesResponse'
      tags:
      - Profile
    """
    # enable_cache()
    profile = obj_or_404(get_profile(profile_id, authz=request.authz))
    require(request.authz.can(profile.get("collection_id"),
                              request.authz.READ))
    tag_request(collection_id=profile.get("collection_id"))
    exclude = [item["entity_id"] for item in profile["items"]]
    result = MatchQuery.handle(request,
                               entity=profile["merged"],
                               exclude=exclude)
    entities = list(result.results)
    result.results = []
    for obj in entities:
        item = {
            "score": compare(model, profile["merged"], obj),
            "judgement": Judgement.NO_JUDGEMENT,
            "collection_id": profile.get("collection_id"),
            "entity": obj,
        }
        result.results.append(item)
    return SimilarSerializer.jsonify_result(result)
예제 #12
0
def match():
    enable_cache()
    entity = parse_request(EntityUpdateSchema)
    record_audit(Audit.ACT_MATCH, entity=entity)
    entity = model.get_proxy(entity)
    collection_ids = request.args.getlist('collection_ids')
    result = MatchQuery.handle(request,
                               entity=entity,
                               collection_ids=collection_ids,
                               schema=CombinedSchema)
    return jsonify(result)
예제 #13
0
def similar(entity_id):
    """
    ---
    get:
      summary: Get similar entities
      description: >
        Get a list of similar entities to the entity with id `entity_id`
      parameters:
      - in: path
        name: entity_id
        required: true
        schema:
          type: string
      - in: query
        name: 'filter:schema'
        schema:
          items:
            type: string
          type: array
      - in: query
        name: 'filter:schemata'
        schema:
          items:
            type: string
          type: array
      responses:
        '200':
          description: Returns a list of scored and judged entities
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SimilarResponse'
      tags:
      - Entity
    """
    # enable_cache()
    entity = get_index_entity(entity_id, request.authz.READ)
    tag_request(collection_id=entity.get("collection_id"))
    proxy = model.get_proxy(entity)
    result = MatchQuery.handle(request, entity=proxy)
    entities = list(result.results)
    pairs = [(entity_id, s.get("id")) for s in entities]
    judgements = pairwise_judgements(pairs, entity.get("collection_id"))
    result.results = []
    for obj in entities:
        item = {
            "score": compare(model, proxy, obj),
            "judgement": judgements.get((entity_id, obj.get("id"))),
            "collection_id": entity.get("collection_id"),
            "entity": obj,
        }
        result.results.append(item)
    return SimilarSerializer.jsonify_result(result)
예제 #14
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)}
예제 #15
0
def similar(entity_id):
    """
    ---
    get:
      summary: Get similar entities
      description: >
        Get a list of similar entities to the entity with id `entity_id`
      parameters:
      - in: path
        name: entity_id
        required: true
        schema:
          type: string
      - in: query
        name: 'filter:schema'
        schema:
          items:
            type: string
          type: array
      - in: query
        name: 'filter:schemata'
        schema:
          items:
            type: string
          type: array
      responses:
        '200':
          description: Returns a list of entities
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EntitiesResponse'
      tags:
      - Entity
    """
    enable_cache()
    entity = get_index_entity(entity_id, request.authz.READ)
    tag_request(collection_id=entity.get('collection_id'))
    entity = model.get_proxy(entity)
    result = MatchQuery.handle(request, entity=entity)
    return EntitySerializer.jsonify_result(result)
예제 #16
0
def match():
    """
    ---
    post:
      summary: Query for similar entities
      description: >-
        Query for similar entities matching a given entity inside a given list
        of collections.
      parameters:
      - in: query
        name: collection_ids
        schema:
          type: array
          items:
            type: string
      responses:
        '200':
          description: Returns a list of entities in result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EntitiesResponse'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EntityUpdate'
      tags:
      - Entity
    """
    entity = parse_request("EntityUpdate")
    entity = model.get_proxy(entity, cleaned=False)
    tag_request(schema=entity.schema.name, caption=entity.caption)
    collection_ids = request.args.getlist("collection_ids")
    result = MatchQuery.handle(request,
                               entity=entity,
                               collection_ids=collection_ids)
    return EntitySerializer.jsonify_result(result)
예제 #17
0
파일: entities_api.py 프로젝트: nt0z/aleph
def match():
    enable_cache()
    entity = parse_request(EntityUpdateSchema)
    entity = model.get_proxy(entity)
    result = MatchQuery.handle(request, entity=entity, schema=CombinedSchema)
    return jsonify(result)