nodes: 0, module; 1, function_definition; 2, function_name:get_item_sh; 3, parameters; 4, block; 5, identifier:self; 6, identifier:item; 7, default_parameter; 8, default_parameter; 9, expression_statement; 10, expression_statement; 11, comment:# Item enriched; 12, expression_statement; 13, if_statement; 14, if_statement; 15, expression_statement; 16, for_statement; 17, comment:# Add the author field common in all data sources; 18, expression_statement; 19, if_statement; 20, return_statement; 21, identifier:roles; 22, None; 23, identifier:date_field; 24, None; 25, comment:"""
          Add sorting hat enrichment fields for different roles
  
          If there are no roles, just add the author fields.
  
          """; 26, assignment; 27, assignment; 28, not_operator; 29, block; 30, not_operator; 31, block; 32, else_clause; 33, assignment; 34, identifier:rol; 35, identifier:roles; 36, block; 37, assignment; 38, boolean_operator; 39, block; 40, identifier:eitem_sh; 41, identifier:eitem_sh; 42, dictionary; 43, identifier:author_field; 44, call; 45, identifier:roles; 46, expression_statement; 47, identifier:date_field; 48, expression_statement; 49, block; 50, identifier:users_data; 51, call; 52, if_statement; 53, identifier:rol_author; 54, string; 55, comparison_operator:author_field in users_data; 56, comparison_operator:author_field != rol_author; 57, expression_statement; 58, expression_statement; 59, if_statement; 60, if_statement; 61, if_statement; 62, attribute; 63, argument_list; 64, assignment; 65, assignment; 66, expression_statement; 67, attribute; 68, argument_list; 69, comparison_operator:rol in users_data; 70, block; 71, string_content:author; 72, identifier:author_field; 73, identifier:users_data; 74, identifier:author_field; 75, identifier:rol_author; 76, assignment; 77, call; 78, not_operator; 79, block; 80, not_operator; 81, block; 82, not_operator; 83, block; 84, identifier:self; 85, identifier:get_field_author; 86, identifier:roles; 87, list; 88, identifier:item_date; 89, call; 90, assignment; 91, identifier:self; 92, identifier:get_users_data; 93, identifier:item; 94, identifier:rol; 95, identifier:users_data; 96, expression_statement; 97, expression_statement; 98, if_statement; 99, if_statement; 100, if_statement; 101, identifier:identity; 102, call; 103, attribute; 104, argument_list; 105, subscript; 106, expression_statement; 107, subscript; 108, expression_statement; 109, subscript; 110, expression_statement; 111, identifier:author_field; 112, identifier:str_to_datetime; 113, argument_list; 114, identifier:item_date; 115, call; 116, assignment; 117, call; 118, not_operator; 119, block; 120, not_operator; 121, block; 122, not_operator; 123, block; 124, attribute; 125, argument_list; 126, identifier:eitem_sh; 127, identifier:update; 128, call; 129, identifier:eitem_sh; 130, string; 131, assignment; 132, identifier:eitem_sh; 133, string; 134, assignment; 135, identifier:eitem_sh; 136, string; 137, assignment; 138, subscript; 139, identifier:str_to_datetime; 140, argument_list; 141, identifier:identity; 142, call; 143, attribute; 144, argument_list; 145, subscript; 146, expression_statement; 147, subscript; 148, expression_statement; 149, subscript; 150, expression_statement; 151, identifier:self; 152, identifier:get_sh_identity; 153, identifier:item; 154, identifier:author_field; 155, attribute; 156, argument_list; 157, string_content:author_org_name; 158, subscript; 159, identifier:SH_UNKNOWN_VALUE; 160, string_content:author_name; 161, subscript; 162, identifier:SH_UNKNOWN_VALUE; 163, string_content:author_user_name; 164, subscript; 165, identifier:SH_UNKNOWN_VALUE; 166, identifier:item; 167, call; 168, subscript; 169, attribute; 170, argument_list; 171, identifier:eitem_sh; 172, identifier:update; 173, call; 174, identifier:eitem_sh; 175, binary_operator:rol + '_org_name'; 176, assignment; 177, identifier:eitem_sh; 178, binary_operator:rol + '_name'; 179, assignment; 180, identifier:eitem_sh; 181, binary_operator:rol + '_user_name'; 182, assignment; 183, identifier:self; 184, identifier:get_item_sh_fields; 185, identifier:identity; 186, identifier:item_date; 187, keyword_argument; 188, identifier:eitem_sh; 189, string; 190, identifier:eitem_sh; 191, string; 192, identifier:eitem_sh; 193, string; 194, attribute; 195, argument_list; 196, identifier:item; 197, identifier:date_field; 198, identifier:self; 199, identifier:get_sh_identity; 200, identifier:item; 201, identifier:rol; 202, attribute; 203, argument_list; 204, identifier:rol; 205, string; 206, subscript; 207, identifier:SH_UNKNOWN_VALUE; 208, identifier:rol; 209, string; 210, subscript; 211, identifier:SH_UNKNOWN_VALUE; 212, identifier:rol; 213, string; 214, subscript; 215, identifier:SH_UNKNOWN_VALUE; 216, identifier:rol; 217, identifier:rol_author; 218, string_content:author_org_name; 219, string_content:author_name; 220, string_content:author_user_name; 221, identifier:self; 222, identifier:get_field_date; 223, identifier:self; 224, identifier:get_item_sh_fields; 225, identifier:identity; 226, identifier:item_date; 227, keyword_argument; 228, string_content:_org_name; 229, identifier:eitem_sh; 230, binary_operator:rol + '_org_name'; 231, string_content:_name; 232, identifier:eitem_sh; 233, binary_operator:rol + '_name'; 234, string_content:_user_name; 235, identifier:eitem_sh; 236, binary_operator:rol + '_user_name'; 237, identifier:rol; 238, identifier:rol; 239, identifier:rol; 240, string; 241, identifier:rol; 242, string; 243, identifier:rol; 244, string; 245, string_content:_org_name; 246, string_content:_name; 247, string_content:_user_name
code: def get_item_sh(self, item, roles=None, date_field=None):
          """
          Add sorting hat enrichment fields for different roles
  
          If there are no roles, just add the author fields.
  
          """
  
          eitem_sh = {}  # Item enriched
  
          author_field = self.get_field_author()
  
          if not roles:
              roles = [author_field]
  
          if not date_field:
              item_date = str_to_datetime(item[self.get_field_date()])
          else:
              item_date = str_to_datetime(item[date_field])
  
          users_data = self.get_users_data(item)
  
          for rol in roles:
              if rol in users_data:
                  identity = self.get_sh_identity(item, rol)
                  eitem_sh.update(self.get_item_sh_fields(identity, item_date, rol=rol))
  
                  if not eitem_sh[rol + '_org_name']:
                      eitem_sh[rol + '_org_name'] = SH_UNKNOWN_VALUE
  
                  if not eitem_sh[rol + '_name']:
                      eitem_sh[rol + '_name'] = SH_UNKNOWN_VALUE
  
                  if not eitem_sh[rol + '_user_name']:
                      eitem_sh[rol + '_user_name'] = SH_UNKNOWN_VALUE
  
          # Add the author field common in all data sources
          rol_author = 'author'
          if author_field in users_data and author_field != rol_author:
              identity = self.get_sh_identity(item, author_field)
              eitem_sh.update(self.get_item_sh_fields(identity, item_date, rol=rol_author))
  
              if not eitem_sh['author_org_name']:
                  eitem_sh['author_org_name'] = SH_UNKNOWN_VALUE
  
              if not eitem_sh['author_name']:
                  eitem_sh['author_name'] = SH_UNKNOWN_VALUE
  
              if not eitem_sh['author_user_name']:
                  eitem_sh['author_user_name'] = SH_UNKNOWN_VALUE
  
          return eitem_sh