MCPcopy Create free account
hub / github.com/alephdata/aleph / similar

Function similar

aleph/views/profiles_api.py:90–141  ·  view source on GitHub ↗

--- 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 na

(profile_id)

Source from the content-addressed store, hash-verified

88
89@blueprint.route("/api/2/profiles/<profile_id>/similar", methods=["GET"])
90def similar(profile_id):
91 """
92 ---
93 get:
94 summary: Get similar entities
95 description: >
96 Get a list of similar entities to the profile with id `profile_id`
97 parameters:
98 - in: path
99 name: profile_id
100 required: true
101 schema:
102 type: string
103 - in: query
104 name: 'filter:schema'
105 schema:
106 items:
107 type: string
108 type: array
109 - in: query
110 name: 'filter:schemata'
111 schema:
112 items:
113 type: string
114 type: array
115 responses:
116 '200':
117 description: Returns a list of entities
118 content:
119 application/json:
120 schema:
121 $ref: '#/components/schemas/EntitiesResponse'
122 tags:
123 - Profile
124 """
125 # enable_cache()
126 profile = obj_or_404(get_profile(profile_id, authz=request.authz))
127 require(request.authz.can(profile.get("collection_id"), request.authz.READ))
128 tag_request(collection_id=profile.get("collection_id"))
129 exclude = [item["entity_id"] for item in profile["items"]]
130 result = MatchQuery.handle(request, entity=profile["merged"], exclude=exclude)
131 entities = list(result.results)
132 result.results = []
133 for obj in entities:
134 item = {
135 "score": compare(model, profile["merged"], model.get_proxy(obj)),
136 "judgement": Judgement.NO_JUDGEMENT,
137 "collection_id": profile.get("collection_id"),
138 "entity": obj,
139 }
140 result.results.append(item)
141 return SimilarSerializer.jsonify_result(result)
142
143
144@blueprint.route("/api/2/profiles/<profile_id>/expand", methods=["GET"])

Callers

nothing calls this directly

Calls 8

obj_or_404Function · 0.90
get_profileFunction · 0.90
requireFunction · 0.90
tag_requestFunction · 0.90
canMethod · 0.80
handleMethod · 0.80
jsonify_resultMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected