import json
import avesterra as av
[docs]
def examples_of_get_features_by_retrieve(entity: av.AvEntity, attribute: av.AvAttribute, auth: av.AvAuthorization):
"""
This function shows how to get features from an entity. Its extremely helpful
when you don't actually know what facts are in an entity or need to
iterate though the facts.
:param entity: The entity ID of the entity to get the facts.
:param attribute: The attribute of the entity to obtain the features for.
:param auth: The Orchestra server authorization that allows entity operations.
"""
features_as_json = json.loads(av.retrieve_features(entity, attribute, 1, auth))
print(f"Features AS JSON: {features_as_json}")
john_address = av.get_feature(entity, attribute, 'home_address', auth)
print(f"Features AS JSON: {john_address}")
# print("")
# print("----------------Examples of get facts by retrieve:----------------")
# facts_as_json = json.loads(facts.retrieve_facts(entity, auth))
# for fact in facts_as_json['Facts']:
# attribute = fact[0] # This is the key (e.g., 'ADDRESS_ATTRIBUTE')
# value = fact[1].get('STRING', None) # Extract the 'STRING' value from the dictionary
# print(f"Attribute: {attribute}, Value: {value}")
# print("------------------------------------------------------------------\n")
[docs]
def examples_of_get_features_by_brute_force(entity: av.AvEntity, auth: av.AvAuthorization):
"""
This function shows how to get features 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 feature from entity - need to know the key
home_address = av.get_feature(entity, av.AvAttribute.ADDRESS, 'home_address', auth)
work_address = av.get_feature(entity, av.AvAttribute.ADDRESS, 'work_address', auth)
print("")
print("----------------Examples of get features by brute force:----------------")
print(f"Entity: {entity} home address: {home_address} work address: {work_address}")
print("------------------------------------------------------------------\n")