nodes: 0, module; 1, function_definition; 2, function_name:combine_duplicate_stmts; 3, parameters; 4, block; 5, identifier:stmts; 6, expression_statement; 7, comment:# Helper function to get a list of evidence matches keys; 8, function_definition; 9, comment:# Iterate over groups of duplicate statements; 10, expression_statement; 11, for_statement; 12, return_statement; 13, comment:"""Combine evidence from duplicate Statements.
  
          Statements are deemed to be duplicates if they have the same key
          returned by the `matches_key()` method of the Statement class. This
          generally means that statements must be identical in terms of their
          arguments and can differ only in their associated `Evidence` objects.
  
          This function keeps the first instance of each set of duplicate
          statements and merges the lists of Evidence from all of the other
          statements.
  
          Parameters
          ----------
          stmts : list of :py:class:`indra.statements.Statement`
              Set of statements to de-duplicate.
  
          Returns
          -------
          list of :py:class:`indra.statements.Statement`
              Unique statements with accumulated evidence across duplicates.
  
          Examples
          --------
          De-duplicate and combine evidence for two statements differing only
          in their evidence lists:
  
          >>> map2k1 = Agent('MAP2K1')
          >>> mapk1 = Agent('MAPK1')
          >>> stmt1 = Phosphorylation(map2k1, mapk1, 'T', '185',
          ... evidence=[Evidence(text='evidence 1')])
          >>> stmt2 = Phosphorylation(map2k1, mapk1, 'T', '185',
          ... evidence=[Evidence(text='evidence 2')])
          >>> uniq_stmts = Preassembler.combine_duplicate_stmts([stmt1, stmt2])
          >>> uniq_stmts
          [Phosphorylation(MAP2K1(), MAPK1(), T, 185)]
          >>> sorted([e.text for e in uniq_stmts[0].evidence]) # doctest:+IGNORE_UNICODE
          ['evidence 1', 'evidence 2']
          """; 14, function_name:_ev_keys; 15, parameters; 16, block; 17, assignment; 18, pattern_list; 19, call; 20, block; 21, identifier:unique_stmts; 22, identifier:sts; 23, expression_statement; 24, for_statement; 25, return_statement; 26, identifier:unique_stmts; 27, list; 28, identifier:_; 29, identifier:duplicates; 30, attribute; 31, argument_list; 32, expression_statement; 33, comment:# Get the first statement and add the evidence of all subsequent; 34, comment:# Statements to it; 35, expression_statement; 36, expression_statement; 37, for_statement; 38, expression_statement; 39, if_statement; 40, comment:# This should never be None or anything else; 41, assert_statement; 42, expression_statement; 43, assignment; 44, identifier:stmt; 45, identifier:sts; 46, block; 47, identifier:ev_keys; 48, identifier:Preassembler; 49, identifier:_get_stmt_matching_groups; 50, identifier:stmts; 51, assignment; 52, assignment; 53, assignment; 54, pattern_list; 55, call; 56, block; 57, assignment; 58, comparison_operator:len(end_ev_keys) != len(start_ev_keys); 59, block; 60, call; 61, call; 62, identifier:ev_keys; 63, list; 64, for_statement; 65, identifier:ev_keys; 66, call; 67, identifier:duplicates; 68, call; 69, identifier:start_ev_keys; 70, call; 71, identifier:stmt_ix; 72, identifier:stmt; 73, identifier:enumerate; 74, argument_list; 75, if_statement; 76, if_statement; 77, expression_statement; 78, expression_statement; 79, for_statement; 80, identifier:end_ev_keys; 81, call; 82, call; 83, call; 84, expression_statement; 85, identifier:isinstance; 86, argument_list; 87, attribute; 88, argument_list; 89, identifier:ev; 90, attribute; 91, block; 92, identifier:set; 93, argument_list; 94, identifier:list; 95, argument_list; 96, identifier:_ev_keys; 97, argument_list; 98, identifier:duplicates; 99, comparison_operator:stmt_ix is 0; 100, block; 101, comparison_operator:len(duplicates) == 1; 102, block; 103, assignment; 104, assignment; 105, identifier:ev; 106, attribute; 107, block; 108, identifier:_ev_keys; 109, argument_list; 110, identifier:len; 111, argument_list; 112, identifier:len; 113, argument_list; 114, call; 115, identifier:new_stmt; 116, identifier:Statement; 117, identifier:unique_stmts; 118, identifier:append; 119, identifier:new_stmt; 120, identifier:stmt; 121, identifier:evidence; 122, expression_statement; 123, identifier:duplicates; 124, identifier:duplicates; 125, identifier:stmt_ix; 126, integer:0; 127, expression_statement; 128, call; 129, integer:1; 130, expression_statement; 131, identifier:raw_text; 132, list_comprehension; 133, identifier:raw_grounding; 134, list_comprehension; 135, identifier:stmt; 136, identifier:evidence; 137, expression_statement; 138, if_statement; 139, list; 140, identifier:end_ev_keys; 141, identifier:start_ev_keys; 142, attribute; 143, argument_list; 144, call; 145, assignment; 146, identifier:len; 147, argument_list; 148, assignment; 149, conditional_expression:None if ag is None else ag.db_refs.get('TEXT'); 150, for_in_clause; 151, conditional_expression:None if ag is None else ag.db_refs; 152, for_in_clause; 153, assignment; 154, comparison_operator:ev_key not in ev_keys; 155, comment:# In case there are already agents annotations, we; 156, comment:# just add a new key for raw_text, otherwise create; 157, comment:# a new key; 158, block; 159, identifier:new_stmt; 160, identifier:logger; 161, identifier:debug; 162, binary_operator:'%d redundant evidences eliminated.' %
                               (len(start_ev_keys) - len(end_ev_keys)); 163, attribute; 164, argument_list; 165, identifier:new_stmt; 166, call; 167, identifier:duplicates; 168, attribute; 169, attribute; 170, None; 171, comparison_operator:ag is None; 172, call; 173, identifier:ag; 174, call; 175, None; 176, comparison_operator:ag is None; 177, attribute; 178, identifier:ag; 179, call; 180, identifier:ev_key; 181, binary_operator:ev.matches_key() + str(raw_text) + \
                          str(raw_grounding); 182, identifier:ev_key; 183, identifier:ev_keys; 184, if_statement; 185, if_statement; 186, expression_statement; 187, expression_statement; 188, expression_statement; 189, string; 190, parenthesized_expression; 191, identifier:ev_keys; 192, identifier:append; 193, call; 194, attribute; 195, argument_list; 196, identifier:new_stmt; 197, identifier:uuid; 198, identifier:stmt; 199, identifier:uuid; 200, identifier:ag; 201, None; 202, attribute; 203, argument_list; 204, attribute; 205, argument_list; 206, identifier:ag; 207, None; 208, identifier:ag; 209, identifier:db_refs; 210, attribute; 211, argument_list; 212, binary_operator:ev.matches_key() + str(raw_text); 213, line_continuation:\; 214, call; 215, comparison_operator:'agents' in ev.annotations; 216, block; 217, else_clause; 218, comparison_operator:'prior_uuids' not in ev.annotations; 219, block; 220, call; 221, call; 222, call; 223, string_content:%d redundant evidences eliminated.; 224, binary_operator:len(start_ev_keys) - len(end_ev_keys); 225, attribute; 226, argument_list; 227, identifier:stmt; 228, identifier:make_generic_copy; 229, attribute; 230, identifier:get; 231, string; 232, identifier:stmt; 233, identifier:agent_list; 234, keyword_argument; 235, identifier:stmt; 236, identifier:agent_list; 237, keyword_argument; 238, call; 239, call; 240, identifier:str; 241, argument_list; 242, string; 243, attribute; 244, expression_statement; 245, expression_statement; 246, block; 247, string; 248, attribute; 249, expression_statement; 250, attribute; 251, argument_list; 252, attribute; 253, argument_list; 254, attribute; 255, argument_list; 256, call; 257, call; 258, identifier:ev; 259, identifier:matches_key; 260, identifier:ag; 261, identifier:db_refs; 262, string_content:TEXT; 263, identifier:deep_sorted; 264, True; 265, identifier:deep_sorted; 266, True; 267, attribute; 268, argument_list; 269, identifier:str; 270, argument_list; 271, identifier:raw_grounding; 272, string_content:agents; 273, identifier:ev; 274, identifier:annotations; 275, assignment; 276, assignment; 277, expression_statement; 278, string_content:prior_uuids; 279, identifier:ev; 280, identifier:annotations; 281, assignment; 282, subscript; 283, identifier:append; 284, attribute; 285, attribute; 286, identifier:append; 287, identifier:ev; 288, identifier:ev_keys; 289, identifier:add; 290, identifier:ev_key; 291, identifier:len; 292, argument_list; 293, identifier:len; 294, argument_list; 295, identifier:ev; 296, identifier:matches_key; 297, identifier:raw_text; 298, subscript; 299, identifier:raw_text; 300, subscript; 301, line_continuation:\; 302, identifier:raw_grounding; 303, assignment; 304, subscript; 305, list; 306, attribute; 307, string; 308, identifier:stmt; 309, identifier:uuid; 310, identifier:new_stmt; 311, identifier:evidence; 312, identifier:start_ev_keys; 313, identifier:end_ev_keys; 314, subscript; 315, string; 316, subscript; 317, string; 318, subscript; 319, line_continuation:\; 320, dictionary; 321, attribute; 322, string; 323, identifier:ev; 324, identifier:annotations; 325, string_content:prior_uuids; 326, attribute; 327, string; 328, string_content:raw_text; 329, attribute; 330, string; 331, string_content:raw_grounding; 332, attribute; 333, string; 334, pair; 335, pair; 336, identifier:ev; 337, identifier:annotations; 338, string_content:prior_uuids; 339, identifier:ev; 340, identifier:annotations; 341, string_content:agents; 342, identifier:ev; 343, identifier:annotations; 344, string_content:agents; 345, identifier:ev; 346, identifier:annotations; 347, string_content:agents; 348, string; 349, identifier:raw_text; 350, string; 351, identifier:raw_grounding; 352, string_content:raw_text; 353, string_content:raw_grounding
code: def combine_duplicate_stmts(stmts):
          """Combine evidence from duplicate Statements.
  
          Statements are deemed to be duplicates if they have the same key
          returned by the `matches_key()` method of the Statement class. This
          generally means that statements must be identical in terms of their
          arguments and can differ only in their associated `Evidence` objects.
  
          This function keeps the first instance of each set of duplicate
          statements and merges the lists of Evidence from all of the other
          statements.
  
          Parameters
          ----------
          stmts : list of :py:class:`indra.statements.Statement`
              Set of statements to de-duplicate.
  
          Returns
          -------
          list of :py:class:`indra.statements.Statement`
              Unique statements with accumulated evidence across duplicates.
  
          Examples
          --------
          De-duplicate and combine evidence for two statements differing only
          in their evidence lists:
  
          >>> map2k1 = Agent('MAP2K1')
          >>> mapk1 = Agent('MAPK1')
          >>> stmt1 = Phosphorylation(map2k1, mapk1, 'T', '185',
          ... evidence=[Evidence(text='evidence 1')])
          >>> stmt2 = Phosphorylation(map2k1, mapk1, 'T', '185',
          ... evidence=[Evidence(text='evidence 2')])
          >>> uniq_stmts = Preassembler.combine_duplicate_stmts([stmt1, stmt2])
          >>> uniq_stmts
          [Phosphorylation(MAP2K1(), MAPK1(), T, 185)]
          >>> sorted([e.text for e in uniq_stmts[0].evidence]) # doctest:+IGNORE_UNICODE
          ['evidence 1', 'evidence 2']
          """
          # Helper function to get a list of evidence matches keys
          def _ev_keys(sts):
              ev_keys = []
              for stmt in sts:
                  for ev in stmt.evidence:
                      ev_keys.append(ev.matches_key())
              return ev_keys
          # Iterate over groups of duplicate statements
          unique_stmts = []
          for _, duplicates in Preassembler._get_stmt_matching_groups(stmts):
              ev_keys = set()
              # Get the first statement and add the evidence of all subsequent
              # Statements to it
              duplicates = list(duplicates)
              start_ev_keys = _ev_keys(duplicates)
              for stmt_ix, stmt in enumerate(duplicates):
                  if stmt_ix is 0:
                      new_stmt = stmt.make_generic_copy()
                  if len(duplicates) == 1:
                      new_stmt.uuid = stmt.uuid
                  raw_text = [None if ag is None else ag.db_refs.get('TEXT')
                              for ag in stmt.agent_list(deep_sorted=True)]
                  raw_grounding = [None if ag is None else ag.db_refs
                                   for ag in stmt.agent_list(deep_sorted=True)]
                  for ev in stmt.evidence:
                      ev_key = ev.matches_key() + str(raw_text) + \
                          str(raw_grounding)
                      if ev_key not in ev_keys:
                          # In case there are already agents annotations, we
                          # just add a new key for raw_text, otherwise create
                          # a new key
                          if 'agents' in ev.annotations:
                              ev.annotations['agents']['raw_text'] = raw_text
                              ev.annotations['agents']['raw_grounding'] = \
                                  raw_grounding
                          else:
                              ev.annotations['agents'] = \
                                  {'raw_text': raw_text,
                                   'raw_grounding': raw_grounding}
                          if 'prior_uuids' not in ev.annotations:
                              ev.annotations['prior_uuids'] = []
                          ev.annotations['prior_uuids'].append(stmt.uuid)
                          new_stmt.evidence.append(ev)
                          ev_keys.add(ev_key)
              end_ev_keys = _ev_keys([new_stmt])
              if len(end_ev_keys) != len(start_ev_keys):
                  logger.debug('%d redundant evidences eliminated.' %
                               (len(start_ev_keys) - len(end_ev_keys)))
              # This should never be None or anything else
              assert isinstance(new_stmt, Statement)
              unique_stmts.append(new_stmt)
          return unique_stmts