Ejemplo n.º 1
0
def index(collection_id):
    """
    ---
    get:
      summary: Fetch cross-reference results
      description: >-
        Fetch cross-reference matches for entities in the collection
        with id `collection_id`
      parameters:
      - in: path
        name: collection_id
        required: true
        schema:
          type: integer
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                allOf:
                - $ref: '#/components/schemas/QueryResponse'
                properties:
                  results:
                    type: array
                    items:
                      $ref: '#/components/schemas/XrefResponse'
      tags:
      - Xref
      - Collection
    """
    get_index_collection(collection_id)
    result = XrefQuery.handle(request, collection_id=collection_id)
    return XrefSerializer.jsonify_result(result)
Ejemplo n.º 2
0
def index(collection_id):
    """
    ---
    get:
      summary: Fetch cross-reference results
      description: >-
        Fetch cross-reference matches for entities in the collection
        with id `collection_id`
      parameters:
      - in: path
        name: collection_id
        required: true
        schema:
          type: integer
      - in: query
        name: evaluation_mode
        required: false
        schema:
          type: bool
          default: false
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                allOf:
                - $ref: '#/components/schemas/QueryResponse'
                properties:
                  results:
                    type: array
                    items:
                      $ref: '#/components/schemas/XrefResponse'
      tags:
      - Xref
      - Collection
    """
    get_index_collection(collection_id, request.authz.READ)
    result = XrefQuery.handle(request, collection_id=collection_id)
    pairs = []
    for xref in result.results:
        pairs.append((xref.get("entity_id"), xref.get("match_id")))
    judgements = pairwise_judgements(pairs, collection_id)
    for xref in result.results:
        key = (xref.get("entity_id"), xref.get("match_id"))
        xref["judgement"] = judgements.get(key)
    return XrefSerializer.jsonify_result(result)
Ejemplo n.º 3
0
def reconcile(collection_id=None):
    """Reconciliation API, emulates Google Refine API."""
    collection = None
    if collection_id is not None:
        collection = get_index_collection(collection_id)
    query = request.values.get('query')
    if query is not None:
        # single
        try:
            query = json.loads(query)
        except ValueError:
            query = {'query': query}
        return jsonify(reconcile_op(query, collection))

    queries = request.values.get('queries')
    if queries is not None:
        # multiple requests in one query
        try:
            qs = json.loads(queries)
            results = {}
            for k, q in qs.items():
                results[k] = reconcile_op(q, collection)
            return jsonify(results)
        except ValueError:
            raise BadRequest()
    return reconcile_index(collection)
Ejemplo n.º 4
0
def view(collection_id):
    """
    ---
    get:
      summary: Get a collection
      description: Return the collection with id `collection_id`
      parameters:
      - description: The collection ID.
        in: path
        name: collection_id
        required: true
        schema:
          minimum: 1
          type: integer
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CollectionFull'
      tags:
      - Collection
    """
    data = get_index_collection(collection_id)
    cobj = get_db_collection(collection_id)
    if get_flag("refresh", False):
        update_collection_stats(collection_id, ["schema"])
    data.update({
        "statistics": get_collection_stats(cobj.id),
        "status": get_status(cobj),
        "shallow": False,
    })
    return CollectionSerializer.jsonify(data)
Ejemplo n.º 5
0
def view(collection_id):
    """
    ---
    get:
      summary: Get a collection
      description: Return the collection with id `collection_id`
      parameters:
      - description: The collection ID.
        in: path
        name: collection_id
        required: true
        schema:
          minimum: 1
          type: integer
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Collection'
      tags:
      - Collection
    """
    collection = get_index_collection(collection_id)
    return CollectionSerializer.jsonify(collection)
Ejemplo n.º 6
0
def reconcile(collection_id=None):
    """Reconciliation API, emulates Google Refine API."""
    collection = None
    if collection_id is not None:
        collection = get_index_collection(collection_id)
    query = request.values.get('query')
    if query is not None:
        # single
        try:
            query = json.loads(query)
        except ValueError:
            query = {'query': query}
        return jsonify(reconcile_op(query, collection))

    queries = request.values.get('queries')
    if queries is not None:
        # multiple requests in one query
        try:
            qs = json.loads(queries)
            results = {}
            for k, q in qs.items():
                results[k] = reconcile_op(q, collection)
            return jsonify(results)
        except ValueError:
            raise BadRequest()
    return reconcile_index(collection)
Ejemplo n.º 7
0
def index(collection_id):
    """
    ---
    get:
      summary: Fetch cross-reference results
      description: >-
        Fetch cross-reference matches for entities in the collection
        with id `collection_id`
      parameters:
      - in: path
        name: collection_id
        required: true
        schema:
          type: integer
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                allOf:
                - $ref: '#/components/schemas/QueryResponse'
                properties:
                  results:
                    type: array
                    items:
                      $ref: '#/components/schemas/XrefResponse'
      tags:
      - Xref
      - Collection
    """
    get_index_collection(collection_id)
    result = XrefQuery.handle(request, collection_id=collection_id)
    context_id = result.parser.getint('context_id', request.authz.id)
    if context_id is not None:
        require(request.authz.can_read_role(context_id))
        pairs = []
        for xref in result.results:
            pairs.append((xref.get('entity_id'), xref.get('match_id')))
        decisions = Linkage.decisions(pairs, context_id)
        for xref in result.results:
            key = (xref.get('entity_id'), xref.get('match_id'))
            xref['decision'] = decisions.get(key)
    return XrefSerializer.jsonify_result(result)
Ejemplo n.º 8
0
def reconcile(collection_id=None):
    """Reconciliation API, emulates Google Refine API.
    ---
    post:
      summary: Freebase reconciliation API
      description: >
        An implementation of the reconciliation API from Freebase, used
        by OpenRefine to match entities.
      parameters:
      - description: The collection ID.
        in: path
        name: collection_id
        required: true
        schema:
          minimum: 1
          type: integer
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                query:
                  type: object
      responses:
        '200':
          description: OK
      tags:
      - Collection
    """
    collection = None
    if collection_id is not None:
        collection = get_index_collection(collection_id)
    query = request.values.get("query")
    if query is not None:
        # single
        try:
            query = json.loads(query)
        except ValueError:
            query = {"query": query}
        return jsonify(reconcile_op(query, collection))

    queries = request.values.get("queries")
    if queries is not None:
        # multiple requests in one query
        try:
            qs = json.loads(queries)
            results = {}
            for k, q in qs.items():
                results[k] = reconcile_op(q, collection)
            return jsonify(results)
        except ValueError:
            raise BadRequest()
    return reconcile_index(collection)
Ejemplo n.º 9
0
def view(id):
    collection = get_index_collection(id)
    record_audit(Audit.ACT_COLLECTION, id=id)
    return serialize_data(collection, CollectionSchema)
Ejemplo n.º 10
0
def view(id):
    collection = get_index_collection(id)
    record_audit(Audit.ACT_COLLECTION, id=id)
    return CollectionSerializer.jsonify(collection)
Ejemplo n.º 11
0
def view(id):
    collection = get_index_collection(id)
    return jsonify(collection, schema=CollectionSchema)
Ejemplo n.º 12
0
def view(collection_id):
    collection = get_index_collection(collection_id)
    return CollectionSerializer.jsonify(collection)
Ejemplo n.º 13
0
def view(collection_id):
    collection = get_index_collection(collection_id)
    record_audit(Audit.ACT_COLLECTION, id=collection_id)
    return CollectionSerializer.jsonify(collection)
Ejemplo n.º 14
0
def view(id):
    collection = get_index_collection(id)
    return serialize_data(collection, CollectionSchema)