Source code for module.utils.how_to_get_facets_from_entities

import json
import avesterra as av


[docs] def examples_of_get_facets_by_retrieve(entity: av.AvEntity, auth: av.AvAuthorization): """ This function shows how to get facets from an entity. :param entity: The entity ID of the entity to get the facts. :param auth: The Orchestra server authorization that allows entity operations. """ print("") print("----------------Examples of get facets by retrieve:----------------") print("------------------------------------------------------------------") object_as_json = json.loads(av.retrieve_facts(entity, auth)) for fact in object_as_json['Facts']: attribute = fact[0] facets = fact[2] for facet in facets: print(f"Fact: {attribute} Fact Value: {fact[1].get('STRING', None)}, " f"Facet: {facet}") print("------------------------------------------------------------------\n")
[docs] def examples_of_get_facets_by_brute_force(entity: av.AvEntity, auth: av.AvAuthorization): """ This function shows how to get facets from an entity, by specifying which attributes you want to get. :param entity: The entity ID of the entity to get the facts. :param auth: The Orchestra server authorization that allows entity operations. """ # Get the address facets from entity - need to lookup by the facet names # Home Address and Work Address home_address = av.get_facet(entity=entity, attribute=av.AvAttribute.ADDRESS, name='Home Address', authorization=auth) work_address = av.get_facet(entity=entity, attribute=av.AvAttribute.ADDRESS, name='Work Address', authorization=auth) print("") print("----------------Examples of get facets by brute force:----------------") print(f"Entity: {entity} home address: {home_address} work address: {work_address}") print("------------------------------------------------------------------\n")
[docs] def examples_of_get_factors_by_retrieve(entity: av.AvEntity, auth: av.AvAuthorization): """ This function shows how to get factors from an entity. :param entity: The entity ID of the entity to get the factors. :param auth: The Orchestra server authorization that allows entity operations. """ print("") print("----------------Examples of get factors by retrieve:----------------") object_as_json = json.loads(av.retrieve_entity(entity=entity, authorization=auth).decode()) for fact in object_as_json['Facts']: m_facets = fact[2] for facet in m_facets: m_factors = facet[2] for factor in m_factors: print(f"Fact: {fact[0]} Fact Value: {fact[1].get('STRING', None)}," f"Facet: {facet[1]}, Factor: {factor} ") print("------------------------------------------------------------------\n")
[docs] def examples_of_get_factors_by_brute_force(entity: av.AvEntity, auth: av.AvAuthorization): """ This function shows how to get factors from an entity, by specifying which attributes you want to get. :param entity: The entity ID of the entity to get the facts. :param auth: The Orchestra server authorization that allows entity operations. """ # Let's get the factors. Need to know the facet name and the factor key city = av.get_factor(entity=entity, attribute=av.AvAttribute.ADDRESS, name='Work Address', key='city', authorization=auth) state = av.get_factor(entity=entity, attribute=av.AvAttribute.ADDRESS, name='Work Address', key='state', authorization=auth) zip = av.get_factor(entity=entity, attribute=av.AvAttribute.ADDRESS, name='Work Address', key='zip', authorization=auth) print("") print("----------------Examples of get factors by brute force:----------------") print(f"Entity: {entity} Work address: city: {city} state: {state} zip: {zip}") print("------------------------------------------------------------------\n")