def test_name_entity(self): proxy = model.get_proxy( { "id": "banana", "schema": "Person", "properties": { "name": ["Carl", "Karl", "Carlo", "CARL"], }, } ) name_entity(proxy) name = proxy.get("name") assert 1 == len(name), name assert name[0] not in proxy.get("alias"), proxy.get("alias") proxy = model.get_proxy( { "id": "banana", "schema": "Person", "properties": { "name": ["Carl"], }, } ) name_entity(proxy) assert ["Carl"] == proxy.get("name"), proxy.get("name")
def _query_mentions(collection): aggregator = get_aggregator(collection, origin=ORIGIN) aggregator.delete(origin=ORIGIN) writer = aggregator.bulk() for proxy in _iter_mentions(collection): schemata = set() countries = set() for score, _, collection_id, match in _query_item(proxy): schemata.add(match.schema) countries.update(match.get_type_values(registry.country)) yield score, proxy, collection_id, match if len(schemata): # Assign only those countries that are backed by one of # the matches: countries = countries.intersection(proxy.get("country")) proxy.set("country", countries) # Try to be more specific about schema: _merge_schemata(proxy, schemata) # Pick a principal name: proxy = name_entity(proxy) proxy.context["mutable"] = True log.debug("Reifying [%s]: %s", proxy.schema.name, proxy) writer.put(proxy, fragment="mention") # pprint(proxy.to_dict()) writer.flush() aggregator.close()
def get_profile(entityset_id, authz=None): """A profile is an entityset having a party. The idea is to cache profile metadata for the API, and to generate a merged view of all the entities the current user has access to.""" if entityset_id is None: return key = cache.object_key(EntitySet, entityset_id) data = cache.get_complex(key) stub = Stub() if data is None: entityset = get_entityset(entityset_id) if entityset is None: return data = entityset.to_dict() data["items"] = [] for item in entityset.items(): data["items"].append(item.to_dict()) cache.set_complex(key, data, expires=cache.EXPIRE) # Filter the subset of items the current user can access if authz is not None: items = [ i for i in data["items"] if authz.can(i["collection_id"], authz.READ) ] data["items"] = items # Load the constituent entities for the profile and generate a # combined proxy with all of the given properties. for item in data["items"]: if Judgement(item["judgement"]) == Judgement.POSITIVE: resolver.queue(stub, Entity, item.get("entity_id")) resolver.resolve(stub) merged = None data["proxies"] = [] for item in data["items"]: item["entity"] = resolver.get(stub, Entity, item.get("entity_id")) if item["entity"] is not None: proxy = model.get_proxy(item["entity"]) proxy.context = {} data["proxies"].append(proxy) if merged is None: merged = proxy.clone() merged.context["entities"] = [proxy.id] else: merged.merge(proxy) merged.context["entities"].append(proxy.id) if merged is None: merged = model.make_entity(Entity.LEGAL_ENTITY) # Polish it a bit: merged.id = data.get("id") merged = name_entity(merged) data["merged"] = merged data["label"] = merged.caption data["shallow"] = False return data
def test_name_entity(self): proxy = model.get_proxy({ 'id': 'banana', 'schema': 'Person', 'properties': { 'name': ['Carl', 'Karl', 'Carlo', 'CARL'], } }) name_entity(proxy) name = proxy.get('name') assert 1 == len(name), name assert name[0] not in proxy.get('alias'), proxy.get('alias') proxy = model.get_proxy({ 'id': 'banana', 'schema': 'Person', 'properties': { 'name': ['Carl'], } }) name_entity(proxy) assert ['Carl'] == proxy.get('name'), proxy.get('name')
def export_assembler(entity): entity = simplify_provenance(entity) entity = remove_prefix_dates(entity) return name_entity(entity)