sequence
stringlengths
1.27k
35.1k
code
stringlengths
75
8.58k
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_regulate_amounts'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '10', '21', '25', '37', '41', '52', '64']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'qstr'}; {'id': '9', 'type': 'string', 'children': [], 'value': '"$.events.frames[(@.type is \'transcription\')]"'}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '13', 'type': 'call', 'children': ['14', '19']}; {'id': '14', 'type': 'attribute', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'execute'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'qstr'}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'all_res'}; {'id': '24', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '25', 'type': 'if_statement', 'children': ['26', '29']}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': 'is'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '28', 'type': 'None', 'children': []}; {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'augmented_assignment', 'children': ['32', '33'], 'value': '+='}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'all_res'}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'qstr'}; {'id': '40', 'type': 'string', 'children': [], 'value': '"$.events.frames[(@.type is \'amount\')]"'}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '44', 'type': 'call', 'children': ['45', '50']}; {'id': '45', 'type': 'attribute', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'execute'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'qstr'}; {'id': '52', 'type': 'if_statement', 'children': ['53', '56']}; {'id': '53', 'type': 'comparison_operator', 'children': ['54', '55'], 'value': 'is'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '55', 'type': 'None', 'children': []}; {'id': '56', 'type': 'block', 'children': ['57']}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'augmented_assignment', 'children': ['59', '60'], 'value': '+='}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'all_res'}; {'id': '60', 'type': 'call', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '64', 'type': 'for_statement', 'children': ['65', '66', '67']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'all_res'}; {'id': '67', 'type': 'block', 'children': ['68', '77', '86', '95', '106', '112', '118', '122', '143', '149', '160', '168', '179']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'subtype'}; {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'string', 'children': [], 'value': "'subtype'"}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'epistemics'}; {'id': '80', 'type': 'call', 'children': ['81', '84']}; {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': '_get_epistemics'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '86', 'type': 'if_statement', 'children': ['87', '93']}; {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'epistemics'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'string', 'children': [], 'value': "'negated'"}; {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'continue_statement', 'children': []}; {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '100']}; {'id': '97', 'type': 'pattern_list', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '100', 'type': 'call', 'children': ['101', '104']}; {'id': '101', 'type': 'attribute', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': '_get_annot_context'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}; {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'frame_id'}; {'id': '109', 'type': 'subscript', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '111', 'type': 'string', 'children': [], 'value': "'frame_id'"}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}; {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '115', 'type': 'subscript', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '117', 'type': 'string', 'children': [], 'value': "'arguments'"}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}; {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'theme'}; {'id': '121', 'type': 'None', 'children': []}; {'id': '122', 'type': 'for_statement', 'children': ['123', '124', '125']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '125', 'type': 'block', 'children': ['126']}; {'id': '126', 'type': 'if_statement', 'children': ['127', '135']}; {'id': '127', 'type': 'comparison_operator', 'children': ['128', '134'], 'value': '=='}; {'id': '128', 'type': 'call', 'children': ['129', '132']}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': '_get_arg_type'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '134', 'type': 'string', 'children': [], 'value': "'theme'"}; {'id': '135', 'type': 'block', 'children': ['136', '142']}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}; {'id': '137', 'type': 'assignment', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'theme'}; {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '141', 'type': 'string', 'children': [], 'value': "'arg'"}; {'id': '142', 'type': 'break_statement', 'children': []}; {'id': '143', 'type': 'if_statement', 'children': ['144', '147']}; {'id': '144', 'type': 'comparison_operator', 'children': ['145', '146'], 'value': 'is'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'theme'}; {'id': '146', 'type': 'None', 'children': []}; {'id': '147', 'type': 'block', 'children': ['148']}; {'id': '148', 'type': 'continue_statement', 'children': []}; {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '154']}; {'id': '151', 'type': 'pattern_list', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'theme_agent'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'theme_coords'}; {'id': '154', 'type': 'call', 'children': ['155', '158']}; {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': '_get_agent_from_entity'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'theme'}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}; {'id': '161', 'type': 'assignment', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'qstr'}; {'id': '163', 'type': 'binary_operator', 'children': ['164', '165'], 'value': '+'}; {'id': '164', 'type': 'string', 'children': [], 'value': '"$.events.frames[(@.type is \'regulation\') and "'}; {'id': '165', 'type': 'binary_operator', 'children': ['166', '167'], 'value': '%'}; {'id': '166', 'type': 'string', 'children': [], 'value': '"(@.arguments[0].arg is \'%s\')]"'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'frame_id'}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}; {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'reg_res'}; {'id': '171', 'type': 'call', 'children': ['172', '177']}; {'id': '172', 'type': 'attribute', 'children': ['173', '176']}; {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'execute'}; {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'qstr'}; {'id': '179', 'type': 'for_statement', 'children': ['180', '181', '182']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'reg'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'reg_res'}; {'id': '182', 'type': 'block', 'children': ['183', '191', '219', '225', '235', '261', '268', '277', '300']}; {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '188']}; {'id': '185', 'type': 'pattern_list', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'controller_agent'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'controller_coords'}; {'id': '188', 'type': 'expression_list', 'children': ['189', '190']}; {'id': '189', 'type': 'None', 'children': []}; {'id': '190', 'type': 'None', 'children': []}; {'id': '191', 'type': 'for_statement', 'children': ['192', '193', '196']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '193', 'type': 'subscript', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'reg'}; {'id': '195', 'type': 'string', 'children': [], 'value': "'arguments'"}; {'id': '196', 'type': 'block', 'children': ['197']}; {'id': '197', 'type': 'if_statement', 'children': ['198', '206']}; {'id': '198', 'type': 'comparison_operator', 'children': ['199', '205'], 'value': '=='}; {'id': '199', 'type': 'call', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': '_get_arg_type'}; {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '205', 'type': 'string', 'children': [], 'value': "'controller'"}; {'id': '206', 'type': 'block', 'children': ['207']}; {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'assignment', 'children': ['209', '212', '213']}; {'id': '209', 'type': 'pattern_list', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'controller_agent'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'controller_coords'}; {'id': '212', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '213', 'type': 'call', 'children': ['214', '217']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': '_get_controller_agent'}; {'id': '217', 'type': 'argument_list', 'children': ['218']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '219', 'type': 'expression_statement', 'children': ['220']}; {'id': '220', 'type': 'assignment', 'children': ['221', '222']}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'sentence'}; {'id': '222', 'type': 'subscript', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'reg'}; {'id': '224', 'type': 'string', 'children': [], 'value': "'verbose-text'"}; {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '232']}; {'id': '227', 'type': 'subscript', 'children': ['228', '231']}; {'id': '228', 'type': 'subscript', 'children': ['229', '230']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '230', 'type': 'string', 'children': [], 'value': "'agents'"}; {'id': '231', 'type': 'string', 'children': [], 'value': "'coords'"}; {'id': '232', 'type': 'list', 'children': ['233', '234'], 'value': '[controller_coords,\n theme_coords]'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'controller_coords'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'theme_coords'}; {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'assignment', 'children': ['237', '238']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '238', 'type': 'call', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'Evidence'}; {'id': '240', 'type': 'argument_list', 'children': ['241', '244', '247', '250', '255', '258']}; {'id': '241', 'type': 'keyword_argument', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'source_api'}; {'id': '243', 'type': 'string', 'children': [], 'value': "'reach'"}; {'id': '244', 'type': 'keyword_argument', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'sentence'}; {'id': '247', 'type': 'keyword_argument', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '250', 'type': 'keyword_argument', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'pmid'}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'citation'}; {'id': '255', 'type': 'keyword_argument', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '258', 'type': 'keyword_argument', 'children': ['259', '260']}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'epistemics'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'epistemics'}; {'id': '261', 'type': 'expression_statement', 'children': ['262']}; {'id': '262', 'type': 'assignment', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '264', 'type': 'list', 'children': ['265', '266', '267'], 'value': '[controller_agent, theme_agent, ev]'}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'controller_agent'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'theme_agent'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '268', 'type': 'expression_statement', 'children': ['269']}; {'id': '269', 'type': 'assignment', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'subtype'}; {'id': '271', 'type': 'call', 'children': ['272', '275']}; {'id': '272', 'type': 'attribute', 'children': ['273', '274']}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'reg'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '275', 'type': 'argument_list', 'children': ['276']}; {'id': '276', 'type': 'string', 'children': [], 'value': "'subtype'"}; {'id': '277', 'type': 'if_statement', 'children': ['278', '281', '290']}; {'id': '278', 'type': 'comparison_operator', 'children': ['279', '280'], 'value': '=='}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'subtype'}; {'id': '280', 'type': 'string', 'children': [], 'value': "'positive-regulation'"}; {'id': '281', 'type': 'block', 'children': ['282']}; {'id': '282', 'type': 'expression_statement', 'children': ['283']}; {'id': '283', 'type': 'assignment', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '285', 'type': 'call', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'IncreaseAmount'}; {'id': '287', 'type': 'argument_list', 'children': ['288']}; {'id': '288', 'type': 'list_splat', 'children': ['289']}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '290', 'type': 'else_clause', 'children': ['291']}; {'id': '291', 'type': 'block', 'children': ['292']}; {'id': '292', 'type': 'expression_statement', 'children': ['293']}; {'id': '293', 'type': 'assignment', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '295', 'type': 'call', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'DecreaseAmount'}; {'id': '297', 'type': 'argument_list', 'children': ['298']}; {'id': '298', 'type': 'list_splat', 'children': ['299']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '300', 'type': 'expression_statement', 'children': ['301']}; {'id': '301', 'type': 'call', 'children': ['302', '307']}; {'id': '302', 'type': 'attribute', 'children': ['303', '306']}; {'id': '303', 'type': 'attribute', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'statements'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '307', 'type': 'argument_list', 'children': ['308']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'st'}
def get_regulate_amounts(self): qstr = "$.events.frames[(@.type is 'transcription')]" res = self.tree.execute(qstr) all_res = [] if res is not None: all_res += list(res) qstr = "$.events.frames[(@.type is 'amount')]" res = self.tree.execute(qstr) if res is not None: all_res += list(res) for r in all_res: subtype = r.get('subtype') epistemics = self._get_epistemics(r) if epistemics.get('negated'): continue annotations, context = self._get_annot_context(r) frame_id = r['frame_id'] args = r['arguments'] theme = None for a in args: if self._get_arg_type(a) == 'theme': theme = a['arg'] break if theme is None: continue theme_agent, theme_coords = self._get_agent_from_entity(theme) qstr = "$.events.frames[(@.type is 'regulation') and " + \ "(@.arguments[0].arg is '%s')]" % frame_id reg_res = self.tree.execute(qstr) for reg in reg_res: controller_agent, controller_coords = None, None for a in reg['arguments']: if self._get_arg_type(a) == 'controller': controller_agent, controller_coords = \ self._get_controller_agent(a) sentence = reg['verbose-text'] annotations['agents']['coords'] = [controller_coords, theme_coords] ev = Evidence(source_api='reach', text=sentence, annotations=annotations, pmid=self.citation, context=context, epistemics=epistemics) args = [controller_agent, theme_agent, ev] subtype = reg.get('subtype') if subtype == 'positive-regulation': st = IncreaseAmount(*args) else: st = DecreaseAmount(*args) self.statements.append(st)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_entity_coordinates'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'entity_term'}; {'id': '6', 'type': 'block', 'children': ['7', '16', '23', '29', '40', '47', '61', '70', '77', '86', '93', '102', '111', '122', '131', '140', '151']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sent_id'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'entity_term'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}; {'id': '15', 'type': 'string', 'children': [], 'value': "'sentence'"}; {'id': '16', 'type': 'if_statement', 'children': ['17', '20']}; {'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'sent_id'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21']}; {'id': '21', 'type': 'return_statement', 'children': ['22']}; {'id': '22', 'type': 'None', 'children': []}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'qstr'}; {'id': '26', 'type': 'binary_operator', 'children': ['27', '28'], 'value': '%'}; {'id': '27', 'type': 'string', 'children': [], 'value': '"$.sentences.frames[(@.frame_id is \\\'%s\')]"'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'sent_id'}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '32', 'type': 'call', 'children': ['33', '38']}; {'id': '33', 'type': 'attribute', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'execute'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'qstr'}; {'id': '40', 'type': 'if_statement', 'children': ['41', '44']}; {'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'is'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '43', 'type': 'None', 'children': []}; {'id': '44', 'type': 'block', 'children': ['45']}; {'id': '45', 'type': 'return_statement', 'children': ['46']}; {'id': '46', 'type': 'None', 'children': []}; {'id': '47', 'type': 'try_statement', 'children': ['48', '56']}; {'id': '48', 'type': 'block', 'children': ['49']}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'sentence'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '56', 'type': 'except_clause', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'StopIteration'}; {'id': '58', 'type': 'block', 'children': ['59']}; {'id': '59', 'type': 'return_statement', 'children': ['60']}; {'id': '60', 'type': 'None', 'children': []}; {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'sent_start'}; {'id': '64', 'type': 'call', 'children': ['65', '68']}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'sentence'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}; {'id': '69', 'type': 'string', 'children': [], 'value': "'start-pos'"}; {'id': '70', 'type': 'if_statement', 'children': ['71', '74']}; {'id': '71', 'type': 'comparison_operator', 'children': ['72', '73'], 'value': 'is'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'sent_start'}; {'id': '73', 'type': 'None', 'children': []}; {'id': '74', 'type': 'block', 'children': ['75']}; {'id': '75', 'type': 'return_statement', 'children': ['76']}; {'id': '76', 'type': 'None', 'children': []}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'sent_start'}; {'id': '80', 'type': 'call', 'children': ['81', '84']}; {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'sent_start'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}; {'id': '85', 'type': 'string', 'children': [], 'value': "'offset'"}; {'id': '86', 'type': 'if_statement', 'children': ['87', '90']}; {'id': '87', 'type': 'comparison_operator', 'children': ['88', '89'], 'value': 'is'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'sent_start'}; {'id': '89', 'type': 'None', 'children': []}; {'id': '90', 'type': 'block', 'children': ['91']}; {'id': '91', 'type': 'return_statement', 'children': ['92']}; {'id': '92', 'type': 'None', 'children': []}; {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'entity_start'}; {'id': '96', 'type': 'call', 'children': ['97', '100']}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'entity_term'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}; {'id': '101', 'type': 'string', 'children': [], 'value': "'start-pos'"}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'entity_stop'}; {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'entity_term'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'string', 'children': [], 'value': "'end-pos'"}; {'id': '111', 'type': 'if_statement', 'children': ['112', '119']}; {'id': '112', 'type': 'boolean_operator', 'children': ['113', '116'], 'value': 'or'}; {'id': '113', 'type': 'comparison_operator', 'children': ['114', '115'], 'value': 'is'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'entity_start'}; {'id': '115', 'type': 'None', 'children': []}; {'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': 'is'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'entity_stop'}; {'id': '118', 'type': 'None', 'children': []}; {'id': '119', 'type': 'block', 'children': ['120']}; {'id': '120', 'type': 'return_statement', 'children': ['121']}; {'id': '121', 'type': 'None', 'children': []}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}; {'id': '123', 'type': 'assignment', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'entity_start'}; {'id': '125', 'type': 'call', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'entity_start'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'string', 'children': [], 'value': "'offset'"}; {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'entity_stop'}; {'id': '134', 'type': 'call', 'children': ['135', '138']}; {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'entity_stop'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}; {'id': '139', 'type': 'string', 'children': [], 'value': "'offset'"}; {'id': '140', 'type': 'if_statement', 'children': ['141', '148']}; {'id': '141', 'type': 'boolean_operator', 'children': ['142', '145'], 'value': 'or'}; {'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': 'is'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'entity_start'}; {'id': '144', 'type': 'None', 'children': []}; {'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': 'is'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'entity_stop'}; {'id': '147', 'type': 'None', 'children': []}; {'id': '148', 'type': 'block', 'children': ['149']}; {'id': '149', 'type': 'return_statement', 'children': ['150']}; {'id': '150', 'type': 'None', 'children': []}; {'id': '151', 'type': 'return_statement', 'children': ['152']}; {'id': '152', 'type': 'tuple', 'children': ['153', '156']}; {'id': '153', 'type': 'binary_operator', 'children': ['154', '155'], 'value': '-'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'entity_start'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'sent_start'}; {'id': '156', 'type': 'binary_operator', 'children': ['157', '158'], 'value': '-'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'entity_stop'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'sent_start'}
def _get_entity_coordinates(self, entity_term): sent_id = entity_term.get('sentence') if sent_id is None: return None qstr = "$.sentences.frames[(@.frame_id is \'%s')]" % sent_id res = self.tree.execute(qstr) if res is None: return None try: sentence = next(res) except StopIteration: return None sent_start = sentence.get('start-pos') if sent_start is None: return None sent_start = sent_start.get('offset') if sent_start is None: return None entity_start = entity_term.get('start-pos') entity_stop = entity_term.get('end-pos') if entity_start is None or entity_stop is None: return None entity_start = entity_start.get('offset') entity_stop = entity_stop.get('offset') if entity_start is None or entity_stop is None: return None return (entity_start - sent_start, entity_stop - sent_start)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_evidence'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'relation'}; {'id': '6', 'type': 'block', 'children': ['7', '16', '20', '24', '211', '226', '249', '253', '262', '271', '280', '295', '312', '333']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'provenance'}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'relation'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}; {'id': '15', 'type': 'string', 'children': [], 'value': "'provenance'"}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '23', 'type': 'None', 'children': []}; {'id': '24', 'type': 'if_statement', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'provenance'}; {'id': '26', 'type': 'block', 'children': ['27', '38', '159', '176']}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'sentence_tag'}; {'id': '30', 'type': 'call', 'children': ['31', '36']}; {'id': '31', 'type': 'attribute', 'children': ['32', '35']}; {'id': '32', 'type': 'subscript', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'provenance'}; {'id': '34', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}; {'id': '37', 'type': 'string', 'children': [], 'value': "'sentence'"}; {'id': '38', 'type': 'if_statement', 'children': ['39', '44']}; {'id': '39', 'type': 'boolean_operator', 'children': ['40', '41'], 'value': 'and'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'sentence_tag'}; {'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'in'}; {'id': '42', 'type': 'string', 'children': [], 'value': "'@id'"}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'sentence_tag'}; {'id': '44', 'type': 'block', 'children': ['45', '51', '64', '78', '88', '113', '123']}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'sentence_id'}; {'id': '48', 'type': 'subscript', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'sentence_tag'}; {'id': '50', 'type': 'string', 'children': [], 'value': "'@id'"}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'sentence'}; {'id': '54', 'type': 'call', 'children': ['55', '62']}; {'id': '55', 'type': 'attribute', 'children': ['56', '61']}; {'id': '56', 'type': 'attribute', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'doc'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'sentences'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'sentence_id'}; {'id': '64', 'type': 'if_statement', 'children': ['65', '68']}; {'id': '65', 'type': 'comparison_operator', 'children': ['66', '67'], 'value': 'is'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'sentence'}; {'id': '67', 'type': 'None', 'children': []}; {'id': '68', 'type': 'block', 'children': ['69']}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '72', 'type': 'call', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': '_sanitize'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}; {'id': '75', 'type': 'subscript', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'sentence'}; {'id': '77', 'type': 'string', 'children': [], 'value': "'text'"}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}; {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'timexes'}; {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'sentence'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '85', 'type': 'argument_list', 'children': ['86', '87']}; {'id': '86', 'type': 'string', 'children': [], 'value': "'timexes'"}; {'id': '87', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '88', 'type': 'if_statement', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'timexes'}; {'id': '90', 'type': 'block', 'children': ['91', '97', '104']}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'timex'}; {'id': '94', 'type': 'subscript', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'timexes'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'tc'}; {'id': '100', 'type': 'call', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'time_context_from_timex'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'timex'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}; {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'WorldContext'}; {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'keyword_argument', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'tc'}; {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'geolocs'}; {'id': '116', 'type': 'call', 'children': ['117', '120']}; {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'sentence'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '120', 'type': 'argument_list', 'children': ['121', '122']}; {'id': '121', 'type': 'string', 'children': [], 'value': "'geolocs'"}; {'id': '122', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '123', 'type': 'if_statement', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'geolocs'}; {'id': '125', 'type': 'block', 'children': ['126', '132', '139']}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}; {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'geoloc'}; {'id': '129', 'type': 'subscript', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'geolocs'}; {'id': '131', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}; {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'rc'}; {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'ref_context_from_geoloc'}; {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'geoloc'}; {'id': '139', 'type': 'if_statement', 'children': ['140', '141', '148']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '141', 'type': 'block', 'children': ['142']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}; {'id': '143', 'type': 'assignment', 'children': ['144', '147']}; {'id': '144', 'type': 'attribute', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'geo_location'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'rc'}; {'id': '148', 'type': 'else_clause', 'children': ['149']}; {'id': '149', 'type': 'block', 'children': ['150']}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}; {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'WorldContext'}; {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'keyword_argument', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'geo_location'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'rc'}; {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'doc_id'}; {'id': '162', 'type': 'call', 'children': ['163', '174']}; {'id': '163', 'type': 'attribute', 'children': ['164', '173']}; {'id': '164', 'type': 'call', 'children': ['165', '170']}; {'id': '165', 'type': 'attribute', 'children': ['166', '169']}; {'id': '166', 'type': 'subscript', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'provenance'}; {'id': '168', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '170', 'type': 'argument_list', 'children': ['171', '172']}; {'id': '171', 'type': 'string', 'children': [], 'value': "'document'"}; {'id': '172', 'type': 'dictionary', 'children': []}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '174', 'type': 'argument_list', 'children': ['175']}; {'id': '175', 'type': 'string', 'children': [], 'value': "'@id'"}; {'id': '176', 'type': 'if_statement', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'doc_id'}; {'id': '178', 'type': 'block', 'children': ['179', '198']}; {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '182', 'type': 'call', 'children': ['183', '196']}; {'id': '183', 'type': 'attribute', 'children': ['184', '195']}; {'id': '184', 'type': 'call', 'children': ['185', '192']}; {'id': '185', 'type': 'attribute', 'children': ['186', '191']}; {'id': '186', 'type': 'attribute', 'children': ['187', '190']}; {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'doc'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'documents'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '192', 'type': 'argument_list', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'doc_id'}; {'id': '194', 'type': 'dictionary', 'children': []}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '196', 'type': 'argument_list', 'children': ['197']}; {'id': '197', 'type': 'string', 'children': [], 'value': "'title'"}; {'id': '198', 'type': 'if_statement', 'children': ['199', '200']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '200', 'type': 'block', 'children': ['201']}; {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'assignment', 'children': ['203', '210']}; {'id': '203', 'type': 'subscript', 'children': ['204', '209']}; {'id': '204', 'type': 'subscript', 'children': ['205', '208']}; {'id': '205', 'type': 'subscript', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'provenance'}; {'id': '207', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '208', 'type': 'string', 'children': [], 'value': "'document'"}; {'id': '209', 'type': 'string', 'children': [], 'value': "'title'"}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'assignment', 'children': ['213', '214']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '214', 'type': 'dictionary', 'children': ['215', '223']}; {'id': '215', 'type': 'pair', 'children': ['216', '217']}; {'id': '216', 'type': 'string', 'children': [], 'value': "'found_by'"}; {'id': '217', 'type': 'call', 'children': ['218', '221']}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'relation'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'string', 'children': [], 'value': "'rule'"}; {'id': '223', 'type': 'pair', 'children': ['224', '225']}; {'id': '224', 'type': 'string', 'children': [], 'value': "'provenance'"}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'provenance'}; {'id': '226', 'type': 'if_statement', 'children': ['227', '234']}; {'id': '227', 'type': 'comparison_operator', 'children': ['228', '233'], 'value': 'is'}; {'id': '228', 'type': 'attribute', 'children': ['229', '232']}; {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'doc'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'dct'}; {'id': '233', 'type': 'None', 'children': []}; {'id': '234', 'type': 'block', 'children': ['235']}; {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'assignment', 'children': ['237', '240']}; {'id': '237', 'type': 'subscript', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '239', 'type': 'string', 'children': [], 'value': "'document_creation_time'"}; {'id': '240', 'type': 'call', 'children': ['241', '248']}; {'id': '241', 'type': 'attribute', 'children': ['242', '247']}; {'id': '242', 'type': 'attribute', 'children': ['243', '246']}; {'id': '243', 'type': 'attribute', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'doc'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'dct'}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'to_json'}; {'id': '248', 'type': 'argument_list', 'children': []}; {'id': '249', 'type': 'expression_statement', 'children': ['250']}; {'id': '250', 'type': 'assignment', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'epistemics'}; {'id': '252', 'type': 'dictionary', 'children': []}; {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'assignment', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'negations'}; {'id': '256', 'type': 'call', 'children': ['257', '260']}; {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'get_negation'}; {'id': '260', 'type': 'argument_list', 'children': ['261']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'relation'}; {'id': '262', 'type': 'expression_statement', 'children': ['263']}; {'id': '263', 'type': 'assignment', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'hedgings'}; {'id': '265', 'type': 'call', 'children': ['266', '269']}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'get_hedging'}; {'id': '269', 'type': 'argument_list', 'children': ['270']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'relation'}; {'id': '271', 'type': 'if_statement', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'hedgings'}; {'id': '273', 'type': 'block', 'children': ['274']}; {'id': '274', 'type': 'expression_statement', 'children': ['275']}; {'id': '275', 'type': 'assignment', 'children': ['276', '279']}; {'id': '276', 'type': 'subscript', 'children': ['277', '278']}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'epistemics'}; {'id': '278', 'type': 'string', 'children': [], 'value': "'hedgings'"}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'hedgings'}; {'id': '280', 'type': 'if_statement', 'children': ['281', '282']}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'negations'}; {'id': '282', 'type': 'block', 'children': ['283', '289']}; {'id': '283', 'type': 'expression_statement', 'children': ['284']}; {'id': '284', 'type': 'assignment', 'children': ['285', '288']}; {'id': '285', 'type': 'subscript', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'epistemics'}; {'id': '287', 'type': 'string', 'children': [], 'value': "'negated'"}; {'id': '288', 'type': 'True', 'children': []}; {'id': '289', 'type': 'expression_statement', 'children': ['290']}; {'id': '290', 'type': 'assignment', 'children': ['291', '294']}; {'id': '291', 'type': 'subscript', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '293', 'type': 'string', 'children': [], 'value': "'negated_texts'"}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'negations'}; {'id': '295', 'type': 'if_statement', 'children': ['296', '299']}; {'id': '296', 'type': 'comparison_operator', 'children': ['297', '298'], 'value': 'is'}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '298', 'type': 'None', 'children': []}; {'id': '299', 'type': 'block', 'children': ['300']}; {'id': '300', 'type': 'expression_statement', 'children': ['301']}; {'id': '301', 'type': 'assignment', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '303', 'type': 'call', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': '_sanitize'}; {'id': '305', 'type': 'argument_list', 'children': ['306']}; {'id': '306', 'type': 'call', 'children': ['307', '310']}; {'id': '307', 'type': 'attribute', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'event'}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '310', 'type': 'argument_list', 'children': ['311']}; {'id': '311', 'type': 'string', 'children': [], 'value': "'text'"}; {'id': '312', 'type': 'expression_statement', 'children': ['313']}; {'id': '313', 'type': 'assignment', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '315', 'type': 'call', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'Evidence'}; {'id': '317', 'type': 'argument_list', 'children': ['318', '321', '324', '327', '330']}; {'id': '318', 'type': 'keyword_argument', 'children': ['319', '320']}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'source_api'}; {'id': '320', 'type': 'string', 'children': [], 'value': "'eidos'"}; {'id': '321', 'type': 'keyword_argument', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '324', 'type': 'keyword_argument', 'children': ['325', '326']}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '327', 'type': 'keyword_argument', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'context'}; {'id': '330', 'type': 'keyword_argument', 'children': ['331', '332']}; {'id': '331', 'type': 'identifier', 'children': [], 'value': 'epistemics'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'epistemics'}; {'id': '333', 'type': 'return_statement', 'children': ['334']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'ev'}
def get_evidence(self, relation): provenance = relation.get('provenance') text = None context = None if provenance: sentence_tag = provenance[0].get('sentence') if sentence_tag and '@id' in sentence_tag: sentence_id = sentence_tag['@id'] sentence = self.doc.sentences.get(sentence_id) if sentence is not None: text = _sanitize(sentence['text']) timexes = sentence.get('timexes', []) if timexes: timex = timexes[0] tc = time_context_from_timex(timex) context = WorldContext(time=tc) geolocs = sentence.get('geolocs', []) if geolocs: geoloc = geolocs[0] rc = ref_context_from_geoloc(geoloc) if context: context.geo_location = rc else: context = WorldContext(geo_location=rc) doc_id = provenance[0].get('document', {}).get('@id') if doc_id: title = self.doc.documents.get(doc_id, {}).get('title') if title: provenance[0]['document']['title'] = title annotations = {'found_by': relation.get('rule'), 'provenance': provenance} if self.doc.dct is not None: annotations['document_creation_time'] = self.doc.dct.to_json() epistemics = {} negations = self.get_negation(relation) hedgings = self.get_hedging(relation) if hedgings: epistemics['hedgings'] = hedgings if negations: epistemics['negated'] = True annotations['negated_texts'] = negations if text is None: text = _sanitize(event.get('text')) ev = Evidence(source_api='eidos', text=text, annotations=annotations, context=context, epistemics=epistemics) return ev
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_groundings'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '5', 'type': 'block', 'children': ['6', '77', '86', '95', '101', '160']}; {'id': '6', 'type': 'function_definition', 'children': ['7', '8', '10']}; {'id': '7', 'type': 'function_name', 'children': [], 'value': 'get_grounding_entries'}; {'id': '8', 'type': 'parameters', 'children': ['9']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'grounding'}; {'id': '10', 'type': 'block', 'children': ['11', '17', '21', '31', '75']}; {'id': '11', 'type': 'if_statement', 'children': ['12', '14']}; {'id': '12', 'type': 'not_operator', 'children': ['13']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'grounding'}; {'id': '14', 'type': 'block', 'children': ['15']}; {'id': '15', 'type': 'return_statement', 'children': ['16']}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '20', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'grounding'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30']}; {'id': '29', 'type': 'string', 'children': [], 'value': "'values'"}; {'id': '30', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '31', 'type': 'if_statement', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'for_statement', 'children': ['35', '36', '37']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '37', 'type': 'block', 'children': ['38', '47', '56', '66']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'ont_concept'}; {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'string', 'children': [], 'value': "'ontologyConcept'"}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '50', 'type': 'call', 'children': ['51', '54']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}; {'id': '55', 'type': 'string', 'children': [], 'value': "'value'"}; {'id': '56', 'type': 'if_statement', 'children': ['57', '64']}; {'id': '57', 'type': 'boolean_operator', 'children': ['58', '61'], 'value': 'or'}; {'id': '58', 'type': 'comparison_operator', 'children': ['59', '60'], 'value': 'is'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'ont_concept'}; {'id': '60', 'type': 'None', 'children': []}; {'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'is'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '63', 'type': 'None', 'children': []}; {'id': '64', 'type': 'block', 'children': ['65']}; {'id': '65', 'type': 'continue_statement', 'children': []}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'tuple', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'ont_concept'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '75', 'type': 'return_statement', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '80', 'type': 'dictionary', 'children': ['81']}; {'id': '81', 'type': 'pair', 'children': ['82', '83']}; {'id': '82', 'type': 'string', 'children': [], 'value': "'TEXT'"}; {'id': '83', 'type': 'subscript', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '85', 'type': 'string', 'children': [], 'value': "'text'"}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}; {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'groundings'}; {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'string', 'children': [], 'value': "'groundings'"}; {'id': '95', 'type': 'if_statement', 'children': ['96', '98']}; {'id': '96', 'type': 'not_operator', 'children': ['97']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'groundings'}; {'id': '98', 'type': 'block', 'children': ['99']}; {'id': '99', 'type': 'return_statement', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '101', 'type': 'for_statement', 'children': ['102', '103', '104']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'groundings'}; {'id': '104', 'type': 'block', 'children': ['105', '112']}; {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '108', 'type': 'call', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'get_grounding_entries'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '112', 'type': 'if_statement', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '114', 'type': 'block', 'children': ['115', '125']}; {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '118', 'type': 'call', 'children': ['119', '124']}; {'id': '119', 'type': 'attribute', 'children': ['120', '123']}; {'id': '120', 'type': 'subscript', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '122', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'upper'}; {'id': '124', 'type': 'argument_list', 'children': []}; {'id': '125', 'type': 'if_statement', 'children': ['126', '129', '152']}; {'id': '126', 'type': 'comparison_operator', 'children': ['127', '128'], 'value': '=='}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '128', 'type': 'string', 'children': [], 'value': "'UN'"}; {'id': '129', 'type': 'block', 'children': ['130']}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}; {'id': '131', 'type': 'assignment', 'children': ['132', '135']}; {'id': '132', 'type': 'subscript', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '135', 'type': 'list_comprehension', 'children': ['136', '149']}; {'id': '136', 'type': 'tuple', 'children': ['137', '146']}; {'id': '137', 'type': 'call', 'children': ['138', '143']}; {'id': '138', 'type': 'attribute', 'children': ['139', '142']}; {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '141', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '143', 'type': 'argument_list', 'children': ['144', '145']}; {'id': '144', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '145', 'type': 'string', 'children': [], 'value': "'_'"}; {'id': '146', 'type': 'subscript', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '148', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '149', 'type': 'for_in_clause', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '152', 'type': 'else_clause', 'children': ['153']}; {'id': '153', 'type': 'block', 'children': ['154']}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}; {'id': '155', 'type': 'assignment', 'children': ['156', '159']}; {'id': '156', 'type': 'subscript', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'entries'}; {'id': '160', 'type': 'return_statement', 'children': ['161']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'db_refs'}
def get_groundings(entity): def get_grounding_entries(grounding): if not grounding: return None entries = [] values = grounding.get('values', []) if values: for entry in values: ont_concept = entry.get('ontologyConcept') value = entry.get('value') if ont_concept is None or value is None: continue entries.append((ont_concept, value)) return entries db_refs = {'TEXT': entity['text']} groundings = entity.get('groundings') if not groundings: return db_refs for g in groundings: entries = get_grounding_entries(g) if entries: key = g['name'].upper() if key == 'UN': db_refs[key] = [(s[0].replace(' ', '_'), s[1]) for s in entries] else: db_refs[key] = entries return db_refs
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'make_model'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'grounding_ontology'}; {'id': '7', 'type': 'string', 'children': [], 'value': "'UN'"}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'grounding_threshold'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12', '23', '29', '45', '55', '312']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '16']}; {'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'is'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'grounding_threshold'}; {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17']}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'grounding_threshold'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'grounding_threshold'}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'grounding_ontology'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'grounding_ontology'}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'statements'}; {'id': '32', 'type': 'list_comprehension', 'children': ['33', '34', '39']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '34', 'type': 'for_in_clause', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'statements'}; {'id': '39', 'type': 'if_clause', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'Influence'}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'CAG'}; {'id': '50', 'type': 'call', 'children': ['51', '54']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'nx'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'MultiDiGraph'}; {'id': '54', 'type': 'argument_list', 'children': []}; {'id': '55', 'type': 'for_statement', 'children': ['56', '57', '58']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'statements'}; {'id': '58', 'type': 'block', 'children': ['59', '82', '134', '141', '194', '198', '236']}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'has_both_polarity'}; {'id': '62', 'type': '()', 'children': ['63']}; {'id': '63', 'type': 'boolean_operator', 'children': ['64', '73'], 'value': 'and'}; {'id': '64', 'type': 'comparison_operator', 'children': ['65', '72'], 'value': 'is'}; {'id': '65', 'type': 'subscript', 'children': ['66', '71']}; {'id': '66', 'type': 'attribute', 'children': ['67', '70']}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'subj'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '71', 'type': 'string', 'children': [], 'value': "'polarity'"}; {'id': '72', 'type': 'None', 'children': []}; {'id': '73', 'type': 'comparison_operator', 'children': ['74', '81'], 'value': 'is'}; {'id': '74', 'type': 'subscript', 'children': ['75', '80']}; {'id': '75', 'type': 'attribute', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '80', 'type': 'string', 'children': [], 'value': "'polarity'"}; {'id': '81', 'type': 'None', 'children': []}; {'id': '82', 'type': 'for_statement', 'children': ['83', '86', '111']}; {'id': '83', 'type': 'pattern_list', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '86', 'type': 'call', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '100']}; {'id': '89', 'type': 'tuple', 'children': ['90', '95']}; {'id': '90', 'type': 'attribute', 'children': ['91', '94']}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'subj'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'concept'}; {'id': '95', 'type': 'attribute', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'concept'}; {'id': '100', 'type': 'tuple', 'children': ['101', '106']}; {'id': '101', 'type': 'attribute', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'subj'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '106', 'type': 'attribute', 'children': ['107', '110']}; {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '111', 'type': 'block', 'children': ['112']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}; {'id': '113', 'type': 'call', 'children': ['114', '119']}; {'id': '114', 'type': 'attribute', 'children': ['115', '118']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'CAG'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'add_node'}; {'id': '119', 'type': 'argument_list', 'children': ['120', '126', '129']}; {'id': '120', 'type': 'call', 'children': ['121', '124']}; {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': '_node_name'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '126', 'type': 'keyword_argument', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'simulable'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'has_both_polarity'}; {'id': '129', 'type': 'keyword_argument', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'mods'}; {'id': '131', 'type': 'subscript', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '133', 'type': 'string', 'children': [], 'value': "'adjectives'"}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}; {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'linestyle'}; {'id': '137', 'type': 'conditional_expression', 'children': ['138', '139', '140'], 'value': 'if'}; {'id': '138', 'type': 'string', 'children': [], 'value': "'solid'"}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'has_both_polarity'}; {'id': '140', 'type': 'string', 'children': [], 'value': "'dotted'"}; {'id': '141', 'type': 'if_statement', 'children': ['142', '143', '184']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'has_both_polarity'}; {'id': '143', 'type': 'block', 'children': ['144', '163']}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}; {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'same_polarity'}; {'id': '147', 'type': '()', 'children': ['148']}; {'id': '148', 'type': 'comparison_operator', 'children': ['149', '156'], 'value': '=='}; {'id': '149', 'type': 'subscript', 'children': ['150', '155']}; {'id': '150', 'type': 'attribute', 'children': ['151', '154']}; {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'subj'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '155', 'type': 'string', 'children': [], 'value': "'polarity'"}; {'id': '156', 'type': 'subscript', 'children': ['157', '162']}; {'id': '157', 'type': 'attribute', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '162', 'type': 'string', 'children': [], 'value': "'polarity'"}; {'id': '163', 'type': 'if_statement', 'children': ['164', '165', '174']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'same_polarity'}; {'id': '165', 'type': 'block', 'children': ['166']}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}; {'id': '167', 'type': 'assignment', 'children': ['168', '171']}; {'id': '168', 'type': 'pattern_list', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'target_arrow_shape'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'linecolor'}; {'id': '171', 'type': 'tuple', 'children': ['172', '173']}; {'id': '172', 'type': 'string', 'children': [], 'value': "'circle'"}; {'id': '173', 'type': 'string', 'children': [], 'value': "'green'"}; {'id': '174', 'type': 'else_clause', 'children': ['175']}; {'id': '175', 'type': 'block', 'children': ['176']}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}; {'id': '177', 'type': 'assignment', 'children': ['178', '181']}; {'id': '178', 'type': 'pattern_list', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'target_arrow_shape'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'linecolor'}; {'id': '181', 'type': 'tuple', 'children': ['182', '183']}; {'id': '182', 'type': 'string', 'children': [], 'value': "'tee'"}; {'id': '183', 'type': 'string', 'children': [], 'value': "'maroon'"}; {'id': '184', 'type': 'else_clause', 'children': ['185']}; {'id': '185', 'type': 'block', 'children': ['186']}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}; {'id': '187', 'type': 'assignment', 'children': ['188', '191']}; {'id': '188', 'type': 'pattern_list', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'target_arrow_shape'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'linecolor'}; {'id': '191', 'type': 'tuple', 'children': ['192', '193']}; {'id': '192', 'type': 'string', 'children': [], 'value': "'triangle'"}; {'id': '193', 'type': 'string', 'children': [], 'value': "'maroon'"}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}; {'id': '195', 'type': 'assignment', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'provenance'}; {'id': '197', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '198', 'type': 'if_statement', 'children': ['199', '202']}; {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'evidence'}; {'id': '202', 'type': 'block', 'children': ['203', '219']}; {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'assignment', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'provenance'}; {'id': '206', 'type': 'call', 'children': ['207', '216']}; {'id': '207', 'type': 'attribute', 'children': ['208', '215']}; {'id': '208', 'type': 'attribute', 'children': ['209', '214']}; {'id': '209', 'type': 'subscript', 'children': ['210', '213']}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'evidence'}; {'id': '213', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '216', 'type': 'argument_list', 'children': ['217', '218']}; {'id': '217', 'type': 'string', 'children': [], 'value': "'provenance'"}; {'id': '218', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '219', 'type': 'if_statement', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'provenance'}; {'id': '221', 'type': 'block', 'children': ['222']}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}; {'id': '223', 'type': 'assignment', 'children': ['224', '229']}; {'id': '224', 'type': 'subscript', 'children': ['225', '228']}; {'id': '225', 'type': 'subscript', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'provenance'}; {'id': '227', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '228', 'type': 'string', 'children': [], 'value': "'text'"}; {'id': '229', 'type': 'attribute', 'children': ['230', '235']}; {'id': '230', 'type': 'subscript', 'children': ['231', '234']}; {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'evidence'}; {'id': '234', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}; {'id': '237', 'type': 'call', 'children': ['238', '243']}; {'id': '238', 'type': 'attribute', 'children': ['239', '242']}; {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'CAG'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'add_edge'}; {'id': '243', 'type': 'argument_list', 'children': ['244', '254', '264', '273', '282', '291', '300', '303', '306', '309']}; {'id': '244', 'type': 'call', 'children': ['245', '248']}; {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '247', 'type': 'identifier', 'children': [], 'value': '_node_name'}; {'id': '248', 'type': 'argument_list', 'children': ['249']}; {'id': '249', 'type': 'attribute', 'children': ['250', '253']}; {'id': '250', 'type': 'attribute', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'subj'}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'concept'}; {'id': '254', 'type': 'call', 'children': ['255', '258']}; {'id': '255', 'type': 'attribute', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '257', 'type': 'identifier', 'children': [], 'value': '_node_name'}; {'id': '258', 'type': 'argument_list', 'children': ['259']}; {'id': '259', 'type': 'attribute', 'children': ['260', '263']}; {'id': '260', 'type': 'attribute', 'children': ['261', '262']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'concept'}; {'id': '264', 'type': 'keyword_argument', 'children': ['265', '266']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'subj_polarity'}; {'id': '266', 'type': 'subscript', 'children': ['267', '272']}; {'id': '267', 'type': 'attribute', 'children': ['268', '271']}; {'id': '268', 'type': 'attribute', 'children': ['269', '270']}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'subj'}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '272', 'type': 'string', 'children': [], 'value': "'polarity'"}; {'id': '273', 'type': 'keyword_argument', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'subj_adjectives'}; {'id': '275', 'type': 'subscript', 'children': ['276', '281']}; {'id': '276', 'type': 'attribute', 'children': ['277', '280']}; {'id': '277', 'type': 'attribute', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'subj'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '281', 'type': 'string', 'children': [], 'value': "'adjectives'"}; {'id': '282', 'type': 'keyword_argument', 'children': ['283', '284']}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'obj_polarity'}; {'id': '284', 'type': 'subscript', 'children': ['285', '290']}; {'id': '285', 'type': 'attribute', 'children': ['286', '289']}; {'id': '286', 'type': 'attribute', 'children': ['287', '288']}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '290', 'type': 'string', 'children': [], 'value': "'polarity'"}; {'id': '291', 'type': 'keyword_argument', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'obj_adjectives'}; {'id': '293', 'type': 'subscript', 'children': ['294', '299']}; {'id': '294', 'type': 'attribute', 'children': ['295', '298']}; {'id': '295', 'type': 'attribute', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '299', 'type': 'string', 'children': [], 'value': "'adjectives'"}; {'id': '300', 'type': 'keyword_argument', 'children': ['301', '302']}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'linestyle'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'linestyle'}; {'id': '303', 'type': 'keyword_argument', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'linecolor'}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'linecolor'}; {'id': '306', 'type': 'keyword_argument', 'children': ['307', '308']}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'targetArrowShape'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'target_arrow_shape'}; {'id': '309', 'type': 'keyword_argument', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'provenance'}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'provenance'}; {'id': '312', 'type': 'return_statement', 'children': ['313']}; {'id': '313', 'type': 'attribute', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '315', 'type': 'identifier', 'children': [], 'value': 'CAG'}
def make_model(self, grounding_ontology='UN', grounding_threshold=None): if grounding_threshold is not None: self.grounding_threshold = grounding_threshold self.grounding_ontology = grounding_ontology statements = [stmt for stmt in self.statements if isinstance(stmt, Influence)] self.CAG = nx.MultiDiGraph() for s in statements: has_both_polarity = (s.subj.delta['polarity'] is not None and s.obj.delta['polarity'] is not None) for node, delta in zip((s.subj.concept, s.obj.concept), (s.subj.delta, s.obj.delta)): self.CAG.add_node(self._node_name(node), simulable=has_both_polarity, mods=delta['adjectives']) linestyle = 'solid' if has_both_polarity else 'dotted' if has_both_polarity: same_polarity = (s.subj.delta['polarity'] == s.obj.delta['polarity']) if same_polarity: target_arrow_shape, linecolor = ('circle', 'green') else: target_arrow_shape, linecolor = ('tee', 'maroon') else: target_arrow_shape, linecolor = ('triangle', 'maroon') provenance = [] if s.evidence: provenance = s.evidence[0].annotations.get('provenance', []) if provenance: provenance[0]['text'] = s.evidence[0].text self.CAG.add_edge( self._node_name(s.subj.concept), self._node_name(s.obj.concept), subj_polarity=s.subj.delta['polarity'], subj_adjectives=s.subj.delta['adjectives'], obj_polarity=s.obj.delta['polarity'], obj_adjectives=s.obj.delta['adjectives'], linestyle=linestyle, linecolor=linecolor, targetArrowShape=target_arrow_shape, provenance=provenance, ) return self.CAG
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'process_directory_statements_sorted_by_pmid'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'directory_name'}; {'id': '5', 'type': 'block', 'children': ['6', '13', '23', '46']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 's_dict'}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'mp'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'process_directory'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'directory_name'}; {'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'lazy'}; {'id': '22', 'type': 'True', 'children': []}; {'id': '23', 'type': 'for_statement', 'children': ['24', '25', '30']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'statement'}; {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'mp'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'iter_statements'}; {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'block', 'children': ['31']}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '44']}; {'id': '33', 'type': 'attribute', 'children': ['34', '43']}; {'id': '34', 'type': 'subscript', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 's_dict'}; {'id': '36', 'type': 'attribute', 'children': ['37', '42']}; {'id': '37', 'type': 'subscript', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'statement'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'evidence'}; {'id': '41', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'pmid'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'statement'}; {'id': '46', 'type': 'return_statement', 'children': ['47']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 's_dict'}
def process_directory_statements_sorted_by_pmid(directory_name): s_dict = defaultdict(list) mp = process_directory(directory_name, lazy=True) for statement in mp.iter_statements(): s_dict[statement.evidence[0].pmid].append(statement) return s_dict
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'process_file_sorted_by_pmid'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'file_name'}; {'id': '5', 'type': 'block', 'children': ['6', '13', '23', '46']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 's_dict'}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'mp'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'process_file'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'file_name'}; {'id': '20', 'type': 'keyword_argument', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'lazy'}; {'id': '22', 'type': 'True', 'children': []}; {'id': '23', 'type': 'for_statement', 'children': ['24', '25', '30']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'statement'}; {'id': '25', 'type': 'call', 'children': ['26', '29']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'mp'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'iter_statements'}; {'id': '29', 'type': 'argument_list', 'children': []}; {'id': '30', 'type': 'block', 'children': ['31']}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '44']}; {'id': '33', 'type': 'attribute', 'children': ['34', '43']}; {'id': '34', 'type': 'subscript', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 's_dict'}; {'id': '36', 'type': 'attribute', 'children': ['37', '42']}; {'id': '37', 'type': 'subscript', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'statement'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'evidence'}; {'id': '41', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'pmid'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'statement'}; {'id': '46', 'type': 'return_statement', 'children': ['47']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 's_dict'}
def process_file_sorted_by_pmid(file_name): s_dict = defaultdict(list) mp = process_file(file_name, lazy=True) for statement in mp.iter_statements(): s_dict[statement.evidence[0].pmid].append(statement) return s_dict
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'extract_context'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'annot_manager'}; {'id': '6', 'type': 'block', 'children': ['7', '71', '77', '85', '115', '139', '217', '225']}; {'id': '7', 'type': 'function_definition', 'children': ['8', '9', '12']}; {'id': '8', 'type': 'function_name', 'children': [], 'value': 'get_annot'}; {'id': '9', 'type': 'parameters', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '12', 'type': 'block', 'children': ['13', '23', '69']}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '22', 'type': 'None', 'children': []}; {'id': '23', 'type': 'if_statement', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '25', 'type': 'block', 'children': ['26', '42', '65']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'val_list'}; {'id': '29', 'type': 'list_comprehension', 'children': ['30', '31', '40']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '31', 'type': 'for_in_clause', 'children': ['32', '35']}; {'id': '32', 'type': 'pattern_list', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'tf'}; {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '39', 'type': 'argument_list', 'children': []}; {'id': '40', 'type': 'if_clause', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'tf'}; {'id': '42', 'type': 'if_statement', 'children': ['43', '49', '59']}; {'id': '43', 'type': 'comparison_operator', 'children': ['44', '48'], 'value': '>'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'val_list'}; {'id': '48', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'binary_operator', 'children': ['57', '58'], 'value': '%'}; {'id': '57', 'type': 'string', 'children': [], 'value': '\'More than one "%s" in annotations\''}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '59', 'type': 'elif_clause', 'children': ['60', '62']}; {'id': '60', 'type': 'not_operator', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'val_list'}; {'id': '62', 'type': 'block', 'children': ['63']}; {'id': '63', 'type': 'return_statement', 'children': ['64']}; {'id': '64', 'type': 'None', 'children': []}; {'id': '65', 'type': 'return_statement', 'children': ['66']}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'val_list'}; {'id': '68', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '69', 'type': 'return_statement', 'children': ['70']}; {'id': '70', 'type': 'None', 'children': []}; {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'bc'}; {'id': '74', 'type': 'call', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'BioContext'}; {'id': '76', 'type': 'argument_list', 'children': []}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'species'}; {'id': '80', 'type': 'call', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'get_annot'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '84', 'type': 'string', 'children': [], 'value': "'Species'"}; {'id': '85', 'type': 'if_statement', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'species'}; {'id': '87', 'type': 'block', 'children': ['88', '98']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'annot_manager'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'get_mapping'}; {'id': '95', 'type': 'argument_list', 'children': ['96', '97']}; {'id': '96', 'type': 'string', 'children': [], 'value': "'Species'"}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'species'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'assignment', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'bc'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'species'}; {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'RefContext'}; {'id': '105', 'type': 'argument_list', 'children': ['106', '109']}; {'id': '106', 'type': 'keyword_argument', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '109', 'type': 'keyword_argument', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '111', 'type': 'dictionary', 'children': ['112']}; {'id': '112', 'type': 'pair', 'children': ['113', '114']}; {'id': '113', 'type': 'string', 'children': [], 'value': "'TAXONOMY'"}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'species'}; {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'mappings'}; {'id': '118', 'type': 'tuple', 'children': ['119', '123', '127', '131', '135']}; {'id': '119', 'type': 'tuple', 'children': ['120', '121', '122']}; {'id': '120', 'type': 'string', 'children': [], 'value': "'CellLine'"}; {'id': '121', 'type': 'string', 'children': [], 'value': "'cell_line'"}; {'id': '122', 'type': 'None', 'children': []}; {'id': '123', 'type': 'tuple', 'children': ['124', '125', '126']}; {'id': '124', 'type': 'string', 'children': [], 'value': "'Disease'"}; {'id': '125', 'type': 'string', 'children': [], 'value': "'disease'"}; {'id': '126', 'type': 'None', 'children': []}; {'id': '127', 'type': 'tuple', 'children': ['128', '129', '130']}; {'id': '128', 'type': 'string', 'children': [], 'value': "'Anatomy'"}; {'id': '129', 'type': 'string', 'children': [], 'value': "'organ'"}; {'id': '130', 'type': 'None', 'children': []}; {'id': '131', 'type': 'tuple', 'children': ['132', '133', '134']}; {'id': '132', 'type': 'string', 'children': [], 'value': "'Cell'"}; {'id': '133', 'type': 'string', 'children': [], 'value': "'cell_type'"}; {'id': '134', 'type': 'None', 'children': []}; {'id': '135', 'type': 'tuple', 'children': ['136', '137', '138']}; {'id': '136', 'type': 'string', 'children': [], 'value': "'CellStructure'"}; {'id': '137', 'type': 'string', 'children': [], 'value': "'location'"}; {'id': '138', 'type': 'string', 'children': [], 'value': "'MESH'"}; {'id': '139', 'type': 'for_statement', 'children': ['140', '144', '145']}; {'id': '140', 'type': 'pattern_list', 'children': ['141', '142', '143']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'bel_name'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'indra_name'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'ns'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'mappings'}; {'id': '145', 'type': 'block', 'children': ['146', '154']}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}; {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'ann'}; {'id': '149', 'type': 'call', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'get_annot'}; {'id': '151', 'type': 'argument_list', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'bel_name'}; {'id': '154', 'type': 'if_statement', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'ann'}; {'id': '156', 'type': 'block', 'children': ['157', '167', '173', '199']}; {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'assignment', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '160', 'type': 'call', 'children': ['161', '164']}; {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'annot_manager'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'get_mapping'}; {'id': '164', 'type': 'argument_list', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'bel_name'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'ann'}; {'id': '167', 'type': 'if_statement', 'children': ['168', '171']}; {'id': '168', 'type': 'comparison_operator', 'children': ['169', '170'], 'value': 'is'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '170', 'type': 'None', 'children': []}; {'id': '171', 'type': 'block', 'children': ['172']}; {'id': '172', 'type': 'continue_statement', 'children': []}; {'id': '173', 'type': 'if_statement', 'children': ['174', '176', '189']}; {'id': '174', 'type': 'not_operator', 'children': ['175']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'ns'}; {'id': '176', 'type': 'block', 'children': ['177']}; {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'assignment', 'children': ['179', '182']}; {'id': '179', 'type': 'pattern_list', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'db_ns'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'db_id'}; {'id': '182', 'type': 'call', 'children': ['183', '186']}; {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '186', 'type': 'argument_list', 'children': ['187', '188']}; {'id': '187', 'type': 'string', 'children': [], 'value': "'_'"}; {'id': '188', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '189', 'type': 'else_clause', 'children': ['190']}; {'id': '190', 'type': 'block', 'children': ['191']}; {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '196']}; {'id': '193', 'type': 'pattern_list', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'db_ns'}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'db_id'}; {'id': '196', 'type': 'expression_list', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'ns'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'ref'}; {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'call', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'setattr'}; {'id': '202', 'type': 'argument_list', 'children': ['203', '204', '205']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'bc'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'indra_name'}; {'id': '205', 'type': 'call', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'RefContext'}; {'id': '207', 'type': 'argument_list', 'children': ['208', '211']}; {'id': '208', 'type': 'keyword_argument', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'ann'}; {'id': '211', 'type': 'keyword_argument', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '213', 'type': 'dictionary', 'children': ['214']}; {'id': '214', 'type': 'pair', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'db_ns'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'db_id'}; {'id': '217', 'type': 'if_statement', 'children': ['218', '220']}; {'id': '218', 'type': 'not_operator', 'children': ['219']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'bc'}; {'id': '220', 'type': 'block', 'children': ['221']}; {'id': '221', 'type': 'expression_statement', 'children': ['222']}; {'id': '222', 'type': 'assignment', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'bc'}; {'id': '224', 'type': 'None', 'children': []}; {'id': '225', 'type': 'return_statement', 'children': ['226']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'bc'}
def extract_context(annotations, annot_manager): def get_annot(annotations, key): val = annotations.pop(key, None) if val: val_list = [v for v, tf in val.items() if tf] if len(val_list) > 1: logger.warning('More than one "%s" in annotations' % key) elif not val_list: return None return val_list[0] return None bc = BioContext() species = get_annot(annotations, 'Species') if species: name = annot_manager.get_mapping('Species', species) bc.species = RefContext(name=name, db_refs={'TAXONOMY': species}) mappings = (('CellLine', 'cell_line', None), ('Disease', 'disease', None), ('Anatomy', 'organ', None), ('Cell', 'cell_type', None), ('CellStructure', 'location', 'MESH')) for bel_name, indra_name, ns in mappings: ann = get_annot(annotations, bel_name) if ann: ref = annot_manager.get_mapping(bel_name, ann) if ref is None: continue if not ns: db_ns, db_id = ref.split('_', 1) else: db_ns, db_id = ns, ref setattr(bc, indra_name, RefContext(name=ann, db_refs={db_ns: db_id})) if not bc: bc = None return bc
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_format_evidence_text'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '5', 'type': 'block', 'children': ['6', '80', '84', '308']}; {'id': '6', 'type': 'function_definition', 'children': ['7', '8', '10']}; {'id': '7', 'type': 'function_name', 'children': [], 'value': 'get_role'}; {'id': '8', 'type': 'parameters', 'children': ['9']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'ag_ix'}; {'id': '10', 'type': 'block', 'children': ['11']}; {'id': '11', 'type': 'if_statement', 'children': ['12', '44', '47']}; {'id': '12', 'type': 'boolean_operator', 'children': ['13', '38', '39'], 'value': 'or'}; {'id': '13', 'type': 'boolean_operator', 'children': ['14', '33'], 'value': 'or'}; {'id': '14', 'type': 'boolean_operator', 'children': ['15', '27', '28'], 'value': 'or'}; {'id': '15', 'type': 'boolean_operator', 'children': ['16', '21', '22'], 'value': 'or'}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'Complex'}; {'id': '21', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '24', 'type': 'argument_list', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'SelfModification'}; {'id': '27', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'ActiveForm'}; {'id': '33', 'type': 'call', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '35', 'type': 'argument_list', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'Conversion'}; {'id': '38', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '41', 'type': 'argument_list', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'Translocation'}; {'id': '44', 'type': 'block', 'children': ['45']}; {'id': '45', 'type': 'return_statement', 'children': ['46']}; {'id': '46', 'type': 'string', 'children': [], 'value': "'other'"}; {'id': '47', 'type': 'else_clause', 'children': ['48']}; {'id': '48', 'type': 'block', 'children': ['49', '73']}; {'id': '49', 'type': 'assert_statement', 'children': ['50', '60']}; {'id': '50', 'type': 'comparison_operator', 'children': ['51', '59'], 'value': '=='}; {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '58']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'agent_list'}; {'id': '58', 'type': 'argument_list', 'children': []}; {'id': '59', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '60', 'type': 'tuple', 'children': ['61', '69']}; {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '68']}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'agent_list'}; {'id': '68', 'type': 'argument_list', 'children': []}; {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '73', 'type': 'return_statement', 'children': ['74']}; {'id': '74', 'type': 'conditional_expression', 'children': ['75', '76', '79'], 'value': 'if'}; {'id': '75', 'type': 'string', 'children': [], 'value': "'subject'"}; {'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': '=='}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'ag_ix'}; {'id': '78', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '79', 'type': 'string', 'children': [], 'value': "'object'"}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}; {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'ev_list'}; {'id': '83', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '84', 'type': 'for_statement', 'children': ['85', '88', '94']}; {'id': '85', 'type': 'pattern_list', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'ix'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '88', 'type': 'call', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'evidence'}; {'id': '94', 'type': 'block', 'children': ['95', '137', '280']}; {'id': '95', 'type': 'if_statement', 'children': ['96', '114', '129']}; {'id': '96', 'type': 'boolean_operator', 'children': ['97', '108', '109'], 'value': 'and'}; {'id': '97', 'type': 'boolean_operator', 'children': ['98', '103'], 'value': 'and'}; {'id': '98', 'type': 'comparison_operator', 'children': ['99', '102'], 'value': '=='}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'source_api'}; {'id': '102', 'type': 'string', 'children': [], 'value': "'biopax'"}; {'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': 'in'}; {'id': '104', 'type': 'string', 'children': [], 'value': "'source_sub_id'"}; {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '108', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '109', 'type': 'subscript', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '113', 'type': 'string', 'children': [], 'value': "'source_sub_id'"}; {'id': '114', 'type': 'block', 'children': ['115']}; {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'source_api'}; {'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '%'}; {'id': '119', 'type': 'string', 'children': [], 'value': "'%s:%s'"}; {'id': '120', 'type': 'tuple', 'children': ['121', '124']}; {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'source_api'}; {'id': '124', 'type': 'subscript', 'children': ['125', '128']}; {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '128', 'type': 'string', 'children': [], 'value': "'source_sub_id'"}; {'id': '129', 'type': 'else_clause', 'children': ['130']}; {'id': '130', 'type': 'block', 'children': ['131']}; {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'source_api'}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'source_api'}; {'id': '137', 'type': 'if_statement', 'children': ['138', '143', '148']}; {'id': '138', 'type': 'comparison_operator', 'children': ['139', '142'], 'value': 'is'}; {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '142', 'type': 'None', 'children': []}; {'id': '143', 'type': 'block', 'children': ['144']}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}; {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'format_text'}; {'id': '147', 'type': 'None', 'children': []}; {'id': '148', 'type': 'else_clause', 'children': ['149']}; {'id': '149', 'type': 'block', 'children': ['150', '154', '270']}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}; {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '153', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '154', 'type': 'for_statement', 'children': ['155', '158', '166']}; {'id': '155', 'type': 'pattern_list', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'ix'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'ag'}; {'id': '158', 'type': 'call', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}; {'id': '161', 'type': 'call', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'agent_list'}; {'id': '165', 'type': 'argument_list', 'children': []}; {'id': '166', 'type': 'block', 'children': ['167', '173', '208', '214', '221', '227', '231']}; {'id': '167', 'type': 'if_statement', 'children': ['168', '171']}; {'id': '168', 'type': 'comparison_operator', 'children': ['169', '170'], 'value': 'is'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'ag'}; {'id': '170', 'type': 'None', 'children': []}; {'id': '171', 'type': 'block', 'children': ['172']}; {'id': '172', 'type': 'continue_statement', 'children': []}; {'id': '173', 'type': 'try_statement', 'children': ['174', '194']}; {'id': '174', 'type': 'block', 'children': ['175', '187']}; {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'assignment', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'ag_text'}; {'id': '178', 'type': 'subscript', 'children': ['179', '186']}; {'id': '179', 'type': 'subscript', 'children': ['180', '185']}; {'id': '180', 'type': 'subscript', 'children': ['181', '184']}; {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '184', 'type': 'string', 'children': [], 'value': "'agents'"}; {'id': '185', 'type': 'string', 'children': [], 'value': "'raw_text'"}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'ix'}; {'id': '187', 'type': 'if_statement', 'children': ['188', '191']}; {'id': '188', 'type': 'comparison_operator', 'children': ['189', '190'], 'value': 'is'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'ag_text'}; {'id': '190', 'type': 'None', 'children': []}; {'id': '191', 'type': 'block', 'children': ['192']}; {'id': '192', 'type': 'raise_statement', 'children': ['193']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '194', 'type': 'except_clause', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '196', 'type': 'block', 'children': ['197']}; {'id': '197', 'type': 'expression_statement', 'children': ['198']}; {'id': '198', 'type': 'assignment', 'children': ['199', '200']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'ag_text'}; {'id': '200', 'type': 'call', 'children': ['201', '206']}; {'id': '201', 'type': 'attribute', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'ag'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '206', 'type': 'argument_list', 'children': ['207']}; {'id': '207', 'type': 'string', 'children': [], 'value': "'TEXT'"}; {'id': '208', 'type': 'if_statement', 'children': ['209', '212']}; {'id': '209', 'type': 'comparison_operator', 'children': ['210', '211'], 'value': 'is'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'ag_text'}; {'id': '211', 'type': 'None', 'children': []}; {'id': '212', 'type': 'block', 'children': ['213']}; {'id': '213', 'type': 'continue_statement', 'children': []}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}; {'id': '215', 'type': 'assignment', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'role'}; {'id': '217', 'type': 'call', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'get_role'}; {'id': '219', 'type': 'argument_list', 'children': ['220']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'ix'}; {'id': '221', 'type': 'expression_statement', 'children': ['222']}; {'id': '222', 'type': 'assignment', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'tag_start'}; {'id': '224', 'type': 'binary_operator', 'children': ['225', '226'], 'value': '%'}; {'id': '225', 'type': 'string', 'children': [], 'value': '\'<span class="badge badge-%s">\''}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'role'}; {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '230']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'tag_close'}; {'id': '230', 'type': 'string', 'children': [], 'value': "'</span>'"}; {'id': '231', 'type': 'expression_statement', 'children': ['232']}; {'id': '232', 'type': 'augmented_assignment', 'children': ['233', '234'], 'value': '+='}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '234', 'type': 'list_comprehension', 'children': ['235', '254']}; {'id': '235', 'type': 'tuple', 'children': ['236', '241', '251', '252', '253']}; {'id': '236', 'type': 'call', 'children': ['237', '240']}; {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '240', 'type': 'argument_list', 'children': []}; {'id': '241', 'type': 'binary_operator', 'children': ['242', '247'], 'value': '+'}; {'id': '242', 'type': 'call', 'children': ['243', '246']}; {'id': '243', 'type': 'attribute', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'start'}; {'id': '246', 'type': 'argument_list', 'children': []}; {'id': '247', 'type': 'call', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '249', 'type': 'argument_list', 'children': ['250']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'ag_text'}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'ag_text'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'tag_start'}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'tag_close'}; {'id': '254', 'type': 'for_in_clause', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '256', 'type': 'call', 'children': ['257', '260']}; {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'finditer'}; {'id': '260', 'type': 'argument_list', 'children': ['261', '267']}; {'id': '261', 'type': 'call', 'children': ['262', '265']}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'escape'}; {'id': '265', 'type': 'argument_list', 'children': ['266']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'ag_text'}; {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '270', 'type': 'expression_statement', 'children': ['271']}; {'id': '271', 'type': 'assignment', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'format_text'}; {'id': '273', 'type': 'call', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'tag_text'}; {'id': '275', 'type': 'argument_list', 'children': ['276', '279']}; {'id': '276', 'type': 'attribute', 'children': ['277', '278']}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'indices'}; {'id': '280', 'type': 'expression_statement', 'children': ['281']}; {'id': '281', 'type': 'call', 'children': ['282', '285']}; {'id': '282', 'type': 'attribute', 'children': ['283', '284']}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'ev_list'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '285', 'type': 'argument_list', 'children': ['286']}; {'id': '286', 'type': 'dictionary', 'children': ['287', '290', '295', '300', '303']}; {'id': '287', 'type': 'pair', 'children': ['288', '289']}; {'id': '288', 'type': 'string', 'children': [], 'value': "'source_api'"}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'source_api'}; {'id': '290', 'type': 'pair', 'children': ['291', '292']}; {'id': '291', 'type': 'string', 'children': [], 'value': "'pmid'"}; {'id': '292', 'type': 'attribute', 'children': ['293', '294']}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'pmid'}; {'id': '295', 'type': 'pair', 'children': ['296', '297']}; {'id': '296', 'type': 'string', 'children': [], 'value': "'text_refs'"}; {'id': '297', 'type': 'attribute', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'text_refs'}; {'id': '300', 'type': 'pair', 'children': ['301', '302']}; {'id': '301', 'type': 'string', 'children': [], 'value': "'text'"}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'format_text'}; {'id': '303', 'type': 'pair', 'children': ['304', '305']}; {'id': '304', 'type': 'string', 'children': [], 'value': "'source_hash'"}; {'id': '305', 'type': 'attribute', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'source_hash'}; {'id': '308', 'type': 'return_statement', 'children': ['309']}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'ev_list'}
def _format_evidence_text(stmt): def get_role(ag_ix): if isinstance(stmt, Complex) or \ isinstance(stmt, SelfModification) or \ isinstance(stmt, ActiveForm) or isinstance(stmt, Conversion) or\ isinstance(stmt, Translocation): return 'other' else: assert len(stmt.agent_list()) == 2, (len(stmt.agent_list()), type(stmt)) return 'subject' if ag_ix == 0 else 'object' ev_list = [] for ix, ev in enumerate(stmt.evidence): if ev.source_api == 'biopax' and \ 'source_sub_id' in ev.annotations and \ ev.annotations['source_sub_id']: source_api = '%s:%s' % (ev.source_api, ev.annotations['source_sub_id']) else: source_api = ev.source_api if ev.text is None: format_text = None else: indices = [] for ix, ag in enumerate(stmt.agent_list()): if ag is None: continue try: ag_text = ev.annotations['agents']['raw_text'][ix] if ag_text is None: raise KeyError except KeyError: ag_text = ag.db_refs.get('TEXT') if ag_text is None: continue role = get_role(ix) tag_start = '<span class="badge badge-%s">' % role tag_close = '</span>' indices += [(m.start(), m.start() + len(ag_text), ag_text, tag_start, tag_close) for m in re.finditer(re.escape(ag_text), ev.text)] format_text = tag_text(ev.text, indices) ev_list.append({'source_api': source_api, 'pmid': ev.pmid, 'text_refs': ev.text_refs, 'text': format_text, 'source_hash': ev.source_hash }) return ev_list
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_full_text'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'paper_id'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'idtype'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'preferred_content_type'}; {'id': '8', 'type': 'string', 'children': [], 'value': "'text/xml'"}; {'id': '9', 'type': 'block', 'children': ['10', '26', '34', '43', '52', '61', '80', '91', '215']}; {'id': '10', 'type': 'if_statement', 'children': ['11', '18']}; {'id': '11', 'type': 'comparison_operator', 'children': ['12', '13', '14'], 'value': 'not'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'preferred_content_type'}; {'id': '13', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '14', 'type': 'tuple', 'children': ['15', '16', '17']}; {'id': '15', 'type': 'string', 'children': [], 'value': "'text/xml'"}; {'id': '16', 'type': 'string', 'children': [], 'value': "'text/plain'"}; {'id': '17', 'type': 'string', 'children': [], 'value': "'application/pdf'"}; {'id': '18', 'type': 'block', 'children': ['19']}; {'id': '19', 'type': 'raise_statement', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'concatenated_string', 'children': ['24', '25']}; {'id': '24', 'type': 'string', 'children': [], 'value': '"preferred_content_type must be one of \'text/xml\', "'}; {'id': '25', 'type': 'string', 'children': [], 'value': '"\'text/plain\', or \'application/pdf\'."'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'ids'}; {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'id_lookup'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'paper_id'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'idtype'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'pmcid'}; {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'ids'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'string', 'children': [], 'value': "'pmcid'"}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'pmid'}; {'id': '46', 'type': 'call', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'ids'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'string', 'children': [], 'value': "'pmid'"}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'doi'}; {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'ids'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'string', 'children': [], 'value': "'doi'"}; {'id': '61', 'type': 'if_statement', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'pmcid'}; {'id': '63', 'type': 'block', 'children': ['64', '73']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'nxml'}; {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'pmc_client'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'get_xml'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'pmcid'}; {'id': '73', 'type': 'if_statement', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'nxml'}; {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'return_statement', 'children': ['77']}; {'id': '77', 'type': 'expression_list', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'nxml'}; {'id': '79', 'type': 'string', 'children': [], 'value': "'pmc_oa_xml'"}; {'id': '80', 'type': 'if_statement', 'children': ['81', '86']}; {'id': '81', 'type': 'boolean_operator', 'children': ['82', '84'], 'value': 'and'}; {'id': '82', 'type': 'not_operator', 'children': ['83']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'doi'}; {'id': '84', 'type': 'not_operator', 'children': ['85']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'pmid'}; {'id': '86', 'type': 'block', 'children': ['87']}; {'id': '87', 'type': 'return_statement', 'children': ['88']}; {'id': '88', 'type': 'tuple', 'children': ['89', '90']}; {'id': '89', 'type': 'None', 'children': []}; {'id': '90', 'type': 'None', 'children': []}; {'id': '91', 'type': 'if_statement', 'children': ['92', '93', '189']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'doi'}; {'id': '93', 'type': 'block', 'children': ['94', '103', '156']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}; {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'publisher'}; {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'crossref_client'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'get_publisher'}; {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'doi'}; {'id': '103', 'type': 'if_statement', 'children': ['104', '107']}; {'id': '104', 'type': 'comparison_operator', 'children': ['105', '106'], 'value': '=='}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'publisher'}; {'id': '106', 'type': 'string', 'children': [], 'value': "'Elsevier BV'"}; {'id': '107', 'type': 'block', 'children': ['108', '117', '147']}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}; {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'binary_operator', 'children': ['115', '116'], 'value': '%'}; {'id': '115', 'type': 'string', 'children': [], 'value': "'Elsevier: %s'"}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'pmid'}; {'id': '117', 'type': 'try_statement', 'children': ['118', '128']}; {'id': '118', 'type': 'block', 'children': ['119']}; {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'article_xml'}; {'id': '122', 'type': 'call', 'children': ['123', '126']}; {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'elsevier_client'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'download_article'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'doi'}; {'id': '128', 'type': 'except_clause', 'children': ['129', '133']}; {'id': '129', 'type': 'as_pattern', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '131', 'type': 'as_pattern_target', 'children': ['132']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '133', 'type': 'block', 'children': ['134', '143']}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}; {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'binary_operator', 'children': ['141', '142'], 'value': '%'}; {'id': '141', 'type': 'string', 'children': [], 'value': '"Error downloading Elsevier article: %s"'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'article_xml'}; {'id': '146', 'type': 'None', 'children': []}; {'id': '147', 'type': 'if_statement', 'children': ['148', '151']}; {'id': '148', 'type': 'comparison_operator', 'children': ['149', '150'], 'value': 'is'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'article_xml'}; {'id': '150', 'type': 'None', 'children': []}; {'id': '151', 'type': 'block', 'children': ['152']}; {'id': '152', 'type': 'return_statement', 'children': ['153']}; {'id': '153', 'type': 'tuple', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'article_xml'}; {'id': '155', 'type': 'string', 'children': [], 'value': "'elsevier_xml'"}; {'id': '156', 'type': 'if_statement', 'children': ['157', '158', '183']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'pmid'}; {'id': '158', 'type': 'block', 'children': ['159', '168']}; {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'abstract'}; {'id': '162', 'type': 'call', 'children': ['163', '166']}; {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'pubmed_client'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'get_abstract'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'pmid'}; {'id': '168', 'type': 'if_statement', 'children': ['169', '172', '177']}; {'id': '169', 'type': 'comparison_operator', 'children': ['170', '171'], 'value': 'is'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'abstract'}; {'id': '171', 'type': 'None', 'children': []}; {'id': '172', 'type': 'block', 'children': ['173']}; {'id': '173', 'type': 'return_statement', 'children': ['174']}; {'id': '174', 'type': 'tuple', 'children': ['175', '176']}; {'id': '175', 'type': 'None', 'children': []}; {'id': '176', 'type': 'None', 'children': []}; {'id': '177', 'type': 'else_clause', 'children': ['178']}; {'id': '178', 'type': 'block', 'children': ['179']}; {'id': '179', 'type': 'return_statement', 'children': ['180']}; {'id': '180', 'type': 'expression_list', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'abstract'}; {'id': '182', 'type': 'string', 'children': [], 'value': "'abstract'"}; {'id': '183', 'type': 'else_clause', 'children': ['184']}; {'id': '184', 'type': 'block', 'children': ['185']}; {'id': '185', 'type': 'return_statement', 'children': ['186']}; {'id': '186', 'type': 'tuple', 'children': ['187', '188']}; {'id': '187', 'type': 'None', 'children': []}; {'id': '188', 'type': 'None', 'children': []}; {'id': '189', 'type': 'else_clause', 'children': ['190']}; {'id': '190', 'type': 'block', 'children': ['191', '200']}; {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'abstract'}; {'id': '194', 'type': 'call', 'children': ['195', '198']}; {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'pubmed_client'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'get_abstract'}; {'id': '198', 'type': 'argument_list', 'children': ['199']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'pmid'}; {'id': '200', 'type': 'if_statement', 'children': ['201', '204', '209']}; {'id': '201', 'type': 'comparison_operator', 'children': ['202', '203'], 'value': 'is'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'abstract'}; {'id': '203', 'type': 'None', 'children': []}; {'id': '204', 'type': 'block', 'children': ['205']}; {'id': '205', 'type': 'return_statement', 'children': ['206']}; {'id': '206', 'type': 'tuple', 'children': ['207', '208']}; {'id': '207', 'type': 'None', 'children': []}; {'id': '208', 'type': 'None', 'children': []}; {'id': '209', 'type': 'else_clause', 'children': ['210']}; {'id': '210', 'type': 'block', 'children': ['211']}; {'id': '211', 'type': 'return_statement', 'children': ['212']}; {'id': '212', 'type': 'expression_list', 'children': ['213', '214']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'abstract'}; {'id': '214', 'type': 'string', 'children': [], 'value': "'abstract'"}; {'id': '215', 'type': 'assert_statement', 'children': ['216']}; {'id': '216', 'type': 'False', 'children': []}
def get_full_text(paper_id, idtype, preferred_content_type='text/xml'): if preferred_content_type not in \ ('text/xml', 'text/plain', 'application/pdf'): raise ValueError("preferred_content_type must be one of 'text/xml', " "'text/plain', or 'application/pdf'.") ids = id_lookup(paper_id, idtype) pmcid = ids.get('pmcid') pmid = ids.get('pmid') doi = ids.get('doi') if pmcid: nxml = pmc_client.get_xml(pmcid) if nxml: return nxml, 'pmc_oa_xml' if not doi and not pmid: return (None, None) if doi: publisher = crossref_client.get_publisher(doi) if publisher == 'Elsevier BV': logger.info('Elsevier: %s' % pmid) try: article_xml = elsevier_client.download_article(doi) except Exception as e: logger.error("Error downloading Elsevier article: %s" % e) article_xml = None if article_xml is not None: return (article_xml, 'elsevier_xml') if pmid: abstract = pubmed_client.get_abstract(pmid) if abstract is None: return (None, None) else: return abstract, 'abstract' else: return (None, None) else: abstract = pubmed_client.get_abstract(pmid) if abstract is None: return (None, None) else: return abstract, 'abstract' assert False
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'process_text'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'pmid'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'python2_path'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12', '65', '79', '90', '100']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '16']}; {'id': '13', 'type': 'comparison_operator', 'children': ['14', '15'], 'value': 'is'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'python2_path'}; {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17']}; {'id': '17', 'type': 'for_statement', 'children': ['18', '19', '31']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '19', 'type': 'call', 'children': ['20', '27']}; {'id': '20', 'type': 'attribute', 'children': ['21', '26']}; {'id': '21', 'type': 'subscript', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'environ'}; {'id': '25', 'type': 'string', 'children': [], 'value': '"PATH"'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'pathsep'}; {'id': '31', 'type': 'block', 'children': ['32', '44']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'proposed_python2_path'}; {'id': '35', 'type': 'call', 'children': ['36', '41']}; {'id': '36', 'type': 'attribute', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '41', 'type': 'argument_list', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '43', 'type': 'string', 'children': [], 'value': "'python2.7'"}; {'id': '44', 'type': 'if_statement', 'children': ['45', '53']}; {'id': '45', 'type': 'call', 'children': ['46', '51']}; {'id': '46', 'type': 'attribute', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'proposed_python2_path'}; {'id': '53', 'type': 'block', 'children': ['54', '58', '64']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}; {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'python2_path'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'proposed_python2_path'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '61', 'type': 'argument_list', 'children': ['62', '63']}; {'id': '62', 'type': 'string', 'children': [], 'value': "'Found python 2 interpreter at'"}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'python2_path'}; {'id': '64', 'type': 'break_statement', 'children': []}; {'id': '65', 'type': 'if_statement', 'children': ['66', '69']}; {'id': '66', 'type': 'comparison_operator', 'children': ['67', '68'], 'value': 'is'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'python2_path'}; {'id': '68', 'type': 'None', 'children': []}; {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'raise_statement', 'children': ['71']}; {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'binary_operator', 'children': ['75', '78'], 'value': '+'}; {'id': '75', 'type': 'binary_operator', 'children': ['76', '77'], 'value': '+'}; {'id': '76', 'type': 'string', 'children': [], 'value': "'Could not find python2 in the directories '"}; {'id': '77', 'type': 'string', 'children': [], 'value': "'listed in the PATH environment variable. '"}; {'id': '78', 'type': 'string', 'children': [], 'value': "'Need python2 to run TEES.'"}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '85']}; {'id': '81', 'type': 'pattern_list', 'children': ['82', '83', '84']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'a1_text'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'a2_text'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'sentence_segmentations'}; {'id': '85', 'type': 'call', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'run_on_text'}; {'id': '87', 'type': 'argument_list', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'python2_path'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}; {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'tp'}; {'id': '93', 'type': 'call', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'TEESProcessor'}; {'id': '95', 'type': 'argument_list', 'children': ['96', '97', '98', '99']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'a1_text'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'a2_text'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'sentence_segmentations'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'pmid'}; {'id': '100', 'type': 'return_statement', 'children': ['101']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'tp'}
def process_text(text, pmid=None, python2_path=None): if python2_path is None: for path in os.environ["PATH"].split(os.pathsep): proposed_python2_path = os.path.join(path, 'python2.7') if os.path.isfile(proposed_python2_path): python2_path = proposed_python2_path print('Found python 2 interpreter at', python2_path) break if python2_path is None: raise Exception('Could not find python2 in the directories ' + 'listed in the PATH environment variable. ' + 'Need python2 to run TEES.') a1_text, a2_text, sentence_segmentations = run_on_text(text, python2_path) tp = TEESProcessor(a1_text, a2_text, sentence_segmentations, pmid) return tp
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'run_on_text'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'python2_path'}; {'id': '6', 'type': 'block', 'children': ['7', '14', '135', '151', '155', '166', '181', '368', '375', '382']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'tees_path'}; {'id': '10', 'type': 'call', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'get_config'}; {'id': '12', 'type': 'argument_list', 'children': ['13']}; {'id': '13', 'type': 'string', 'children': [], 'value': "'TEES_PATH'"}; {'id': '14', 'type': 'if_statement', 'children': ['15', '18']}; {'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'is'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'tees_path'}; {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'block', 'children': ['19']}; {'id': '19', 'type': 'for_statement', 'children': ['20', '21', '22']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'cpath'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'tees_candidate_paths'}; {'id': '22', 'type': 'block', 'children': ['23', '34']}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'cpath'}; {'id': '26', 'type': 'call', 'children': ['27', '32']}; {'id': '27', 'type': 'attribute', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'expanduser'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'cpath'}; {'id': '34', 'type': 'if_statement', 'children': ['35', '43']}; {'id': '35', 'type': 'call', 'children': ['36', '41']}; {'id': '36', 'type': 'attribute', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'cpath'}; {'id': '43', 'type': 'block', 'children': ['44', '48', '81', '85', '118']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'has_expected_files'}; {'id': '47', 'type': 'True', 'children': []}; {'id': '48', 'type': 'for_statement', 'children': ['49', '50', '51']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'tees_installation_files'}; {'id': '51', 'type': 'block', 'children': ['52', '64', '75']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '55', 'type': 'call', 'children': ['56', '61']}; {'id': '56', 'type': 'attribute', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '61', 'type': 'argument_list', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'cpath'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'present'}; {'id': '67', 'type': 'call', 'children': ['68', '73']}; {'id': '68', 'type': 'attribute', 'children': ['69', '72']}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'fpath'}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'has_expected_files'}; {'id': '78', 'type': 'boolean_operator', 'children': ['79', '80'], 'value': 'and'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'has_expected_files'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'present'}; {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'has_expected_dirs'}; {'id': '84', 'type': 'True', 'children': []}; {'id': '85', 'type': 'for_statement', 'children': ['86', '87', '88']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'tees_installation_dirs'}; {'id': '88', 'type': 'block', 'children': ['89', '101', '112']}; {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'dpath'}; {'id': '92', 'type': 'call', 'children': ['93', '98']}; {'id': '93', 'type': 'attribute', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'cpath'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'present'}; {'id': '104', 'type': 'call', 'children': ['105', '110']}; {'id': '105', 'type': 'attribute', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'dpath'}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}; {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'has_expected_dirs'}; {'id': '115', 'type': 'boolean_operator', 'children': ['116', '117'], 'value': 'and'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'has_expected_dirs'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'present'}; {'id': '118', 'type': 'if_statement', 'children': ['119', '122']}; {'id': '119', 'type': 'boolean_operator', 'children': ['120', '121'], 'value': 'and'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'has_expected_files'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'has_expected_dirs'}; {'id': '122', 'type': 'block', 'children': ['123', '127', '134']}; {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'tees_path'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'cpath'}; {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}; {'id': '131', 'type': 'binary_operator', 'children': ['132', '133'], 'value': '+'}; {'id': '132', 'type': 'string', 'children': [], 'value': "'Found TEES installation at '"}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'cpath'}; {'id': '134', 'type': 'break_statement', 'children': []}; {'id': '135', 'type': 'if_statement', 'children': ['136', '145']}; {'id': '136', 'type': 'not_operator', 'children': ['137']}; {'id': '137', 'type': 'call', 'children': ['138', '143']}; {'id': '138', 'type': 'attribute', 'children': ['139', '142']}; {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'isdir'}; {'id': '143', 'type': 'argument_list', 'children': ['144']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'tees_path'}; {'id': '145', 'type': 'block', 'children': ['146']}; {'id': '146', 'type': 'raise_statement', 'children': ['147']}; {'id': '147', 'type': 'call', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'string', 'children': [], 'value': "'Provided TEES directory does not exist.'"}; {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'classify_path'}; {'id': '154', 'type': 'string', 'children': [], 'value': "'classify.py'"}; {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'}; {'id': '158', 'type': 'call', 'children': ['159', '162']}; {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'tempfile'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'mkdtemp'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}; {'id': '163', 'type': 'keyword_argument', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'suffix'}; {'id': '165', 'type': 'string', 'children': [], 'value': "'indra_tees_processor'"}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}; {'id': '167', 'type': 'assignment', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'pwd'}; {'id': '169', 'type': 'call', 'children': ['170', '175']}; {'id': '170', 'type': 'attribute', 'children': ['171', '174']}; {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'abspath'}; {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'call', 'children': ['177', '180']}; {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'getcwd'}; {'id': '180', 'type': 'argument_list', 'children': []}; {'id': '181', 'type': 'try_statement', 'children': ['182', '353']}; {'id': '182', 'type': 'block', 'children': ['183', '195', '223', '235', '247', '259']}; {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'text_path'}; {'id': '186', 'type': 'call', 'children': ['187', '192']}; {'id': '187', 'type': 'attribute', 'children': ['188', '191']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '192', 'type': 'argument_list', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'}; {'id': '194', 'type': 'string', 'children': [], 'value': "'text.txt'"}; {'id': '195', 'type': 'with_statement', 'children': ['196', '215']}; {'id': '196', 'type': 'with_clause', 'children': ['197']}; {'id': '197', 'type': 'with_item', 'children': ['198']}; {'id': '198', 'type': 'as_pattern', 'children': ['199', '212', '213']}; {'id': '199', 'type': 'call', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'codecs'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '203', 'type': 'argument_list', 'children': ['204', '205', '206', '209']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'text_path'}; {'id': '205', 'type': 'string', 'children': [], 'value': "'w'"}; {'id': '206', 'type': 'keyword_argument', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '208', 'type': 'string', 'children': [], 'value': "'latin-1'"}; {'id': '209', 'type': 'keyword_argument', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'errors'}; {'id': '211', 'type': 'string', 'children': [], 'value': "'ignore'"}; {'id': '212', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '213', 'type': 'as_pattern_target', 'children': ['214']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '215', 'type': 'block', 'children': ['216']}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}; {'id': '217', 'type': 'call', 'children': ['218', '221']}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'write'}; {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'assignment', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'output_path'}; {'id': '226', 'type': 'call', 'children': ['227', '232']}; {'id': '227', 'type': 'attribute', 'children': ['228', '231']}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '232', 'type': 'argument_list', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'}; {'id': '234', 'type': 'string', 'children': [], 'value': "'output'"}; {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'assignment', 'children': ['237', '238']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'model_path'}; {'id': '238', 'type': 'call', 'children': ['239', '244']}; {'id': '239', 'type': 'attribute', 'children': ['240', '243']}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '244', 'type': 'argument_list', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'tees_path'}; {'id': '246', 'type': 'string', 'children': [], 'value': "'tees_data/models/GE11-test/'"}; {'id': '247', 'type': 'expression_statement', 'children': ['248']}; {'id': '248', 'type': 'assignment', 'children': ['249', '250']}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '250', 'type': 'list', 'children': ['251', '252', '253', '254', '255', '256', '257', '258'], 'value': "[python2_path, classify_path, '-m', model_path,\n '-i', text_path,\n '-o', output_path]"}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'python2_path'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'classify_path'}; {'id': '253', 'type': 'string', 'children': [], 'value': "'-m'"}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'model_path'}; {'id': '255', 'type': 'string', 'children': [], 'value': "'-i'"}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'text_path'}; {'id': '257', 'type': 'string', 'children': [], 'value': "'-o'"}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'output_path'}; {'id': '259', 'type': 'try_statement', 'children': ['260', '338']}; {'id': '260', 'type': 'block', 'children': ['261', '276', '283', '305', '311', '321', '326', '331']}; {'id': '261', 'type': 'expression_statement', 'children': ['262']}; {'id': '262', 'type': 'assignment', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'pwd'}; {'id': '264', 'type': 'call', 'children': ['265', '270']}; {'id': '265', 'type': 'attribute', 'children': ['266', '269']}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'abspath'}; {'id': '270', 'type': 'argument_list', 'children': ['271']}; {'id': '271', 'type': 'call', 'children': ['272', '275']}; {'id': '272', 'type': 'attribute', 'children': ['273', '274']}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'getcwd'}; {'id': '275', 'type': 'argument_list', 'children': []}; {'id': '276', 'type': 'expression_statement', 'children': ['277']}; {'id': '277', 'type': 'call', 'children': ['278', '281']}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'chdir'}; {'id': '281', 'type': 'argument_list', 'children': ['282']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'tees_path'}; {'id': '283', 'type': 'expression_statement', 'children': ['284']}; {'id': '284', 'type': 'assignment', 'children': ['285', '286']}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '286', 'type': 'call', 'children': ['287', '290']}; {'id': '287', 'type': 'attribute', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'Popen'}; {'id': '290', 'type': 'argument_list', 'children': ['291', '292', '297', '302']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'command'}; {'id': '292', 'type': 'keyword_argument', 'children': ['293', '294']}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'stdout'}; {'id': '294', 'type': 'attribute', 'children': ['295', '296']}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'PIPE'}; {'id': '297', 'type': 'keyword_argument', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'stderr'}; {'id': '299', 'type': 'attribute', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'subprocess'}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'PIPE'}; {'id': '302', 'type': 'keyword_argument', 'children': ['303', '304']}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'cwd'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'tees_path'}; {'id': '305', 'type': 'expression_statement', 'children': ['306']}; {'id': '306', 'type': 'call', 'children': ['307', '310']}; {'id': '307', 'type': 'attribute', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'wait'}; {'id': '310', 'type': 'argument_list', 'children': []}; {'id': '311', 'type': 'expression_statement', 'children': ['312']}; {'id': '312', 'type': 'assignment', 'children': ['313', '316']}; {'id': '313', 'type': 'tuple_pattern', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'so'}; {'id': '315', 'type': 'identifier', 'children': [], 'value': 'se'}; {'id': '316', 'type': 'call', 'children': ['317', '320']}; {'id': '317', 'type': 'attribute', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'communicate'}; {'id': '320', 'type': 'argument_list', 'children': []}; {'id': '321', 'type': 'expression_statement', 'children': ['322']}; {'id': '322', 'type': 'call', 'children': ['323', '324']}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '324', 'type': 'argument_list', 'children': ['325']}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'so'}; {'id': '326', 'type': 'expression_statement', 'children': ['327']}; {'id': '327', 'type': 'call', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '329', 'type': 'argument_list', 'children': ['330']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'se'}; {'id': '331', 'type': 'expression_statement', 'children': ['332']}; {'id': '332', 'type': 'call', 'children': ['333', '336']}; {'id': '333', 'type': 'attribute', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '335', 'type': 'identifier', 'children': [], 'value': 'chdir'}; {'id': '336', 'type': 'argument_list', 'children': ['337']}; {'id': '337', 'type': 'identifier', 'children': [], 'value': 'pwd'}; {'id': '338', 'type': 'except_clause', 'children': ['339', '343']}; {'id': '339', 'type': 'as_pattern', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'BaseException'}; {'id': '341', 'type': 'as_pattern_target', 'children': ['342']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '343', 'type': 'block', 'children': ['344', '351']}; {'id': '344', 'type': 'expression_statement', 'children': ['345']}; {'id': '345', 'type': 'call', 'children': ['346', '349']}; {'id': '346', 'type': 'attribute', 'children': ['347', '348']}; {'id': '347', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'chdir'}; {'id': '349', 'type': 'argument_list', 'children': ['350']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'pwd'}; {'id': '351', 'type': 'raise_statement', 'children': ['352']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '353', 'type': 'except_clause', 'children': ['354', '358']}; {'id': '354', 'type': 'as_pattern', 'children': ['355', '356']}; {'id': '355', 'type': 'identifier', 'children': [], 'value': 'BaseException'}; {'id': '356', 'type': 'as_pattern_target', 'children': ['357']}; {'id': '357', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '358', 'type': 'block', 'children': ['359', '366']}; {'id': '359', 'type': 'expression_statement', 'children': ['360']}; {'id': '360', 'type': 'call', 'children': ['361', '364']}; {'id': '361', 'type': 'attribute', 'children': ['362', '363']}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'shutil'}; {'id': '363', 'type': 'identifier', 'children': [], 'value': 'rmtree'}; {'id': '364', 'type': 'argument_list', 'children': ['365']}; {'id': '365', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'}; {'id': '366', 'type': 'raise_statement', 'children': ['367']}; {'id': '367', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '368', 'type': 'expression_statement', 'children': ['369']}; {'id': '369', 'type': 'assignment', 'children': ['370', '371']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'output_tuple'}; {'id': '371', 'type': 'call', 'children': ['372', '373']}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'extract_output'}; {'id': '373', 'type': 'argument_list', 'children': ['374']}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'}; {'id': '375', 'type': 'expression_statement', 'children': ['376']}; {'id': '376', 'type': 'call', 'children': ['377', '380']}; {'id': '377', 'type': 'attribute', 'children': ['378', '379']}; {'id': '378', 'type': 'identifier', 'children': [], 'value': 'shutil'}; {'id': '379', 'type': 'identifier', 'children': [], 'value': 'rmtree'}; {'id': '380', 'type': 'argument_list', 'children': ['381']}; {'id': '381', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'}; {'id': '382', 'type': 'return_statement', 'children': ['383']}; {'id': '383', 'type': 'identifier', 'children': [], 'value': 'output_tuple'}
def run_on_text(text, python2_path): tees_path = get_config('TEES_PATH') if tees_path is None: for cpath in tees_candidate_paths: cpath = os.path.expanduser(cpath) if os.path.isdir(cpath): has_expected_files = True for f in tees_installation_files: fpath = os.path.join(cpath, f) present = os.path.isfile(fpath) has_expected_files = has_expected_files and present has_expected_dirs = True for d in tees_installation_dirs: dpath = os.path.join(cpath, d) present = os.path.isdir(dpath) has_expected_dirs = has_expected_dirs and present if has_expected_files and has_expected_dirs: tees_path = cpath print('Found TEES installation at ' + cpath) break if not os.path.isdir(tees_path): raise Exception('Provided TEES directory does not exist.') classify_path = 'classify.py' tmp_dir = tempfile.mkdtemp(suffix='indra_tees_processor') pwd = os.path.abspath(os.getcwd()) try: text_path = os.path.join(tmp_dir, 'text.txt') with codecs.open(text_path, 'w', encoding='latin-1', errors='ignore') \ as f: f.write(text) output_path = os.path.join(tmp_dir, 'output') model_path = os.path.join(tees_path, 'tees_data/models/GE11-test/') command = [python2_path, classify_path, '-m', model_path, '-i', text_path, '-o', output_path] try: pwd = os.path.abspath(os.getcwd()) os.chdir(tees_path) p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=tees_path) p.wait() (so, se) = p.communicate() print(so) print(se) os.chdir(pwd) except BaseException as e: os.chdir(pwd) raise e except BaseException as e: shutil.rmtree(tmp_dir) raise e output_tuple = extract_output(tmp_dir) shutil.rmtree(tmp_dir) return output_tuple
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'extract_output'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '5', 'type': 'block', 'children': ['6', '18', '27', '56', '62', '91', '102']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'sentences_glob'}; {'id': '9', 'type': 'call', 'children': ['10', '15']}; {'id': '10', 'type': 'attribute', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '17', 'type': 'string', 'children': [], 'value': "'*-preprocessed.xml.gz'"}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'sentences_filename_candidates'}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'sentences_glob'}; {'id': '27', 'type': 'if_statement', 'children': ['28', '34']}; {'id': '28', 'type': 'comparison_operator', 'children': ['29', '33'], 'value': '!='}; {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'sentences_filename_candidates'}; {'id': '33', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '34', 'type': 'block', 'children': ['35', '39', '51']}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '38', 'type': 'string', 'children': [], 'value': "'Looking for exactly one file matching %s but found %d matches'"}; {'id': '39', 'type': 'raise_statement', 'children': ['40']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'binary_operator', 'children': ['44', '45'], 'value': '%'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '45', 'type': 'tuple', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'sentences_glob'}; {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'sentences_filename_candidates'}; {'id': '51', 'type': 'return_statement', 'children': ['52']}; {'id': '52', 'type': 'expression_list', 'children': ['53', '54', '55']}; {'id': '53', 'type': 'None', 'children': []}; {'id': '54', 'type': 'None', 'children': []}; {'id': '55', 'type': 'None', 'children': []}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'sentence_segmentation_filename'}; {'id': '59', 'type': 'subscript', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'sentences_filename_candidates'}; {'id': '61', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '62', 'type': 'with_statement', 'children': ['63', '77']}; {'id': '63', 'type': 'with_clause', 'children': ['64']}; {'id': '64', 'type': 'with_item', 'children': ['65']}; {'id': '65', 'type': 'as_pattern', 'children': ['66', '75']}; {'id': '66', 'type': 'call', 'children': ['67', '70']}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'gzip'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'GzipFile'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '74']}; {'id': '71', 'type': 'subscript', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'sentences_filename_candidates'}; {'id': '73', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '74', 'type': 'string', 'children': [], 'value': "'r'"}; {'id': '75', 'type': 'as_pattern_target', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}; {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'sentence_segmentations'}; {'id': '81', 'type': 'call', 'children': ['82', '89']}; {'id': '82', 'type': 'attribute', 'children': ['83', '88']}; {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '87', 'type': 'argument_list', 'children': []}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'}; {'id': '94', 'type': 'call', 'children': ['95', '98']}; {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'tempfile'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'mkdtemp'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}; {'id': '99', 'type': 'keyword_argument', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'suffix'}; {'id': '101', 'type': 'string', 'children': [], 'value': "'indra_tees_processor'"}; {'id': '102', 'type': 'try_statement', 'children': ['103', '354']}; {'id': '103', 'type': 'block', 'children': ['104', '116', '125', '145', '156', '160', '164', '168', '231', '264', '276', '309', '342', '349']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}; {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'tarfile_glob'}; {'id': '107', 'type': 'call', 'children': ['108', '113']}; {'id': '108', 'type': 'attribute', 'children': ['109', '112']}; {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '113', 'type': 'argument_list', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'output_dir'}; {'id': '115', 'type': 'string', 'children': [], 'value': "'*-events.tar.gz'"}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}; {'id': '117', 'type': 'assignment', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'candidate_tarfiles'}; {'id': '119', 'type': 'call', 'children': ['120', '123']}; {'id': '120', 'type': 'attribute', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'glob'}; {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'tarfile_glob'}; {'id': '125', 'type': 'if_statement', 'children': ['126', '132']}; {'id': '126', 'type': 'comparison_operator', 'children': ['127', '131'], 'value': '!='}; {'id': '127', 'type': 'call', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '129', 'type': 'argument_list', 'children': ['130']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'candidate_tarfiles'}; {'id': '131', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '132', 'type': 'block', 'children': ['133', '140']}; {'id': '133', 'type': 'raise_statement', 'children': ['134']}; {'id': '134', 'type': 'call', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}; {'id': '137', 'type': 'binary_operator', 'children': ['138', '139'], 'value': '%'}; {'id': '138', 'type': 'string', 'children': [], 'value': "'Expected exactly one match for glob %s'"}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'tarfile_glob'}; {'id': '140', 'type': 'return_statement', 'children': ['141']}; {'id': '141', 'type': 'expression_list', 'children': ['142', '143', '144']}; {'id': '142', 'type': 'None', 'children': []}; {'id': '143', 'type': 'None', 'children': []}; {'id': '144', 'type': 'None', 'children': []}; {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'tar_file'}; {'id': '148', 'type': 'call', 'children': ['149', '152']}; {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'tarfile'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}; {'id': '153', 'type': 'subscript', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'candidate_tarfiles'}; {'id': '155', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}; {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'a1_file'}; {'id': '159', 'type': 'None', 'children': []}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}; {'id': '161', 'type': 'assignment', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'a2_file'}; {'id': '163', 'type': 'None', 'children': []}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}; {'id': '165', 'type': 'assignment', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'extract_these'}; {'id': '167', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '168', 'type': 'for_statement', 'children': ['169', '170', '175']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '170', 'type': 'call', 'children': ['171', '174']}; {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'tar_file'}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'getmembers'}; {'id': '174', 'type': 'argument_list', 'children': []}; {'id': '175', 'type': 'block', 'children': ['176']}; {'id': '176', 'type': 'if_statement', 'children': ['177', '186']}; {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 're'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '181', 'type': 'argument_list', 'children': ['182', '183']}; {'id': '182', 'type': 'string', 'children': [], 'value': "'[a-zA-Z0-9].*.a[12]'"}; {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '186', 'type': 'block', 'children': ['187', '194']}; {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'call', 'children': ['189', '192']}; {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'extract_these'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '192', 'type': 'argument_list', 'children': ['193']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '194', 'type': 'if_statement', 'children': ['195', '203', '210', '226']}; {'id': '195', 'type': 'call', 'children': ['196', '201']}; {'id': '196', 'type': 'attribute', 'children': ['197', '200']}; {'id': '197', 'type': 'attribute', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'endswith'}; {'id': '201', 'type': 'argument_list', 'children': ['202']}; {'id': '202', 'type': 'string', 'children': [], 'value': "'.a1'"}; {'id': '203', 'type': 'block', 'children': ['204']}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}; {'id': '205', 'type': 'assignment', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'a1_file'}; {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '210', 'type': 'elif_clause', 'children': ['211', '219']}; {'id': '211', 'type': 'call', 'children': ['212', '217']}; {'id': '212', 'type': 'attribute', 'children': ['213', '216']}; {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'endswith'}; {'id': '217', 'type': 'argument_list', 'children': ['218']}; {'id': '218', 'type': 'string', 'children': [], 'value': "'.a2'"}; {'id': '219', 'type': 'block', 'children': ['220']}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}; {'id': '221', 'type': 'assignment', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'a2_file'}; {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '226', 'type': 'else_clause', 'children': ['227']}; {'id': '227', 'type': 'block', 'children': ['228']}; {'id': '228', 'type': 'assert_statement', 'children': ['229']}; {'id': '229', 'type': '()', 'children': ['230']}; {'id': '230', 'type': 'False', 'children': []}; {'id': '231', 'type': 'if_statement', 'children': ['232', '246']}; {'id': '232', 'type': 'boolean_operator', 'children': ['233', '243'], 'value': 'or'}; {'id': '233', 'type': 'boolean_operator', 'children': ['234', '240'], 'value': 'or'}; {'id': '234', 'type': 'comparison_operator', 'children': ['235', '239'], 'value': '!='}; {'id': '235', 'type': 'call', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '237', 'type': 'argument_list', 'children': ['238']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'extract_these'}; {'id': '239', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '240', 'type': 'comparison_operator', 'children': ['241', '242'], 'value': 'is'}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'a1_file'}; {'id': '242', 'type': 'None', 'children': []}; {'id': '243', 'type': 'comparison_operator', 'children': ['244', '245'], 'value': 'is'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'a2_file'}; {'id': '245', 'type': 'None', 'children': []}; {'id': '246', 'type': 'block', 'children': ['247', '259']}; {'id': '247', 'type': 'raise_statement', 'children': ['248']}; {'id': '248', 'type': 'call', 'children': ['249', '250']}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '250', 'type': 'argument_list', 'children': ['251']}; {'id': '251', 'type': 'binary_operator', 'children': ['252', '253'], 'value': '+'}; {'id': '252', 'type': 'string', 'children': [], 'value': "'We thought there would be one .a1 and one .a2'"}; {'id': '253', 'type': 'binary_operator', 'children': ['254', '255'], 'value': '%'}; {'id': '254', 'type': 'string', 'children': [], 'value': "' file in the tarball, but we got %d files total'"}; {'id': '255', 'type': 'call', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '257', 'type': 'argument_list', 'children': ['258']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'extract_these'}; {'id': '259', 'type': 'return_statement', 'children': ['260']}; {'id': '260', 'type': 'expression_list', 'children': ['261', '262', '263']}; {'id': '261', 'type': 'None', 'children': []}; {'id': '262', 'type': 'None', 'children': []}; {'id': '263', 'type': 'None', 'children': []}; {'id': '264', 'type': 'expression_statement', 'children': ['265']}; {'id': '265', 'type': 'call', 'children': ['266', '269']}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'tar_file'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'extractall'}; {'id': '269', 'type': 'argument_list', 'children': ['270', '273']}; {'id': '270', 'type': 'keyword_argument', 'children': ['271', '272']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'}; {'id': '273', 'type': 'keyword_argument', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'members'}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'extract_these'}; {'id': '276', 'type': 'with_statement', 'children': ['277', '300']}; {'id': '277', 'type': 'with_clause', 'children': ['278']}; {'id': '278', 'type': 'with_item', 'children': ['279']}; {'id': '279', 'type': 'as_pattern', 'children': ['280', '298']}; {'id': '280', 'type': 'call', 'children': ['281', '284']}; {'id': '281', 'type': 'attribute', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'codecs'}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '284', 'type': 'argument_list', 'children': ['285', '294', '295']}; {'id': '285', 'type': 'call', 'children': ['286', '291']}; {'id': '286', 'type': 'attribute', 'children': ['287', '290']}; {'id': '287', 'type': 'attribute', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '291', 'type': 'argument_list', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'a1_file'}; {'id': '294', 'type': 'string', 'children': [], 'value': "'r'"}; {'id': '295', 'type': 'keyword_argument', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '297', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '298', 'type': 'as_pattern_target', 'children': ['299']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '300', 'type': 'block', 'children': ['301']}; {'id': '301', 'type': 'expression_statement', 'children': ['302']}; {'id': '302', 'type': 'assignment', 'children': ['303', '304']}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'a1_text'}; {'id': '304', 'type': 'call', 'children': ['305', '308']}; {'id': '305', 'type': 'attribute', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '308', 'type': 'argument_list', 'children': []}; {'id': '309', 'type': 'with_statement', 'children': ['310', '333']}; {'id': '310', 'type': 'with_clause', 'children': ['311']}; {'id': '311', 'type': 'with_item', 'children': ['312']}; {'id': '312', 'type': 'as_pattern', 'children': ['313', '331']}; {'id': '313', 'type': 'call', 'children': ['314', '317']}; {'id': '314', 'type': 'attribute', 'children': ['315', '316']}; {'id': '315', 'type': 'identifier', 'children': [], 'value': 'codecs'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '317', 'type': 'argument_list', 'children': ['318', '327', '328']}; {'id': '318', 'type': 'call', 'children': ['319', '324']}; {'id': '319', 'type': 'attribute', 'children': ['320', '323']}; {'id': '320', 'type': 'attribute', 'children': ['321', '322']}; {'id': '321', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '324', 'type': 'argument_list', 'children': ['325', '326']}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'a2_file'}; {'id': '327', 'type': 'string', 'children': [], 'value': "'r'"}; {'id': '328', 'type': 'keyword_argument', 'children': ['329', '330']}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'encoding'}; {'id': '330', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '331', 'type': 'as_pattern_target', 'children': ['332']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '333', 'type': 'block', 'children': ['334']}; {'id': '334', 'type': 'expression_statement', 'children': ['335']}; {'id': '335', 'type': 'assignment', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'a2_text'}; {'id': '337', 'type': 'call', 'children': ['338', '341']}; {'id': '338', 'type': 'attribute', 'children': ['339', '340']}; {'id': '339', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'read'}; {'id': '341', 'type': 'argument_list', 'children': []}; {'id': '342', 'type': 'expression_statement', 'children': ['343']}; {'id': '343', 'type': 'call', 'children': ['344', '347']}; {'id': '344', 'type': 'attribute', 'children': ['345', '346']}; {'id': '345', 'type': 'identifier', 'children': [], 'value': 'shutil'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'rmtree'}; {'id': '347', 'type': 'argument_list', 'children': ['348']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'}; {'id': '349', 'type': 'return_statement', 'children': ['350']}; {'id': '350', 'type': 'expression_list', 'children': ['351', '352', '353']}; {'id': '351', 'type': 'identifier', 'children': [], 'value': 'a1_text'}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'a2_text'}; {'id': '353', 'type': 'identifier', 'children': [], 'value': 'sentence_segmentations'}; {'id': '354', 'type': 'except_clause', 'children': ['355', '359']}; {'id': '355', 'type': 'as_pattern', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'BaseException'}; {'id': '357', 'type': 'as_pattern_target', 'children': ['358']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '359', 'type': 'block', 'children': ['360', '367', '374', '376']}; {'id': '360', 'type': 'expression_statement', 'children': ['361']}; {'id': '361', 'type': 'call', 'children': ['362', '363']}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'print'}; {'id': '363', 'type': 'argument_list', 'children': ['364']}; {'id': '364', 'type': 'binary_operator', 'children': ['365', '366'], 'value': '+'}; {'id': '365', 'type': 'string', 'children': [], 'value': "'Not removing temporary directory: '"}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'}; {'id': '367', 'type': 'expression_statement', 'children': ['368']}; {'id': '368', 'type': 'call', 'children': ['369', '372']}; {'id': '369', 'type': 'attribute', 'children': ['370', '371']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'shutil'}; {'id': '371', 'type': 'identifier', 'children': [], 'value': 'rmtree'}; {'id': '372', 'type': 'argument_list', 'children': ['373']}; {'id': '373', 'type': 'identifier', 'children': [], 'value': 'tmp_dir'}; {'id': '374', 'type': 'raise_statement', 'children': ['375']}; {'id': '375', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '376', 'type': 'return_statement', 'children': ['377']}; {'id': '377', 'type': 'expression_list', 'children': ['378', '379', '380']}; {'id': '378', 'type': 'None', 'children': []}; {'id': '379', 'type': 'None', 'children': []}; {'id': '380', 'type': 'None', 'children': []}
def extract_output(output_dir): sentences_glob = os.path.join(output_dir, '*-preprocessed.xml.gz') sentences_filename_candidates = glob.glob(sentences_glob) if len(sentences_filename_candidates) != 1: m = 'Looking for exactly one file matching %s but found %d matches' raise Exception(m % ( sentences_glob, len(sentences_filename_candidates))) return None, None, None sentence_segmentation_filename = sentences_filename_candidates[0] with gzip.GzipFile(sentences_filename_candidates[0], 'r') as f: sentence_segmentations = f.read().decode('utf-8') tmp_dir = tempfile.mkdtemp(suffix='indra_tees_processor') try: tarfile_glob = os.path.join(output_dir, '*-events.tar.gz') candidate_tarfiles = glob.glob(tarfile_glob) if len(candidate_tarfiles) != 1: raise Exception('Expected exactly one match for glob %s' % tarfile_glob) return None, None, None tar_file = tarfile.open(candidate_tarfiles[0]) a1_file = None a2_file = None extract_these = [] for m in tar_file.getmembers(): if re.match('[a-zA-Z0-9].*.a[12]', m.name): extract_these.append(m) if m.name.endswith('.a1'): a1_file = m.name elif m.name.endswith('.a2'): a2_file = m.name else: assert(False) if len(extract_these) != 2 or a1_file is None or a2_file is None: raise Exception('We thought there would be one .a1 and one .a2' + ' file in the tarball, but we got %d files total' % len(extract_these)) return None, None, None tar_file.extractall(path=tmp_dir, members=extract_these) with codecs.open(os.path.join(tmp_dir, a1_file), 'r', encoding='utf-8') as f: a1_text = f.read() with codecs.open(os.path.join(tmp_dir, a2_file), 'r', encoding='utf-8') as f: a2_text = f.read() shutil.rmtree(tmp_dir) return a1_text, a2_text, sentence_segmentations except BaseException as e: print('Not removing temporary directory: ' + tmp_dir) shutil.rmtree(tmp_dir) raise e return None, None, None
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_drug_inhibition_stmts'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'drug'}; {'id': '5', 'type': 'block', 'children': ['6', '17', '28', '61', '71', '87', '94', '100', '107', '115', '122', '138', '142', '270']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'chebi_id'}; {'id': '9', 'type': 'call', 'children': ['10', '15']}; {'id': '10', 'type': 'attribute', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'drug'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'string', 'children': [], 'value': "'CHEBI'"}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'mesh_id'}; {'id': '20', 'type': 'call', 'children': ['21', '26']}; {'id': '21', 'type': 'attribute', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'drug'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'string', 'children': [], 'value': "'MESH'"}; {'id': '28', 'type': 'if_statement', 'children': ['29', '30', '40', '50']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'chebi_id'}; {'id': '30', 'type': 'block', 'children': ['31']}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'drug_chembl_id'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'chebi_client'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'get_chembl_id'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'chebi_id'}; {'id': '40', 'type': 'elif_clause', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'mesh_id'}; {'id': '42', 'type': 'block', 'children': ['43']}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'drug_chembl_id'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'get_chembl_id'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'mesh_id'}; {'id': '50', 'type': 'else_clause', 'children': ['51']}; {'id': '51', 'type': 'block', 'children': ['52', '59']}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'string', 'children': [], 'value': "'Drug missing ChEBI or MESH grounding.'"}; {'id': '59', 'type': 'return_statement', 'children': ['60']}; {'id': '60', 'type': 'None', 'children': []}; {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'call', 'children': ['63', '66']}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}; {'id': '67', 'type': 'binary_operator', 'children': ['68', '69'], 'value': '%'}; {'id': '68', 'type': 'string', 'children': [], 'value': "'Drug: %s'"}; {'id': '69', 'type': '()', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'drug_chembl_id'}; {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'query_dict'}; {'id': '74', 'type': 'dictionary', 'children': ['75', '78']}; {'id': '75', 'type': 'pair', 'children': ['76', '77']}; {'id': '76', 'type': 'string', 'children': [], 'value': "'query'"}; {'id': '77', 'type': 'string', 'children': [], 'value': "'activity'"}; {'id': '78', 'type': 'pair', 'children': ['79', '80']}; {'id': '79', 'type': 'string', 'children': [], 'value': "'params'"}; {'id': '80', 'type': 'dictionary', 'children': ['81', '84']}; {'id': '81', 'type': 'pair', 'children': ['82', '83']}; {'id': '82', 'type': 'string', 'children': [], 'value': "'molecule_chembl_id'"}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'drug_chembl_id'}; {'id': '84', 'type': 'pair', 'children': ['85', '86']}; {'id': '85', 'type': 'string', 'children': [], 'value': "'limit'"}; {'id': '86', 'type': 'integer', 'children': [], 'value': '10000'}; {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '90', 'type': 'call', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'send_query'}; {'id': '92', 'type': 'argument_list', 'children': ['93']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'query_dict'}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}; {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'activities'}; {'id': '97', 'type': 'subscript', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '99', 'type': 'string', 'children': [], 'value': "'activities'"}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}; {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'targ_act_dict'}; {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'activities_by_target'}; {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'activities'}; {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'target_chembl_ids'}; {'id': '110', 'type': 'list_comprehension', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '112', 'type': 'for_in_clause', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'targ_act_dict'}; {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'protein_targets'}; {'id': '118', 'type': 'call', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'get_protein_targets_only'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'target_chembl_ids'}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}; {'id': '123', 'type': 'assignment', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'filtered_targ_act_dict'}; {'id': '125', 'type': 'dictionary_comprehension', 'children': ['126', '131']}; {'id': '126', 'type': 'pair', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '128', 'type': 'subscript', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'targ_act_dict'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '131', 'type': 'for_in_clause', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '133', 'type': 'list_comprehension', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '135', 'type': 'for_in_clause', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'protein_targets'}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}; {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'stmts'}; {'id': '141', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '142', 'type': 'for_statement', 'children': ['143', '144', '145']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'target_chembl_id'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'filtered_targ_act_dict'}; {'id': '145', 'type': 'block', 'children': ['146', '152', '166', '170', '178', '191', '195', '218']}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}; {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'target_activity_ids'}; {'id': '149', 'type': 'subscript', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'filtered_targ_act_dict'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'target_chembl_id'}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}; {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'target_activites'}; {'id': '155', 'type': 'list_comprehension', 'children': ['156', '157', '160']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '157', 'type': 'for_in_clause', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'activities'}; {'id': '160', 'type': 'if_clause', 'children': ['161']}; {'id': '161', 'type': 'comparison_operator', 'children': ['162', '165'], 'value': 'in'}; {'id': '162', 'type': 'subscript', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '164', 'type': 'string', 'children': [], 'value': "'activity_id'"}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'target_activity_ids'}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}; {'id': '167', 'type': 'assignment', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'target_upids'}; {'id': '169', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}; {'id': '171', 'type': 'assignment', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'targ_comp'}; {'id': '173', 'type': 'subscript', 'children': ['174', '177']}; {'id': '174', 'type': 'subscript', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'protein_targets'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'target_chembl_id'}; {'id': '177', 'type': 'string', 'children': [], 'value': "'target_components'"}; {'id': '178', 'type': 'for_statement', 'children': ['179', '180', '181']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 't_c'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'targ_comp'}; {'id': '181', 'type': 'block', 'children': ['182']}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}; {'id': '183', 'type': 'call', 'children': ['184', '187']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'target_upids'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'subscript', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 't_c'}; {'id': '190', 'type': 'string', 'children': [], 'value': "'accession'"}; {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'evidence'}; {'id': '194', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '195', 'type': 'for_statement', 'children': ['196', '197', '198']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'assay'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'target_activites'}; {'id': '198', 'type': 'block', 'children': ['199', '206', '211']}; {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '202', 'type': 'call', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'get_evidence'}; {'id': '204', 'type': 'argument_list', 'children': ['205']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'assay'}; {'id': '206', 'type': 'if_statement', 'children': ['207', '209']}; {'id': '207', 'type': 'not_operator', 'children': ['208']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '209', 'type': 'block', 'children': ['210']}; {'id': '210', 'type': 'continue_statement', 'children': []}; {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'call', 'children': ['213', '216']}; {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'evidence'}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '216', 'type': 'argument_list', 'children': ['217']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '218', 'type': 'if_statement', 'children': ['219', '225']}; {'id': '219', 'type': 'comparison_operator', 'children': ['220', '224'], 'value': '>'}; {'id': '220', 'type': 'call', 'children': ['221', '222']}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '222', 'type': 'argument_list', 'children': ['223']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'evidence'}; {'id': '224', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '225', 'type': 'block', 'children': ['226']}; {'id': '226', 'type': 'for_statement', 'children': ['227', '228', '229']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'target_upid'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'target_upids'}; {'id': '229', 'type': 'block', 'children': ['230', '239', '252', '263']}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}; {'id': '231', 'type': 'assignment', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'agent_name'}; {'id': '233', 'type': 'call', 'children': ['234', '237']}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'uniprot_client'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'get_gene_name'}; {'id': '237', 'type': 'argument_list', 'children': ['238']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'target_upid'}; {'id': '239', 'type': 'expression_statement', 'children': ['240']}; {'id': '240', 'type': 'assignment', 'children': ['241', '242']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'target_agent'}; {'id': '242', 'type': 'call', 'children': ['243', '244']}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'Agent'}; {'id': '244', 'type': 'argument_list', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'agent_name'}; {'id': '246', 'type': 'keyword_argument', 'children': ['247', '248']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '248', 'type': 'dictionary', 'children': ['249']}; {'id': '249', 'type': 'pair', 'children': ['250', '251']}; {'id': '250', 'type': 'string', 'children': [], 'value': "'UP'"}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'target_upid'}; {'id': '252', 'type': 'expression_statement', 'children': ['253']}; {'id': '253', 'type': 'assignment', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '255', 'type': 'call', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'Inhibition'}; {'id': '257', 'type': 'argument_list', 'children': ['258', '259', '260']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'drug'}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'target_agent'}; {'id': '260', 'type': 'keyword_argument', 'children': ['261', '262']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'evidence'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'evidence'}; {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'call', 'children': ['265', '268']}; {'id': '265', 'type': 'attribute', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'stmts'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '268', 'type': 'argument_list', 'children': ['269']}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '270', 'type': 'return_statement', 'children': ['271']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'stmts'}
def get_drug_inhibition_stmts(drug): chebi_id = drug.db_refs.get('CHEBI') mesh_id = drug.db_refs.get('MESH') if chebi_id: drug_chembl_id = chebi_client.get_chembl_id(chebi_id) elif mesh_id: drug_chembl_id = get_chembl_id(mesh_id) else: logger.error('Drug missing ChEBI or MESH grounding.') return None logger.info('Drug: %s' % (drug_chembl_id)) query_dict = {'query': 'activity', 'params': {'molecule_chembl_id': drug_chembl_id, 'limit': 10000} } res = send_query(query_dict) activities = res['activities'] targ_act_dict = activities_by_target(activities) target_chembl_ids = [x for x in targ_act_dict] protein_targets = get_protein_targets_only(target_chembl_ids) filtered_targ_act_dict = {t: targ_act_dict[t] for t in [x for x in protein_targets]} stmts = [] for target_chembl_id in filtered_targ_act_dict: target_activity_ids = filtered_targ_act_dict[target_chembl_id] target_activites = [x for x in activities if x['activity_id'] in target_activity_ids] target_upids = [] targ_comp = protein_targets[target_chembl_id]['target_components'] for t_c in targ_comp: target_upids.append(t_c['accession']) evidence = [] for assay in target_activites: ev = get_evidence(assay) if not ev: continue evidence.append(ev) if len(evidence) > 0: for target_upid in target_upids: agent_name = uniprot_client.get_gene_name(target_upid) target_agent = Agent(agent_name, db_refs={'UP': target_upid}) st = Inhibition(drug, target_agent, evidence=evidence) stmts.append(st) return stmts
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge_groundings'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '5', 'type': 'block', 'children': ['6', '117', '293', '297', '323']}; {'id': '6', 'type': 'function_definition', 'children': ['7', '8', '10']}; {'id': '7', 'type': 'function_name', 'children': [], 'value': 'surface_grounding'}; {'id': '8', 'type': 'parameters', 'children': ['9']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '10', 'type': 'block', 'children': ['11']}; {'id': '11', 'type': 'for_statement', 'children': ['12', '15', '23']}; {'id': '12', 'type': 'pattern_list', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'concept'}; {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'agent_list'}; {'id': '22', 'type': 'argument_list', 'children': []}; {'id': '23', 'type': 'block', 'children': ['24', '30', '34', '104', '111']}; {'id': '24', 'type': 'if_statement', 'children': ['25', '28']}; {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'is'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'concept'}; {'id': '27', 'type': 'None', 'children': []}; {'id': '28', 'type': 'block', 'children': ['29']}; {'id': '29', 'type': 'continue_statement', 'children': []}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'aggregate_groundings'}; {'id': '33', 'type': 'dictionary', 'children': []}; {'id': '34', 'type': 'for_statement', 'children': ['35', '36', '39']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'evidence'}; {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'if_statement', 'children': ['41', '46']}; {'id': '41', 'type': 'comparison_operator', 'children': ['42', '43'], 'value': 'in'}; {'id': '42', 'type': 'string', 'children': [], 'value': "'agents'"}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '46', 'type': 'block', 'children': ['47', '59']}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'groundings'}; {'id': '50', 'type': 'subscript', 'children': ['51', '58']}; {'id': '51', 'type': 'subscript', 'children': ['52', '57']}; {'id': '52', 'type': 'subscript', 'children': ['53', '56']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '56', 'type': 'string', 'children': [], 'value': "'agents'"}; {'id': '57', 'type': 'string', 'children': [], 'value': "'raw_grounding'"}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '59', 'type': 'for_statement', 'children': ['60', '63', '68']}; {'id': '60', 'type': 'pattern_list', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'ns'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'groundings'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '67', 'type': 'argument_list', 'children': []}; {'id': '68', 'type': 'block', 'children': ['69', '80']}; {'id': '69', 'type': 'if_statement', 'children': ['70', '73']}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '72'], 'value': 'not'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'ns'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'aggregate_groundings'}; {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}; {'id': '75', 'type': 'assignment', 'children': ['76', '79']}; {'id': '76', 'type': 'subscript', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'aggregate_groundings'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'ns'}; {'id': '79', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '80', 'type': 'if_statement', 'children': ['81', '86', '93']}; {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '83', 'type': 'argument_list', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '86', 'type': 'block', 'children': ['87']}; {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'augmented_assignment', 'children': ['89', '92'], 'value': '+='}; {'id': '89', 'type': 'subscript', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'aggregate_groundings'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'ns'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '93', 'type': 'else_clause', 'children': ['94']}; {'id': '94', 'type': 'block', 'children': ['95']}; {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'call', 'children': ['97', '102']}; {'id': '97', 'type': 'attribute', 'children': ['98', '101']}; {'id': '98', 'type': 'subscript', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'aggregate_groundings'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'ns'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}; {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'best_groundings'}; {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'get_best_groundings'}; {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'aggregate_groundings'}; {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '116']}; {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'concept'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'best_groundings'}; {'id': '117', 'type': 'function_definition', 'children': ['118', '119', '121']}; {'id': '118', 'type': 'function_name', 'children': [], 'value': 'get_best_groundings'}; {'id': '119', 'type': 'parameters', 'children': ['120']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'aggregate_groundings'}; {'id': '121', 'type': 'block', 'children': ['122', '126', '291']}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}; {'id': '123', 'type': 'assignment', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'best_groundings'}; {'id': '125', 'type': 'dictionary', 'children': []}; {'id': '126', 'type': 'for_statement', 'children': ['127', '130', '135']}; {'id': '127', 'type': 'pattern_list', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'ns'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '130', 'type': 'call', 'children': ['131', '134']}; {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'aggregate_groundings'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '134', 'type': 'argument_list', 'children': []}; {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'if_statement', 'children': ['137', '151', '221', '255']}; {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'list_comprehension', 'children': ['141', '148']}; {'id': '141', 'type': 'call', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '143', 'type': 'argument_list', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '145', 'type': 'tuple', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '148', 'type': 'for_in_clause', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '151', 'type': 'block', 'children': ['152', '158', '198']}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}; {'id': '153', 'type': 'assignment', 'children': ['154', '157']}; {'id': '154', 'type': 'subscript', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'best_groundings'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'ns'}; {'id': '157', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '158', 'type': 'for_statement', 'children': ['159', '160', '167']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'unique_value'}; {'id': '160', 'type': 'set_comprehension', 'children': ['161', '164']}; {'id': '161', 'type': 'subscript', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '163', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '164', 'type': 'for_in_clause', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '167', 'type': 'block', 'children': ['168', '184']}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}; {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'scores'}; {'id': '171', 'type': 'list_comprehension', 'children': ['172', '175', '178']}; {'id': '172', 'type': 'subscript', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '174', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '175', 'type': 'for_in_clause', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '178', 'type': 'if_clause', 'children': ['179']}; {'id': '179', 'type': 'comparison_operator', 'children': ['180', '183'], 'value': '=='}; {'id': '180', 'type': 'subscript', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '182', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'unique_value'}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}; {'id': '185', 'type': 'call', 'children': ['186', '191']}; {'id': '186', 'type': 'attribute', 'children': ['187', '190']}; {'id': '187', 'type': 'subscript', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'best_groundings'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'ns'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'tuple', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'unique_value'}; {'id': '194', 'type': 'call', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '196', 'type': 'argument_list', 'children': ['197']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'scores'}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}; {'id': '199', 'type': 'assignment', 'children': ['200', '203', '204']}; {'id': '200', 'type': 'subscript', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'best_groundings'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'ns'}; {'id': '203', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '204', 'type': 'call', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '206', 'type': 'argument_list', 'children': ['207', '210', '218']}; {'id': '207', 'type': 'subscript', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'best_groundings'}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'ns'}; {'id': '210', 'type': 'keyword_argument', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '212', 'type': 'lambda', 'children': ['213', '215']}; {'id': '213', 'type': 'lambda_parameters', 'children': ['214']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '215', 'type': 'subscript', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '217', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '218', 'type': 'keyword_argument', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '220', 'type': 'True', 'children': []}; {'id': '221', 'type': 'elif_clause', 'children': ['222', '237']}; {'id': '222', 'type': 'call', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '224', 'type': 'argument_list', 'children': ['225']}; {'id': '225', 'type': 'list_comprehension', 'children': ['226', '234']}; {'id': '226', 'type': 'not_operator', 'children': ['227']}; {'id': '227', 'type': 'call', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '229', 'type': 'argument_list', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '231', 'type': 'tuple', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '234', 'type': 'for_in_clause', 'children': ['235', '236']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '237', 'type': 'block', 'children': ['238']}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}; {'id': '239', 'type': 'assignment', 'children': ['240', '243']}; {'id': '240', 'type': 'subscript', 'children': ['241', '242']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'best_groundings'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'ns'}; {'id': '243', 'type': 'call', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '245', 'type': 'argument_list', 'children': ['246', '250']}; {'id': '246', 'type': 'call', 'children': ['247', '248']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '248', 'type': 'argument_list', 'children': ['249']}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '250', 'type': 'keyword_argument', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '255', 'type': 'else_clause', 'children': ['256']}; {'id': '256', 'type': 'block', 'children': ['257', '274']}; {'id': '257', 'type': 'expression_statement', 'children': ['258']}; {'id': '258', 'type': 'assignment', 'children': ['259', '260']}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'unscored_vals'}; {'id': '260', 'type': 'list_comprehension', 'children': ['261', '262', '265']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '262', 'type': 'for_in_clause', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '265', 'type': 'if_clause', 'children': ['266']}; {'id': '266', 'type': 'not_operator', 'children': ['267']}; {'id': '267', 'type': 'call', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '269', 'type': 'argument_list', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '271', 'type': 'tuple', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '274', 'type': 'expression_statement', 'children': ['275']}; {'id': '275', 'type': 'assignment', 'children': ['276', '279']}; {'id': '276', 'type': 'subscript', 'children': ['277', '278']}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'best_groundings'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'ns'}; {'id': '279', 'type': 'call', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '281', 'type': 'argument_list', 'children': ['282', '286']}; {'id': '282', 'type': 'call', 'children': ['283', '284']}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '284', 'type': 'argument_list', 'children': ['285']}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'unscored_vals'}; {'id': '286', 'type': 'keyword_argument', 'children': ['287', '288']}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '288', 'type': 'attribute', 'children': ['289', '290']}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'unscored_vals'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '291', 'type': 'return_statement', 'children': ['292']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'best_groundings'}; {'id': '293', 'type': 'expression_statement', 'children': ['294']}; {'id': '294', 'type': 'assignment', 'children': ['295', '296']}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '296', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '297', 'type': 'for_statement', 'children': ['298', '299', '300']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '300', 'type': 'block', 'children': ['301', '316']}; {'id': '301', 'type': 'if_statement', 'children': ['302', '310']}; {'id': '302', 'type': 'not_operator', 'children': ['303']}; {'id': '303', 'type': 'call', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '305', 'type': 'argument_list', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '307', 'type': 'tuple', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'Complex'}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'Conversion'}; {'id': '310', 'type': 'block', 'children': ['311']}; {'id': '311', 'type': 'expression_statement', 'children': ['312']}; {'id': '312', 'type': 'call', 'children': ['313', '314']}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'surface_grounding'}; {'id': '314', 'type': 'argument_list', 'children': ['315']}; {'id': '315', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '316', 'type': 'expression_statement', 'children': ['317']}; {'id': '317', 'type': 'call', 'children': ['318', '321']}; {'id': '318', 'type': 'attribute', 'children': ['319', '320']}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '321', 'type': 'argument_list', 'children': ['322']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '323', 'type': 'return_statement', 'children': ['324']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}
def merge_groundings(stmts_in): def surface_grounding(stmt): for idx, concept in enumerate(stmt.agent_list()): if concept is None: continue aggregate_groundings = {} for ev in stmt.evidence: if 'agents' in ev.annotations: groundings = ev.annotations['agents']['raw_grounding'][idx] for ns, value in groundings.items(): if ns not in aggregate_groundings: aggregate_groundings[ns] = [] if isinstance(value, list): aggregate_groundings[ns] += value else: aggregate_groundings[ns].append(value) best_groundings = get_best_groundings(aggregate_groundings) concept.db_refs = best_groundings def get_best_groundings(aggregate_groundings): best_groundings = {} for ns, values in aggregate_groundings.items(): if all([isinstance(v, (tuple, list)) for v in values]): best_groundings[ns] = [] for unique_value in {v[0] for v in values}: scores = [v[1] for v in values if v[0] == unique_value] best_groundings[ns].append((unique_value, max(scores))) best_groundings[ns] = \ sorted(best_groundings[ns], key=lambda x: x[1], reverse=True) elif all([not isinstance(v, (tuple, list)) for v in values]): best_groundings[ns] = max(set(values), key=values.count) else: unscored_vals = [v for v in values if not isinstance(v, (tuple, list))] best_groundings[ns] = max(set(unscored_vals), key=unscored_vals.count) return best_groundings stmts_out = [] for stmt in stmts_in: if not isinstance(stmt, (Complex, Conversion)): surface_grounding(stmt) stmts_out.append(stmt) return stmts_out
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'merge_deltas'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '5', 'type': 'block', 'children': ['6', '10', '298']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '9', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '10', 'type': 'for_statement', 'children': ['11', '12', '13']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '13', 'type': 'block', 'children': ['14', '30', '34', '89', '108', '128', '230', '291']}; {'id': '14', 'type': 'if_statement', 'children': ['15', '21']}; {'id': '15', 'type': 'not_operator', 'children': ['16']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'Influence'}; {'id': '21', 'type': 'block', 'children': ['22', '29']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '29', 'type': 'continue_statement', 'children': []}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'deltas'}; {'id': '33', 'type': 'dictionary', 'children': []}; {'id': '34', 'type': 'for_statement', 'children': ['35', '36', '39']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'role'}; {'id': '36', 'type': 'tuple', 'children': ['37', '38']}; {'id': '37', 'type': 'string', 'children': [], 'value': "'subj'"}; {'id': '38', 'type': 'string', 'children': [], 'value': "'obj'"}; {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'for_statement', 'children': ['41', '42', '45']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '42', 'type': 'tuple', 'children': ['43', '44']}; {'id': '43', 'type': 'string', 'children': [], 'value': "'polarity'"}; {'id': '44', 'type': 'string', 'children': [], 'value': "'adjectives'"}; {'id': '45', 'type': 'block', 'children': ['46', '52', '58']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '49', 'type': 'tuple', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'role'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'assignment', 'children': ['54', '57']}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'deltas'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '57', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '58', 'type': 'for_statement', 'children': ['59', '60', '63']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '60', 'type': 'attribute', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'evidence'}; {'id': '63', 'type': 'block', 'children': ['64', '77']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '67', 'type': 'call', 'children': ['68', '73']}; {'id': '68', 'type': 'attribute', 'children': ['69', '72']}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'binary_operator', 'children': ['75', '76'], 'value': '%'}; {'id': '75', 'type': 'string', 'children': [], 'value': "'%s_%s'"}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '84']}; {'id': '79', 'type': 'attribute', 'children': ['80', '83']}; {'id': '80', 'type': 'subscript', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'deltas'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}; {'id': '85', 'type': 'conditional_expression', 'children': ['86', '87', '88'], 'value': 'if'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '88', 'type': 'None', 'children': []}; {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'polarity_pairs'}; {'id': '92', 'type': 'call', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}; {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '97', 'type': 'argument_list', 'children': ['98', '103']}; {'id': '98', 'type': 'subscript', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'deltas'}; {'id': '100', 'type': 'tuple', 'children': ['101', '102']}; {'id': '101', 'type': 'string', 'children': [], 'value': "'subj'"}; {'id': '102', 'type': 'string', 'children': [], 'value': "'polarity'"}; {'id': '103', 'type': 'subscript', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'deltas'}; {'id': '105', 'type': 'tuple', 'children': ['106', '107']}; {'id': '106', 'type': 'string', 'children': [], 'value': "'obj'"}; {'id': '107', 'type': 'string', 'children': [], 'value': "'polarity'"}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}; {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'both_pols'}; {'id': '111', 'type': 'list_comprehension', 'children': ['112', '113', '116']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '113', 'type': 'for_in_clause', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'polarity_pairs'}; {'id': '116', 'type': 'if_clause', 'children': ['117']}; {'id': '117', 'type': 'boolean_operator', 'children': ['118', '123'], 'value': 'and'}; {'id': '118', 'type': 'comparison_operator', 'children': ['119', '122'], 'value': 'is'}; {'id': '119', 'type': 'subscript', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '121', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '122', 'type': 'None', 'children': []}; {'id': '123', 'type': 'comparison_operator', 'children': ['124', '127'], 'value': 'is'}; {'id': '124', 'type': 'subscript', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '126', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '127', 'type': 'None', 'children': []}; {'id': '128', 'type': 'if_statement', 'children': ['129', '130', '168']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'both_pols'}; {'id': '130', 'type': 'block', 'children': ['131', '148', '158']}; {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '136']}; {'id': '133', 'type': 'pattern_list', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'subj_pol'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'obj_pol'}; {'id': '136', 'type': 'call', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '138', 'type': 'argument_list', 'children': ['139', '143']}; {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'both_pols'}; {'id': '143', 'type': 'keyword_argument', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'both_pols'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}; {'id': '149', 'type': 'assignment', 'children': ['150', '157']}; {'id': '150', 'type': 'subscript', 'children': ['151', '156']}; {'id': '151', 'type': 'attribute', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'subj'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '156', 'type': 'string', 'children': [], 'value': "'polarity'"}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'subj_pol'}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}; {'id': '159', 'type': 'assignment', 'children': ['160', '167']}; {'id': '160', 'type': 'subscript', 'children': ['161', '166']}; {'id': '161', 'type': 'attribute', 'children': ['162', '165']}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '166', 'type': 'string', 'children': [], 'value': "'polarity'"}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'obj_pol'}; {'id': '168', 'type': 'else_clause', 'children': ['169']}; {'id': '169', 'type': 'block', 'children': ['170', '190']}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}; {'id': '171', 'type': 'assignment', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'one_pol'}; {'id': '173', 'type': 'list_comprehension', 'children': ['174', '175', '178']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '175', 'type': 'for_in_clause', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'polarity_pairs'}; {'id': '178', 'type': 'if_clause', 'children': ['179']}; {'id': '179', 'type': 'boolean_operator', 'children': ['180', '185'], 'value': 'or'}; {'id': '180', 'type': 'comparison_operator', 'children': ['181', '184'], 'value': 'is'}; {'id': '181', 'type': 'subscript', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '183', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '184', 'type': 'None', 'children': []}; {'id': '185', 'type': 'comparison_operator', 'children': ['186', '189'], 'value': 'is'}; {'id': '186', 'type': 'subscript', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'pair'}; {'id': '188', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '189', 'type': 'None', 'children': []}; {'id': '190', 'type': 'if_statement', 'children': ['191', '192']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'one_pol'}; {'id': '192', 'type': 'block', 'children': ['193', '210', '220']}; {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '198']}; {'id': '195', 'type': 'pattern_list', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'subj_pol'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'obj_pol'}; {'id': '198', 'type': 'call', 'children': ['199', '200']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '200', 'type': 'argument_list', 'children': ['201', '205']}; {'id': '201', 'type': 'call', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'one_pol'}; {'id': '205', 'type': 'keyword_argument', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'one_pol'}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}; {'id': '211', 'type': 'assignment', 'children': ['212', '219']}; {'id': '212', 'type': 'subscript', 'children': ['213', '218']}; {'id': '213', 'type': 'attribute', 'children': ['214', '217']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'subj'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '218', 'type': 'string', 'children': [], 'value': "'polarity'"}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'subj_pol'}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}; {'id': '221', 'type': 'assignment', 'children': ['222', '229']}; {'id': '222', 'type': 'subscript', 'children': ['223', '228']}; {'id': '223', 'type': 'attribute', 'children': ['224', '227']}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '228', 'type': 'string', 'children': [], 'value': "'polarity'"}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'obj_pol'}; {'id': '230', 'type': 'for_statement', 'children': ['231', '234', '249']}; {'id': '231', 'type': 'pattern_list', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'role'}; {'id': '234', 'type': 'tuple', 'children': ['235', '242']}; {'id': '235', 'type': 'tuple', 'children': ['236', '241']}; {'id': '236', 'type': 'attribute', 'children': ['237', '240']}; {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'subj'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '241', 'type': 'string', 'children': [], 'value': "'subj'"}; {'id': '242', 'type': 'tuple', 'children': ['243', '248']}; {'id': '243', 'type': 'attribute', 'children': ['244', '247']}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'delta'}; {'id': '248', 'type': 'string', 'children': [], 'value': "'obj'"}; {'id': '249', 'type': 'block', 'children': ['250', '254', '285']}; {'id': '250', 'type': 'expression_statement', 'children': ['251']}; {'id': '251', 'type': 'assignment', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'all_adjectives'}; {'id': '253', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '254', 'type': 'for_statement', 'children': ['255', '256', '261']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'adj'}; {'id': '256', 'type': 'subscript', 'children': ['257', '258']}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'deltas'}; {'id': '258', 'type': 'tuple', 'children': ['259', '260']}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'role'}; {'id': '260', 'type': 'string', 'children': [], 'value': "'adjectives'"}; {'id': '261', 'type': 'block', 'children': ['262']}; {'id': '262', 'type': 'if_statement', 'children': ['263', '268', '273']}; {'id': '263', 'type': 'call', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '265', 'type': 'argument_list', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'adj'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '268', 'type': 'block', 'children': ['269']}; {'id': '269', 'type': 'expression_statement', 'children': ['270']}; {'id': '270', 'type': 'augmented_assignment', 'children': ['271', '272'], 'value': '+='}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'all_adjectives'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'adj'}; {'id': '273', 'type': 'elif_clause', 'children': ['274', '277']}; {'id': '274', 'type': 'comparison_operator', 'children': ['275', '276'], 'value': 'is'}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'adj'}; {'id': '276', 'type': 'None', 'children': []}; {'id': '277', 'type': 'block', 'children': ['278']}; {'id': '278', 'type': 'expression_statement', 'children': ['279']}; {'id': '279', 'type': 'call', 'children': ['280', '283']}; {'id': '280', 'type': 'attribute', 'children': ['281', '282']}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'all_adjectives'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '283', 'type': 'argument_list', 'children': ['284']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'adj'}; {'id': '285', 'type': 'expression_statement', 'children': ['286']}; {'id': '286', 'type': 'assignment', 'children': ['287', '290']}; {'id': '287', 'type': 'subscript', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '289', 'type': 'string', 'children': [], 'value': "'adjectives'"}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'all_adjectives'}; {'id': '291', 'type': 'expression_statement', 'children': ['292']}; {'id': '292', 'type': 'call', 'children': ['293', '296']}; {'id': '293', 'type': 'attribute', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '296', 'type': 'argument_list', 'children': ['297']}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '298', 'type': 'return_statement', 'children': ['299']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}
def merge_deltas(stmts_in): stmts_out = [] for stmt in stmts_in: if not isinstance(stmt, Influence): stmts_out.append(stmt) continue deltas = {} for role in ('subj', 'obj'): for info in ('polarity', 'adjectives'): key = (role, info) deltas[key] = [] for ev in stmt.evidence: entry = ev.annotations.get('%s_%s' % key) deltas[key].append(entry if entry else None) polarity_pairs = list(zip(deltas[('subj', 'polarity')], deltas[('obj', 'polarity')])) both_pols = [pair for pair in polarity_pairs if pair[0] is not None and pair[1] is not None] if both_pols: subj_pol, obj_pol = max(set(both_pols), key=both_pols.count) stmt.subj.delta['polarity'] = subj_pol stmt.obj.delta['polarity'] = obj_pol else: one_pol = [pair for pair in polarity_pairs if pair[0] is not None or pair[1] is not None] if one_pol: subj_pol, obj_pol = max(set(one_pol), key=one_pol.count) stmt.subj.delta['polarity'] = subj_pol stmt.obj.delta['polarity'] = obj_pol for attr, role in ((stmt.subj.delta, 'subj'), (stmt.obj.delta, 'obj')): all_adjectives = [] for adj in deltas[(role, 'adjectives')]: if isinstance(adj, list): all_adjectives += adj elif adj is not None: all_adjectives.append(adj) attr['adjectives'] = all_adjectives stmts_out.append(stmt) return stmts_out
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'map_sequence'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '7', 'type': 'block', 'children': ['8', '17', '29', '36', '58', '69', '73', '106', '112', '124', '133', '142', '144']}; {'id': '8', 'type': 'import_from_statement', 'children': ['9', '13', '15']}; {'id': '9', 'type': 'dotted_name', 'children': ['10', '11', '12']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'indra'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'preassembler'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'sitemapper'}; {'id': '13', 'type': 'dotted_name', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'SiteMapper'}; {'id': '15', 'type': 'dotted_name', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'default_site_map'}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'call', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'binary_operator', 'children': ['24', '25'], 'value': '%'}; {'id': '24', 'type': 'string', 'children': [], 'value': "'Mapping sites on %d statements...'"}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'kwarg_list'}; {'id': '32', 'type': 'list', 'children': ['33', '34', '35'], 'value': "['do_methionine_offset', 'do_orthology_mapping',\n 'do_isoform_mapping']"}; {'id': '33', 'type': 'string', 'children': [], 'value': "'do_methionine_offset'"}; {'id': '34', 'type': 'string', 'children': [], 'value': "'do_orthology_mapping'"}; {'id': '35', 'type': 'string', 'children': [], 'value': "'do_isoform_mapping'"}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'assignment', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'sm'}; {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'SiteMapper'}; {'id': '41', 'type': 'argument_list', 'children': ['42', '43', '52']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'default_site_map'}; {'id': '43', 'type': 'keyword_argument', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'use_cache'}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '49', 'type': 'argument_list', 'children': ['50', '51']}; {'id': '50', 'type': 'string', 'children': [], 'value': "'use_cache'"}; {'id': '51', 'type': 'False', 'children': []}; {'id': '52', 'type': 'dictionary_splat', 'children': ['53']}; {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': '_filter'}; {'id': '55', 'type': 'argument_list', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'kwarg_list'}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'assignment', 'children': ['60', '63']}; {'id': '60', 'type': 'pattern_list', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'valid'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'mapped'}; {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'sm'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'map_sites'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'correctly_mapped_stmts'}; {'id': '72', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '73', 'type': 'for_statement', 'children': ['74', '75', '76']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'ms'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'mapped'}; {'id': '76', 'type': 'block', 'children': ['77', '94']}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'correctly_mapped'}; {'id': '80', 'type': 'call', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}; {'id': '83', 'type': 'list_comprehension', 'children': ['84', '89']}; {'id': '84', 'type': 'call', 'children': ['85', '88']}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'mm'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'has_mapping'}; {'id': '88', 'type': 'argument_list', 'children': []}; {'id': '89', 'type': 'for_in_clause', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'mm'}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'ms'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'mapped_mods'}; {'id': '94', 'type': 'if_statement', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'correctly_mapped'}; {'id': '96', 'type': 'block', 'children': ['97']}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'correctly_mapped_stmts'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}; {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'ms'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'mapped_stmt'}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}; {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '109', 'type': 'binary_operator', 'children': ['110', '111'], 'value': '+'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'valid'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'correctly_mapped_stmts'}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}; {'id': '113', 'type': 'call', 'children': ['114', '117']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '%'}; {'id': '119', 'type': 'string', 'children': [], 'value': "'%d statements with valid sites'"}; {'id': '120', 'type': 'call', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}; {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'string', 'children': [], 'value': "'save'"}; {'id': '133', 'type': 'if_statement', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}; {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'dump_statements'}; {'id': '139', 'type': 'argument_list', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '142', 'type': 'delete_statement', 'children': ['143']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'sm'}; {'id': '144', 'type': 'return_statement', 'children': ['145']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}
def map_sequence(stmts_in, **kwargs): from indra.preassembler.sitemapper import SiteMapper, default_site_map logger.info('Mapping sites on %d statements...' % len(stmts_in)) kwarg_list = ['do_methionine_offset', 'do_orthology_mapping', 'do_isoform_mapping'] sm = SiteMapper(default_site_map, use_cache=kwargs.pop('use_cache', False), **_filter(kwargs, kwarg_list)) valid, mapped = sm.map_sites(stmts_in) correctly_mapped_stmts = [] for ms in mapped: correctly_mapped = all([mm.has_mapping() for mm in ms.mapped_mods]) if correctly_mapped: correctly_mapped_stmts.append(ms.mapped_stmt) stmts_out = valid + correctly_mapped_stmts logger.info('%d statements with valid sites' % len(stmts_out)) dump_pkl = kwargs.get('save') if dump_pkl: dump_statements(stmts_out, dump_pkl) del sm return stmts_out
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter_by_type'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'stmt_type'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '8', 'type': 'block', 'children': ['9', '19', '39', '74', '86', '95', '104']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'invert'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}; {'id': '17', 'type': 'string', 'children': [], 'value': "'invert'"}; {'id': '18', 'type': 'False', 'children': []}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'call', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'binary_operator', 'children': ['26', '27'], 'value': '%'}; {'id': '26', 'type': 'string', 'children': [], 'value': "'Filtering %d statements for type %s%s...'"}; {'id': '27', 'type': 'tuple', 'children': ['28', '32', '36']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '32', 'type': 'conditional_expression', 'children': ['33', '34', '35'], 'value': 'if'}; {'id': '33', 'type': 'string', 'children': [], 'value': "'not '"}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'invert'}; {'id': '35', 'type': 'string', 'children': [], 'value': "''"}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'stmt_type'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '39', 'type': 'if_statement', 'children': ['40', '42', '57']}; {'id': '40', 'type': 'not_operator', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'invert'}; {'id': '42', 'type': 'block', 'children': ['43']}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '46', 'type': 'list_comprehension', 'children': ['47', '48', '51']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '48', 'type': 'for_in_clause', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '51', 'type': 'if_clause', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'stmt_type'}; {'id': '57', 'type': 'else_clause', 'children': ['58']}; {'id': '58', 'type': 'block', 'children': ['59']}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '62', 'type': 'list_comprehension', 'children': ['63', '64', '67']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '64', 'type': 'for_in_clause', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '67', 'type': 'if_clause', 'children': ['68']}; {'id': '68', 'type': 'not_operator', 'children': ['69']}; {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '71', 'type': 'argument_list', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'stmt_type'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}; {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'binary_operator', 'children': ['81', '82'], 'value': '%'}; {'id': '81', 'type': 'string', 'children': [], 'value': "'%d statements after filter...'"}; {'id': '82', 'type': 'call', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}; {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'string', 'children': [], 'value': "'save'"}; {'id': '95', 'type': 'if_statement', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'dump_statements'}; {'id': '101', 'type': 'argument_list', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '104', 'type': 'return_statement', 'children': ['105']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}
def filter_by_type(stmts_in, stmt_type, **kwargs): invert = kwargs.get('invert', False) logger.info('Filtering %d statements for type %s%s...' % (len(stmts_in), 'not ' if invert else '', stmt_type.__name__)) if not invert: stmts_out = [st for st in stmts_in if isinstance(st, stmt_type)] else: stmts_out = [st for st in stmts_in if not isinstance(st, stmt_type)] logger.info('%d statements after filter...' % len(stmts_out)) dump_pkl = kwargs.get('save') if dump_pkl: dump_statements(stmts_out, dump_pkl) return stmts_out
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter_grounded_only'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '7', 'type': 'block', 'children': ['8', '18', '30', '34', '43', '127', '139', '148', '157']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'remove_bound'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '17']}; {'id': '16', 'type': 'string', 'children': [], 'value': "'remove_bound'"}; {'id': '17', 'type': 'False', 'children': []}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'binary_operator', 'children': ['25', '26'], 'value': '%'}; {'id': '25', 'type': 'string', 'children': [], 'value': "'Filtering %d statements for grounded agents...'"}; {'id': '26', 'type': 'call', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '33', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'score_threshold'}; {'id': '37', 'type': 'call', 'children': ['38', '41']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'string', 'children': [], 'value': "'score_threshold'"}; {'id': '43', 'type': 'for_statement', 'children': ['44', '45', '46']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '46', 'type': 'block', 'children': ['47', '51', '117']}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'grounded'}; {'id': '50', 'type': 'True', 'children': []}; {'id': '51', 'type': 'for_statement', 'children': ['52', '53', '58']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'agent_list'}; {'id': '57', 'type': 'argument_list', 'children': []}; {'id': '58', 'type': 'block', 'children': ['59']}; {'id': '59', 'type': 'if_statement', 'children': ['60', '63']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'is'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '62', 'type': 'None', 'children': []}; {'id': '63', 'type': 'block', 'children': ['64', '75', '87', '96']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'criterion'}; {'id': '67', 'type': 'lambda', 'children': ['68', '70']}; {'id': '68', 'type': 'lambda_parameters', 'children': ['69']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': '_agent_is_grounded'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'score_threshold'}; {'id': '75', 'type': 'if_statement', 'children': ['76', '81']}; {'id': '76', 'type': 'not_operator', 'children': ['77']}; {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'criterion'}; {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '81', 'type': 'block', 'children': ['82', '86']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}; {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'grounded'}; {'id': '85', 'type': 'False', 'children': []}; {'id': '86', 'type': 'break_statement', 'children': []}; {'id': '87', 'type': 'if_statement', 'children': ['88', '94']}; {'id': '88', 'type': 'not_operator', 'children': ['89']}; {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '91', 'type': 'argument_list', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'Agent'}; {'id': '94', 'type': 'block', 'children': ['95']}; {'id': '95', 'type': 'continue_statement', 'children': []}; {'id': '96', 'type': 'if_statement', 'children': ['97', '98', '105']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'remove_bound'}; {'id': '98', 'type': 'block', 'children': ['99']}; {'id': '99', 'type': 'expression_statement', 'children': ['100']}; {'id': '100', 'type': 'call', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': '_remove_bound_conditions'}; {'id': '102', 'type': 'argument_list', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'criterion'}; {'id': '105', 'type': 'elif_clause', 'children': ['106', '111']}; {'id': '106', 'type': 'call', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': '_any_bound_condition_fails_criterion'}; {'id': '108', 'type': 'argument_list', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'criterion'}; {'id': '111', 'type': 'block', 'children': ['112', '116']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}; {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'grounded'}; {'id': '115', 'type': 'False', 'children': []}; {'id': '116', 'type': 'break_statement', 'children': []}; {'id': '117', 'type': 'if_statement', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'grounded'}; {'id': '119', 'type': 'block', 'children': ['120']}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}; {'id': '121', 'type': 'call', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '132']}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}; {'id': '133', 'type': 'binary_operator', 'children': ['134', '135'], 'value': '%'}; {'id': '134', 'type': 'string', 'children': [], 'value': "'%d statements after filter...'"}; {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '142', 'type': 'call', 'children': ['143', '146']}; {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}; {'id': '147', 'type': 'string', 'children': [], 'value': "'save'"}; {'id': '148', 'type': 'if_statement', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '150', 'type': 'block', 'children': ['151']}; {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'dump_statements'}; {'id': '154', 'type': 'argument_list', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '157', 'type': 'return_statement', 'children': ['158']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}
def filter_grounded_only(stmts_in, **kwargs): remove_bound = kwargs.get('remove_bound', False) logger.info('Filtering %d statements for grounded agents...' % len(stmts_in)) stmts_out = [] score_threshold = kwargs.get('score_threshold') for st in stmts_in: grounded = True for agent in st.agent_list(): if agent is not None: criterion = lambda x: _agent_is_grounded(x, score_threshold) if not criterion(agent): grounded = False break if not isinstance(agent, Agent): continue if remove_bound: _remove_bound_conditions(agent, criterion) elif _any_bound_condition_fails_criterion(agent, criterion): grounded = False break if grounded: stmts_out.append(st) logger.info('%d statements after filter...' % len(stmts_out)) dump_pkl = kwargs.get('save') if dump_pkl: dump_statements(stmts_out, dump_pkl) return stmts_out
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter_genes_only'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '7', 'type': 'block', 'children': ['8', '18', '27', '39', '43', '120', '132', '141', '150']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'remove_bound'}; {'id': '11', 'type': 'boolean_operator', 'children': ['12', '15'], 'value': 'and'}; {'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'in'}; {'id': '13', 'type': 'string', 'children': [], 'value': "'remove_bound'"}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '15', 'type': 'subscript', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '17', 'type': 'string', 'children': [], 'value': "'remove_bound'"}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'specific_only'}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'string', 'children': [], 'value': "'specific_only'"}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '%'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'Filtering %d statements for ones containing genes only...'"}; {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '42', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '43', 'type': 'for_statement', 'children': ['44', '45', '46']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '46', 'type': 'block', 'children': ['47', '51', '110']}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'genes_only'}; {'id': '50', 'type': 'True', 'children': []}; {'id': '51', 'type': 'for_statement', 'children': ['52', '53', '58']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'agent_list'}; {'id': '57', 'type': 'argument_list', 'children': []}; {'id': '58', 'type': 'block', 'children': ['59']}; {'id': '59', 'type': 'if_statement', 'children': ['60', '63']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'is'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '62', 'type': 'None', 'children': []}; {'id': '63', 'type': 'block', 'children': ['64', '75', '87']}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'criterion'}; {'id': '67', 'type': 'lambda', 'children': ['68', '70']}; {'id': '68', 'type': 'lambda_parameters', 'children': ['69']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': '_agent_is_gene'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'specific_only'}; {'id': '75', 'type': 'if_statement', 'children': ['76', '81']}; {'id': '76', 'type': 'not_operator', 'children': ['77']}; {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'criterion'}; {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '81', 'type': 'block', 'children': ['82', '86']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}; {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'genes_only'}; {'id': '85', 'type': 'False', 'children': []}; {'id': '86', 'type': 'break_statement', 'children': []}; {'id': '87', 'type': 'if_statement', 'children': ['88', '89', '96']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'remove_bound'}; {'id': '89', 'type': 'block', 'children': ['90']}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}; {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': '_remove_bound_conditions'}; {'id': '93', 'type': 'argument_list', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'criterion'}; {'id': '96', 'type': 'else_clause', 'children': ['97']}; {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'if_statement', 'children': ['99', '104']}; {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': '_any_bound_condition_fails_criterion'}; {'id': '101', 'type': 'argument_list', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'criterion'}; {'id': '104', 'type': 'block', 'children': ['105', '109']}; {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'genes_only'}; {'id': '108', 'type': 'False', 'children': []}; {'id': '109', 'type': 'break_statement', 'children': []}; {'id': '110', 'type': 'if_statement', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'genes_only'}; {'id': '112', 'type': 'block', 'children': ['113']}; {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '118']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}; {'id': '121', 'type': 'call', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'binary_operator', 'children': ['127', '128'], 'value': '%'}; {'id': '127', 'type': 'string', 'children': [], 'value': "'%d statements after filter...'"}; {'id': '128', 'type': 'call', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}; {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'string', 'children': [], 'value': "'save'"}; {'id': '141', 'type': 'if_statement', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '143', 'type': 'block', 'children': ['144']}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}; {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'dump_statements'}; {'id': '147', 'type': 'argument_list', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '150', 'type': 'return_statement', 'children': ['151']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}
def filter_genes_only(stmts_in, **kwargs): remove_bound = 'remove_bound' in kwargs and kwargs['remove_bound'] specific_only = kwargs.get('specific_only') logger.info('Filtering %d statements for ones containing genes only...' % len(stmts_in)) stmts_out = [] for st in stmts_in: genes_only = True for agent in st.agent_list(): if agent is not None: criterion = lambda a: _agent_is_gene(a, specific_only) if not criterion(agent): genes_only = False break if remove_bound: _remove_bound_conditions(agent, criterion) else: if _any_bound_condition_fails_criterion(agent, criterion): genes_only = False break if genes_only: stmts_out.append(st) logger.info('%d statements after filter...' % len(stmts_out)) dump_pkl = kwargs.get('save') if dump_pkl: dump_statements(stmts_out, dump_pkl) return stmts_out
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter_gene_list'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'gene_list'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'policy'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'allow_families'}; {'id': '9', 'type': 'False', 'children': []}; {'id': '10', 'type': 'dictionary_splat_pattern', 'children': ['11']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '12', 'type': 'block', 'children': ['13', '23', '33', '86', '93', '147', '151', '200', '358', '370', '379', '388']}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'invert'}; {'id': '16', 'type': 'call', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '20', 'type': 'argument_list', 'children': ['21', '22']}; {'id': '21', 'type': 'string', 'children': [], 'value': "'invert'"}; {'id': '22', 'type': 'False', 'children': []}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'remove_bound'}; {'id': '26', 'type': 'call', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '30', 'type': 'argument_list', 'children': ['31', '32']}; {'id': '31', 'type': 'string', 'children': [], 'value': "'remove_bound'"}; {'id': '32', 'type': 'False', 'children': []}; {'id': '33', 'type': 'if_statement', 'children': ['34', '39', '49']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'not'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'policy'}; {'id': '36', 'type': 'tuple', 'children': ['37', '38']}; {'id': '37', 'type': 'string', 'children': [], 'value': "'one'"}; {'id': '38', 'type': 'string', 'children': [], 'value': "'all'"}; {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'binary_operator', 'children': ['47', '48'], 'value': '%'}; {'id': '47', 'type': 'string', 'children': [], 'value': "'Policy %s is invalid, not applying filter.'"}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'policy'}; {'id': '49', 'type': 'else_clause', 'children': ['50']}; {'id': '50', 'type': 'block', 'children': ['51', '60', '67']}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'genes_str'}; {'id': '54', 'type': 'call', 'children': ['55', '58']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'gene_list'}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}; {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'inv_str'}; {'id': '63', 'type': 'conditional_expression', 'children': ['64', '65', '66'], 'value': 'if'}; {'id': '64', 'type': 'string', 'children': [], 'value': "'not '"}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'invert'}; {'id': '66', 'type': 'string', 'children': [], 'value': "''"}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'call', 'children': ['69', '72']}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}; {'id': '73', 'type': 'binary_operator', 'children': ['74', '78'], 'value': '%'}; {'id': '74', 'type': '()', 'children': ['75']}; {'id': '75', 'type': 'concatenated_string', 'children': ['76', '77']}; {'id': '76', 'type': 'string', 'children': [], 'value': '\'Filtering %d statements for ones %scontaining "%s" of: \''}; {'id': '77', 'type': 'string', 'children': [], 'value': "'%s...'"}; {'id': '78', 'type': 'tuple', 'children': ['79', '83', '84', '85']}; {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'inv_str'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'policy'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'genes_str'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}; {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'filter_list'}; {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'gene_list'}; {'id': '93', 'type': 'if_statement', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'allow_families'}; {'id': '95', 'type': 'block', 'children': ['96']}; {'id': '96', 'type': 'for_statement', 'children': ['97', '98', '99']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'hgnc_name'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'gene_list'}; {'id': '99', 'type': 'block', 'children': ['100', '112', '123']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}; {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'gene_uri'}; {'id': '103', 'type': 'call', 'children': ['104', '109']}; {'id': '104', 'type': 'attribute', 'children': ['105', '108']}; {'id': '105', 'type': 'subscript', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'hierarchies'}; {'id': '107', 'type': 'string', 'children': [], 'value': "'entity'"}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'get_uri'}; {'id': '109', 'type': 'argument_list', 'children': ['110', '111']}; {'id': '110', 'type': 'string', 'children': [], 'value': "'HGNC'"}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'hgnc_name'}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}; {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'parents'}; {'id': '115', 'type': 'call', 'children': ['116', '121']}; {'id': '116', 'type': 'attribute', 'children': ['117', '120']}; {'id': '117', 'type': 'subscript', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'hierarchies'}; {'id': '119', 'type': 'string', 'children': [], 'value': "'entity'"}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'get_parents'}; {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'gene_uri'}; {'id': '123', 'type': 'for_statement', 'children': ['124', '125', '126']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'par_uri'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'parents'}; {'id': '126', 'type': 'block', 'children': ['127', '140']}; {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '132']}; {'id': '129', 'type': 'pattern_list', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'ns'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '132', 'type': 'call', 'children': ['133', '138']}; {'id': '133', 'type': 'attribute', 'children': ['134', '137']}; {'id': '134', 'type': 'subscript', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'hierarchies'}; {'id': '136', 'type': 'string', 'children': [], 'value': "'entity'"}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'ns_id_from_uri'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'par_uri'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}; {'id': '141', 'type': 'call', 'children': ['142', '145']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'filter_list'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '150', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '151', 'type': 'if_statement', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'remove_bound'}; {'id': '153', 'type': 'block', 'children': ['154', '182']}; {'id': '154', 'type': 'if_statement', 'children': ['155', '157', '169']}; {'id': '155', 'type': 'not_operator', 'children': ['156']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'invert'}; {'id': '157', 'type': 'block', 'children': ['158']}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}; {'id': '159', 'type': 'assignment', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'keep_criterion'}; {'id': '161', 'type': 'lambda', 'children': ['162', '164']}; {'id': '162', 'type': 'lambda_parameters', 'children': ['163']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '164', 'type': 'comparison_operator', 'children': ['165', '168'], 'value': 'in'}; {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'filter_list'}; {'id': '169', 'type': 'else_clause', 'children': ['170']}; {'id': '170', 'type': 'block', 'children': ['171']}; {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'assignment', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'keep_criterion'}; {'id': '174', 'type': 'lambda', 'children': ['175', '177']}; {'id': '175', 'type': 'lambda_parameters', 'children': ['176']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '177', 'type': 'comparison_operator', 'children': ['178', '181'], 'value': 'not'}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'filter_list'}; {'id': '182', 'type': 'for_statement', 'children': ['183', '184', '185']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '185', 'type': 'block', 'children': ['186']}; {'id': '186', 'type': 'for_statement', 'children': ['187', '188', '193']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '188', 'type': 'call', 'children': ['189', '192']}; {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'agent_list'}; {'id': '192', 'type': 'argument_list', 'children': []}; {'id': '193', 'type': 'block', 'children': ['194']}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}; {'id': '195', 'type': 'call', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': '_remove_bound_conditions'}; {'id': '197', 'type': 'argument_list', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'keep_criterion'}; {'id': '200', 'type': 'if_statement', 'children': ['201', '204', '276', '352']}; {'id': '201', 'type': 'comparison_operator', 'children': ['202', '203'], 'value': '=='}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'policy'}; {'id': '203', 'type': 'string', 'children': [], 'value': "'one'"}; {'id': '204', 'type': 'block', 'children': ['205']}; {'id': '205', 'type': 'for_statement', 'children': ['206', '207', '208']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '208', 'type': 'block', 'children': ['209', '213', '235', '256']}; {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'found_gene'}; {'id': '212', 'type': 'False', 'children': []}; {'id': '213', 'type': 'if_statement', 'children': ['214', '216', '225']}; {'id': '214', 'type': 'not_operator', 'children': ['215']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'remove_bound'}; {'id': '216', 'type': 'block', 'children': ['217']}; {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'assignment', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'agent_list'}; {'id': '220', 'type': 'call', 'children': ['221', '224']}; {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'agent_list_with_bound_condition_agents'}; {'id': '224', 'type': 'argument_list', 'children': []}; {'id': '225', 'type': 'else_clause', 'children': ['226']}; {'id': '226', 'type': 'block', 'children': ['227']}; {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '230']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'agent_list'}; {'id': '230', 'type': 'call', 'children': ['231', '234']}; {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'agent_list'}; {'id': '234', 'type': 'argument_list', 'children': []}; {'id': '235', 'type': 'for_statement', 'children': ['236', '237', '238']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'agent_list'}; {'id': '238', 'type': 'block', 'children': ['239']}; {'id': '239', 'type': 'if_statement', 'children': ['240', '243']}; {'id': '240', 'type': 'comparison_operator', 'children': ['241', '242'], 'value': 'is'}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '242', 'type': 'None', 'children': []}; {'id': '243', 'type': 'block', 'children': ['244']}; {'id': '244', 'type': 'if_statement', 'children': ['245', '250']}; {'id': '245', 'type': 'comparison_operator', 'children': ['246', '249'], 'value': 'in'}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'filter_list'}; {'id': '250', 'type': 'block', 'children': ['251', '255']}; {'id': '251', 'type': 'expression_statement', 'children': ['252']}; {'id': '252', 'type': 'assignment', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'found_gene'}; {'id': '254', 'type': 'True', 'children': []}; {'id': '255', 'type': 'break_statement', 'children': []}; {'id': '256', 'type': 'if_statement', 'children': ['257', '268']}; {'id': '257', 'type': 'boolean_operator', 'children': ['258', '263'], 'value': 'or'}; {'id': '258', 'type': '()', 'children': ['259']}; {'id': '259', 'type': 'boolean_operator', 'children': ['260', '261'], 'value': 'and'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'found_gene'}; {'id': '261', 'type': 'not_operator', 'children': ['262']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'invert'}; {'id': '263', 'type': '()', 'children': ['264']}; {'id': '264', 'type': 'boolean_operator', 'children': ['265', '267'], 'value': 'and'}; {'id': '265', 'type': 'not_operator', 'children': ['266']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'found_gene'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'invert'}; {'id': '268', 'type': 'block', 'children': ['269']}; {'id': '269', 'type': 'expression_statement', 'children': ['270']}; {'id': '270', 'type': 'call', 'children': ['271', '274']}; {'id': '271', 'type': 'attribute', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '274', 'type': 'argument_list', 'children': ['275']}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '276', 'type': 'elif_clause', 'children': ['277', '280']}; {'id': '277', 'type': 'comparison_operator', 'children': ['278', '279'], 'value': '=='}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'policy'}; {'id': '279', 'type': 'string', 'children': [], 'value': "'all'"}; {'id': '280', 'type': 'block', 'children': ['281']}; {'id': '281', 'type': 'for_statement', 'children': ['282', '283', '284']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '284', 'type': 'block', 'children': ['285', '289', '311', '332']}; {'id': '285', 'type': 'expression_statement', 'children': ['286']}; {'id': '286', 'type': 'assignment', 'children': ['287', '288']}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'found_genes'}; {'id': '288', 'type': 'True', 'children': []}; {'id': '289', 'type': 'if_statement', 'children': ['290', '292', '301']}; {'id': '290', 'type': 'not_operator', 'children': ['291']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'remove_bound'}; {'id': '292', 'type': 'block', 'children': ['293']}; {'id': '293', 'type': 'expression_statement', 'children': ['294']}; {'id': '294', 'type': 'assignment', 'children': ['295', '296']}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'agent_list'}; {'id': '296', 'type': 'call', 'children': ['297', '300']}; {'id': '297', 'type': 'attribute', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'agent_list_with_bound_condition_agents'}; {'id': '300', 'type': 'argument_list', 'children': []}; {'id': '301', 'type': 'else_clause', 'children': ['302']}; {'id': '302', 'type': 'block', 'children': ['303']}; {'id': '303', 'type': 'expression_statement', 'children': ['304']}; {'id': '304', 'type': 'assignment', 'children': ['305', '306']}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'agent_list'}; {'id': '306', 'type': 'call', 'children': ['307', '310']}; {'id': '307', 'type': 'attribute', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'agent_list'}; {'id': '310', 'type': 'argument_list', 'children': []}; {'id': '311', 'type': 'for_statement', 'children': ['312', '313', '314']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'agent_list'}; {'id': '314', 'type': 'block', 'children': ['315']}; {'id': '315', 'type': 'if_statement', 'children': ['316', '319']}; {'id': '316', 'type': 'comparison_operator', 'children': ['317', '318'], 'value': 'is'}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '318', 'type': 'None', 'children': []}; {'id': '319', 'type': 'block', 'children': ['320']}; {'id': '320', 'type': 'if_statement', 'children': ['321', '326']}; {'id': '321', 'type': 'comparison_operator', 'children': ['322', '325'], 'value': 'not'}; {'id': '322', 'type': 'attribute', 'children': ['323', '324']}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'filter_list'}; {'id': '326', 'type': 'block', 'children': ['327', '331']}; {'id': '327', 'type': 'expression_statement', 'children': ['328']}; {'id': '328', 'type': 'assignment', 'children': ['329', '330']}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'found_genes'}; {'id': '330', 'type': 'False', 'children': []}; {'id': '331', 'type': 'break_statement', 'children': []}; {'id': '332', 'type': 'if_statement', 'children': ['333', '344']}; {'id': '333', 'type': 'boolean_operator', 'children': ['334', '339'], 'value': 'or'}; {'id': '334', 'type': '()', 'children': ['335']}; {'id': '335', 'type': 'boolean_operator', 'children': ['336', '337'], 'value': 'and'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'found_genes'}; {'id': '337', 'type': 'not_operator', 'children': ['338']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'invert'}; {'id': '339', 'type': '()', 'children': ['340']}; {'id': '340', 'type': 'boolean_operator', 'children': ['341', '343'], 'value': 'and'}; {'id': '341', 'type': 'not_operator', 'children': ['342']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'found_genes'}; {'id': '343', 'type': 'identifier', 'children': [], 'value': 'invert'}; {'id': '344', 'type': 'block', 'children': ['345']}; {'id': '345', 'type': 'expression_statement', 'children': ['346']}; {'id': '346', 'type': 'call', 'children': ['347', '350']}; {'id': '347', 'type': 'attribute', 'children': ['348', '349']}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '349', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '350', 'type': 'argument_list', 'children': ['351']}; {'id': '351', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '352', 'type': 'else_clause', 'children': ['353']}; {'id': '353', 'type': 'block', 'children': ['354']}; {'id': '354', 'type': 'expression_statement', 'children': ['355']}; {'id': '355', 'type': 'assignment', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '357', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '358', 'type': 'expression_statement', 'children': ['359']}; {'id': '359', 'type': 'call', 'children': ['360', '363']}; {'id': '360', 'type': 'attribute', 'children': ['361', '362']}; {'id': '361', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '363', 'type': 'argument_list', 'children': ['364']}; {'id': '364', 'type': 'binary_operator', 'children': ['365', '366'], 'value': '%'}; {'id': '365', 'type': 'string', 'children': [], 'value': "'%d statements after filter...'"}; {'id': '366', 'type': 'call', 'children': ['367', '368']}; {'id': '367', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '368', 'type': 'argument_list', 'children': ['369']}; {'id': '369', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '370', 'type': 'expression_statement', 'children': ['371']}; {'id': '371', 'type': 'assignment', 'children': ['372', '373']}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '373', 'type': 'call', 'children': ['374', '377']}; {'id': '374', 'type': 'attribute', 'children': ['375', '376']}; {'id': '375', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '377', 'type': 'argument_list', 'children': ['378']}; {'id': '378', 'type': 'string', 'children': [], 'value': "'save'"}; {'id': '379', 'type': 'if_statement', 'children': ['380', '381']}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '381', 'type': 'block', 'children': ['382']}; {'id': '382', 'type': 'expression_statement', 'children': ['383']}; {'id': '383', 'type': 'call', 'children': ['384', '385']}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'dump_statements'}; {'id': '385', 'type': 'argument_list', 'children': ['386', '387']}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '387', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '388', 'type': 'return_statement', 'children': ['389']}; {'id': '389', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}
def filter_gene_list(stmts_in, gene_list, policy, allow_families=False, **kwargs): invert = kwargs.get('invert', False) remove_bound = kwargs.get('remove_bound', False) if policy not in ('one', 'all'): logger.error('Policy %s is invalid, not applying filter.' % policy) else: genes_str = ', '.join(gene_list) inv_str = 'not ' if invert else '' logger.info(('Filtering %d statements for ones %scontaining "%s" of: ' '%s...') % (len(stmts_in), inv_str, policy, genes_str)) filter_list = copy(gene_list) if allow_families: for hgnc_name in gene_list: gene_uri = hierarchies['entity'].get_uri('HGNC', hgnc_name) parents = hierarchies['entity'].get_parents(gene_uri) for par_uri in parents: ns, id = hierarchies['entity'].ns_id_from_uri(par_uri) filter_list.append(id) stmts_out = [] if remove_bound: if not invert: keep_criterion = lambda a: a.name in filter_list else: keep_criterion = lambda a: a.name not in filter_list for st in stmts_in: for agent in st.agent_list(): _remove_bound_conditions(agent, keep_criterion) if policy == 'one': for st in stmts_in: found_gene = False if not remove_bound: agent_list = st.agent_list_with_bound_condition_agents() else: agent_list = st.agent_list() for agent in agent_list: if agent is not None: if agent.name in filter_list: found_gene = True break if (found_gene and not invert) or (not found_gene and invert): stmts_out.append(st) elif policy == 'all': for st in stmts_in: found_genes = True if not remove_bound: agent_list = st.agent_list_with_bound_condition_agents() else: agent_list = st.agent_list() for agent in agent_list: if agent is not None: if agent.name not in filter_list: found_genes = False break if (found_genes and not invert) or (not found_genes and invert): stmts_out.append(st) else: stmts_out = stmts_in logger.info('%d statements after filter...' % len(stmts_out)) dump_pkl = kwargs.get('save') if dump_pkl: dump_statements(stmts_out, dump_pkl) return stmts_out
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter_by_db_refs'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'namespace'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'policy'}; {'id': '8', 'type': 'dictionary_splat_pattern', 'children': ['9']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '10', 'type': 'block', 'children': ['11', '21', '31', '86', '170', '179', '207', '219', '228', '237']}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'invert'}; {'id': '14', 'type': 'call', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '18', 'type': 'argument_list', 'children': ['19', '20']}; {'id': '19', 'type': 'string', 'children': [], 'value': "'invert'"}; {'id': '20', 'type': 'False', 'children': []}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'match_suffix'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30']}; {'id': '29', 'type': 'string', 'children': [], 'value': "'match_suffix'"}; {'id': '30', 'type': 'False', 'children': []}; {'id': '31', 'type': 'if_statement', 'children': ['32', '37', '48']}; {'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'not'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'policy'}; {'id': '34', 'type': 'tuple', 'children': ['35', '36']}; {'id': '35', 'type': 'string', 'children': [], 'value': "'one'"}; {'id': '36', 'type': 'string', 'children': [], 'value': "'all'"}; {'id': '37', 'type': 'block', 'children': ['38', '47']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'binary_operator', 'children': ['45', '46'], 'value': '%'}; {'id': '45', 'type': 'string', 'children': [], 'value': "'Policy %s is invalid, not applying filter.'"}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'policy'}; {'id': '47', 'type': 'return_statement', 'children': []}; {'id': '48', 'type': 'else_clause', 'children': ['49']}; {'id': '49', 'type': 'block', 'children': ['50', '59', '66']}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'name_str'}; {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'rev_mod'}; {'id': '62', 'type': 'conditional_expression', 'children': ['63', '64', '65'], 'value': 'if'}; {'id': '63', 'type': 'string', 'children': [], 'value': "'not '"}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'invert'}; {'id': '65', 'type': 'string', 'children': [], 'value': "''"}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'binary_operator', 'children': ['73', '77'], 'value': '%'}; {'id': '73', 'type': '()', 'children': ['74']}; {'id': '74', 'type': 'concatenated_string', 'children': ['75', '76']}; {'id': '75', 'type': 'string', 'children': [], 'value': "'Filtering %d statements for those with %s agents %s'"}; {'id': '76', 'type': 'string', 'children': [], 'value': "'grounded to: %s in the %s namespace...'"}; {'id': '77', 'type': 'tuple', 'children': ['78', '82', '83', '84', '85']}; {'id': '78', 'type': 'call', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'policy'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'rev_mod'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'name_str'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'namespace'}; {'id': '86', 'type': 'function_definition', 'children': ['87', '88', '90']}; {'id': '87', 'type': 'function_name', 'children': [], 'value': 'meets_criterion'}; {'id': '88', 'type': 'parameters', 'children': ['89']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '90', 'type': 'block', 'children': ['91', '100', '108', '123', '127', '160']}; {'id': '91', 'type': 'if_statement', 'children': ['92', '97']}; {'id': '92', 'type': 'comparison_operator', 'children': ['93', '94'], 'value': 'not'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'namespace'}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'return_statement', 'children': ['99']}; {'id': '99', 'type': 'False', 'children': []}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}; {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '103', 'type': 'subscript', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'namespace'}; {'id': '108', 'type': 'if_statement', 'children': ['109', '114']}; {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '111', 'type': 'argument_list', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '114', 'type': 'block', 'children': ['115']}; {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '118', 'type': 'subscript', 'children': ['119', '122']}; {'id': '119', 'type': 'subscript', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '121', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '122', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '126', 'type': 'False', 'children': []}; {'id': '127', 'type': 'if_statement', 'children': ['128', '129', '149']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'match_suffix'}; {'id': '129', 'type': 'block', 'children': ['130']}; {'id': '130', 'type': 'if_statement', 'children': ['131', '144']}; {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'list_comprehension', 'children': ['135', '141']}; {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'endswith'}; {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '141', 'type': 'for_in_clause', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '144', 'type': 'block', 'children': ['145']}; {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '148', 'type': 'True', 'children': []}; {'id': '149', 'type': 'else_clause', 'children': ['150']}; {'id': '150', 'type': 'block', 'children': ['151']}; {'id': '151', 'type': 'if_statement', 'children': ['152', '155']}; {'id': '152', 'type': 'comparison_operator', 'children': ['153', '154'], 'value': 'in'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'entry'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}; {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '159', 'type': 'True', 'children': []}; {'id': '160', 'type': 'if_statement', 'children': ['161', '162', '166']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'invert'}; {'id': '162', 'type': 'block', 'children': ['163']}; {'id': '163', 'type': 'return_statement', 'children': ['164']}; {'id': '164', 'type': 'not_operator', 'children': ['165']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '166', 'type': 'else_clause', 'children': ['167']}; {'id': '167', 'type': 'block', 'children': ['168']}; {'id': '168', 'type': 'return_statement', 'children': ['169']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}; {'id': '171', 'type': 'assignment', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'enough'}; {'id': '173', 'type': 'conditional_expression', 'children': ['174', '175', '178'], 'value': 'if'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '175', 'type': 'comparison_operator', 'children': ['176', '177'], 'value': '=='}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'policy'}; {'id': '177', 'type': 'string', 'children': [], 'value': "'all'"}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '182', 'type': 'list_comprehension', 'children': ['183', '184', '187']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '184', 'type': 'for_in_clause', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '187', 'type': 'if_clause', 'children': ['188']}; {'id': '188', 'type': 'call', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'enough'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}; {'id': '191', 'type': 'list_comprehension', 'children': ['192', '196', '203']}; {'id': '192', 'type': 'call', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'meets_criterion'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'ag'}; {'id': '196', 'type': 'for_in_clause', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'ag'}; {'id': '198', 'type': 'call', 'children': ['199', '202']}; {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'agent_list'}; {'id': '202', 'type': 'argument_list', 'children': []}; {'id': '203', 'type': 'if_clause', 'children': ['204']}; {'id': '204', 'type': 'comparison_operator', 'children': ['205', '206'], 'value': 'is'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'ag'}; {'id': '206', 'type': 'None', 'children': []}; {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'call', 'children': ['209', '212']}; {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '212', 'type': 'argument_list', 'children': ['213']}; {'id': '213', 'type': 'binary_operator', 'children': ['214', '215'], 'value': '%'}; {'id': '214', 'type': 'string', 'children': [], 'value': "'%d Statements after filter...'"}; {'id': '215', 'type': 'call', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '217', 'type': 'argument_list', 'children': ['218']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '219', 'type': 'expression_statement', 'children': ['220']}; {'id': '220', 'type': 'assignment', 'children': ['221', '222']}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '222', 'type': 'call', 'children': ['223', '226']}; {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '226', 'type': 'argument_list', 'children': ['227']}; {'id': '227', 'type': 'string', 'children': [], 'value': "'save'"}; {'id': '228', 'type': 'if_statement', 'children': ['229', '230']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '230', 'type': 'block', 'children': ['231']}; {'id': '231', 'type': 'expression_statement', 'children': ['232']}; {'id': '232', 'type': 'call', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'dump_statements'}; {'id': '234', 'type': 'argument_list', 'children': ['235', '236']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '237', 'type': 'return_statement', 'children': ['238']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}
def filter_by_db_refs(stmts_in, namespace, values, policy, **kwargs): invert = kwargs.get('invert', False) match_suffix = kwargs.get('match_suffix', False) if policy not in ('one', 'all'): logger.error('Policy %s is invalid, not applying filter.' % policy) return else: name_str = ', '.join(values) rev_mod = 'not ' if invert else '' logger.info(('Filtering %d statements for those with %s agents %s' 'grounded to: %s in the %s namespace...') % (len(stmts_in), policy, rev_mod, name_str, namespace)) def meets_criterion(agent): if namespace not in agent.db_refs: return False entry = agent.db_refs[namespace] if isinstance(entry, list): entry = entry[0][0] ret = False if match_suffix: if any([entry.endswith(e) for e in values]): ret = True else: if entry in values: ret = True if invert: return not ret else: return ret enough = all if policy == 'all' else any stmts_out = [s for s in stmts_in if enough([meets_criterion(ag) for ag in s.agent_list() if ag is not None])] logger.info('%d Statements after filter...' % len(stmts_out)) dump_pkl = kwargs.get('save') if dump_pkl: dump_statements(stmts_out, dump_pkl) return stmts_out
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter_human_only'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '7', 'type': 'block', 'children': ['8', '14', '33', '42', '54', '58', '91', '155', '167', '176']}; {'id': '8', 'type': 'import_from_statement', 'children': ['9', '12']}; {'id': '9', 'type': 'dotted_name', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'indra'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'databases'}; {'id': '12', 'type': 'dotted_name', 'children': ['13']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'uniprot_client'}; {'id': '14', 'type': 'if_statement', 'children': ['15', '22', '27']}; {'id': '15', 'type': 'boolean_operator', 'children': ['16', '19'], 'value': 'and'}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'in'}; {'id': '17', 'type': 'string', 'children': [], 'value': "'remove_bound'"}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '19', 'type': 'subscript', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '21', 'type': 'string', 'children': [], 'value': "'remove_bound'"}; {'id': '22', 'type': 'block', 'children': ['23']}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'remove_bound'}; {'id': '26', 'type': 'True', 'children': []}; {'id': '27', 'type': 'else_clause', 'children': ['28']}; {'id': '28', 'type': 'block', 'children': ['29']}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'remove_bound'}; {'id': '32', 'type': 'False', 'children': []}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'string', 'children': [], 'value': "'save'"}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'binary_operator', 'children': ['49', '50'], 'value': '%'}; {'id': '49', 'type': 'string', 'children': [], 'value': "'Filtering %d statements for human genes only...'"}; {'id': '50', 'type': 'call', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '52', 'type': 'argument_list', 'children': ['53']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}; {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '57', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '58', 'type': 'function_definition', 'children': ['59', '60', '62']}; {'id': '59', 'type': 'function_name', 'children': [], 'value': 'criterion'}; {'id': '60', 'type': 'parameters', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '62', 'type': 'block', 'children': ['63', '74']}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'upid'}; {'id': '66', 'type': 'call', 'children': ['67', '72']}; {'id': '67', 'type': 'attribute', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}; {'id': '73', 'type': 'string', 'children': [], 'value': "'UP'"}; {'id': '74', 'type': 'if_statement', 'children': ['75', '84', '87']}; {'id': '75', 'type': 'boolean_operator', 'children': ['76', '77'], 'value': 'and'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'upid'}; {'id': '77', 'type': 'not_operator', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'uniprot_client'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'is_human'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'upid'}; {'id': '84', 'type': 'block', 'children': ['85']}; {'id': '85', 'type': 'return_statement', 'children': ['86']}; {'id': '86', 'type': 'False', 'children': []}; {'id': '87', 'type': 'else_clause', 'children': ['88']}; {'id': '88', 'type': 'block', 'children': ['89']}; {'id': '89', 'type': 'return_statement', 'children': ['90']}; {'id': '90', 'type': 'True', 'children': []}; {'id': '91', 'type': 'for_statement', 'children': ['92', '93', '94']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '94', 'type': 'block', 'children': ['95', '99', '145']}; {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'human_genes'}; {'id': '98', 'type': 'True', 'children': []}; {'id': '99', 'type': 'for_statement', 'children': ['100', '101', '106']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'agent_list'}; {'id': '105', 'type': 'argument_list', 'children': []}; {'id': '106', 'type': 'block', 'children': ['107']}; {'id': '107', 'type': 'if_statement', 'children': ['108', '111']}; {'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': 'is'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '110', 'type': 'None', 'children': []}; {'id': '111', 'type': 'block', 'children': ['112', '124']}; {'id': '112', 'type': 'if_statement', 'children': ['113', '118']}; {'id': '113', 'type': 'not_operator', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'criterion'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '118', 'type': 'block', 'children': ['119', '123']}; {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'human_genes'}; {'id': '122', 'type': 'False', 'children': []}; {'id': '123', 'type': 'break_statement', 'children': []}; {'id': '124', 'type': 'if_statement', 'children': ['125', '126', '133']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'remove_bound'}; {'id': '126', 'type': 'block', 'children': ['127']}; {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': '_remove_bound_conditions'}; {'id': '130', 'type': 'argument_list', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'criterion'}; {'id': '133', 'type': 'elif_clause', 'children': ['134', '139']}; {'id': '134', 'type': 'call', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': '_any_bound_condition_fails_criterion'}; {'id': '136', 'type': 'argument_list', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'criterion'}; {'id': '139', 'type': 'block', 'children': ['140', '144']}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}; {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'human_genes'}; {'id': '143', 'type': 'False', 'children': []}; {'id': '144', 'type': 'break_statement', 'children': []}; {'id': '145', 'type': 'if_statement', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'human_genes'}; {'id': '147', 'type': 'block', 'children': ['148']}; {'id': '148', 'type': 'expression_statement', 'children': ['149']}; {'id': '149', 'type': 'call', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'call', 'children': ['157', '160']}; {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '160', 'type': 'argument_list', 'children': ['161']}; {'id': '161', 'type': 'binary_operator', 'children': ['162', '163'], 'value': '%'}; {'id': '162', 'type': 'string', 'children': [], 'value': "'%d statements after filter...'"}; {'id': '163', 'type': 'call', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '167', 'type': 'if_statement', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '169', 'type': 'block', 'children': ['170']}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}; {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'dump_statements'}; {'id': '173', 'type': 'argument_list', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '176', 'type': 'return_statement', 'children': ['177']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}
def filter_human_only(stmts_in, **kwargs): from indra.databases import uniprot_client if 'remove_bound' in kwargs and kwargs['remove_bound']: remove_bound = True else: remove_bound = False dump_pkl = kwargs.get('save') logger.info('Filtering %d statements for human genes only...' % len(stmts_in)) stmts_out = [] def criterion(agent): upid = agent.db_refs.get('UP') if upid and not uniprot_client.is_human(upid): return False else: return True for st in stmts_in: human_genes = True for agent in st.agent_list(): if agent is not None: if not criterion(agent): human_genes = False break if remove_bound: _remove_bound_conditions(agent, criterion) elif _any_bound_condition_fails_criterion(agent, criterion): human_genes = False break if human_genes: stmts_out.append(st) logger.info('%d statements after filter...' % len(stmts_out)) if dump_pkl: dump_statements(stmts_out, dump_pkl) return stmts_out
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter_direct'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '7', 'type': 'block', 'children': ['8', '60', '72', '76', '93', '105', '114', '123']}; {'id': '8', 'type': 'function_definition', 'children': ['9', '10', '12']}; {'id': '9', 'type': 'function_name', 'children': [], 'value': 'get_is_direct'}; {'id': '10', 'type': 'parameters', 'children': ['11']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '12', 'type': 'block', 'children': ['13', '17', '53', '58']}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'any_indirect'}; {'id': '16', 'type': 'False', 'children': []}; {'id': '17', 'type': 'for_statement', 'children': ['18', '19', '22']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'evidence'}; {'id': '22', 'type': 'block', 'children': ['23']}; {'id': '23', 'type': 'if_statement', 'children': ['24', '34', '37']}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '33'], 'value': 'is'}; {'id': '25', 'type': 'call', 'children': ['26', '31']}; {'id': '26', 'type': 'attribute', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'epistemics'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'string', 'children': [], 'value': "'direct'"}; {'id': '33', 'type': 'True', 'children': []}; {'id': '34', 'type': 'block', 'children': ['35']}; {'id': '35', 'type': 'return_statement', 'children': ['36']}; {'id': '36', 'type': 'True', 'children': []}; {'id': '37', 'type': 'elif_clause', 'children': ['38', '48']}; {'id': '38', 'type': 'comparison_operator', 'children': ['39', '47'], 'value': 'is'}; {'id': '39', 'type': 'call', 'children': ['40', '45']}; {'id': '40', 'type': 'attribute', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'epistemics'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'string', 'children': [], 'value': "'direct'"}; {'id': '47', 'type': 'False', 'children': []}; {'id': '48', 'type': 'block', 'children': ['49']}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'any_indirect'}; {'id': '52', 'type': 'True', 'children': []}; {'id': '53', 'type': 'if_statement', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'any_indirect'}; {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'return_statement', 'children': ['57']}; {'id': '57', 'type': 'False', 'children': []}; {'id': '58', 'type': 'return_statement', 'children': ['59']}; {'id': '59', 'type': 'True', 'children': []}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}; {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'binary_operator', 'children': ['67', '68'], 'value': '%'}; {'id': '67', 'type': 'string', 'children': [], 'value': "'Filtering %d statements to direct ones...'"}; {'id': '68', 'type': 'call', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '75', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '76', 'type': 'for_statement', 'children': ['77', '78', '79']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'if_statement', 'children': ['81', '85']}; {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'get_is_direct'}; {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}; {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'call', 'children': ['95', '98']}; {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}; {'id': '99', 'type': 'binary_operator', 'children': ['100', '101'], 'value': '%'}; {'id': '100', 'type': 'string', 'children': [], 'value': "'%d statements after filter...'"}; {'id': '101', 'type': 'call', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '103', 'type': 'argument_list', 'children': ['104']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '108', 'type': 'call', 'children': ['109', '112']}; {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}; {'id': '113', 'type': 'string', 'children': [], 'value': "'save'"}; {'id': '114', 'type': 'if_statement', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '116', 'type': 'block', 'children': ['117']}; {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'call', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'dump_statements'}; {'id': '120', 'type': 'argument_list', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '123', 'type': 'return_statement', 'children': ['124']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}
def filter_direct(stmts_in, **kwargs): def get_is_direct(stmt): any_indirect = False for ev in stmt.evidence: if ev.epistemics.get('direct') is True: return True elif ev.epistemics.get('direct') is False: any_indirect = True if any_indirect: return False return True logger.info('Filtering %d statements to direct ones...' % len(stmts_in)) stmts_out = [] for st in stmts_in: if get_is_direct(st): stmts_out.append(st) logger.info('%d statements after filter...' % len(stmts_out)) dump_pkl = kwargs.get('save') if dump_pkl: dump_statements(stmts_out, dump_pkl) return stmts_out
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter_evidence_source'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'source_apis'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'policy'}; {'id': '8', 'type': 'string', 'children': [], 'value': "'one'"}; {'id': '9', 'type': 'dictionary_splat_pattern', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '11', 'type': 'block', 'children': ['12', '32', '36', '121', '133', '142', '151']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'binary_operator', 'children': ['19', '20'], 'value': '%'}; {'id': '19', 'type': 'string', 'children': [], 'value': '\'Filtering %d statements to evidence source "%s" of: %s...\''}; {'id': '20', 'type': 'tuple', 'children': ['21', '25', '26']}; {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'policy'}; {'id': '26', 'type': 'call', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'string', 'children': [], 'value': "', '"}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'source_apis'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '35', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '36', 'type': 'for_statement', 'children': ['37', '38', '39']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '39', 'type': 'block', 'children': ['40', '55', '75', '100']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'sources'}; {'id': '43', 'type': 'call', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'list_comprehension', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'source_api'}; {'id': '50', 'type': 'for_in_clause', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'evidence'}; {'id': '55', 'type': 'if_statement', 'children': ['56', '59']}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': '=='}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'policy'}; {'id': '58', 'type': 'string', 'children': [], 'value': "'one'"}; {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'if_statement', 'children': ['61', '67']}; {'id': '61', 'type': 'call', 'children': ['62', '65']}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'sources'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'intersection'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'source_apis'}; {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '75', 'type': 'if_statement', 'children': ['76', '79']}; {'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': '=='}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'policy'}; {'id': '78', 'type': 'string', 'children': [], 'value': "'all'"}; {'id': '79', 'type': 'block', 'children': ['80']}; {'id': '80', 'type': 'if_statement', 'children': ['81', '92']}; {'id': '81', 'type': 'comparison_operator', 'children': ['82', '88'], 'value': '=='}; {'id': '82', 'type': 'call', 'children': ['83', '86']}; {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'sources'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'intersection'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'source_apis'}; {'id': '88', 'type': 'call', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'source_apis'}; {'id': '92', 'type': 'block', 'children': ['93']}; {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'call', 'children': ['95', '98']}; {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '100', 'type': 'if_statement', 'children': ['101', '104']}; {'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': '=='}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'policy'}; {'id': '103', 'type': 'string', 'children': [], 'value': "'none'"}; {'id': '104', 'type': 'block', 'children': ['105']}; {'id': '105', 'type': 'if_statement', 'children': ['106', '113']}; {'id': '106', 'type': 'not_operator', 'children': ['107']}; {'id': '107', 'type': 'call', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'sources'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'intersection'}; {'id': '111', 'type': 'argument_list', 'children': ['112']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'source_apis'}; {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}; {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '126']}; {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}; {'id': '127', 'type': 'binary_operator', 'children': ['128', '129'], 'value': '%'}; {'id': '128', 'type': 'string', 'children': [], 'value': "'%d statements after filter...'"}; {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '136', 'type': 'call', 'children': ['137', '140']}; {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}; {'id': '141', 'type': 'string', 'children': [], 'value': "'save'"}; {'id': '142', 'type': 'if_statement', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '144', 'type': 'block', 'children': ['145']}; {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'call', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'dump_statements'}; {'id': '148', 'type': 'argument_list', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '151', 'type': 'return_statement', 'children': ['152']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}
def filter_evidence_source(stmts_in, source_apis, policy='one', **kwargs): logger.info('Filtering %d statements to evidence source "%s" of: %s...' % (len(stmts_in), policy, ', '.join(source_apis))) stmts_out = [] for st in stmts_in: sources = set([ev.source_api for ev in st.evidence]) if policy == 'one': if sources.intersection(source_apis): stmts_out.append(st) if policy == 'all': if sources.intersection(source_apis) == set(source_apis): stmts_out.append(st) if policy == 'none': if not sources.intersection(source_apis): stmts_out.append(st) logger.info('%d statements after filter...' % len(stmts_out)) dump_pkl = kwargs.get('save') if dump_pkl: dump_statements(stmts_out, dump_pkl) return stmts_out
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter_inconsequential_mods'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'whitelist'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'dictionary_splat_pattern', 'children': ['9']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '10', 'type': 'block', 'children': ['11', '20', '34', '38', '104', '126', '130', '211', '223', '232', '241']}; {'id': '11', 'type': 'if_statement', 'children': ['12', '15']}; {'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'is'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'whitelist'}; {'id': '14', 'type': 'None', 'children': []}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'whitelist'}; {'id': '19', 'type': 'dictionary', 'children': []}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'binary_operator', 'children': ['27', '33'], 'value': '+'}; {'id': '27', 'type': 'binary_operator', 'children': ['28', '29'], 'value': '%'}; {'id': '28', 'type': 'string', 'children': [], 'value': "'Filtering %d statements to remove'"}; {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '33', 'type': 'string', 'children': [], 'value': "' inconsequential modifications...'"}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'states_used'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'whitelist'}; {'id': '38', 'type': 'for_statement', 'children': ['39', '40', '41']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'for_statement', 'children': ['43', '44', '49']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '44', 'type': 'call', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'agent_list'}; {'id': '48', 'type': 'argument_list', 'children': []}; {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'if_statement', 'children': ['51', '54']}; {'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'is'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '53', 'type': 'None', 'children': []}; {'id': '54', 'type': 'block', 'children': ['55']}; {'id': '55', 'type': 'if_statement', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'mods'}; {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'for_statement', 'children': ['61', '62', '65']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'mc'}; {'id': '62', 'type': 'attribute', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'mods'}; {'id': '65', 'type': 'block', 'children': ['66', '79']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'mod'}; {'id': '69', 'type': 'tuple', 'children': ['70', '73', '76']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'mc'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'mod_type'}; {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'mc'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'residue'}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'mc'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'position'}; {'id': '79', 'type': 'try_statement', 'children': ['80', '92']}; {'id': '80', 'type': 'block', 'children': ['81']}; {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '90']}; {'id': '83', 'type': 'attribute', 'children': ['84', '89']}; {'id': '84', 'type': 'subscript', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'states_used'}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '90', 'type': 'argument_list', 'children': ['91']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'mod'}; {'id': '92', 'type': 'except_clause', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '94', 'type': 'block', 'children': ['95']}; {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'assignment', 'children': ['97', '102']}; {'id': '97', 'type': 'subscript', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'states_used'}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '102', 'type': 'list', 'children': ['103'], 'value': '[mod]'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'mod'}; {'id': '104', 'type': 'for_statement', 'children': ['105', '108', '113']}; {'id': '105', 'type': 'pattern_list', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '108', 'type': 'call', 'children': ['109', '112']}; {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'states_used'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '112', 'type': 'argument_list', 'children': []}; {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}; {'id': '115', 'type': 'assignment', 'children': ['116', '119']}; {'id': '116', 'type': 'subscript', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'states_used'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}; {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '129', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '130', 'type': 'for_statement', 'children': ['131', '132', '133']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '133', 'type': 'block', 'children': ['134', '138', '200']}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}; {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'skip'}; {'id': '137', 'type': 'False', 'children': []}; {'id': '138', 'type': 'if_statement', 'children': ['139', '144']}; {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '141', 'type': 'argument_list', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'Modification'}; {'id': '144', 'type': 'block', 'children': ['145', '153', '166', '177', '191']}; {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'mod_type'}; {'id': '148', 'type': 'subscript', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'modclass_to_modtype'}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '153', 'type': 'if_statement', 'children': ['154', '159']}; {'id': '154', 'type': 'call', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '156', 'type': 'argument_list', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'RemoveModification'}; {'id': '159', 'type': 'block', 'children': ['160']}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}; {'id': '161', 'type': 'assignment', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'mod_type'}; {'id': '163', 'type': 'subscript', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'modtype_to_inverse'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'mod_type'}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}; {'id': '167', 'type': 'assignment', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'mod'}; {'id': '169', 'type': 'tuple', 'children': ['170', '171', '174']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'mod_type'}; {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'residue'}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'position'}; {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'assignment', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'used'}; {'id': '180', 'type': 'call', 'children': ['181', '184']}; {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'states_used'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '184', 'type': 'argument_list', 'children': ['185', '190']}; {'id': '185', 'type': 'attribute', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '190', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '191', 'type': 'if_statement', 'children': ['192', '195']}; {'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': 'not'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'mod'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'used'}; {'id': '195', 'type': 'block', 'children': ['196']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}; {'id': '197', 'type': 'assignment', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'skip'}; {'id': '199', 'type': 'True', 'children': []}; {'id': '200', 'type': 'if_statement', 'children': ['201', '203']}; {'id': '201', 'type': 'not_operator', 'children': ['202']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'skip'}; {'id': '203', 'type': 'block', 'children': ['204']}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}; {'id': '205', 'type': 'call', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '209', 'type': 'argument_list', 'children': ['210']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'call', 'children': ['213', '216']}; {'id': '213', 'type': 'attribute', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '216', 'type': 'argument_list', 'children': ['217']}; {'id': '217', 'type': 'binary_operator', 'children': ['218', '219'], 'value': '%'}; {'id': '218', 'type': 'string', 'children': [], 'value': "'%d statements after filter...'"}; {'id': '219', 'type': 'call', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'assignment', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '226', 'type': 'call', 'children': ['227', '230']}; {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '230', 'type': 'argument_list', 'children': ['231']}; {'id': '231', 'type': 'string', 'children': [], 'value': "'save'"}; {'id': '232', 'type': 'if_statement', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '234', 'type': 'block', 'children': ['235']}; {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'call', 'children': ['237', '238']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'dump_statements'}; {'id': '238', 'type': 'argument_list', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '241', 'type': 'return_statement', 'children': ['242']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}
def filter_inconsequential_mods(stmts_in, whitelist=None, **kwargs): if whitelist is None: whitelist = {} logger.info('Filtering %d statements to remove' % len(stmts_in) + ' inconsequential modifications...') states_used = whitelist for stmt in stmts_in: for agent in stmt.agent_list(): if agent is not None: if agent.mods: for mc in agent.mods: mod = (mc.mod_type, mc.residue, mc.position) try: states_used[agent.name].append(mod) except KeyError: states_used[agent.name] = [mod] for k, v in states_used.items(): states_used[k] = list(set(v)) stmts_out = [] for stmt in stmts_in: skip = False if isinstance(stmt, Modification): mod_type = modclass_to_modtype[stmt.__class__] if isinstance(stmt, RemoveModification): mod_type = modtype_to_inverse[mod_type] mod = (mod_type, stmt.residue, stmt.position) used = states_used.get(stmt.sub.name, []) if mod not in used: skip = True if not skip: stmts_out.append(stmt) logger.info('%d statements after filter...' % len(stmts_out)) dump_pkl = kwargs.get('save') if dump_pkl: dump_statements(stmts_out, dump_pkl) return stmts_out
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter_inconsequential_acts'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'whitelist'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'dictionary_splat_pattern', 'children': ['9']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '10', 'type': 'block', 'children': ['11', '20', '34', '38', '93', '115', '119', '170', '182', '191', '200']}; {'id': '11', 'type': 'if_statement', 'children': ['12', '15']}; {'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'is'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'whitelist'}; {'id': '14', 'type': 'None', 'children': []}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'whitelist'}; {'id': '19', 'type': 'dictionary', 'children': []}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'binary_operator', 'children': ['27', '33'], 'value': '+'}; {'id': '27', 'type': 'binary_operator', 'children': ['28', '29'], 'value': '%'}; {'id': '28', 'type': 'string', 'children': [], 'value': "'Filtering %d statements to remove'"}; {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '33', 'type': 'string', 'children': [], 'value': "' inconsequential activations...'"}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'states_used'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'whitelist'}; {'id': '38', 'type': 'for_statement', 'children': ['39', '40', '41']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'for_statement', 'children': ['43', '44', '49']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '44', 'type': 'call', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'agent_list'}; {'id': '48', 'type': 'argument_list', 'children': []}; {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'if_statement', 'children': ['51', '54']}; {'id': '51', 'type': 'comparison_operator', 'children': ['52', '53'], 'value': 'is'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '53', 'type': 'None', 'children': []}; {'id': '54', 'type': 'block', 'children': ['55']}; {'id': '55', 'type': 'if_statement', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'activity'}; {'id': '59', 'type': 'block', 'children': ['60', '68']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}; {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'act'}; {'id': '63', 'type': 'attribute', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'activity'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'activity_type'}; {'id': '68', 'type': 'try_statement', 'children': ['69', '81']}; {'id': '69', 'type': 'block', 'children': ['70']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'call', 'children': ['72', '79']}; {'id': '72', 'type': 'attribute', 'children': ['73', '78']}; {'id': '73', 'type': 'subscript', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'states_used'}; {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'act'}; {'id': '81', 'type': 'except_clause', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '83', 'type': 'block', 'children': ['84']}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}; {'id': '85', 'type': 'assignment', 'children': ['86', '91']}; {'id': '86', 'type': 'subscript', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'states_used'}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '91', 'type': 'list', 'children': ['92'], 'value': '[act]'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'act'}; {'id': '93', 'type': 'for_statement', 'children': ['94', '97', '102']}; {'id': '94', 'type': 'pattern_list', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'states_used'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '101', 'type': 'argument_list', 'children': []}; {'id': '102', 'type': 'block', 'children': ['103']}; {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '108']}; {'id': '105', 'type': 'subscript', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'states_used'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '108', 'type': 'call', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}; {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '118', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '119', 'type': 'for_statement', 'children': ['120', '121', '122']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'stmts_in'}; {'id': '122', 'type': 'block', 'children': ['123', '127', '159']}; {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'skip'}; {'id': '126', 'type': 'False', 'children': []}; {'id': '127', 'type': 'if_statement', 'children': ['128', '133']}; {'id': '128', 'type': 'call', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '130', 'type': 'argument_list', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'RegulateActivity'}; {'id': '133', 'type': 'block', 'children': ['134', '148']}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}; {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'used'}; {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'states_used'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '141', 'type': 'argument_list', 'children': ['142', '147']}; {'id': '142', 'type': 'attribute', 'children': ['143', '146']}; {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '147', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '148', 'type': 'if_statement', 'children': ['149', '154']}; {'id': '149', 'type': 'comparison_operator', 'children': ['150', '153'], 'value': 'not'}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'obj_activity'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'used'}; {'id': '154', 'type': 'block', 'children': ['155']}; {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'skip'}; {'id': '158', 'type': 'True', 'children': []}; {'id': '159', 'type': 'if_statement', 'children': ['160', '162']}; {'id': '160', 'type': 'not_operator', 'children': ['161']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'skip'}; {'id': '162', 'type': 'block', 'children': ['163']}; {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'call', 'children': ['165', '168']}; {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}; {'id': '171', 'type': 'call', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'binary_operator', 'children': ['177', '178'], 'value': '%'}; {'id': '177', 'type': 'string', 'children': [], 'value': "'%d statements after filter...'"}; {'id': '178', 'type': 'call', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '180', 'type': 'argument_list', 'children': ['181']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}; {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'string', 'children': [], 'value': "'save'"}; {'id': '191', 'type': 'if_statement', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '193', 'type': 'block', 'children': ['194']}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}; {'id': '195', 'type': 'call', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'dump_statements'}; {'id': '197', 'type': 'argument_list', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'dump_pkl'}; {'id': '200', 'type': 'return_statement', 'children': ['201']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'stmts_out'}
def filter_inconsequential_acts(stmts_in, whitelist=None, **kwargs): if whitelist is None: whitelist = {} logger.info('Filtering %d statements to remove' % len(stmts_in) + ' inconsequential activations...') states_used = whitelist for stmt in stmts_in: for agent in stmt.agent_list(): if agent is not None: if agent.activity: act = agent.activity.activity_type try: states_used[agent.name].append(act) except KeyError: states_used[agent.name] = [act] for k, v in states_used.items(): states_used[k] = list(set(v)) stmts_out = [] for stmt in stmts_in: skip = False if isinstance(stmt, RegulateActivity): used = states_used.get(stmt.obj.name, []) if stmt.obj_activity not in used: skip = True if not skip: stmts_out.append(stmt) logger.info('%d statements after filter...' % len(stmts_out)) dump_pkl = kwargs.get('save') if dump_pkl: dump_statements(stmts_out, dump_pkl) return stmts_out
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'render_stmt_graph'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'statements'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'reduce'}; {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'english'}; {'id': '10', 'type': 'False', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'rankdir'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'agent_style'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'block', 'children': ['18', '25', '43', '50', '57', '61', '132', '141', '149', '156', '172', '205', '268', '279']}; {'id': '18', 'type': 'import_from_statement', 'children': ['19', '23']}; {'id': '19', 'type': 'dotted_name', 'children': ['20', '21', '22']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'indra'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'assemblers'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'english'}; {'id': '23', 'type': 'dotted_name', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'EnglishAssembler'}; {'id': '25', 'type': 'if_statement', 'children': ['26', '29']}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '28'], 'value': 'is'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'agent_style'}; {'id': '28', 'type': 'None', 'children': []}; {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'agent_style'}; {'id': '33', 'type': 'dictionary', 'children': ['34', '37', '40']}; {'id': '34', 'type': 'pair', 'children': ['35', '36']}; {'id': '35', 'type': 'string', 'children': [], 'value': "'color'"}; {'id': '36', 'type': 'string', 'children': [], 'value': "'lightgray'"}; {'id': '37', 'type': 'pair', 'children': ['38', '39']}; {'id': '38', 'type': 'string', 'children': [], 'value': "'style'"}; {'id': '39', 'type': 'string', 'children': [], 'value': "'filled'"}; {'id': '40', 'type': 'pair', 'children': ['41', '42']}; {'id': '41', 'type': 'string', 'children': [], 'value': "'fontname'"}; {'id': '42', 'type': 'string', 'children': [], 'value': "'arial'"}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'edges'}; {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'stmt_dict'}; {'id': '60', 'type': 'dictionary', 'children': []}; {'id': '61', 'type': 'function_definition', 'children': ['62', '63', '65']}; {'id': '62', 'type': 'function_name', 'children': [], 'value': 'process_stmt'}; {'id': '63', 'type': 'parameters', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '65', 'type': 'block', 'children': ['66', '80', '93']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}; {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'matches_key'}; {'id': '79', 'type': 'argument_list', 'children': []}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}; {'id': '81', 'type': 'assignment', 'children': ['82', '92']}; {'id': '82', 'type': 'subscript', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'stmt_dict'}; {'id': '84', 'type': 'call', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}; {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'matches_key'}; {'id': '91', 'type': 'argument_list', 'children': []}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '93', 'type': 'for_statement', 'children': ['94', '97', '103']}; {'id': '94', 'type': 'pattern_list', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'sby_ix'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'sby_stmt'}; {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'supported_by'}; {'id': '103', 'type': 'block', 'children': ['104', '127']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}; {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'edges'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'tuple', 'children': ['111', '119']}; {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '118']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'matches_key'}; {'id': '118', 'type': 'argument_list', 'children': []}; {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '126']}; {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'sby_stmt'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'matches_key'}; {'id': '126', 'type': 'argument_list', 'children': []}; {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'process_stmt'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'sby_stmt'}; {'id': '132', 'type': 'for_statement', 'children': ['133', '134', '135']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'statements'}; {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}; {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'process_stmt'}; {'id': '139', 'type': 'argument_list', 'children': ['140']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'nx_graph'}; {'id': '144', 'type': 'call', 'children': ['145', '148']}; {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'nx'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'DiGraph'}; {'id': '148', 'type': 'argument_list', 'children': []}; {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'call', 'children': ['151', '154']}; {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'nx_graph'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'add_edges_from'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'edges'}; {'id': '156', 'type': 'if_statement', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'reduce'}; {'id': '158', 'type': 'block', 'children': ['159']}; {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'nx_graph'}; {'id': '162', 'type': 'call', 'children': ['163', '170']}; {'id': '163', 'type': 'attribute', 'children': ['164', '169']}; {'id': '164', 'type': 'attribute', 'children': ['165', '168']}; {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'nx'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'algorithms'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'dag'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'transitive_reduction'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'nx_graph'}; {'id': '172', 'type': 'try_statement', 'children': ['173', '191']}; {'id': '173', 'type': 'block', 'children': ['174']}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}; {'id': '175', 'type': 'assignment', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'pgv_graph'}; {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'pgv'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'AGraph'}; {'id': '181', 'type': 'argument_list', 'children': ['182', '185', '188']}; {'id': '182', 'type': 'keyword_argument', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '184', 'type': 'string', 'children': [], 'value': "'statements'"}; {'id': '185', 'type': 'keyword_argument', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'directed'}; {'id': '187', 'type': 'True', 'children': []}; {'id': '188', 'type': 'keyword_argument', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'rankdir'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'rankdir'}; {'id': '191', 'type': 'except_clause', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'NameError'}; {'id': '193', 'type': 'block', 'children': ['194', '203']}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}; {'id': '195', 'type': 'call', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '199', 'type': 'argument_list', 'children': ['200']}; {'id': '200', 'type': 'concatenated_string', 'children': ['201', '202']}; {'id': '201', 'type': 'string', 'children': [], 'value': "'Cannot generate graph because '"}; {'id': '202', 'type': 'string', 'children': [], 'value': "'pygraphviz could not be imported.'"}; {'id': '203', 'type': 'return_statement', 'children': ['204']}; {'id': '204', 'type': 'None', 'children': []}; {'id': '205', 'type': 'for_statement', 'children': ['206', '207', '212']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '207', 'type': 'call', 'children': ['208', '211']}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'nx_graph'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '211', 'type': 'argument_list', 'children': []}; {'id': '212', 'type': 'block', 'children': ['213', '219', '247']}; {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'assignment', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '216', 'type': 'subscript', 'children': ['217', '218']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'stmt_dict'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '219', 'type': 'if_statement', 'children': ['220', '221', '238']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'english'}; {'id': '221', 'type': 'block', 'children': ['222', '230']}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}; {'id': '223', 'type': 'assignment', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'ea'}; {'id': '225', 'type': 'call', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'EnglishAssembler'}; {'id': '227', 'type': 'argument_list', 'children': ['228']}; {'id': '228', 'type': 'list', 'children': ['229'], 'value': '[stmt]'}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}; {'id': '231', 'type': 'assignment', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'stmt_str'}; {'id': '233', 'type': 'call', 'children': ['234', '237']}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'ea'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'make_model'}; {'id': '237', 'type': 'argument_list', 'children': []}; {'id': '238', 'type': 'else_clause', 'children': ['239']}; {'id': '239', 'type': 'block', 'children': ['240']}; {'id': '240', 'type': 'expression_statement', 'children': ['241']}; {'id': '241', 'type': 'assignment', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'stmt_str'}; {'id': '243', 'type': 'call', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '245', 'type': 'argument_list', 'children': ['246']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '247', 'type': 'expression_statement', 'children': ['248']}; {'id': '248', 'type': 'call', 'children': ['249', '252']}; {'id': '249', 'type': 'attribute', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'pgv_graph'}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'add_node'}; {'id': '252', 'type': 'argument_list', 'children': ['253', '254', '266']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '254', 'type': 'keyword_argument', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '256', 'type': 'binary_operator', 'children': ['257', '258'], 'value': '%'}; {'id': '257', 'type': 'string', 'children': [], 'value': "'%s (%d)'"}; {'id': '258', 'type': 'tuple', 'children': ['259', '260']}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'stmt_str'}; {'id': '260', 'type': 'call', 'children': ['261', '262']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '262', 'type': 'argument_list', 'children': ['263']}; {'id': '263', 'type': 'attribute', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'evidence'}; {'id': '266', 'type': 'dictionary_splat', 'children': ['267']}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'agent_style'}; {'id': '268', 'type': 'expression_statement', 'children': ['269']}; {'id': '269', 'type': 'call', 'children': ['270', '273']}; {'id': '270', 'type': 'attribute', 'children': ['271', '272']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'pgv_graph'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'add_edges_from'}; {'id': '273', 'type': 'argument_list', 'children': ['274']}; {'id': '274', 'type': 'call', 'children': ['275', '278']}; {'id': '275', 'type': 'attribute', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'nx_graph'}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'edges'}; {'id': '278', 'type': 'argument_list', 'children': []}; {'id': '279', 'type': 'return_statement', 'children': ['280']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'pgv_graph'}
def render_stmt_graph(statements, reduce=True, english=False, rankdir=None, agent_style=None): from indra.assemblers.english import EnglishAssembler if agent_style is None: agent_style = {'color': 'lightgray', 'style': 'filled', 'fontname': 'arial'} nodes = set([]) edges = set([]) stmt_dict = {} def process_stmt(stmt): nodes.add(str(stmt.matches_key())) stmt_dict[str(stmt.matches_key())] = stmt for sby_ix, sby_stmt in enumerate(stmt.supported_by): edges.add((str(stmt.matches_key()), str(sby_stmt.matches_key()))) process_stmt(sby_stmt) for stmt in statements: process_stmt(stmt) nx_graph = nx.DiGraph() nx_graph.add_edges_from(edges) if reduce: nx_graph = nx.algorithms.dag.transitive_reduction(nx_graph) try: pgv_graph = pgv.AGraph(name='statements', directed=True, rankdir=rankdir) except NameError: logger.error('Cannot generate graph because ' 'pygraphviz could not be imported.') return None for node in nx_graph.nodes(): stmt = stmt_dict[node] if english: ea = EnglishAssembler([stmt]) stmt_str = ea.make_model() else: stmt_str = str(stmt) pgv_graph.add_node(node, label='%s (%d)' % (stmt_str, len(stmt.evidence)), **agent_style) pgv_graph.add_edges_from(nx_graph.edges()) return pgv_graph
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'flatten_stmts'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'stmts'}; {'id': '5', 'type': 'block', 'children': ['6', '13', '40']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'total_stmts'}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'stmts'}; {'id': '13', 'type': 'for_statement', 'children': ['14', '15', '16']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'stmts'}; {'id': '16', 'type': 'block', 'children': ['17']}; {'id': '17', 'type': 'if_statement', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'supported_by'}; {'id': '21', 'type': 'block', 'children': ['22', '31']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '25', 'type': 'call', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'flatten_stmts'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'supported_by'}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'total_stmts'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'total_stmts'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'union'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'children'}; {'id': '40', 'type': 'return_statement', 'children': ['41']}; {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'total_stmts'}
def flatten_stmts(stmts): total_stmts = set(stmts) for stmt in stmts: if stmt.supported_by: children = flatten_stmts(stmt.supported_by) total_stmts = total_stmts.union(children) return list(total_stmts)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'combine_duplicate_stmts'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'stmts'}; {'id': '5', 'type': 'block', 'children': ['6', '38', '42', '329']}; {'id': '6', 'type': 'function_definition', 'children': ['7', '8', '10']}; {'id': '7', 'type': 'function_name', 'children': [], 'value': '_ev_keys'}; {'id': '8', 'type': 'parameters', 'children': ['9']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'sts'}; {'id': '10', 'type': 'block', 'children': ['11', '15', '36']}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'ev_keys'}; {'id': '14', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '15', 'type': 'for_statement', 'children': ['16', '17', '18']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'sts'}; {'id': '18', 'type': 'block', 'children': ['19']}; {'id': '19', 'type': 'for_statement', 'children': ['20', '21', '24']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'evidence'}; {'id': '24', 'type': 'block', 'children': ['25']}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'ev_keys'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'call', 'children': ['32', '35']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'matches_key'}; {'id': '35', 'type': 'argument_list', 'children': []}; {'id': '36', 'type': 'return_statement', 'children': ['37']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'ev_keys'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'unique_stmts'}; {'id': '41', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '42', 'type': 'for_statement', 'children': ['43', '46', '52']}; {'id': '43', 'type': 'pattern_list', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'duplicates'}; {'id': '46', 'type': 'call', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'Preassembler'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': '_get_stmt_matching_groups'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'stmts'}; {'id': '52', 'type': 'block', 'children': ['53', '59', '66', '73', '279', '287', '316', '322']}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'ev_keys'}; {'id': '56', 'type': 'call', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '58', 'type': 'argument_list', 'children': []}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'duplicates'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'duplicates'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'start_ev_keys'}; {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': '_ev_keys'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'duplicates'}; {'id': '73', 'type': 'for_statement', 'children': ['74', '77', '81']}; {'id': '74', 'type': 'pattern_list', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'stmt_ix'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'duplicates'}; {'id': '81', 'type': 'block', 'children': ['82', '95', '111', '138', '160']}; {'id': '82', 'type': 'if_statement', 'children': ['83', '86']}; {'id': '83', 'type': 'comparison_operator', 'children': ['84', '85'], 'value': 'is'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'stmt_ix'}; {'id': '85', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '86', 'type': 'block', 'children': ['87']}; {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'new_stmt'}; {'id': '90', 'type': 'call', 'children': ['91', '94']}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'make_generic_copy'}; {'id': '94', 'type': 'argument_list', 'children': []}; {'id': '95', 'type': 'if_statement', 'children': ['96', '102']}; {'id': '96', 'type': 'comparison_operator', 'children': ['97', '101'], 'value': '=='}; {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'duplicates'}; {'id': '101', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '102', 'type': 'block', 'children': ['103']}; {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '108']}; {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'new_stmt'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'raw_text'}; {'id': '114', 'type': 'list_comprehension', 'children': ['115', '128']}; {'id': '115', 'type': 'conditional_expression', 'children': ['116', '117', '120'], 'value': 'if'}; {'id': '116', 'type': 'None', 'children': []}; {'id': '117', 'type': 'comparison_operator', 'children': ['118', '119'], 'value': 'is'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'ag'}; {'id': '119', 'type': 'None', 'children': []}; {'id': '120', 'type': 'call', 'children': ['121', '126']}; {'id': '121', 'type': 'attribute', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'ag'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}; {'id': '127', 'type': 'string', 'children': [], 'value': "'TEXT'"}; {'id': '128', 'type': 'for_in_clause', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'ag'}; {'id': '130', 'type': 'call', 'children': ['131', '134']}; {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'agent_list'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}; {'id': '135', 'type': 'keyword_argument', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'deep_sorted'}; {'id': '137', 'type': 'True', 'children': []}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}; {'id': '139', 'type': 'assignment', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'raw_grounding'}; {'id': '141', 'type': 'list_comprehension', 'children': ['142', '150']}; {'id': '142', 'type': 'conditional_expression', 'children': ['143', '144', '147'], 'value': 'if'}; {'id': '143', 'type': 'None', 'children': []}; {'id': '144', 'type': 'comparison_operator', 'children': ['145', '146'], 'value': 'is'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'ag'}; {'id': '146', 'type': 'None', 'children': []}; {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'ag'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '150', 'type': 'for_in_clause', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'ag'}; {'id': '152', 'type': 'call', 'children': ['153', '156']}; {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'agent_list'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}; {'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'deep_sorted'}; {'id': '159', 'type': 'True', 'children': []}; {'id': '160', 'type': 'for_statement', 'children': ['161', '162', '165']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '162', 'type': 'attribute', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'evidence'}; {'id': '165', 'type': 'block', 'children': ['166', '185']}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}; {'id': '167', 'type': 'assignment', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'ev_key'}; {'id': '169', 'type': 'binary_operator', 'children': ['170', '180', '181'], 'value': '+'}; {'id': '170', 'type': 'binary_operator', 'children': ['171', '176'], 'value': '+'}; {'id': '171', 'type': 'call', 'children': ['172', '175']}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'matches_key'}; {'id': '175', 'type': 'argument_list', 'children': []}; {'id': '176', 'type': 'call', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'raw_text'}; {'id': '180', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '181', 'type': 'call', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '183', 'type': 'argument_list', 'children': ['184']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'raw_grounding'}; {'id': '185', 'type': 'if_statement', 'children': ['186', '189']}; {'id': '186', 'type': 'comparison_operator', 'children': ['187', '188'], 'value': 'not'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'ev_key'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'ev_keys'}; {'id': '189', 'type': 'block', 'children': ['190', '235', '250', '263', '272']}; {'id': '190', 'type': 'if_statement', 'children': ['191', '196', '218']}; {'id': '191', 'type': 'comparison_operator', 'children': ['192', '193'], 'value': 'in'}; {'id': '192', 'type': 'string', 'children': [], 'value': "'agents'"}; {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '196', 'type': 'block', 'children': ['197', '207']}; {'id': '197', 'type': 'expression_statement', 'children': ['198']}; {'id': '198', 'type': 'assignment', 'children': ['199', '206']}; {'id': '199', 'type': 'subscript', 'children': ['200', '205']}; {'id': '200', 'type': 'subscript', 'children': ['201', '204']}; {'id': '201', 'type': 'attribute', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '204', 'type': 'string', 'children': [], 'value': "'agents'"}; {'id': '205', 'type': 'string', 'children': [], 'value': "'raw_text'"}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'raw_text'}; {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'assignment', 'children': ['209', '216', '217']}; {'id': '209', 'type': 'subscript', 'children': ['210', '215']}; {'id': '210', 'type': 'subscript', 'children': ['211', '214']}; {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '214', 'type': 'string', 'children': [], 'value': "'agents'"}; {'id': '215', 'type': 'string', 'children': [], 'value': "'raw_grounding'"}; {'id': '216', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'raw_grounding'}; {'id': '218', 'type': 'else_clause', 'children': ['219']}; {'id': '219', 'type': 'block', 'children': ['220']}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}; {'id': '221', 'type': 'assignment', 'children': ['222', '227', '228']}; {'id': '222', 'type': 'subscript', 'children': ['223', '226']}; {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '226', 'type': 'string', 'children': [], 'value': "'agents'"}; {'id': '227', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '228', 'type': 'dictionary', 'children': ['229', '232']}; {'id': '229', 'type': 'pair', 'children': ['230', '231']}; {'id': '230', 'type': 'string', 'children': [], 'value': "'raw_text'"}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'raw_text'}; {'id': '232', 'type': 'pair', 'children': ['233', '234']}; {'id': '233', 'type': 'string', 'children': [], 'value': "'raw_grounding'"}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'raw_grounding'}; {'id': '235', 'type': 'if_statement', 'children': ['236', '241']}; {'id': '236', 'type': 'comparison_operator', 'children': ['237', '238'], 'value': 'not'}; {'id': '237', 'type': 'string', 'children': [], 'value': "'prior_uuids'"}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '241', 'type': 'block', 'children': ['242']}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}; {'id': '243', 'type': 'assignment', 'children': ['244', '249']}; {'id': '244', 'type': 'subscript', 'children': ['245', '248']}; {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '248', 'type': 'string', 'children': [], 'value': "'prior_uuids'"}; {'id': '249', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '250', 'type': 'expression_statement', 'children': ['251']}; {'id': '251', 'type': 'call', 'children': ['252', '259']}; {'id': '252', 'type': 'attribute', 'children': ['253', '258']}; {'id': '253', 'type': 'subscript', 'children': ['254', '257']}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '257', 'type': 'string', 'children': [], 'value': "'prior_uuids'"}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '259', 'type': 'argument_list', 'children': ['260']}; {'id': '260', 'type': 'attribute', 'children': ['261', '262']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'call', 'children': ['265', '270']}; {'id': '265', 'type': 'attribute', 'children': ['266', '269']}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'new_stmt'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'evidence'}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '270', 'type': 'argument_list', 'children': ['271']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '272', 'type': 'expression_statement', 'children': ['273']}; {'id': '273', 'type': 'call', 'children': ['274', '277']}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'ev_keys'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '277', 'type': 'argument_list', 'children': ['278']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'ev_key'}; {'id': '279', 'type': 'expression_statement', 'children': ['280']}; {'id': '280', 'type': 'assignment', 'children': ['281', '282']}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'end_ev_keys'}; {'id': '282', 'type': 'call', 'children': ['283', '284']}; {'id': '283', 'type': 'identifier', 'children': [], 'value': '_ev_keys'}; {'id': '284', 'type': 'argument_list', 'children': ['285']}; {'id': '285', 'type': 'list', 'children': ['286'], 'value': '[new_stmt]'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'new_stmt'}; {'id': '287', 'type': 'if_statement', 'children': ['288', '297']}; {'id': '288', 'type': 'comparison_operator', 'children': ['289', '293'], 'value': '!='}; {'id': '289', 'type': 'call', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '291', 'type': 'argument_list', 'children': ['292']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'end_ev_keys'}; {'id': '293', 'type': 'call', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '295', 'type': 'argument_list', 'children': ['296']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'start_ev_keys'}; {'id': '297', 'type': 'block', 'children': ['298']}; {'id': '298', 'type': 'expression_statement', 'children': ['299']}; {'id': '299', 'type': 'call', 'children': ['300', '303']}; {'id': '300', 'type': 'attribute', 'children': ['301', '302']}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '303', 'type': 'argument_list', 'children': ['304']}; {'id': '304', 'type': 'binary_operator', 'children': ['305', '306'], 'value': '%'}; {'id': '305', 'type': 'string', 'children': [], 'value': "'%d redundant evidences eliminated.'"}; {'id': '306', 'type': '()', 'children': ['307']}; {'id': '307', 'type': 'binary_operator', 'children': ['308', '312'], 'value': '-'}; {'id': '308', 'type': 'call', 'children': ['309', '310']}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '310', 'type': 'argument_list', 'children': ['311']}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'start_ev_keys'}; {'id': '312', 'type': 'call', 'children': ['313', '314']}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '314', 'type': 'argument_list', 'children': ['315']}; {'id': '315', 'type': 'identifier', 'children': [], 'value': 'end_ev_keys'}; {'id': '316', 'type': 'assert_statement', 'children': ['317']}; {'id': '317', 'type': 'call', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '319', 'type': 'argument_list', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'new_stmt'}; {'id': '321', 'type': 'identifier', 'children': [], 'value': 'Statement'}; {'id': '322', 'type': 'expression_statement', 'children': ['323']}; {'id': '323', 'type': 'call', 'children': ['324', '327']}; {'id': '324', 'type': 'attribute', 'children': ['325', '326']}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'unique_stmts'}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '327', 'type': 'argument_list', 'children': ['328']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'new_stmt'}; {'id': '329', 'type': 'return_statement', 'children': ['330']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'unique_stmts'}
def combine_duplicate_stmts(stmts): def _ev_keys(sts): ev_keys = [] for stmt in sts: for ev in stmt.evidence: ev_keys.append(ev.matches_key()) return ev_keys unique_stmts = [] for _, duplicates in Preassembler._get_stmt_matching_groups(stmts): ev_keys = set() 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: 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))) assert isinstance(new_stmt, Statement) unique_stmts.append(new_stmt) return unique_stmts
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_stmt_by_group'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'stmt_type'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'stmts_this_type'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'eh'}; {'id': '8', 'type': 'block', 'children': ['9', '19', '29', '39', '49', '59', '366', '407', '448']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'stmt_by_first'}; {'id': '12', 'type': 'call', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'collections'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}; {'id': '17', 'type': 'lambda', 'children': ['18']}; {'id': '18', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'stmt_by_second'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'collections'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'lambda', 'children': ['28']}; {'id': '28', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'none_first'}; {'id': '32', 'type': 'call', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'collections'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}; {'id': '37', 'type': 'lambda', 'children': ['38']}; {'id': '38', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'none_second'}; {'id': '42', 'type': 'call', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'collections'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'lambda', 'children': ['48']}; {'id': '48', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'stmt_by_group'}; {'id': '52', 'type': 'call', 'children': ['53', '56']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'collections'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'lambda', 'children': ['58']}; {'id': '58', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '59', 'type': 'for_statement', 'children': ['60', '61', '62']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'stmt_tuple'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'stmts_this_type'}; {'id': '62', 'type': 'block', 'children': ['63', '69', '80']}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '68']}; {'id': '65', 'type': 'pattern_list', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'stmt_tuple'}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'entities'}; {'id': '72', 'type': 'call', 'children': ['73', '76']}; {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': '_get_entities'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '78', '79']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'stmt_type'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'eh'}; {'id': '80', 'type': 'if_statement', 'children': ['81', '84', '125', '196', '231']}; {'id': '81', 'type': 'comparison_operator', 'children': ['82', '83'], 'value': '=='}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'stmt_type'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'Complex'}; {'id': '84', 'type': 'block', 'children': ['85', '89', '96', '102', '109']}; {'id': '85', 'type': 'assert_statement', 'children': ['86']}; {'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': 'not'}; {'id': '87', 'type': 'None', 'children': []}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'entities'}; {'id': '89', 'type': 'assert_statement', 'children': ['90']}; {'id': '90', 'type': 'comparison_operator', 'children': ['91', '95'], 'value': '>'}; {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '93', 'type': 'argument_list', 'children': ['94']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'entities'}; {'id': '95', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}; {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'entities'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '101', 'type': 'argument_list', 'children': []}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'entities'}; {'id': '109', 'type': 'if_statement', 'children': ['110', '115']}; {'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': 'not'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'stmt_tuple'}; {'id': '112', 'type': 'subscript', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'stmt_by_group'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '115', 'type': 'block', 'children': ['116']}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}; {'id': '117', 'type': 'call', 'children': ['118', '123']}; {'id': '118', 'type': 'attribute', 'children': ['119', '122']}; {'id': '119', 'type': 'subscript', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'stmt_by_group'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '123', 'type': 'argument_list', 'children': ['124']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'stmt_tuple'}; {'id': '125', 'type': 'elif_clause', 'children': ['126', '129']}; {'id': '126', 'type': 'comparison_operator', 'children': ['127', '128'], 'value': '=='}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'stmt_type'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'Conversion'}; {'id': '129', 'type': 'block', 'children': ['130', '137', '180']}; {'id': '130', 'type': 'assert_statement', 'children': ['131']}; {'id': '131', 'type': 'comparison_operator', 'children': ['132', '136'], 'value': '>'}; {'id': '132', 'type': 'call', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'entities'}; {'id': '136', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '140', 'type': 'tuple', 'children': ['141', '144', '163']}; {'id': '141', 'type': 'subscript', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'entities'}; {'id': '143', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '144', 'type': 'call', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}; {'id': '147', 'type': 'call', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'subscript', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'entities'}; {'id': '152', 'type': 'slice', 'children': ['153', '154', '155']}; {'id': '153', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '154', 'type': 'colon', 'children': []}; {'id': '155', 'type': 'binary_operator', 'children': ['156', '162'], 'value': '+'}; {'id': '156', 'type': 'call', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}; {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'obj_from'}; {'id': '162', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '163', 'type': 'call', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'call', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}; {'id': '169', 'type': 'subscript', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'entities'}; {'id': '171', 'type': 'slice', 'children': ['172', '179']}; {'id': '172', 'type': 'unary_operator', 'children': ['173'], 'value': '-'}; {'id': '173', 'type': 'call', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'obj_to'}; {'id': '179', 'type': 'colon', 'children': []}; {'id': '180', 'type': 'if_statement', 'children': ['181', '186']}; {'id': '181', 'type': 'comparison_operator', 'children': ['182', '183'], 'value': 'not'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'stmt_tuple'}; {'id': '183', 'type': 'subscript', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'stmt_by_group'}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '186', 'type': 'block', 'children': ['187']}; {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'call', 'children': ['189', '194']}; {'id': '189', 'type': 'attribute', 'children': ['190', '193']}; {'id': '190', 'type': 'subscript', 'children': ['191', '192']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'stmt_by_group'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'stmt_tuple'}; {'id': '196', 'type': 'elif_clause', 'children': ['197', '203']}; {'id': '197', 'type': 'comparison_operator', 'children': ['198', '202'], 'value': '=='}; {'id': '198', 'type': 'call', 'children': ['199', '200']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '200', 'type': 'argument_list', 'children': ['201']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'entities'}; {'id': '202', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '203', 'type': 'block', 'children': ['204', '208', '215']}; {'id': '204', 'type': 'assert_statement', 'children': ['205']}; {'id': '205', 'type': 'comparison_operator', 'children': ['206', '207'], 'value': 'not'}; {'id': '206', 'type': 'None', 'children': []}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'entities'}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}; {'id': '209', 'type': 'assignment', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '211', 'type': 'call', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'entities'}; {'id': '215', 'type': 'if_statement', 'children': ['216', '221']}; {'id': '216', 'type': 'comparison_operator', 'children': ['217', '218'], 'value': 'not'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'stmt_tuple'}; {'id': '218', 'type': 'subscript', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'stmt_by_group'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '221', 'type': 'block', 'children': ['222']}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}; {'id': '223', 'type': 'call', 'children': ['224', '229']}; {'id': '224', 'type': 'attribute', 'children': ['225', '228']}; {'id': '225', 'type': 'subscript', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'stmt_by_group'}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '229', 'type': 'argument_list', 'children': ['230']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'stmt_tuple'}; {'id': '231', 'type': 'else_clause', 'children': ['232']}; {'id': '232', 'type': 'block', 'children': ['233', '240', '247', '253']}; {'id': '233', 'type': 'expression_statement', 'children': ['234']}; {'id': '234', 'type': 'assignment', 'children': ['235', '236']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '236', 'type': 'call', 'children': ['237', '238']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '238', 'type': 'argument_list', 'children': ['239']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'entities'}; {'id': '240', 'type': 'assert_statement', 'children': ['241']}; {'id': '241', 'type': 'comparison_operator', 'children': ['242', '246'], 'value': '=='}; {'id': '242', 'type': 'call', 'children': ['243', '244']}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '244', 'type': 'argument_list', 'children': ['245']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '246', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '247', 'type': 'assert_statement', 'children': ['248']}; {'id': '248', 'type': 'comparison_operator', 'children': ['249', '250'], 'value': '!='}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '250', 'type': 'tuple', 'children': ['251', '252']}; {'id': '251', 'type': 'None', 'children': []}; {'id': '252', 'type': 'None', 'children': []}; {'id': '253', 'type': 'if_statement', 'children': ['254', '267', '279', '305']}; {'id': '254', 'type': 'boolean_operator', 'children': ['255', '260'], 'value': 'and'}; {'id': '255', 'type': 'comparison_operator', 'children': ['256', '259'], 'value': 'is'}; {'id': '256', 'type': 'subscript', 'children': ['257', '258']}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '258', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '259', 'type': 'None', 'children': []}; {'id': '260', 'type': 'comparison_operator', 'children': ['261', '262'], 'value': 'not'}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'stmt_tuple'}; {'id': '262', 'type': 'subscript', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'none_first'}; {'id': '264', 'type': 'subscript', 'children': ['265', '266']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '266', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '267', 'type': 'block', 'children': ['268']}; {'id': '268', 'type': 'expression_statement', 'children': ['269']}; {'id': '269', 'type': 'call', 'children': ['270', '277']}; {'id': '270', 'type': 'attribute', 'children': ['271', '276']}; {'id': '271', 'type': 'subscript', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'none_first'}; {'id': '273', 'type': 'subscript', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '275', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '277', 'type': 'argument_list', 'children': ['278']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'stmt_tuple'}; {'id': '279', 'type': 'elif_clause', 'children': ['280', '293']}; {'id': '280', 'type': 'boolean_operator', 'children': ['281', '286'], 'value': 'and'}; {'id': '281', 'type': 'comparison_operator', 'children': ['282', '285'], 'value': 'is'}; {'id': '282', 'type': 'subscript', 'children': ['283', '284']}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '284', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '285', 'type': 'None', 'children': []}; {'id': '286', 'type': 'comparison_operator', 'children': ['287', '288'], 'value': 'not'}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'stmt_tuple'}; {'id': '288', 'type': 'subscript', 'children': ['289', '290']}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'none_second'}; {'id': '290', 'type': 'subscript', 'children': ['291', '292']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '292', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '293', 'type': 'block', 'children': ['294']}; {'id': '294', 'type': 'expression_statement', 'children': ['295']}; {'id': '295', 'type': 'call', 'children': ['296', '303']}; {'id': '296', 'type': 'attribute', 'children': ['297', '302']}; {'id': '297', 'type': 'subscript', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'none_second'}; {'id': '299', 'type': 'subscript', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '301', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '303', 'type': 'argument_list', 'children': ['304']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'stmt_tuple'}; {'id': '305', 'type': 'elif_clause', 'children': ['306', '309']}; {'id': '306', 'type': 'comparison_operator', 'children': ['307', '308'], 'value': 'not'}; {'id': '307', 'type': 'None', 'children': []}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '309', 'type': 'block', 'children': ['310', '326', '346']}; {'id': '310', 'type': 'if_statement', 'children': ['311', '316']}; {'id': '311', 'type': 'comparison_operator', 'children': ['312', '313'], 'value': 'not'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'stmt_tuple'}; {'id': '313', 'type': 'subscript', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'stmt_by_group'}; {'id': '315', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '316', 'type': 'block', 'children': ['317']}; {'id': '317', 'type': 'expression_statement', 'children': ['318']}; {'id': '318', 'type': 'call', 'children': ['319', '324']}; {'id': '319', 'type': 'attribute', 'children': ['320', '323']}; {'id': '320', 'type': 'subscript', 'children': ['321', '322']}; {'id': '321', 'type': 'identifier', 'children': [], 'value': 'stmt_by_group'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '324', 'type': 'argument_list', 'children': ['325']}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'stmt_tuple'}; {'id': '326', 'type': 'if_statement', 'children': ['327', '334']}; {'id': '327', 'type': 'comparison_operator', 'children': ['328', '329'], 'value': 'not'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '329', 'type': 'subscript', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'stmt_by_first'}; {'id': '331', 'type': 'subscript', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '333', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '334', 'type': 'block', 'children': ['335']}; {'id': '335', 'type': 'expression_statement', 'children': ['336']}; {'id': '336', 'type': 'call', 'children': ['337', '344']}; {'id': '337', 'type': 'attribute', 'children': ['338', '343']}; {'id': '338', 'type': 'subscript', 'children': ['339', '340']}; {'id': '339', 'type': 'identifier', 'children': [], 'value': 'stmt_by_first'}; {'id': '340', 'type': 'subscript', 'children': ['341', '342']}; {'id': '341', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '342', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '343', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '344', 'type': 'argument_list', 'children': ['345']}; {'id': '345', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '346', 'type': 'if_statement', 'children': ['347', '354']}; {'id': '347', 'type': 'comparison_operator', 'children': ['348', '349'], 'value': 'not'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '349', 'type': 'subscript', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'stmt_by_second'}; {'id': '351', 'type': 'subscript', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '353', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '354', 'type': 'block', 'children': ['355']}; {'id': '355', 'type': 'expression_statement', 'children': ['356']}; {'id': '356', 'type': 'call', 'children': ['357', '364']}; {'id': '357', 'type': 'attribute', 'children': ['358', '363']}; {'id': '358', 'type': 'subscript', 'children': ['359', '360']}; {'id': '359', 'type': 'identifier', 'children': [], 'value': 'stmt_by_second'}; {'id': '360', 'type': 'subscript', 'children': ['361', '362']}; {'id': '361', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '362', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '363', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '364', 'type': 'argument_list', 'children': ['365']}; {'id': '365', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '366', 'type': 'if_statement', 'children': ['367', '368']}; {'id': '367', 'type': 'identifier', 'children': [], 'value': 'none_first'}; {'id': '368', 'type': 'block', 'children': ['369']}; {'id': '369', 'type': 'for_statement', 'children': ['370', '373', '378']}; {'id': '370', 'type': 'pattern_list', 'children': ['371', '372']}; {'id': '371', 'type': 'identifier', 'children': [], 'value': 'second_arg'}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'stmts'}; {'id': '373', 'type': 'call', 'children': ['374', '377']}; {'id': '374', 'type': 'attribute', 'children': ['375', '376']}; {'id': '375', 'type': 'identifier', 'children': [], 'value': 'none_first'}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '377', 'type': 'argument_list', 'children': []}; {'id': '378', 'type': 'block', 'children': ['379', '385', '397']}; {'id': '379', 'type': 'expression_statement', 'children': ['380']}; {'id': '380', 'type': 'assignment', 'children': ['381', '382']}; {'id': '381', 'type': 'identifier', 'children': [], 'value': 'second_arg_keys'}; {'id': '382', 'type': 'subscript', 'children': ['383', '384']}; {'id': '383', 'type': 'identifier', 'children': [], 'value': 'stmt_by_second'}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'second_arg'}; {'id': '385', 'type': 'if_statement', 'children': ['386', '388']}; {'id': '386', 'type': 'not_operator', 'children': ['387']}; {'id': '387', 'type': 'identifier', 'children': [], 'value': 'second_arg_keys'}; {'id': '388', 'type': 'block', 'children': ['389']}; {'id': '389', 'type': 'expression_statement', 'children': ['390']}; {'id': '390', 'type': 'assignment', 'children': ['391', '396']}; {'id': '391', 'type': 'subscript', 'children': ['392', '393']}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'stmt_by_group'}; {'id': '393', 'type': 'tuple', 'children': ['394', '395']}; {'id': '394', 'type': 'None', 'children': []}; {'id': '395', 'type': 'identifier', 'children': [], 'value': 'second_arg'}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'stmts'}; {'id': '397', 'type': 'for_statement', 'children': ['398', '399', '400']}; {'id': '398', 'type': 'identifier', 'children': [], 'value': 'second_arg_key'}; {'id': '399', 'type': 'identifier', 'children': [], 'value': 'second_arg_keys'}; {'id': '400', 'type': 'block', 'children': ['401']}; {'id': '401', 'type': 'expression_statement', 'children': ['402']}; {'id': '402', 'type': 'augmented_assignment', 'children': ['403', '406'], 'value': '+='}; {'id': '403', 'type': 'subscript', 'children': ['404', '405']}; {'id': '404', 'type': 'identifier', 'children': [], 'value': 'stmt_by_group'}; {'id': '405', 'type': 'identifier', 'children': [], 'value': 'second_arg_key'}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'stmts'}; {'id': '407', 'type': 'if_statement', 'children': ['408', '409']}; {'id': '408', 'type': 'identifier', 'children': [], 'value': 'none_second'}; {'id': '409', 'type': 'block', 'children': ['410']}; {'id': '410', 'type': 'for_statement', 'children': ['411', '414', '419']}; {'id': '411', 'type': 'pattern_list', 'children': ['412', '413']}; {'id': '412', 'type': 'identifier', 'children': [], 'value': 'first_arg'}; {'id': '413', 'type': 'identifier', 'children': [], 'value': 'stmts'}; {'id': '414', 'type': 'call', 'children': ['415', '418']}; {'id': '415', 'type': 'attribute', 'children': ['416', '417']}; {'id': '416', 'type': 'identifier', 'children': [], 'value': 'none_second'}; {'id': '417', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '418', 'type': 'argument_list', 'children': []}; {'id': '419', 'type': 'block', 'children': ['420', '426', '438']}; {'id': '420', 'type': 'expression_statement', 'children': ['421']}; {'id': '421', 'type': 'assignment', 'children': ['422', '423']}; {'id': '422', 'type': 'identifier', 'children': [], 'value': 'first_arg_keys'}; {'id': '423', 'type': 'subscript', 'children': ['424', '425']}; {'id': '424', 'type': 'identifier', 'children': [], 'value': 'stmt_by_first'}; {'id': '425', 'type': 'identifier', 'children': [], 'value': 'first_arg'}; {'id': '426', 'type': 'if_statement', 'children': ['427', '429']}; {'id': '427', 'type': 'not_operator', 'children': ['428']}; {'id': '428', 'type': 'identifier', 'children': [], 'value': 'first_arg_keys'}; {'id': '429', 'type': 'block', 'children': ['430']}; {'id': '430', 'type': 'expression_statement', 'children': ['431']}; {'id': '431', 'type': 'assignment', 'children': ['432', '437']}; {'id': '432', 'type': 'subscript', 'children': ['433', '434']}; {'id': '433', 'type': 'identifier', 'children': [], 'value': 'stmt_by_group'}; {'id': '434', 'type': 'tuple', 'children': ['435', '436']}; {'id': '435', 'type': 'identifier', 'children': [], 'value': 'first_arg'}; {'id': '436', 'type': 'None', 'children': []}; {'id': '437', 'type': 'identifier', 'children': [], 'value': 'stmts'}; {'id': '438', 'type': 'for_statement', 'children': ['439', '440', '441']}; {'id': '439', 'type': 'identifier', 'children': [], 'value': 'first_arg_key'}; {'id': '440', 'type': 'identifier', 'children': [], 'value': 'first_arg_keys'}; {'id': '441', 'type': 'block', 'children': ['442']}; {'id': '442', 'type': 'expression_statement', 'children': ['443']}; {'id': '443', 'type': 'augmented_assignment', 'children': ['444', '447'], 'value': '+='}; {'id': '444', 'type': 'subscript', 'children': ['445', '446']}; {'id': '445', 'type': 'identifier', 'children': [], 'value': 'stmt_by_group'}; {'id': '446', 'type': 'identifier', 'children': [], 'value': 'first_arg_key'}; {'id': '447', 'type': 'identifier', 'children': [], 'value': 'stmts'}; {'id': '448', 'type': 'return_statement', 'children': ['449']}; {'id': '449', 'type': 'identifier', 'children': [], 'value': 'stmt_by_group'}
def _get_stmt_by_group(self, stmt_type, stmts_this_type, eh): stmt_by_first = collections.defaultdict(lambda: []) stmt_by_second = collections.defaultdict(lambda: []) none_first = collections.defaultdict(lambda: []) none_second = collections.defaultdict(lambda: []) stmt_by_group = collections.defaultdict(lambda: []) for stmt_tuple in stmts_this_type: _, stmt = stmt_tuple entities = self._get_entities(stmt, stmt_type, eh) if stmt_type == Complex: assert None not in entities assert len(entities) > 0 entities.sort() key = tuple(entities) if stmt_tuple not in stmt_by_group[key]: stmt_by_group[key].append(stmt_tuple) elif stmt_type == Conversion: assert len(entities) > 0 key = (entities[0], tuple(sorted(entities[1:len(stmt.obj_from)+1])), tuple(sorted(entities[-len(stmt.obj_to):]))) if stmt_tuple not in stmt_by_group[key]: stmt_by_group[key].append(stmt_tuple) elif len(entities) == 1: assert None not in entities key = tuple(entities) if stmt_tuple not in stmt_by_group[key]: stmt_by_group[key].append(stmt_tuple) else: key = tuple(entities) assert len(key) == 2 assert key != (None, None) if key[0] is None and stmt_tuple not in none_first[key[1]]: none_first[key[1]].append(stmt_tuple) elif key[1] is None and stmt_tuple not in none_second[key[0]]: none_second[key[0]].append(stmt_tuple) elif None not in key: if stmt_tuple not in stmt_by_group[key]: stmt_by_group[key].append(stmt_tuple) if key not in stmt_by_first[key[0]]: stmt_by_first[key[0]].append(key) if key not in stmt_by_second[key[1]]: stmt_by_second[key[1]].append(key) if none_first: for second_arg, stmts in none_first.items(): second_arg_keys = stmt_by_second[second_arg] if not second_arg_keys: stmt_by_group[(None, second_arg)] = stmts for second_arg_key in second_arg_keys: stmt_by_group[second_arg_key] += stmts if none_second: for first_arg, stmts in none_second.items(): first_arg_keys = stmt_by_first[first_arg] if not first_arg_keys: stmt_by_group[(first_arg, None)] = stmts for first_arg_key in first_arg_keys: stmt_by_group[first_arg_key] += stmts return stmt_by_group
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'combine_related'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'return_toplevel'}; {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'poolsize'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'size_cutoff'}; {'id': '13', 'type': 'integer', 'children': [], 'value': '100'}; {'id': '14', 'type': 'block', 'children': ['15', '41', '49', '60', '92', '107', '121']}; {'id': '15', 'type': 'if_statement', 'children': ['16', '21']}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '20'], 'value': 'is'}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'related_stmts'}; {'id': '20', 'type': 'None', 'children': []}; {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'if_statement', 'children': ['23', '24', '29']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'return_toplevel'}; {'id': '24', 'type': 'block', 'children': ['25']}; {'id': '25', 'type': 'return_statement', 'children': ['26']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'related_stmts'}; {'id': '29', 'type': 'else_clause', 'children': ['30']}; {'id': '30', 'type': 'block', 'children': ['31', '37']}; {'id': '31', 'type': 'assert_statement', 'children': ['32']}; {'id': '32', 'type': 'comparison_operator', 'children': ['33', '36'], 'value': 'is'}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'unique_stmts'}; {'id': '36', 'type': 'None', 'children': []}; {'id': '37', 'type': 'return_statement', 'children': ['38']}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'unique_stmts'}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'unique_stmts'}; {'id': '44', 'type': 'call', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'combine_duplicates'}; {'id': '48', 'type': 'argument_list', 'children': []}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'idx_map'}; {'id': '52', 'type': 'call', 'children': ['53', '56']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': '_generate_id_maps'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '58', '59']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'unique_stmts'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'poolsize'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'size_cutoff'}; {'id': '60', 'type': 'for_statement', 'children': ['61', '64', '65']}; {'id': '61', 'type': 'pattern_list', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'ix1'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'ix2'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'idx_map'}; {'id': '65', 'type': 'block', 'children': ['66', '79']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'call', 'children': ['68', '75']}; {'id': '68', 'type': 'attribute', 'children': ['69', '74']}; {'id': '69', 'type': 'attribute', 'children': ['70', '73']}; {'id': '70', 'type': 'subscript', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'unique_stmts'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'ix1'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'supported_by'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'subscript', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'unique_stmts'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'ix2'}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '88']}; {'id': '81', 'type': 'attribute', 'children': ['82', '87']}; {'id': '82', 'type': 'attribute', 'children': ['83', '86']}; {'id': '83', 'type': 'subscript', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'unique_stmts'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'ix2'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'supports'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}; {'id': '89', 'type': 'subscript', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'unique_stmts'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'ix1'}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}; {'id': '93', 'type': 'assignment', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'related_stmts'}; {'id': '97', 'type': 'list_comprehension', 'children': ['98', '99', '102']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '99', 'type': 'for_in_clause', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'unique_stmts'}; {'id': '102', 'type': 'if_clause', 'children': ['103']}; {'id': '103', 'type': 'not_operator', 'children': ['104']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'supports'}; {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'call', 'children': ['109', '112']}; {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}; {'id': '113', 'type': 'binary_operator', 'children': ['114', '115'], 'value': '%'}; {'id': '114', 'type': 'string', 'children': [], 'value': "'%d top level'"}; {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'related_stmts'}; {'id': '121', 'type': 'if_statement', 'children': ['122', '123', '128']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'return_toplevel'}; {'id': '123', 'type': 'block', 'children': ['124']}; {'id': '124', 'type': 'return_statement', 'children': ['125']}; {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'related_stmts'}; {'id': '128', 'type': 'else_clause', 'children': ['129']}; {'id': '129', 'type': 'block', 'children': ['130']}; {'id': '130', 'type': 'return_statement', 'children': ['131']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'unique_stmts'}
def combine_related(self, return_toplevel=True, poolsize=None, size_cutoff=100): if self.related_stmts is not None: if return_toplevel: return self.related_stmts else: assert self.unique_stmts is not None return self.unique_stmts unique_stmts = self.combine_duplicates() idx_map = self._generate_id_maps(unique_stmts, poolsize, size_cutoff) for ix1, ix2 in idx_map: unique_stmts[ix1].supported_by.append(unique_stmts[ix2]) unique_stmts[ix2].supports.append(unique_stmts[ix1]) self.related_stmts = [st for st in unique_stmts if not st.supports] logger.debug('%d top level' % len(self.related_stmts)) if return_toplevel: return self.related_stmts else: return unique_stmts
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_contradicts'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '14', '24', '49', '57', '67', '73', '79', '83', '191', '197', '247']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'eh'}; {'id': '9', 'type': 'subscript', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'hierarchies'}; {'id': '13', 'type': 'string', 'children': [], 'value': "'entity'"}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'stmts_by_type'}; {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'collections'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'defaultdict'}; {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'lambda', 'children': ['23']}; {'id': '23', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '24', 'type': 'for_statement', 'children': ['25', '28', '34']}; {'id': '25', 'type': 'pattern_list', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'stmts'}; {'id': '34', 'type': 'block', 'children': ['35']}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '45']}; {'id': '37', 'type': 'attribute', 'children': ['38', '44']}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'stmts_by_type'}; {'id': '40', 'type': 'call', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'indra_stmt_type'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'tuple', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'pos_stmts'}; {'id': '52', 'type': 'call', 'children': ['53', '56']}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'AddModification'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': '__subclasses__'}; {'id': '56', 'type': 'argument_list', 'children': []}; {'id': '57', 'type': 'expression_statement', 'children': ['58']}; {'id': '58', 'type': 'assignment', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'neg_stmts'}; {'id': '60', 'type': 'list_comprehension', 'children': ['61', '64']}; {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'modclass_to_inverse'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '64', 'type': 'for_in_clause', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'pos_stmts'}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'augmented_assignment', 'children': ['69', '70'], 'value': '+='}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'pos_stmts'}; {'id': '70', 'type': 'list', 'children': ['71', '72'], 'value': '[Activation, IncreaseAmount]'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'Activation'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'IncreaseAmount'}; {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'augmented_assignment', 'children': ['75', '76'], 'value': '+='}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'neg_stmts'}; {'id': '76', 'type': 'list', 'children': ['77', '78'], 'value': '[Inhibition, DecreaseAmount]'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'Inhibition'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'DecreaseAmount'}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'contradicts'}; {'id': '82', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '83', 'type': 'for_statement', 'children': ['84', '87', '92']}; {'id': '84', 'type': 'pattern_list', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'pst'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'nst'}; {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '89', 'type': 'argument_list', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'pos_stmts'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'neg_stmts'}; {'id': '92', 'type': 'block', 'children': ['93', '103', '113', '124', '135']}; {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'poss'}; {'id': '96', 'type': 'call', 'children': ['97', '100']}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'stmts_by_type'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '100', 'type': 'argument_list', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'pst'}; {'id': '102', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'negs'}; {'id': '106', 'type': 'call', 'children': ['107', '110']}; {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'stmts_by_type'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '110', 'type': 'argument_list', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'nst'}; {'id': '112', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'pos_stmt_by_group'}; {'id': '116', 'type': 'call', 'children': ['117', '120']}; {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': '_get_stmt_by_group'}; {'id': '120', 'type': 'argument_list', 'children': ['121', '122', '123']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'pst'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'poss'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'eh'}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}; {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'neg_stmt_by_group'}; {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': '_get_stmt_by_group'}; {'id': '131', 'type': 'argument_list', 'children': ['132', '133', '134']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'nst'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'negs'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'eh'}; {'id': '135', 'type': 'for_statement', 'children': ['136', '139', '144']}; {'id': '136', 'type': 'pattern_list', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'pg'}; {'id': '139', 'type': 'call', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'pos_stmt_by_group'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '143', 'type': 'argument_list', 'children': []}; {'id': '144', 'type': 'block', 'children': ['145', '155']}; {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'ng'}; {'id': '148', 'type': 'call', 'children': ['149', '152']}; {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'neg_stmt_by_group'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '152', 'type': 'argument_list', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '154', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '155', 'type': 'for_statement', 'children': ['156', '163', '170']}; {'id': '156', 'type': 'pattern_list', 'children': ['157', '160']}; {'id': '157', 'type': 'tuple_pattern', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'st1'}; {'id': '160', 'type': 'tuple_pattern', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'st2'}; {'id': '163', 'type': 'call', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'itertools'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'product'}; {'id': '167', 'type': 'argument_list', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'pg'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'ng'}; {'id': '170', 'type': 'block', 'children': ['171']}; {'id': '171', 'type': 'if_statement', 'children': ['172', '181']}; {'id': '172', 'type': 'call', 'children': ['173', '176']}; {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'st1'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'contradicts'}; {'id': '176', 'type': 'argument_list', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'st2'}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'hierarchies'}; {'id': '181', 'type': 'block', 'children': ['182']}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}; {'id': '183', 'type': 'call', 'children': ['184', '187']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'contradicts'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'tuple', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'st1'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'st2'}; {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'neu_stmts'}; {'id': '194', 'type': 'list', 'children': ['195', '196'], 'value': '[Influence, ActiveForm]'}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'Influence'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'ActiveForm'}; {'id': '197', 'type': 'for_statement', 'children': ['198', '199', '200']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'stt'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'neu_stmts'}; {'id': '200', 'type': 'block', 'children': ['201', '211']}; {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'assignment', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'stmts'}; {'id': '204', 'type': 'call', 'children': ['205', '208']}; {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'stmts_by_type'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '208', 'type': 'argument_list', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'stt'}; {'id': '210', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '211', 'type': 'for_statement', 'children': ['212', '219', '226']}; {'id': '212', 'type': 'pattern_list', 'children': ['213', '216']}; {'id': '213', 'type': 'tuple_pattern', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'st1'}; {'id': '216', 'type': 'tuple_pattern', 'children': ['217', '218']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'st2'}; {'id': '219', 'type': 'call', 'children': ['220', '223']}; {'id': '220', 'type': 'attribute', 'children': ['221', '222']}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'itertools'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'combinations'}; {'id': '223', 'type': 'argument_list', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'stmts'}; {'id': '225', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '226', 'type': 'block', 'children': ['227']}; {'id': '227', 'type': 'if_statement', 'children': ['228', '237']}; {'id': '228', 'type': 'call', 'children': ['229', '232']}; {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'st1'}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'contradicts'}; {'id': '232', 'type': 'argument_list', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'st2'}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'hierarchies'}; {'id': '237', 'type': 'block', 'children': ['238']}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}; {'id': '239', 'type': 'call', 'children': ['240', '243']}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'contradicts'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'tuple', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'st1'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'st2'}; {'id': '247', 'type': 'return_statement', 'children': ['248']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'contradicts'}
def find_contradicts(self): eh = self.hierarchies['entity'] stmts_by_type = collections.defaultdict(lambda: []) for idx, stmt in enumerate(self.stmts): stmts_by_type[indra_stmt_type(stmt)].append((idx, stmt)) pos_stmts = AddModification.__subclasses__() neg_stmts = [modclass_to_inverse[c] for c in pos_stmts] pos_stmts += [Activation, IncreaseAmount] neg_stmts += [Inhibition, DecreaseAmount] contradicts = [] for pst, nst in zip(pos_stmts, neg_stmts): poss = stmts_by_type.get(pst, []) negs = stmts_by_type.get(nst, []) pos_stmt_by_group = self._get_stmt_by_group(pst, poss, eh) neg_stmt_by_group = self._get_stmt_by_group(nst, negs, eh) for key, pg in pos_stmt_by_group.items(): ng = neg_stmt_by_group.get(key, []) for (_, st1), (_, st2) in itertools.product(pg, ng): if st1.contradicts(st2, self.hierarchies): contradicts.append((st1, st2)) neu_stmts = [Influence, ActiveForm] for stt in neu_stmts: stmts = stmts_by_type.get(stt, []) for (_, st1), (_, st2) in itertools.combinations(stmts, 2): if st1.contradicts(st2, self.hierarchies): contradicts.append((st1, st2)) return contradicts
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_text_content_for_pmids'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'pmids'}; {'id': '5', 'type': 'block', 'children': ['6', '21', '25', '62', '66', '72', '109', '120', '124', '151']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'pmc_pmids'}; {'id': '9', 'type': 'call', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '11', 'type': 'argument_list', 'children': ['12']}; {'id': '12', 'type': 'call', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'pmc_client'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'filter_pmids'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'pmids'}; {'id': '18', 'type': 'keyword_argument', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'source_type'}; {'id': '20', 'type': 'string', 'children': [], 'value': "'fulltext'"}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'pmc_ids'}; {'id': '24', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '25', 'type': 'for_statement', 'children': ['26', '27', '28']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'pmid'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'pmc_pmids'}; {'id': '28', 'type': 'block', 'children': ['29', '43']}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'pmc_id'}; {'id': '32', 'type': 'subscript', 'children': ['33', '42']}; {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'pmc_client'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'id_lookup'}; {'id': '37', 'type': 'argument_list', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'pmid'}; {'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'idtype'}; {'id': '41', 'type': 'string', 'children': [], 'value': "'pmid'"}; {'id': '42', 'type': 'string', 'children': [], 'value': "'pmcid'"}; {'id': '43', 'type': 'if_statement', 'children': ['44', '45', '53']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'pmc_id'}; {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'pmc_ids'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'pmc_id'}; {'id': '53', 'type': 'else_clause', 'children': ['54']}; {'id': '54', 'type': 'block', 'children': ['55']}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'pmc_pmids'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'discard'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'pmid'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}; {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'pmc_xmls'}; {'id': '65', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'failed'}; {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '71', 'type': 'argument_list', 'children': []}; {'id': '72', 'type': 'for_statement', 'children': ['73', '74', '75']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'pmc_id'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'pmc_ids'}; {'id': '75', 'type': 'block', 'children': ['76', '102']}; {'id': '76', 'type': 'if_statement', 'children': ['77', '80', '93']}; {'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': 'is'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'pmc_id'}; {'id': '79', 'type': 'None', 'children': []}; {'id': '80', 'type': 'block', 'children': ['81']}; {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '86']}; {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'pmc_xmls'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}; {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'pmc_client'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'get_xml'}; {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'pmc_id'}; {'id': '93', 'type': 'else_clause', 'children': ['94']}; {'id': '94', 'type': 'block', 'children': ['95']}; {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'call', 'children': ['97', '100']}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'failed'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'pmid'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'sleep'}; {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'float', 'children': [], 'value': '0.5'}; {'id': '109', 'type': 'expression_statement', 'children': ['110']}; {'id': '110', 'type': 'assignment', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'remaining_pmids'}; {'id': '112', 'type': 'binary_operator', 'children': ['113', '119'], 'value': '|'}; {'id': '113', 'type': 'binary_operator', 'children': ['114', '118'], 'value': '-'}; {'id': '114', 'type': 'call', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'pmids'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'pmc_pmids'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'failed'}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}; {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'abstracts'}; {'id': '123', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '124', 'type': 'for_statement', 'children': ['125', '126', '127']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'pmid'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'remaining_pmids'}; {'id': '127', 'type': 'block', 'children': ['128', '137', '144']}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}; {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'abstract'}; {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'pubmed_client'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'get_abstract'}; {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'pmid'}; {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '142']}; {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'abstracts'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'abstract'}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}; {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'sleep'}; {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'float', 'children': [], 'value': '0.5'}; {'id': '151', 'type': 'return_statement', 'children': ['152']}; {'id': '152', 'type': 'list_comprehension', 'children': ['153', '154', '159', '162']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'text_content'}; {'id': '154', 'type': 'for_in_clause', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '156', 'type': 'tuple', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'pmc_xmls'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'abstracts'}; {'id': '159', 'type': 'for_in_clause', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'text_content'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '162', 'type': 'if_clause', 'children': ['163']}; {'id': '163', 'type': 'comparison_operator', 'children': ['164', '165'], 'value': 'is'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'text_content'}; {'id': '165', 'type': 'None', 'children': []}
def get_text_content_for_pmids(pmids): pmc_pmids = set(pmc_client.filter_pmids(pmids, source_type='fulltext')) pmc_ids = [] for pmid in pmc_pmids: pmc_id = pmc_client.id_lookup(pmid, idtype='pmid')['pmcid'] if pmc_id: pmc_ids.append(pmc_id) else: pmc_pmids.discard(pmid) pmc_xmls = [] failed = set() for pmc_id in pmc_ids: if pmc_id is not None: pmc_xmls.append(pmc_client.get_xml(pmc_id)) else: failed.append(pmid) time.sleep(0.5) remaining_pmids = set(pmids) - pmc_pmids | failed abstracts = [] for pmid in remaining_pmids: abstract = pubmed_client.get_abstract(pmid) abstracts.append(abstract) time.sleep(0.5) return [text_content for source in (pmc_xmls, abstracts) for text_content in source if text_content is not None]
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'export_sbgn'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '5', 'type': 'block', 'children': ['6', '10', '14', '20', '27', '36', '41', '47', '51', '92', '314', '327']}; {'id': '6', 'type': 'import_statement', 'children': ['7']}; {'id': '7', 'type': 'dotted_name', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'lxml'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'etree'}; {'id': '10', 'type': 'import_statement', 'children': ['11']}; {'id': '11', 'type': 'dotted_name', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'lxml'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'builder'}; {'id': '14', 'type': 'import_from_statement', 'children': ['15', '18']}; {'id': '15', 'type': 'dotted_name', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'pysb'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'bng'}; {'id': '18', 'type': 'dotted_name', 'children': ['19']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'generate_equations'}; {'id': '20', 'type': 'import_from_statement', 'children': ['21', '25']}; {'id': '21', 'type': 'dotted_name', 'children': ['22', '23', '24']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'indra'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'assemblers'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'sbgn'}; {'id': '25', 'type': 'dotted_name', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'SBGNAssembler'}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '+'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'Generating reaction network with BNG for SBGN export. '"}; {'id': '35', 'type': 'string', 'children': [], 'value': "'This could take a long time.'"}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'generate_equations'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'sa'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'SBGNAssembler'}; {'id': '46', 'type': 'argument_list', 'children': []}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'glyphs'}; {'id': '50', 'type': 'dictionary', 'children': []}; {'id': '51', 'type': 'for_statement', 'children': ['52', '55', '61']}; {'id': '52', 'type': 'pattern_list', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'species'}; {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'species'}; {'id': '61', 'type': 'block', 'children': ['62', '71', '77', '86']}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}; {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'glyph'}; {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'sa'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': '_glyph_for_complex_pattern'}; {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'species'}; {'id': '71', 'type': 'if_statement', 'children': ['72', '75']}; {'id': '72', 'type': 'comparison_operator', 'children': ['73', '74'], 'value': 'is'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'glyph'}; {'id': '74', 'type': 'None', 'children': []}; {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'continue_statement', 'children': []}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '84']}; {'id': '79', 'type': 'attribute', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'sa'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': '_map'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'glyph'}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}; {'id': '87', 'type': 'assignment', 'children': ['88', '91']}; {'id': '88', 'type': 'subscript', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'glyphs'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'glyph'}; {'id': '92', 'type': 'for_statement', 'children': ['93', '94', '97']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'reaction'}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'reactions'}; {'id': '97', 'type': 'block', 'children': ['98', '114', '130', '146', '155', '223', '291']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'reactants'}; {'id': '101', 'type': 'binary_operator', 'children': ['102', '108'], 'value': '-'}; {'id': '102', 'type': 'call', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}; {'id': '105', 'type': 'subscript', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'reaction'}; {'id': '107', 'type': 'string', 'children': [], 'value': "'reactants'"}; {'id': '108', 'type': 'call', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}; {'id': '111', 'type': 'subscript', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'reaction'}; {'id': '113', 'type': 'string', 'children': [], 'value': "'products'"}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}; {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'products'}; {'id': '117', 'type': 'binary_operator', 'children': ['118', '124'], 'value': '-'}; {'id': '118', 'type': 'call', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}; {'id': '121', 'type': 'subscript', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'reaction'}; {'id': '123', 'type': 'string', 'children': [], 'value': "'products'"}; {'id': '124', 'type': 'call', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}; {'id': '127', 'type': 'subscript', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'reaction'}; {'id': '129', 'type': 'string', 'children': [], 'value': "'reactants'"}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}; {'id': '131', 'type': 'assignment', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'controllers'}; {'id': '133', 'type': 'binary_operator', 'children': ['134', '140'], 'value': '&'}; {'id': '134', 'type': 'call', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}; {'id': '137', 'type': 'subscript', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'reaction'}; {'id': '139', 'type': 'string', 'children': [], 'value': "'reactants'"}; {'id': '140', 'type': 'call', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}; {'id': '143', 'type': 'subscript', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'reaction'}; {'id': '145', 'type': 'string', 'children': [], 'value': "'products'"}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}; {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'process_glyph'}; {'id': '149', 'type': 'call', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'sa'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': '_process_glyph'}; {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'string', 'children': [], 'value': "'process'"}; {'id': '155', 'type': 'if_statement', 'children': ['156', '158', '176']}; {'id': '156', 'type': 'not_operator', 'children': ['157']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'reactants'}; {'id': '158', 'type': 'block', 'children': ['159', '167']}; {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'glyph_id'}; {'id': '162', 'type': 'call', 'children': ['163', '166']}; {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'sa'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': '_none_glyph'}; {'id': '166', 'type': 'argument_list', 'children': []}; {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'call', 'children': ['169', '172']}; {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'sa'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': '_arc'}; {'id': '172', 'type': 'argument_list', 'children': ['173', '174', '175']}; {'id': '173', 'type': 'string', 'children': [], 'value': "'consumption'"}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'glyph_id'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'process_glyph'}; {'id': '176', 'type': 'else_clause', 'children': ['177']}; {'id': '177', 'type': 'block', 'children': ['178']}; {'id': '178', 'type': 'for_statement', 'children': ['179', '180', '181']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'reactants'}; {'id': '181', 'type': 'block', 'children': ['182', '191', '214']}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}; {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'glyph'}; {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'glyphs'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '191', 'type': 'if_statement', 'children': ['192', '195', '204']}; {'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': 'is'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'glyph'}; {'id': '194', 'type': 'None', 'children': []}; {'id': '195', 'type': 'block', 'children': ['196']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}; {'id': '197', 'type': 'assignment', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'glyph_id'}; {'id': '199', 'type': 'call', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'sa'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': '_none_glyph'}; {'id': '203', 'type': 'argument_list', 'children': []}; {'id': '204', 'type': 'else_clause', 'children': ['205']}; {'id': '205', 'type': 'block', 'children': ['206']}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}; {'id': '207', 'type': 'assignment', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'glyph_id'}; {'id': '209', 'type': 'subscript', 'children': ['210', '213']}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'glyph'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'attrib'}; {'id': '213', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}; {'id': '215', 'type': 'call', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'sa'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': '_arc'}; {'id': '219', 'type': 'argument_list', 'children': ['220', '221', '222']}; {'id': '220', 'type': 'string', 'children': [], 'value': "'consumption'"}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'glyph_id'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'process_glyph'}; {'id': '223', 'type': 'if_statement', 'children': ['224', '226', '244']}; {'id': '224', 'type': 'not_operator', 'children': ['225']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'products'}; {'id': '226', 'type': 'block', 'children': ['227', '235']}; {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '230']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'glyph_id'}; {'id': '230', 'type': 'call', 'children': ['231', '234']}; {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'sa'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': '_none_glyph'}; {'id': '234', 'type': 'argument_list', 'children': []}; {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'call', 'children': ['237', '240']}; {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'sa'}; {'id': '239', 'type': 'identifier', 'children': [], 'value': '_arc'}; {'id': '240', 'type': 'argument_list', 'children': ['241', '242', '243']}; {'id': '241', 'type': 'string', 'children': [], 'value': "'production'"}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'process_glyph'}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'glyph_id'}; {'id': '244', 'type': 'else_clause', 'children': ['245']}; {'id': '245', 'type': 'block', 'children': ['246']}; {'id': '246', 'type': 'for_statement', 'children': ['247', '248', '249']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'products'}; {'id': '249', 'type': 'block', 'children': ['250', '259', '282']}; {'id': '250', 'type': 'expression_statement', 'children': ['251']}; {'id': '251', 'type': 'assignment', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'glyph'}; {'id': '253', 'type': 'call', 'children': ['254', '257']}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'glyphs'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '257', 'type': 'argument_list', 'children': ['258']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '259', 'type': 'if_statement', 'children': ['260', '263', '272']}; {'id': '260', 'type': 'comparison_operator', 'children': ['261', '262'], 'value': 'is'}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'glyph'}; {'id': '262', 'type': 'None', 'children': []}; {'id': '263', 'type': 'block', 'children': ['264']}; {'id': '264', 'type': 'expression_statement', 'children': ['265']}; {'id': '265', 'type': 'assignment', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'glyph_id'}; {'id': '267', 'type': 'call', 'children': ['268', '271']}; {'id': '268', 'type': 'attribute', 'children': ['269', '270']}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'sa'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': '_none_glyph'}; {'id': '271', 'type': 'argument_list', 'children': []}; {'id': '272', 'type': 'else_clause', 'children': ['273']}; {'id': '273', 'type': 'block', 'children': ['274']}; {'id': '274', 'type': 'expression_statement', 'children': ['275']}; {'id': '275', 'type': 'assignment', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'glyph_id'}; {'id': '277', 'type': 'subscript', 'children': ['278', '281']}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'glyph'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'attrib'}; {'id': '281', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '282', 'type': 'expression_statement', 'children': ['283']}; {'id': '283', 'type': 'call', 'children': ['284', '287']}; {'id': '284', 'type': 'attribute', 'children': ['285', '286']}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'sa'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': '_arc'}; {'id': '287', 'type': 'argument_list', 'children': ['288', '289', '290']}; {'id': '288', 'type': 'string', 'children': [], 'value': "'production'"}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'process_glyph'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'glyph_id'}; {'id': '291', 'type': 'for_statement', 'children': ['292', '293', '294']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'controllers'}; {'id': '294', 'type': 'block', 'children': ['295', '301']}; {'id': '295', 'type': 'expression_statement', 'children': ['296']}; {'id': '296', 'type': 'assignment', 'children': ['297', '298']}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'glyph'}; {'id': '298', 'type': 'subscript', 'children': ['299', '300']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'glyphs'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '301', 'type': 'expression_statement', 'children': ['302']}; {'id': '302', 'type': 'call', 'children': ['303', '306']}; {'id': '303', 'type': 'attribute', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'sa'}; {'id': '305', 'type': 'identifier', 'children': [], 'value': '_arc'}; {'id': '306', 'type': 'argument_list', 'children': ['307', '308', '313']}; {'id': '307', 'type': 'string', 'children': [], 'value': "'catalysis'"}; {'id': '308', 'type': 'subscript', 'children': ['309', '312']}; {'id': '309', 'type': 'attribute', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'glyph'}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'attrib'}; {'id': '312', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'process_glyph'}; {'id': '314', 'type': 'expression_statement', 'children': ['315']}; {'id': '315', 'type': 'assignment', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'sbgn_str'}; {'id': '317', 'type': 'call', 'children': ['318', '325']}; {'id': '318', 'type': 'attribute', 'children': ['319', '324']}; {'id': '319', 'type': 'call', 'children': ['320', '323']}; {'id': '320', 'type': 'attribute', 'children': ['321', '322']}; {'id': '321', 'type': 'identifier', 'children': [], 'value': 'sa'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'print_model'}; {'id': '323', 'type': 'argument_list', 'children': []}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'decode'}; {'id': '325', 'type': 'argument_list', 'children': ['326']}; {'id': '326', 'type': 'string', 'children': [], 'value': "'utf-8'"}; {'id': '327', 'type': 'return_statement', 'children': ['328']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'sbgn_str'}
def export_sbgn(model): import lxml.etree import lxml.builder from pysb.bng import generate_equations from indra.assemblers.sbgn import SBGNAssembler logger.info('Generating reaction network with BNG for SBGN export. ' + 'This could take a long time.') generate_equations(model) sa = SBGNAssembler() glyphs = {} for idx, species in enumerate(model.species): glyph = sa._glyph_for_complex_pattern(species) if glyph is None: continue sa._map.append(glyph) glyphs[idx] = glyph for reaction in model.reactions: reactants = set(reaction['reactants']) - set(reaction['products']) products = set(reaction['products']) - set(reaction['reactants']) controllers = set(reaction['reactants']) & set(reaction['products']) process_glyph = sa._process_glyph('process') if not reactants: glyph_id = sa._none_glyph() sa._arc('consumption', glyph_id, process_glyph) else: for r in reactants: glyph = glyphs.get(r) if glyph is None: glyph_id = sa._none_glyph() else: glyph_id = glyph.attrib['id'] sa._arc('consumption', glyph_id, process_glyph) if not products: glyph_id = sa._none_glyph() sa._arc('production', process_glyph, glyph_id) else: for p in products: glyph = glyphs.get(p) if glyph is None: glyph_id = sa._none_glyph() else: glyph_id = glyph.attrib['id'] sa._arc('production', process_glyph, glyph_id) for c in controllers: glyph = glyphs[c] sa._arc('catalysis', glyph.attrib['id'], process_glyph) sbgn_str = sa.print_model().decode('utf-8') return sbgn_str
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_profile_data'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'study_id'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'gene_list'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'profile_filter'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'case_set_filter'}; {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '19', '32', '41', '48', '73', '93', '101', '121', '137', '188']}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'genetic_profiles'}; {'id': '14', 'type': 'call', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'get_genetic_profiles'}; {'id': '16', 'type': 'argument_list', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'study_id'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'profile_filter'}; {'id': '19', 'type': 'if_statement', 'children': ['20', '21', '28']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'genetic_profiles'}; {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'genetic_profile'}; {'id': '25', 'type': 'subscript', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'genetic_profiles'}; {'id': '27', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '28', 'type': 'else_clause', 'children': ['29']}; {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'return_statement', 'children': ['31']}; {'id': '31', 'type': 'dictionary', 'children': []}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'gene_list_str'}; {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'string', 'children': [], 'value': "','"}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'gene_list'}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'case_set_ids'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'get_case_lists'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'study_id'}; {'id': '48', 'type': 'if_statement', 'children': ['49', '50', '65']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'case_set_filter'}; {'id': '50', 'type': 'block', 'children': ['51']}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'case_set_id'}; {'id': '54', 'type': 'subscript', 'children': ['55', '64']}; {'id': '55', 'type': 'list_comprehension', 'children': ['56', '57', '60']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '57', 'type': 'for_in_clause', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'case_set_ids'}; {'id': '60', 'type': 'if_clause', 'children': ['61']}; {'id': '61', 'type': 'comparison_operator', 'children': ['62', '63'], 'value': 'in'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'case_set_filter'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '64', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '65', 'type': 'else_clause', 'children': ['66']}; {'id': '66', 'type': 'block', 'children': ['67']}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'case_set_id'}; {'id': '70', 'type': 'binary_operator', 'children': ['71', '72'], 'value': '+'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'study_id'}; {'id': '72', 'type': 'string', 'children': [], 'value': "'_all'"}; {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '76', 'type': 'dictionary', 'children': ['77', '80', '83', '86', '89']}; {'id': '77', 'type': 'pair', 'children': ['78', '79']}; {'id': '78', 'type': 'string', 'children': [], 'value': "'cmd'"}; {'id': '79', 'type': 'string', 'children': [], 'value': "'getProfileData'"}; {'id': '80', 'type': 'pair', 'children': ['81', '82']}; {'id': '81', 'type': 'string', 'children': [], 'value': "'case_set_id'"}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'case_set_id'}; {'id': '83', 'type': 'pair', 'children': ['84', '85']}; {'id': '84', 'type': 'string', 'children': [], 'value': "'genetic_profile_id'"}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'genetic_profile'}; {'id': '86', 'type': 'pair', 'children': ['87', '88']}; {'id': '87', 'type': 'string', 'children': [], 'value': "'gene_list'"}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'gene_list_str'}; {'id': '89', 'type': 'pair', 'children': ['90', '91']}; {'id': '90', 'type': 'string', 'children': [], 'value': "'skiprows'"}; {'id': '91', 'type': 'unary_operator', 'children': ['92'], 'value': '-'}; {'id': '92', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '96', 'type': 'call', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'send_request'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}; {'id': '99', 'type': 'dictionary_splat', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'case_list_df'}; {'id': '104', 'type': 'list_comprehension', 'children': ['105', '106', '115']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '106', 'type': 'for_in_clause', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '108', 'type': 'call', 'children': ['109', '114']}; {'id': '109', 'type': 'attribute', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'tolist'}; {'id': '114', 'type': 'argument_list', 'children': []}; {'id': '115', 'type': 'if_clause', 'children': ['116']}; {'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': 'not'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '118', 'type': 'list', 'children': ['119', '120'], 'value': "['GENE_ID', 'COMMON']"}; {'id': '119', 'type': 'string', 'children': [], 'value': "'GENE_ID'"}; {'id': '120', 'type': 'string', 'children': [], 'value': "'COMMON'"}; {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'profile_data'}; {'id': '124', 'type': 'dictionary_comprehension', 'children': ['125', '134']}; {'id': '125', 'type': 'pair', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'case'}; {'id': '127', 'type': 'dictionary_comprehension', 'children': ['128', '131']}; {'id': '128', 'type': 'pair', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '130', 'type': 'None', 'children': []}; {'id': '131', 'type': 'for_in_clause', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'gene_list'}; {'id': '134', 'type': 'for_in_clause', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'case'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'case_list_df'}; {'id': '137', 'type': 'for_statement', 'children': ['138', '139', '140']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'case'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'case_list_df'}; {'id': '140', 'type': 'block', 'children': ['141', '151', '161']}; {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'profile_values'}; {'id': '144', 'type': 'call', 'children': ['145', '150']}; {'id': '145', 'type': 'attribute', 'children': ['146', '149']}; {'id': '146', 'type': 'subscript', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'case'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'tolist'}; {'id': '150', 'type': 'argument_list', 'children': []}; {'id': '151', 'type': 'expression_statement', 'children': ['152']}; {'id': '152', 'type': 'assignment', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'df_gene_list'}; {'id': '154', 'type': 'call', 'children': ['155', '160']}; {'id': '155', 'type': 'attribute', 'children': ['156', '159']}; {'id': '156', 'type': 'subscript', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '158', 'type': 'string', 'children': [], 'value': "'COMMON'"}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'tolist'}; {'id': '160', 'type': 'argument_list', 'children': []}; {'id': '161', 'type': 'for_statement', 'children': ['162', '165', '170']}; {'id': '162', 'type': 'pattern_list', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'cv'}; {'id': '165', 'type': 'call', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '167', 'type': 'argument_list', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'df_gene_list'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'profile_values'}; {'id': '170', 'type': 'block', 'children': ['171']}; {'id': '171', 'type': 'if_statement', 'children': ['172', '179']}; {'id': '172', 'type': 'not_operator', 'children': ['173']}; {'id': '173', 'type': 'call', 'children': ['174', '177']}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'pandas'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'isnull'}; {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'cv'}; {'id': '179', 'type': 'block', 'children': ['180']}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}; {'id': '181', 'type': 'assignment', 'children': ['182', '187']}; {'id': '182', 'type': 'subscript', 'children': ['183', '186']}; {'id': '183', 'type': 'subscript', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'profile_data'}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'case'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'cv'}; {'id': '188', 'type': 'return_statement', 'children': ['189']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'profile_data'}
def get_profile_data(study_id, gene_list, profile_filter, case_set_filter=None): genetic_profiles = get_genetic_profiles(study_id, profile_filter) if genetic_profiles: genetic_profile = genetic_profiles[0] else: return {} gene_list_str = ','.join(gene_list) case_set_ids = get_case_lists(study_id) if case_set_filter: case_set_id = [x for x in case_set_ids if case_set_filter in x][0] else: case_set_id = study_id + '_all' data = {'cmd': 'getProfileData', 'case_set_id': case_set_id, 'genetic_profile_id': genetic_profile, 'gene_list': gene_list_str, 'skiprows': -1} df = send_request(**data) case_list_df = [x for x in df.columns.tolist() if x not in ['GENE_ID', 'COMMON']] profile_data = {case: {g: None for g in gene_list} for case in case_list_df} for case in case_list_df: profile_values = df[case].tolist() df_gene_list = df['COMMON'].tolist() for g, cv in zip(df_gene_list, profile_values): if not pandas.isnull(cv): profile_data[case][g] = cv return profile_data
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'print_cx'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'pretty'}; {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '64', '70', '80', '94', '100', '123', '141', '154', '171', '197']}; {'id': '9', 'type': 'function_definition', 'children': ['10', '11', '13']}; {'id': '10', 'type': 'function_name', 'children': [], 'value': '_get_aspect_metadata'}; {'id': '11', 'type': 'parameters', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'aspect'}; {'id': '13', 'type': 'block', 'children': ['14', '38', '44', '62']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '17', 'type': 'conditional_expression', 'children': ['18', '29', '37'], 'value': 'if'}; {'id': '18', 'type': 'call', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '20', 'type': 'argument_list', 'children': ['21']}; {'id': '21', 'type': 'call', 'children': ['22', '27']}; {'id': '22', 'type': 'attribute', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'cx'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'aspect'}; {'id': '29', 'type': 'call', 'children': ['30', '35']}; {'id': '30', 'type': 'attribute', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'cx'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '35', 'type': 'argument_list', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'aspect'}; {'id': '37', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '38', 'type': 'if_statement', 'children': ['39', '41']}; {'id': '39', 'type': 'not_operator', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'return_statement', 'children': ['43']}; {'id': '43', 'type': 'None', 'children': []}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '47', 'type': 'dictionary', 'children': ['48', '51', '56', '59']}; {'id': '48', 'type': 'pair', 'children': ['49', '50']}; {'id': '49', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'aspect'}; {'id': '51', 'type': 'pair', 'children': ['52', '53']}; {'id': '52', 'type': 'string', 'children': [], 'value': "'idCounter'"}; {'id': '53', 'type': 'attribute', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': '_id_counter'}; {'id': '56', 'type': 'pair', 'children': ['57', '58']}; {'id': '57', 'type': 'string', 'children': [], 'value': "'consistencyGroup'"}; {'id': '58', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '59', 'type': 'pair', 'children': ['60', '61']}; {'id': '60', 'type': 'string', 'children': [], 'value': "'elementCount'"}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '62', 'type': 'return_statement', 'children': ['63']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'full_cx'}; {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'OrderedDict'}; {'id': '69', 'type': 'argument_list', 'children': []}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'assignment', 'children': ['72', '75']}; {'id': '72', 'type': 'subscript', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'full_cx'}; {'id': '74', 'type': 'string', 'children': [], 'value': "'numberVerification'"}; {'id': '75', 'type': 'list', 'children': ['76'], 'value': "[{'longNumber': 281474976710655}]"}; {'id': '76', 'type': 'dictionary', 'children': ['77']}; {'id': '77', 'type': 'pair', 'children': ['78', '79']}; {'id': '78', 'type': 'string', 'children': [], 'value': "'longNumber'"}; {'id': '79', 'type': 'integer', 'children': [], 'value': '281474976710655'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}; {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'aspects'}; {'id': '83', 'type': 'list', 'children': ['84', '85', '86', '87', '88', '89', '90', '91', '92', '93'], 'value': "['nodes', 'edges', 'supports', 'citations', 'edgeAttributes',\n 'edgeCitations', 'edgeSupports', 'networkAttributes',\n 'nodeAttributes', 'cartesianLayout']"}; {'id': '84', 'type': 'string', 'children': [], 'value': "'nodes'"}; {'id': '85', 'type': 'string', 'children': [], 'value': "'edges'"}; {'id': '86', 'type': 'string', 'children': [], 'value': "'supports'"}; {'id': '87', 'type': 'string', 'children': [], 'value': "'citations'"}; {'id': '88', 'type': 'string', 'children': [], 'value': "'edgeAttributes'"}; {'id': '89', 'type': 'string', 'children': [], 'value': "'edgeCitations'"}; {'id': '90', 'type': 'string', 'children': [], 'value': "'edgeSupports'"}; {'id': '91', 'type': 'string', 'children': [], 'value': "'networkAttributes'"}; {'id': '92', 'type': 'string', 'children': [], 'value': "'nodeAttributes'"}; {'id': '93', 'type': 'string', 'children': [], 'value': "'cartesianLayout'"}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}; {'id': '95', 'type': 'assignment', 'children': ['96', '99']}; {'id': '96', 'type': 'subscript', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'full_cx'}; {'id': '98', 'type': 'string', 'children': [], 'value': "'metaData'"}; {'id': '99', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '100', 'type': 'for_statement', 'children': ['101', '102', '103']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'aspect'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'aspects'}; {'id': '103', 'type': 'block', 'children': ['104', '111']}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}; {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': '_get_aspect_metadata'}; {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'aspect'}; {'id': '111', 'type': 'if_statement', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}; {'id': '115', 'type': 'call', 'children': ['116', '121']}; {'id': '116', 'type': 'attribute', 'children': ['117', '120']}; {'id': '117', 'type': 'subscript', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'full_cx'}; {'id': '119', 'type': 'string', 'children': [], 'value': "'metaData'"}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '121', 'type': 'argument_list', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'metadata'}; {'id': '123', 'type': 'for_statement', 'children': ['124', '127', '134']}; {'id': '124', 'type': 'pattern_list', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '127', 'type': 'call', 'children': ['128', '133']}; {'id': '128', 'type': 'attribute', 'children': ['129', '132']}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'cx'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '133', 'type': 'argument_list', 'children': []}; {'id': '134', 'type': 'block', 'children': ['135']}; {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '140']}; {'id': '137', 'type': 'subscript', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'full_cx'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '146']}; {'id': '143', 'type': 'subscript', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'full_cx'}; {'id': '145', 'type': 'string', 'children': [], 'value': "'status'"}; {'id': '146', 'type': 'list', 'children': ['147'], 'value': "[{'error': '', 'success': True}]"}; {'id': '147', 'type': 'dictionary', 'children': ['148', '151']}; {'id': '148', 'type': 'pair', 'children': ['149', '150']}; {'id': '149', 'type': 'string', 'children': [], 'value': "'error'"}; {'id': '150', 'type': 'string', 'children': [], 'value': "''"}; {'id': '151', 'type': 'pair', 'children': ['152', '153']}; {'id': '152', 'type': 'string', 'children': [], 'value': "'success'"}; {'id': '153', 'type': 'True', 'children': []}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}; {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'full_cx'}; {'id': '157', 'type': 'list_comprehension', 'children': ['158', '162']}; {'id': '158', 'type': 'dictionary', 'children': ['159']}; {'id': '159', 'type': 'pair', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '162', 'type': 'for_in_clause', 'children': ['163', '166']}; {'id': '163', 'type': 'pattern_list', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '166', 'type': 'call', 'children': ['167', '170']}; {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'full_cx'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '170', 'type': 'argument_list', 'children': []}; {'id': '171', 'type': 'if_statement', 'children': ['172', '173', '186']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'pretty'}; {'id': '173', 'type': 'block', 'children': ['174']}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}; {'id': '175', 'type': 'assignment', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'json_str'}; {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'dumps'}; {'id': '181', 'type': 'argument_list', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'full_cx'}; {'id': '183', 'type': 'keyword_argument', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'indent'}; {'id': '185', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '186', 'type': 'else_clause', 'children': ['187']}; {'id': '187', 'type': 'block', 'children': ['188']}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}; {'id': '189', 'type': 'assignment', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'json_str'}; {'id': '191', 'type': 'call', 'children': ['192', '195']}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'dumps'}; {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'full_cx'}; {'id': '197', 'type': 'return_statement', 'children': ['198']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'json_str'}
def print_cx(self, pretty=True): def _get_aspect_metadata(aspect): count = len(self.cx.get(aspect)) if self.cx.get(aspect) else 0 if not count: return None data = {'name': aspect, 'idCounter': self._id_counter, 'consistencyGroup': 1, 'elementCount': count} return data full_cx = OrderedDict() full_cx['numberVerification'] = [{'longNumber': 281474976710655}] aspects = ['nodes', 'edges', 'supports', 'citations', 'edgeAttributes', 'edgeCitations', 'edgeSupports', 'networkAttributes', 'nodeAttributes', 'cartesianLayout'] full_cx['metaData'] = [] for aspect in aspects: metadata = _get_aspect_metadata(aspect) if metadata: full_cx['metaData'].append(metadata) for k, v in self.cx.items(): full_cx[k] = v full_cx['status'] = [{'error': '', 'success': True}] full_cx = [{k: v} for k, v in full_cx.items()] if pretty: json_str = json.dumps(full_cx, indent=2) else: json_str = json.dumps(full_cx) return json_str
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'set_context'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'cell_type'}; {'id': '6', 'type': 'block', 'children': ['7', '21', '32', '43', '52', '61', '79', '97', '105', '122', '126', '241']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'node_names'}; {'id': '10', 'type': 'list_comprehension', 'children': ['11', '14']}; {'id': '11', 'type': 'subscript', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '13', 'type': 'string', 'children': [], 'value': "'n'"}; {'id': '14', 'type': 'for_in_clause', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '16', 'type': 'subscript', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'cx'}; {'id': '20', 'type': 'string', 'children': [], 'value': "'nodes'"}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'res_expr'}; {'id': '24', 'type': 'call', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'context_client'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'get_protein_expression'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'node_names'}; {'id': '30', 'type': 'list', 'children': ['31'], 'value': '[cell_type]'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'cell_type'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'res_mut'}; {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'context_client'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'get_mutations'}; {'id': '39', 'type': 'argument_list', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'node_names'}; {'id': '41', 'type': 'list', 'children': ['42'], 'value': '[cell_type]'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'cell_type'}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'res_expr'}; {'id': '46', 'type': 'call', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'res_expr'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'cell_type'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'assignment', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'res_mut'}; {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'res_mut'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'cell_type'}; {'id': '61', 'type': 'if_statement', 'children': ['62', '64']}; {'id': '62', 'type': 'not_operator', 'children': ['63']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'res_expr'}; {'id': '64', 'type': 'block', 'children': ['65', '72']}; {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '68', 'type': 'binary_operator', 'children': ['69', '70', '71'], 'value': '%'}; {'id': '69', 'type': 'string', 'children': [], 'value': "'Could not get protein expression for %s cell type.'"}; {'id': '70', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'cell_type'}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '79', 'type': 'if_statement', 'children': ['80', '82']}; {'id': '80', 'type': 'not_operator', 'children': ['81']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'res_mut'}; {'id': '82', 'type': 'block', 'children': ['83', '90']}; {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '86', 'type': 'binary_operator', 'children': ['87', '88', '89'], 'value': '%'}; {'id': '87', 'type': 'string', 'children': [], 'value': "'Could not get mutational status for %s cell type.'"}; {'id': '88', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'cell_type'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}; {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '97', 'type': 'if_statement', 'children': ['98', '103']}; {'id': '98', 'type': 'boolean_operator', 'children': ['99', '101'], 'value': 'and'}; {'id': '99', 'type': 'not_operator', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'res_expr'}; {'id': '101', 'type': 'not_operator', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'res_mut'}; {'id': '103', 'type': 'block', 'children': ['104']}; {'id': '104', 'type': 'return_statement', 'children': []}; {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'call', 'children': ['107', '114']}; {'id': '107', 'type': 'attribute', 'children': ['108', '113']}; {'id': '108', 'type': 'subscript', 'children': ['109', '112']}; {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'cx'}; {'id': '112', 'type': 'string', 'children': [], 'value': "'networkAttributes'"}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}; {'id': '115', 'type': 'dictionary', 'children': ['116', '119']}; {'id': '116', 'type': 'pair', 'children': ['117', '118']}; {'id': '117', 'type': 'string', 'children': [], 'value': "'n'"}; {'id': '118', 'type': 'string', 'children': [], 'value': "'cellular_context'"}; {'id': '119', 'type': 'pair', 'children': ['120', '121']}; {'id': '120', 'type': 'string', 'children': [], 'value': "'v'"}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'cell_type'}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}; {'id': '123', 'type': 'assignment', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'counter'}; {'id': '125', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '126', 'type': 'for_statement', 'children': ['127', '128', '133']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '128', 'type': 'subscript', 'children': ['129', '132']}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'cx'}; {'id': '132', 'type': 'string', 'children': [], 'value': "'nodes'"}; {'id': '133', 'type': 'block', 'children': ['134', '145', '156', '190', '228']}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}; {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'amount'}; {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'res_expr'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'subscript', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '144', 'type': 'string', 'children': [], 'value': "'n'"}; {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'mut'}; {'id': '148', 'type': 'call', 'children': ['149', '152']}; {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'res_mut'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}; {'id': '153', 'type': 'subscript', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '155', 'type': 'string', 'children': [], 'value': "'n'"}; {'id': '156', 'type': 'if_statement', 'children': ['157', '160']}; {'id': '157', 'type': 'comparison_operator', 'children': ['158', '159'], 'value': 'is'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'amount'}; {'id': '159', 'type': 'None', 'children': []}; {'id': '160', 'type': 'block', 'children': ['161', '179']}; {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'node_attribute'}; {'id': '164', 'type': 'dictionary', 'children': ['165', '170', '173']}; {'id': '165', 'type': 'pair', 'children': ['166', '167']}; {'id': '166', 'type': 'string', 'children': [], 'value': "'po'"}; {'id': '167', 'type': 'subscript', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '169', 'type': 'string', 'children': [], 'value': "'@id'"}; {'id': '170', 'type': 'pair', 'children': ['171', '172']}; {'id': '171', 'type': 'string', 'children': [], 'value': "'n'"}; {'id': '172', 'type': 'string', 'children': [], 'value': "'expression_amount'"}; {'id': '173', 'type': 'pair', 'children': ['174', '175']}; {'id': '174', 'type': 'string', 'children': [], 'value': "'v'"}; {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'amount'}; {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'call', 'children': ['181', '188']}; {'id': '181', 'type': 'attribute', 'children': ['182', '187']}; {'id': '182', 'type': 'subscript', 'children': ['183', '186']}; {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'cx'}; {'id': '186', 'type': 'string', 'children': [], 'value': "'nodeAttributes'"}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '188', 'type': 'argument_list', 'children': ['189']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'node_attribute'}; {'id': '190', 'type': 'if_statement', 'children': ['191', '194']}; {'id': '191', 'type': 'comparison_operator', 'children': ['192', '193'], 'value': 'is'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'mut'}; {'id': '193', 'type': 'None', 'children': []}; {'id': '194', 'type': 'block', 'children': ['195', '202', '217']}; {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'assignment', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'is_mutated'}; {'id': '198', 'type': 'conditional_expression', 'children': ['199', '200', '201'], 'value': 'if'}; {'id': '199', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'mut'}; {'id': '201', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '202', 'type': 'expression_statement', 'children': ['203']}; {'id': '203', 'type': 'assignment', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'node_attribute'}; {'id': '205', 'type': 'dictionary', 'children': ['206', '211', '214']}; {'id': '206', 'type': 'pair', 'children': ['207', '208']}; {'id': '207', 'type': 'string', 'children': [], 'value': "'po'"}; {'id': '208', 'type': 'subscript', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '210', 'type': 'string', 'children': [], 'value': "'@id'"}; {'id': '211', 'type': 'pair', 'children': ['212', '213']}; {'id': '212', 'type': 'string', 'children': [], 'value': "'n'"}; {'id': '213', 'type': 'string', 'children': [], 'value': "'is_mutated'"}; {'id': '214', 'type': 'pair', 'children': ['215', '216']}; {'id': '215', 'type': 'string', 'children': [], 'value': "'v'"}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'is_mutated'}; {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'call', 'children': ['219', '226']}; {'id': '219', 'type': 'attribute', 'children': ['220', '225']}; {'id': '220', 'type': 'subscript', 'children': ['221', '224']}; {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'cx'}; {'id': '224', 'type': 'string', 'children': [], 'value': "'nodeAttributes'"}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '226', 'type': 'argument_list', 'children': ['227']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'node_attribute'}; {'id': '228', 'type': 'if_statement', 'children': ['229', '236']}; {'id': '229', 'type': 'boolean_operator', 'children': ['230', '233'], 'value': 'or'}; {'id': '230', 'type': 'comparison_operator', 'children': ['231', '232'], 'value': 'is'}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'mut'}; {'id': '232', 'type': 'None', 'children': []}; {'id': '233', 'type': 'comparison_operator', 'children': ['234', '235'], 'value': 'is'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'amount'}; {'id': '235', 'type': 'None', 'children': []}; {'id': '236', 'type': 'block', 'children': ['237']}; {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'augmented_assignment', 'children': ['239', '240'], 'value': '+='}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'counter'}; {'id': '240', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'call', 'children': ['243', '246']}; {'id': '243', 'type': 'attribute', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}; {'id': '247', 'type': 'binary_operator', 'children': ['248', '249'], 'value': '%'}; {'id': '248', 'type': 'string', 'children': [], 'value': "'Set context for %d nodes.'"}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'counter'}
def set_context(self, cell_type): node_names = [node['n'] for node in self.cx['nodes']] res_expr = context_client.get_protein_expression(node_names, [cell_type]) res_mut = context_client.get_mutations(node_names, [cell_type]) res_expr = res_expr.get(cell_type) res_mut = res_mut.get(cell_type) if not res_expr: msg = 'Could not get protein expression for %s cell type.' % \ cell_type logger.warning(msg) if not res_mut: msg = 'Could not get mutational status for %s cell type.' % \ cell_type logger.warning(msg) if not res_expr and not res_mut: return self.cx['networkAttributes'].append({'n': 'cellular_context', 'v': cell_type}) counter = 0 for node in self.cx['nodes']: amount = res_expr.get(node['n']) mut = res_mut.get(node['n']) if amount is not None: node_attribute = {'po': node['@id'], 'n': 'expression_amount', 'v': int(amount)} self.cx['nodeAttributes'].append(node_attribute) if mut is not None: is_mutated = 1 if mut else 0 node_attribute = {'po': node['@id'], 'n': 'is_mutated', 'v': is_mutated} self.cx['nodeAttributes'].append(node_attribute) if mut is not None or amount is not None: counter += 1 logger.info('Set context for %d nodes.' % counter)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_ids'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'search_term'}; {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '7', 'type': 'block', 'children': ['8', '18', '25', '44', '51', '59', '66', '92', '132', '146', '155', '162', '172', '195']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'use_text_word'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '17']}; {'id': '16', 'type': 'string', 'children': [], 'value': "'use_text_word'"}; {'id': '17', 'type': 'True', 'children': []}; {'id': '18', 'type': 'if_statement', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'use_text_word'}; {'id': '20', 'type': 'block', 'children': ['21']}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'augmented_assignment', 'children': ['23', '24'], 'value': '+='}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'search_term'}; {'id': '24', 'type': 'string', 'children': [], 'value': "'[tw]'"}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '28', 'type': 'dictionary', 'children': ['29', '32', '35', '38', '41']}; {'id': '29', 'type': 'pair', 'children': ['30', '31']}; {'id': '30', 'type': 'string', 'children': [], 'value': "'term'"}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'search_term'}; {'id': '32', 'type': 'pair', 'children': ['33', '34']}; {'id': '33', 'type': 'string', 'children': [], 'value': "'retmax'"}; {'id': '34', 'type': 'integer', 'children': [], 'value': '100000'}; {'id': '35', 'type': 'pair', 'children': ['36', '37']}; {'id': '36', 'type': 'string', 'children': [], 'value': "'retstart'"}; {'id': '37', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '38', 'type': 'pair', 'children': ['39', '40']}; {'id': '39', 'type': 'string', 'children': [], 'value': "'db'"}; {'id': '40', 'type': 'string', 'children': [], 'value': "'pubmed'"}; {'id': '41', 'type': 'pair', 'children': ['42', '43']}; {'id': '42', 'type': 'string', 'children': [], 'value': "'sort'"}; {'id': '43', 'type': 'string', 'children': [], 'value': "'pub+date'"}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'send_request'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'pubmed_search'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '59', 'type': 'if_statement', 'children': ['60', '63']}; {'id': '60', 'type': 'comparison_operator', 'children': ['61', '62'], 'value': 'is'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '62', 'type': 'None', 'children': []}; {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'return_statement', 'children': ['65']}; {'id': '65', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '66', 'type': 'if_statement', 'children': ['67', '75']}; {'id': '67', 'type': 'comparison_operator', 'children': ['68', '74'], 'value': 'is'}; {'id': '68', 'type': 'call', 'children': ['69', '72']}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}; {'id': '73', 'type': 'string', 'children': [], 'value': "'ERROR'"}; {'id': '74', 'type': 'None', 'children': []}; {'id': '75', 'type': 'block', 'children': ['76', '90']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}; {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'attribute', 'children': ['83', '89']}; {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'string', 'children': [], 'value': "'ERROR'"}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '90', 'type': 'return_statement', 'children': ['91']}; {'id': '91', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '92', 'type': 'if_statement', 'children': ['93', '101']}; {'id': '93', 'type': 'comparison_operator', 'children': ['94', '100'], 'value': 'is'}; {'id': '94', 'type': 'call', 'children': ['95', '98']}; {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}; {'id': '99', 'type': 'string', 'children': [], 'value': "'ErrorList'"}; {'id': '100', 'type': 'None', 'children': []}; {'id': '101', 'type': 'block', 'children': ['102', '130']}; {'id': '102', 'type': 'for_statement', 'children': ['103', '104', '114']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '104', 'type': 'call', 'children': ['105', '113']}; {'id': '105', 'type': 'attribute', 'children': ['106', '112']}; {'id': '106', 'type': 'call', 'children': ['107', '110']}; {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}; {'id': '111', 'type': 'string', 'children': [], 'value': "'ErrorList'"}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'getchildren'}; {'id': '113', 'type': 'argument_list', 'children': []}; {'id': '114', 'type': 'block', 'children': ['115']}; {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '120']}; {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}; {'id': '121', 'type': 'binary_operator', 'children': ['122', '123'], 'value': '%'}; {'id': '122', 'type': 'string', 'children': [], 'value': "'Error - %s: %s'"}; {'id': '123', 'type': 'tuple', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'tag'}; {'id': '127', 'type': 'attribute', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'err'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '130', 'type': 'return_statement', 'children': ['131']}; {'id': '131', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}; {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'attribute', 'children': ['139', '145']}; {'id': '139', 'type': 'call', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '143', 'type': 'argument_list', 'children': ['144']}; {'id': '144', 'type': 'string', 'children': [], 'value': "'Count'"}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}; {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'id_terms'}; {'id': '149', 'type': 'call', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'findall'}; {'id': '153', 'type': 'argument_list', 'children': ['154']}; {'id': '154', 'type': 'string', 'children': [], 'value': "'IdList/Id'"}; {'id': '155', 'type': 'if_statement', 'children': ['156', '159']}; {'id': '156', 'type': 'comparison_operator', 'children': ['157', '158'], 'value': 'is'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'id_terms'}; {'id': '158', 'type': 'None', 'children': []}; {'id': '159', 'type': 'block', 'children': ['160']}; {'id': '160', 'type': 'return_statement', 'children': ['161']}; {'id': '161', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}; {'id': '163', 'type': 'assignment', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'ids'}; {'id': '165', 'type': 'list_comprehension', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'idt'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '169', 'type': 'for_in_clause', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'idt'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'id_terms'}; {'id': '172', 'type': 'if_statement', 'children': ['173', '179']}; {'id': '173', 'type': 'comparison_operator', 'children': ['174', '175'], 'value': '!='}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '175', 'type': 'call', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '177', 'type': 'argument_list', 'children': ['178']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'ids'}; {'id': '179', 'type': 'block', 'children': ['180']}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}; {'id': '181', 'type': 'call', 'children': ['182', '185']}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '185', 'type': 'argument_list', 'children': ['186']}; {'id': '186', 'type': 'binary_operator', 'children': ['187', '190'], 'value': '%'}; {'id': '187', 'type': 'concatenated_string', 'children': ['188', '189']}; {'id': '188', 'type': 'string', 'children': [], 'value': "'Not all ids were retrieved for search %s;\\n'"}; {'id': '189', 'type': 'string', 'children': [], 'value': "'limited at %d.'"}; {'id': '190', 'type': 'tuple', 'children': ['191', '192']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'search_term'}; {'id': '192', 'type': 'subscript', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '194', 'type': 'string', 'children': [], 'value': "'retmax'"}; {'id': '195', 'type': 'return_statement', 'children': ['196']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'ids'}
def get_ids(search_term, **kwargs): use_text_word = kwargs.pop('use_text_word', True) if use_text_word: search_term += '[tw]' params = {'term': search_term, 'retmax': 100000, 'retstart': 0, 'db': 'pubmed', 'sort': 'pub+date'} params.update(kwargs) tree = send_request(pubmed_search, params) if tree is None: return [] if tree.find('ERROR') is not None: logger.error(tree.find('ERROR').text) return [] if tree.find('ErrorList') is not None: for err in tree.find('ErrorList').getchildren(): logger.error('Error - %s: %s' % (err.tag, err.text)) return [] count = int(tree.find('Count').text) id_terms = tree.findall('IdList/Id') if id_terms is None: return [] ids = [idt.text for idt in id_terms] if count != len(ids): logger.warning('Not all ids were retrieved for search %s;\n' 'limited at %d.' % (search_term, params['retmax'])) return ids
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_ids_for_gene'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'hgnc_name'}; {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '7', 'type': 'block', 'children': ['8', '17', '27', '36', '46', '59', '66', '74', '81', '107', '116', '123', '139']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'hgnc_id'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'hgnc_client'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'get_hgnc_id'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'hgnc_name'}; {'id': '17', 'type': 'if_statement', 'children': ['18', '21']}; {'id': '18', 'type': 'comparison_operator', 'children': ['19', '20'], 'value': 'is'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'hgnc_id'}; {'id': '20', 'type': 'None', 'children': []}; {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'raise_statement', 'children': ['23']}; {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'string', 'children': [], 'value': "'Invalid HGNC name.'"}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'entrez_id'}; {'id': '30', 'type': 'call', 'children': ['31', '34']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'hgnc_client'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'get_entrez_id'}; {'id': '34', 'type': 'argument_list', 'children': ['35']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'hgnc_id'}; {'id': '36', 'type': 'if_statement', 'children': ['37', '40']}; {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'is'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'entrez_id'}; {'id': '39', 'type': 'None', 'children': []}; {'id': '40', 'type': 'block', 'children': ['41']}; {'id': '41', 'type': 'raise_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'string', 'children': [], 'value': "'Entrez ID not found in HGNC table.'"}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '49', 'type': 'dictionary', 'children': ['50', '53', '56']}; {'id': '50', 'type': 'pair', 'children': ['51', '52']}; {'id': '51', 'type': 'string', 'children': [], 'value': "'db'"}; {'id': '52', 'type': 'string', 'children': [], 'value': "'gene'"}; {'id': '53', 'type': 'pair', 'children': ['54', '55']}; {'id': '54', 'type': 'string', 'children': [], 'value': "'retmode'"}; {'id': '55', 'type': 'string', 'children': [], 'value': "'xml'"}; {'id': '56', 'type': 'pair', 'children': ['57', '58']}; {'id': '57', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'entrez_id'}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '64']}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'send_request'}; {'id': '71', 'type': 'argument_list', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'pubmed_fetch'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '74', 'type': 'if_statement', 'children': ['75', '78']}; {'id': '75', 'type': 'comparison_operator', 'children': ['76', '77'], 'value': 'is'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '77', 'type': 'None', 'children': []}; {'id': '78', 'type': 'block', 'children': ['79']}; {'id': '79', 'type': 'return_statement', 'children': ['80']}; {'id': '80', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '81', 'type': 'if_statement', 'children': ['82', '90']}; {'id': '82', 'type': 'comparison_operator', 'children': ['83', '89'], 'value': 'is'}; {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '87', 'type': 'argument_list', 'children': ['88']}; {'id': '88', 'type': 'string', 'children': [], 'value': "'ERROR'"}; {'id': '89', 'type': 'None', 'children': []}; {'id': '90', 'type': 'block', 'children': ['91', '105']}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '96']}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}; {'id': '97', 'type': 'attribute', 'children': ['98', '104']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'find'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}; {'id': '103', 'type': 'string', 'children': [], 'value': "'ERROR'"}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '105', 'type': 'return_statement', 'children': ['106']}; {'id': '106', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'id_terms'}; {'id': '110', 'type': 'call', 'children': ['111', '114']}; {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'tree'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'findall'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}; {'id': '115', 'type': 'string', 'children': [], 'value': "'.//PubMedId'"}; {'id': '116', 'type': 'if_statement', 'children': ['117', '120']}; {'id': '117', 'type': 'comparison_operator', 'children': ['118', '119'], 'value': 'is'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'id_terms'}; {'id': '119', 'type': 'None', 'children': []}; {'id': '120', 'type': 'block', 'children': ['121']}; {'id': '121', 'type': 'return_statement', 'children': ['122']}; {'id': '122', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'ids'}; {'id': '126', 'type': 'call', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}; {'id': '129', 'type': 'call', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '131', 'type': 'argument_list', 'children': ['132']}; {'id': '132', 'type': 'list_comprehension', 'children': ['133', '136']}; {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'idt'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '136', 'type': 'for_in_clause', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'idt'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'id_terms'}; {'id': '139', 'type': 'return_statement', 'children': ['140']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'ids'}
def get_ids_for_gene(hgnc_name, **kwargs): hgnc_id = hgnc_client.get_hgnc_id(hgnc_name) if hgnc_id is None: raise ValueError('Invalid HGNC name.') entrez_id = hgnc_client.get_entrez_id(hgnc_id) if entrez_id is None: raise ValueError('Entrez ID not found in HGNC table.') params = {'db': 'gene', 'retmode': 'xml', 'id': entrez_id} params.update(kwargs) tree = send_request(pubmed_fetch, params) if tree is None: return [] if tree.find('ERROR') is not None: logger.error(tree.find('ERROR').text) return [] id_terms = tree.findall('.//PubMedId') if id_terms is None: return [] ids = list(set([idt.text for idt in id_terms])) return ids
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_im'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'force_update'}; {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '21', '32', '123', '134', '289', '310', '317', '330', '342', '408']}; {'id': '9', 'type': 'if_statement', 'children': ['10', '16']}; {'id': '10', 'type': 'boolean_operator', 'children': ['11', '14'], 'value': 'and'}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': '_im'}; {'id': '14', 'type': 'not_operator', 'children': ['15']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'force_update'}; {'id': '16', 'type': 'block', 'children': ['17']}; {'id': '17', 'type': 'return_statement', 'children': ['18']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '_im'}; {'id': '21', 'type': 'if_statement', 'children': ['22', '26']}; {'id': '22', 'type': 'not_operator', 'children': ['23']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '26', 'type': 'block', 'children': ['27']}; {'id': '27', 'type': 'raise_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'string', 'children': [], 'value': '"Cannot get influence map if there is no model."'}; {'id': '32', 'type': 'function_definition', 'children': ['33', '34', '36']}; {'id': '33', 'type': 'function_name', 'children': [], 'value': 'add_obs_for_agent'}; {'id': '34', 'type': 'parameters', 'children': ['35']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '36', 'type': 'block', 'children': ['37', '52', '68', '72', '121']}; {'id': '37', 'type': 'expression_statement', 'children': ['38']}; {'id': '38', 'type': 'assignment', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'obj_mps'}; {'id': '40', 'type': 'call', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'pa'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'grounded_monomer_patterns'}; {'id': '47', 'type': 'argument_list', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '52', 'type': 'if_statement', 'children': ['53', '55']}; {'id': '53', 'type': 'not_operator', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'obj_mps'}; {'id': '55', 'type': 'block', 'children': ['56', '67']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'binary_operator', 'children': ['63', '66'], 'value': '%'}; {'id': '63', 'type': 'concatenated_string', 'children': ['64', '65']}; {'id': '64', 'type': 'string', 'children': [], 'value': "'No monomer patterns found in model for agent %s, '"}; {'id': '65', 'type': 'string', 'children': [], 'value': "'skipping'"}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'agent'}; {'id': '67', 'type': 'return_statement', 'children': []}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'obs_list'}; {'id': '71', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '72', 'type': 'for_statement', 'children': ['73', '74', '75']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'obj_mp'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'obj_mps'}; {'id': '75', 'type': 'block', 'children': ['76', '85', '96', '103']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}; {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'obs_name'}; {'id': '79', 'type': 'binary_operator', 'children': ['80', '84'], 'value': '+'}; {'id': '80', 'type': 'call', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': '_monomer_pattern_label'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'obj_mp'}; {'id': '84', 'type': 'string', 'children': [], 'value': "'_obs'"}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'obj_obs'}; {'id': '88', 'type': 'call', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'Observable'}; {'id': '90', 'type': 'argument_list', 'children': ['91', '92', '93']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'obs_name'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'obj_mp'}; {'id': '93', 'type': 'keyword_argument', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': '_export'}; {'id': '95', 'type': 'False', 'children': []}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}; {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'obs_list'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'obs_name'}; {'id': '103', 'type': 'try_statement', 'children': ['104', '114']}; {'id': '104', 'type': 'block', 'children': ['105']}; {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'call', 'children': ['107', '112']}; {'id': '107', 'type': 'attribute', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'add_component'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'obj_obs'}; {'id': '114', 'type': 'except_clause', 'children': ['115', '119']}; {'id': '115', 'type': 'as_pattern', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'ComponentDuplicateNameError'}; {'id': '117', 'type': 'as_pattern_target', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '119', 'type': 'block', 'children': ['120']}; {'id': '120', 'type': 'pass_statement', 'children': []}; {'id': '121', 'type': 'return_statement', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'obs_list'}; {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '130']}; {'id': '125', 'type': 'attribute', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'observables'}; {'id': '130', 'type': 'call', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'ComponentSet'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}; {'id': '133', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '134', 'type': 'for_statement', 'children': ['135', '136', '139']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'statements'}; {'id': '139', 'type': 'block', 'children': ['140']}; {'id': '140', 'type': 'if_statement', 'children': ['141', '146', '199', '239', '263']}; {'id': '141', 'type': 'call', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '143', 'type': 'argument_list', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'Modification'}; {'id': '146', 'type': 'block', 'children': ['147', '155', '168', '184', '191']}; {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'mod_condition_name'}; {'id': '150', 'type': 'subscript', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'modclass_to_modtype'}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '155', 'type': 'if_statement', 'children': ['156', '161']}; {'id': '156', 'type': 'call', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '158', 'type': 'argument_list', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'RemoveModification'}; {'id': '161', 'type': 'block', 'children': ['162']}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}; {'id': '163', 'type': 'assignment', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'mod_condition_name'}; {'id': '165', 'type': 'subscript', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'modtype_to_inverse'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'mod_condition_name'}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}; {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'modified_sub'}; {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': '_add_modification_to_agent'}; {'id': '173', 'type': 'argument_list', 'children': ['174', '177', '178', '181']}; {'id': '174', 'type': 'attribute', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'sub'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'mod_condition_name'}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'residue'}; {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'position'}; {'id': '184', 'type': 'expression_statement', 'children': ['185']}; {'id': '185', 'type': 'assignment', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'obs_list'}; {'id': '187', 'type': 'call', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'add_obs_for_agent'}; {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'modified_sub'}; {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '198']}; {'id': '193', 'type': 'subscript', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'stmt_to_obs'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'obs_list'}; {'id': '199', 'type': 'elif_clause', 'children': ['200', '205']}; {'id': '200', 'type': 'call', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '202', 'type': 'argument_list', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'RegulateActivity'}; {'id': '205', 'type': 'block', 'children': ['206', '224', '231']}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}; {'id': '207', 'type': 'assignment', 'children': ['208', '211', '212']}; {'id': '208', 'type': 'pattern_list', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'regulated_obj'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'polarity'}; {'id': '211', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '212', 'type': 'call', 'children': ['213', '214']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': '_add_activity_to_agent'}; {'id': '214', 'type': 'argument_list', 'children': ['215', '218', '221']}; {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'obj_activity'}; {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'is_activation'}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}; {'id': '225', 'type': 'assignment', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'obs_list'}; {'id': '227', 'type': 'call', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'add_obs_for_agent'}; {'id': '229', 'type': 'argument_list', 'children': ['230']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'regulated_obj'}; {'id': '231', 'type': 'expression_statement', 'children': ['232']}; {'id': '232', 'type': 'assignment', 'children': ['233', '238']}; {'id': '233', 'type': 'subscript', 'children': ['234', '237']}; {'id': '234', 'type': 'attribute', 'children': ['235', '236']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'stmt_to_obs'}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'obs_list'}; {'id': '239', 'type': 'elif_clause', 'children': ['240', '245']}; {'id': '240', 'type': 'call', 'children': ['241', '242']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '242', 'type': 'argument_list', 'children': ['243', '244']}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'RegulateAmount'}; {'id': '245', 'type': 'block', 'children': ['246', '255']}; {'id': '246', 'type': 'expression_statement', 'children': ['247']}; {'id': '247', 'type': 'assignment', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'obs_list'}; {'id': '249', 'type': 'call', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'add_obs_for_agent'}; {'id': '251', 'type': 'argument_list', 'children': ['252']}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '255', 'type': 'expression_statement', 'children': ['256']}; {'id': '256', 'type': 'assignment', 'children': ['257', '262']}; {'id': '257', 'type': 'subscript', 'children': ['258', '261']}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'stmt_to_obs'}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'obs_list'}; {'id': '263', 'type': 'elif_clause', 'children': ['264', '269']}; {'id': '264', 'type': 'call', 'children': ['265', '266']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '266', 'type': 'argument_list', 'children': ['267', '268']}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'Influence'}; {'id': '269', 'type': 'block', 'children': ['270', '281']}; {'id': '270', 'type': 'expression_statement', 'children': ['271']}; {'id': '271', 'type': 'assignment', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'obs_list'}; {'id': '273', 'type': 'call', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'add_obs_for_agent'}; {'id': '275', 'type': 'argument_list', 'children': ['276']}; {'id': '276', 'type': 'attribute', 'children': ['277', '280']}; {'id': '277', 'type': 'attribute', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'concept'}; {'id': '281', 'type': 'expression_statement', 'children': ['282']}; {'id': '282', 'type': 'assignment', 'children': ['283', '288']}; {'id': '283', 'type': 'subscript', 'children': ['284', '287']}; {'id': '284', 'type': 'attribute', 'children': ['285', '286']}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'stmt_to_obs'}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'obs_list'}; {'id': '289', 'type': 'for_statement', 'children': ['290', '291', '294']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'ag'}; {'id': '291', 'type': 'attribute', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'agent_obs'}; {'id': '294', 'type': 'block', 'children': ['295', '302']}; {'id': '295', 'type': 'expression_statement', 'children': ['296']}; {'id': '296', 'type': 'assignment', 'children': ['297', '298']}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'obs_list'}; {'id': '298', 'type': 'call', 'children': ['299', '300']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'add_obs_for_agent'}; {'id': '300', 'type': 'argument_list', 'children': ['301']}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'ag'}; {'id': '302', 'type': 'expression_statement', 'children': ['303']}; {'id': '303', 'type': 'assignment', 'children': ['304', '309']}; {'id': '304', 'type': 'subscript', 'children': ['305', '308']}; {'id': '305', 'type': 'attribute', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'agent_to_obs'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'ag'}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'obs_list'}; {'id': '310', 'type': 'expression_statement', 'children': ['311']}; {'id': '311', 'type': 'call', 'children': ['312', '315']}; {'id': '312', 'type': 'attribute', 'children': ['313', '314']}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '315', 'type': 'argument_list', 'children': ['316']}; {'id': '316', 'type': 'string', 'children': [], 'value': '"Generating influence map"'}; {'id': '317', 'type': 'expression_statement', 'children': ['318']}; {'id': '318', 'type': 'assignment', 'children': ['319', '322']}; {'id': '319', 'type': 'attribute', 'children': ['320', '321']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '321', 'type': 'identifier', 'children': [], 'value': '_im'}; {'id': '322', 'type': 'call', 'children': ['323', '326']}; {'id': '323', 'type': 'attribute', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'generate_im'}; {'id': '326', 'type': 'argument_list', 'children': ['327']}; {'id': '327', 'type': 'attribute', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '330', 'type': 'expression_statement', 'children': ['331']}; {'id': '331', 'type': 'assignment', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'node_attributes'}; {'id': '333', 'type': 'call', 'children': ['334', '337']}; {'id': '334', 'type': 'attribute', 'children': ['335', '336']}; {'id': '335', 'type': 'identifier', 'children': [], 'value': 'nx'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'get_node_attributes'}; {'id': '337', 'type': 'argument_list', 'children': ['338', '341']}; {'id': '338', 'type': 'attribute', 'children': ['339', '340']}; {'id': '339', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': '_im'}; {'id': '341', 'type': 'string', 'children': [], 'value': "'node_type'"}; {'id': '342', 'type': 'for_statement', 'children': ['343', '344', '349']}; {'id': '343', 'type': 'identifier', 'children': [], 'value': 'rule'}; {'id': '344', 'type': 'attribute', 'children': ['345', '348']}; {'id': '345', 'type': 'attribute', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '347', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'rules'}; {'id': '349', 'type': 'block', 'children': ['350', '354', '398']}; {'id': '350', 'type': 'expression_statement', 'children': ['351']}; {'id': '351', 'type': 'assignment', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 'obs_list'}; {'id': '353', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '354', 'type': 'for_statement', 'children': ['355', '356', '366']}; {'id': '355', 'type': 'identifier', 'children': [], 'value': 'neighb'}; {'id': '356', 'type': 'call', 'children': ['357', '362']}; {'id': '357', 'type': 'attribute', 'children': ['358', '361']}; {'id': '358', 'type': 'attribute', 'children': ['359', '360']}; {'id': '359', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '360', 'type': 'identifier', 'children': [], 'value': '_im'}; {'id': '361', 'type': 'identifier', 'children': [], 'value': 'neighbors'}; {'id': '362', 'type': 'argument_list', 'children': ['363']}; {'id': '363', 'type': 'attribute', 'children': ['364', '365']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'rule'}; {'id': '365', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '366', 'type': 'block', 'children': ['367', '375', '389']}; {'id': '367', 'type': 'if_statement', 'children': ['368', '373']}; {'id': '368', 'type': 'comparison_operator', 'children': ['369', '372'], 'value': '!='}; {'id': '369', 'type': 'subscript', 'children': ['370', '371']}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'node_attributes'}; {'id': '371', 'type': 'identifier', 'children': [], 'value': 'neighb'}; {'id': '372', 'type': 'string', 'children': [], 'value': "'variable'"}; {'id': '373', 'type': 'block', 'children': ['374']}; {'id': '374', 'type': 'continue_statement', 'children': []}; {'id': '375', 'type': 'expression_statement', 'children': ['376']}; {'id': '376', 'type': 'assignment', 'children': ['377', '378']}; {'id': '377', 'type': 'identifier', 'children': [], 'value': 'edge_sign'}; {'id': '378', 'type': 'call', 'children': ['379', '380']}; {'id': '379', 'type': 'identifier', 'children': [], 'value': '_get_edge_sign'}; {'id': '380', 'type': 'argument_list', 'children': ['381', '384']}; {'id': '381', 'type': 'attribute', 'children': ['382', '383']}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '383', 'type': 'identifier', 'children': [], 'value': '_im'}; {'id': '384', 'type': 'tuple', 'children': ['385', '388']}; {'id': '385', 'type': 'attribute', 'children': ['386', '387']}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'rule'}; {'id': '387', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'neighb'}; {'id': '389', 'type': 'expression_statement', 'children': ['390']}; {'id': '390', 'type': 'call', 'children': ['391', '394']}; {'id': '391', 'type': 'attribute', 'children': ['392', '393']}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'obs_list'}; {'id': '393', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '394', 'type': 'argument_list', 'children': ['395']}; {'id': '395', 'type': 'tuple', 'children': ['396', '397']}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'neighb'}; {'id': '397', 'type': 'identifier', 'children': [], 'value': 'edge_sign'}; {'id': '398', 'type': 'expression_statement', 'children': ['399']}; {'id': '399', 'type': 'assignment', 'children': ['400', '407']}; {'id': '400', 'type': 'subscript', 'children': ['401', '404']}; {'id': '401', 'type': 'attribute', 'children': ['402', '403']}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '403', 'type': 'identifier', 'children': [], 'value': 'rule_obs_dict'}; {'id': '404', 'type': 'attribute', 'children': ['405', '406']}; {'id': '405', 'type': 'identifier', 'children': [], 'value': 'rule'}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '407', 'type': 'identifier', 'children': [], 'value': 'obs_list'}; {'id': '408', 'type': 'return_statement', 'children': ['409']}; {'id': '409', 'type': 'attribute', 'children': ['410', '411']}; {'id': '410', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '411', 'type': 'identifier', 'children': [], 'value': '_im'}
def get_im(self, force_update=False): if self._im and not force_update: return self._im if not self.model: raise Exception("Cannot get influence map if there is no model.") def add_obs_for_agent(agent): obj_mps = list(pa.grounded_monomer_patterns(self.model, agent)) if not obj_mps: logger.debug('No monomer patterns found in model for agent %s, ' 'skipping' % agent) return obs_list = [] for obj_mp in obj_mps: obs_name = _monomer_pattern_label(obj_mp) + '_obs' obj_obs = Observable(obs_name, obj_mp, _export=False) obs_list.append(obs_name) try: self.model.add_component(obj_obs) except ComponentDuplicateNameError as e: pass return obs_list self.model.observables = ComponentSet([]) for stmt in self.statements: if isinstance(stmt, Modification): mod_condition_name = modclass_to_modtype[stmt.__class__] if isinstance(stmt, RemoveModification): mod_condition_name = modtype_to_inverse[mod_condition_name] modified_sub = _add_modification_to_agent(stmt.sub, mod_condition_name, stmt.residue, stmt.position) obs_list = add_obs_for_agent(modified_sub) self.stmt_to_obs[stmt] = obs_list elif isinstance(stmt, RegulateActivity): regulated_obj, polarity = \ _add_activity_to_agent(stmt.obj, stmt.obj_activity, stmt.is_activation) obs_list = add_obs_for_agent(regulated_obj) self.stmt_to_obs[stmt] = obs_list elif isinstance(stmt, RegulateAmount): obs_list = add_obs_for_agent(stmt.obj) self.stmt_to_obs[stmt] = obs_list elif isinstance(stmt, Influence): obs_list = add_obs_for_agent(stmt.obj.concept) self.stmt_to_obs[stmt] = obs_list for ag in self.agent_obs: obs_list = add_obs_for_agent(ag) self.agent_to_obs[ag] = obs_list logger.info("Generating influence map") self._im = self.generate_im(self.model) node_attributes = nx.get_node_attributes(self._im, 'node_type') for rule in self.model.rules: obs_list = [] for neighb in self._im.neighbors(rule.name): if node_attributes[neighb] != 'variable': continue edge_sign = _get_edge_sign(self._im, (rule.name, neighb)) obs_list.append((neighb, edge_sign)) self.rule_obs_dict[rule.name] = obs_list return self._im
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'check_statement'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'max_paths'}; {'id': '8', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'max_path_length'}; {'id': '11', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '12', 'type': 'block', 'children': ['13', '19', '39', '116', '126', '177', '185', '206', '238']}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'get_im'}; {'id': '18', 'type': 'argument_list', 'children': []}; {'id': '19', 'type': 'if_statement', 'children': ['20', '30']}; {'id': '20', 'type': 'not_operator', 'children': ['21']}; {'id': '21', 'type': 'call', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '25', 'type': 'tuple', 'children': ['26', '27', '28', '29']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'Modification'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'RegulateAmount'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'RegulateActivity'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'Influence'}; {'id': '30', 'type': 'block', 'children': ['31']}; {'id': '31', 'type': 'return_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'PathResult'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36', '37', '38']}; {'id': '35', 'type': 'False', 'children': []}; {'id': '36', 'type': 'string', 'children': [], 'value': "'STATEMENT_TYPE_NOT_HANDLED'"}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'max_paths'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'max_path_length'}; {'id': '39', 'type': 'if_statement', 'children': ['40', '45', '58', '75', '94']}; {'id': '40', 'type': 'call', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '42', 'type': 'argument_list', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'Modification'}; {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'target_polarity'}; {'id': '49', 'type': 'conditional_expression', 'children': ['50', '52', '57'], 'value': 'if'}; {'id': '50', 'type': 'unary_operator', 'children': ['51'], 'value': '-'}; {'id': '51', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '54', 'type': 'argument_list', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'RemoveModification'}; {'id': '57', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '58', 'type': 'elif_clause', 'children': ['59', '64']}; {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '61', 'type': 'argument_list', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'RegulateActivity'}; {'id': '64', 'type': 'block', 'children': ['65']}; {'id': '65', 'type': 'expression_statement', 'children': ['66']}; {'id': '66', 'type': 'assignment', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'target_polarity'}; {'id': '68', 'type': 'conditional_expression', 'children': ['69', '70', '73'], 'value': 'if'}; {'id': '69', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'is_activation'}; {'id': '73', 'type': 'unary_operator', 'children': ['74'], 'value': '-'}; {'id': '74', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '75', 'type': 'elif_clause', 'children': ['76', '81']}; {'id': '76', 'type': 'call', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '78', 'type': 'argument_list', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'RegulateAmount'}; {'id': '81', 'type': 'block', 'children': ['82']}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}; {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'target_polarity'}; {'id': '85', 'type': 'conditional_expression', 'children': ['86', '88', '93'], 'value': 'if'}; {'id': '86', 'type': 'unary_operator', 'children': ['87'], 'value': '-'}; {'id': '87', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '88', 'type': 'call', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '90', 'type': 'argument_list', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'DecreaseAmount'}; {'id': '93', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '94', 'type': 'elif_clause', 'children': ['95', '100']}; {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '97', 'type': 'argument_list', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'Influence'}; {'id': '100', 'type': 'block', 'children': ['101']}; {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'target_polarity'}; {'id': '104', 'type': 'conditional_expression', 'children': ['105', '107', '115'], 'value': 'if'}; {'id': '105', 'type': 'unary_operator', 'children': ['106'], 'value': '-'}; {'id': '106', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '107', 'type': 'comparison_operator', 'children': ['108', '113'], 'value': '=='}; {'id': '108', 'type': 'call', 'children': ['109', '112']}; {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'overall_polarity'}; {'id': '112', 'type': 'argument_list', 'children': []}; {'id': '113', 'type': 'unary_operator', 'children': ['114'], 'value': '-'}; {'id': '114', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '115', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}; {'id': '117', 'type': 'assignment', 'children': ['118', '121']}; {'id': '118', 'type': 'pattern_list', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'subj'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '121', 'type': 'call', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'agent_list'}; {'id': '125', 'type': 'argument_list', 'children': []}; {'id': '126', 'type': 'if_statement', 'children': ['127', '130', '170']}; {'id': '127', 'type': 'comparison_operator', 'children': ['128', '129'], 'value': 'is'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'subj'}; {'id': '129', 'type': 'None', 'children': []}; {'id': '130', 'type': 'block', 'children': ['131', '149']}; {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'subj_mps'}; {'id': '134', 'type': 'call', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '136', 'type': 'argument_list', 'children': ['137']}; {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'pa'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'grounded_monomer_patterns'}; {'id': '141', 'type': 'argument_list', 'children': ['142', '145', '146']}; {'id': '142', 'type': 'attribute', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'subj'}; {'id': '146', 'type': 'keyword_argument', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'ignore_activities'}; {'id': '148', 'type': 'True', 'children': []}; {'id': '149', 'type': 'if_statement', 'children': ['150', '152']}; {'id': '150', 'type': 'not_operator', 'children': ['151']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'subj_mps'}; {'id': '152', 'type': 'block', 'children': ['153', '162']}; {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'call', 'children': ['155', '158']}; {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}; {'id': '159', 'type': 'binary_operator', 'children': ['160', '161'], 'value': '%'}; {'id': '160', 'type': 'string', 'children': [], 'value': "'No monomers found corresponding to agent %s'"}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'subj'}; {'id': '162', 'type': 'return_statement', 'children': ['163']}; {'id': '163', 'type': 'call', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'PathResult'}; {'id': '165', 'type': 'argument_list', 'children': ['166', '167', '168', '169']}; {'id': '166', 'type': 'False', 'children': []}; {'id': '167', 'type': 'string', 'children': [], 'value': "'SUBJECT_MONOMERS_NOT_FOUND'"}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'max_paths'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'max_path_length'}; {'id': '170', 'type': 'else_clause', 'children': ['171']}; {'id': '171', 'type': 'block', 'children': ['172']}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}; {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'subj_mps'}; {'id': '175', 'type': 'list', 'children': ['176'], 'value': '[None]'}; {'id': '176', 'type': 'None', 'children': []}; {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'assignment', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'obs_names'}; {'id': '180', 'type': 'subscript', 'children': ['181', '184']}; {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'stmt_to_obs'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '185', 'type': 'if_statement', 'children': ['186', '188']}; {'id': '186', 'type': 'not_operator', 'children': ['187']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'obs_names'}; {'id': '188', 'type': 'block', 'children': ['189', '198']}; {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'call', 'children': ['191', '194']}; {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}; {'id': '195', 'type': 'binary_operator', 'children': ['196', '197'], 'value': '%'}; {'id': '196', 'type': 'string', 'children': [], 'value': '"No observables for stmt %s, returning False"'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'stmt'}; {'id': '198', 'type': 'return_statement', 'children': ['199']}; {'id': '199', 'type': 'call', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'PathResult'}; {'id': '201', 'type': 'argument_list', 'children': ['202', '203', '204', '205']}; {'id': '202', 'type': 'False', 'children': []}; {'id': '203', 'type': 'string', 'children': [], 'value': "'OBSERVABLES_NOT_FOUND'"}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'max_paths'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'max_path_length'}; {'id': '206', 'type': 'for_statement', 'children': ['207', '210', '217']}; {'id': '207', 'type': 'pattern_list', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'subj_mp'}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'obs_name'}; {'id': '210', 'type': 'call', 'children': ['211', '214']}; {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'itertools'}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'product'}; {'id': '214', 'type': 'argument_list', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'subj_mps'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'obs_names'}; {'id': '217', 'type': 'block', 'children': ['218', '231']}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}; {'id': '219', 'type': 'assignment', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '221', 'type': 'call', 'children': ['222', '225']}; {'id': '222', 'type': 'attribute', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': '_find_im_paths'}; {'id': '225', 'type': 'argument_list', 'children': ['226', '227', '228', '229', '230']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'subj_mp'}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'obs_name'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'target_polarity'}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'max_paths'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'max_path_length'}; {'id': '231', 'type': 'if_statement', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'path_found'}; {'id': '235', 'type': 'block', 'children': ['236']}; {'id': '236', 'type': 'return_statement', 'children': ['237']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '238', 'type': 'return_statement', 'children': ['239']}; {'id': '239', 'type': 'call', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'PathResult'}; {'id': '241', 'type': 'argument_list', 'children': ['242', '243', '244', '245']}; {'id': '242', 'type': 'False', 'children': []}; {'id': '243', 'type': 'string', 'children': [], 'value': "'NO_PATHS_FOUND'"}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'max_paths'}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'max_path_length'}
def check_statement(self, stmt, max_paths=1, max_path_length=5): self.get_im() if not isinstance(stmt, (Modification, RegulateAmount, RegulateActivity, Influence)): return PathResult(False, 'STATEMENT_TYPE_NOT_HANDLED', max_paths, max_path_length) if isinstance(stmt, Modification): target_polarity = -1 if isinstance(stmt, RemoveModification) else 1 elif isinstance(stmt, RegulateActivity): target_polarity = 1 if stmt.is_activation else -1 elif isinstance(stmt, RegulateAmount): target_polarity = -1 if isinstance(stmt, DecreaseAmount) else 1 elif isinstance(stmt, Influence): target_polarity = -1 if stmt.overall_polarity() == -1 else 1 subj, obj = stmt.agent_list() if subj is not None: subj_mps = list(pa.grounded_monomer_patterns(self.model, subj, ignore_activities=True)) if not subj_mps: logger.debug('No monomers found corresponding to agent %s' % subj) return PathResult(False, 'SUBJECT_MONOMERS_NOT_FOUND', max_paths, max_path_length) else: subj_mps = [None] obs_names = self.stmt_to_obs[stmt] if not obs_names: logger.debug("No observables for stmt %s, returning False" % stmt) return PathResult(False, 'OBSERVABLES_NOT_FOUND', max_paths, max_path_length) for subj_mp, obs_name in itertools.product(subj_mps, obs_names): result = self._find_im_paths(subj_mp, obs_name, target_polarity, max_paths, max_path_length) if result.path_found: return result return PathResult(False, 'NO_PATHS_FOUND', max_paths, max_path_length)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '16']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'score_paths'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'paths'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'agents_values'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'loss_of_function'}; {'id': '9', 'type': 'False', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'sigma'}; {'id': '12', 'type': 'float', 'children': [], 'value': '0.15'}; {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'include_final_node'}; {'id': '15', 'type': 'False', 'children': []}; {'id': '16', 'type': 'block', 'children': ['17', '32', '36', '69', '73', '279', '290', '308', '326']}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'obs_model'}; {'id': '20', 'type': 'lambda', 'children': ['21', '23']}; {'id': '21', 'type': 'lambda_parameters', 'children': ['22']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '23', 'type': 'call', 'children': ['24', '29']}; {'id': '24', 'type': 'attribute', 'children': ['25', '28']}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'scipy'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'stats'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'norm'}; {'id': '29', 'type': 'argument_list', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'sigma'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'obs_dict'}; {'id': '35', 'type': 'dictionary', 'children': []}; {'id': '36', 'type': 'for_statement', 'children': ['37', '40', '45']}; {'id': '37', 'type': 'pattern_list', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'ag'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'agents_values'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '44', 'type': 'argument_list', 'children': []}; {'id': '45', 'type': 'block', 'children': ['46', '54']}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'obs_list'}; {'id': '49', 'type': 'subscript', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'agent_to_obs'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'ag'}; {'id': '54', 'type': 'if_statement', 'children': ['55', '58']}; {'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': 'is'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'obs_list'}; {'id': '57', 'type': 'None', 'children': []}; {'id': '58', 'type': 'block', 'children': ['59']}; {'id': '59', 'type': 'for_statement', 'children': ['60', '61', '62']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'obs'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'obs_list'}; {'id': '62', 'type': 'block', 'children': ['63']}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '68']}; {'id': '65', 'type': 'subscript', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'obs_dict'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'obs'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'path_scores'}; {'id': '72', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '73', 'type': 'for_statement', 'children': ['74', '75', '76']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'paths'}; {'id': '76', 'type': 'block', 'children': ['77', '84', '91', '98', '102', '111', '263', '272']}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}; {'id': '83', 'type': 'string', 'children': [], 'value': "'------'"}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}; {'id': '85', 'type': 'call', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'string', 'children': [], 'value': '"Scoring path:"'}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '96']}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '96', 'type': 'argument_list', 'children': ['97']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'assignment', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'path_score'}; {'id': '101', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'last_path_node_index'}; {'id': '105', 'type': 'conditional_expression', 'children': ['106', '108', '109'], 'value': 'if'}; {'id': '106', 'type': 'unary_operator', 'children': ['107'], 'value': '-'}; {'id': '107', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'include_final_node'}; {'id': '109', 'type': 'unary_operator', 'children': ['110'], 'value': '-'}; {'id': '110', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '111', 'type': 'for_statement', 'children': ['112', '115', '120']}; {'id': '112', 'type': 'pattern_list', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'sign'}; {'id': '115', 'type': 'subscript', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '117', 'type': 'slice', 'children': ['118', '119']}; {'id': '118', 'type': 'colon', 'children': []}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'last_path_node_index'}; {'id': '120', 'type': 'block', 'children': ['121', '218']}; {'id': '121', 'type': 'for_statement', 'children': ['122', '125', '130']}; {'id': '122', 'type': 'pattern_list', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'affected_obs'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'rule_obs_sign'}; {'id': '125', 'type': 'subscript', 'children': ['126', '129']}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'rule_obs_dict'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '130', 'type': 'block', 'children': ['131', '139', '147', '160', '169']}; {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'flip_polarity'}; {'id': '134', 'type': 'conditional_expression', 'children': ['135', '137', '138'], 'value': 'if'}; {'id': '135', 'type': 'unary_operator', 'children': ['136'], 'value': '-'}; {'id': '136', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'loss_of_function'}; {'id': '138', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'pred_sign'}; {'id': '142', 'type': 'binary_operator', 'children': ['143', '146'], 'value': '*'}; {'id': '143', 'type': 'binary_operator', 'children': ['144', '145'], 'value': '*'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'sign'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'rule_obs_sign'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'flip_polarity'}; {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'call', 'children': ['149', '152']}; {'id': '149', 'type': 'attribute', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '152', 'type': 'argument_list', 'children': ['153']}; {'id': '153', 'type': 'binary_operator', 'children': ['154', '155'], 'value': '%'}; {'id': '154', 'type': 'string', 'children': [], 'value': "'%s %s: effect %s %s'"}; {'id': '155', 'type': 'tuple', 'children': ['156', '157', '158', '159']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'sign'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'affected_obs'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'pred_sign'}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}; {'id': '161', 'type': 'assignment', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'measured_val'}; {'id': '163', 'type': 'call', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'obs_dict'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'affected_obs'}; {'id': '169', 'type': 'if_statement', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'measured_val'}; {'id': '171', 'type': 'block', 'children': ['172', '203', '214']}; {'id': '172', 'type': 'if_statement', 'children': ['173', '176', '189']}; {'id': '173', 'type': 'comparison_operator', 'children': ['174', '175'], 'value': '<='}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'pred_sign'}; {'id': '175', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '176', 'type': 'block', 'children': ['177']}; {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'assignment', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'prob_correct'}; {'id': '180', 'type': 'call', 'children': ['181', '187']}; {'id': '181', 'type': 'attribute', 'children': ['182', '186']}; {'id': '182', 'type': 'call', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'obs_model'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'measured_val'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'logcdf'}; {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '189', 'type': 'else_clause', 'children': ['190']}; {'id': '190', 'type': 'block', 'children': ['191']}; {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'prob_correct'}; {'id': '194', 'type': 'call', 'children': ['195', '201']}; {'id': '195', 'type': 'attribute', 'children': ['196', '200']}; {'id': '196', 'type': 'call', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'obs_model'}; {'id': '198', 'type': 'argument_list', 'children': ['199']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'measured_val'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'logsf'}; {'id': '201', 'type': 'argument_list', 'children': ['202']}; {'id': '202', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'call', 'children': ['205', '208']}; {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}; {'id': '209', 'type': 'binary_operator', 'children': ['210', '211'], 'value': '%'}; {'id': '210', 'type': 'string', 'children': [], 'value': "'Actual: %s, Log Probability: %s'"}; {'id': '211', 'type': 'tuple', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'measured_val'}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'prob_correct'}; {'id': '214', 'type': 'expression_statement', 'children': ['215']}; {'id': '215', 'type': 'augmented_assignment', 'children': ['216', '217'], 'value': '+='}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'path_score'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'prob_correct'}; {'id': '218', 'type': 'if_statement', 'children': ['219', '225']}; {'id': '219', 'type': 'not_operator', 'children': ['220']}; {'id': '220', 'type': 'subscript', 'children': ['221', '224']}; {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'rule_obs_dict'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '225', 'type': 'block', 'children': ['226', '237', '249', '259']}; {'id': '226', 'type': 'expression_statement', 'children': ['227']}; {'id': '227', 'type': 'call', 'children': ['228', '231']}; {'id': '228', 'type': 'attribute', 'children': ['229', '230']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '231', 'type': 'argument_list', 'children': ['232']}; {'id': '232', 'type': 'binary_operator', 'children': ['233', '234'], 'value': '%'}; {'id': '233', 'type': 'string', 'children': [], 'value': "'%s %s'"}; {'id': '234', 'type': 'tuple', 'children': ['235', '236']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'sign'}; {'id': '237', 'type': 'expression_statement', 'children': ['238']}; {'id': '238', 'type': 'assignment', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'prob_correct'}; {'id': '240', 'type': 'call', 'children': ['241', '247']}; {'id': '241', 'type': 'attribute', 'children': ['242', '246']}; {'id': '242', 'type': 'call', 'children': ['243', '244']}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'obs_model'}; {'id': '244', 'type': 'argument_list', 'children': ['245']}; {'id': '245', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'logcdf'}; {'id': '247', 'type': 'argument_list', 'children': ['248']}; {'id': '248', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '249', 'type': 'expression_statement', 'children': ['250']}; {'id': '250', 'type': 'call', 'children': ['251', '254']}; {'id': '251', 'type': 'attribute', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '254', 'type': 'argument_list', 'children': ['255']}; {'id': '255', 'type': 'binary_operator', 'children': ['256', '257'], 'value': '%'}; {'id': '256', 'type': 'string', 'children': [], 'value': "'Unmeasured node, Log Probability: %s'"}; {'id': '257', 'type': '()', 'children': ['258']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'prob_correct'}; {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'augmented_assignment', 'children': ['261', '262'], 'value': '+='}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'path_score'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'prob_correct'}; {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'call', 'children': ['265', '268']}; {'id': '265', 'type': 'attribute', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '268', 'type': 'argument_list', 'children': ['269']}; {'id': '269', 'type': 'binary_operator', 'children': ['270', '271'], 'value': '%'}; {'id': '270', 'type': 'string', 'children': [], 'value': '"Path score: %s"'}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'path_score'}; {'id': '272', 'type': 'expression_statement', 'children': ['273']}; {'id': '273', 'type': 'call', 'children': ['274', '277']}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'path_scores'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '277', 'type': 'argument_list', 'children': ['278']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'path_score'}; {'id': '279', 'type': 'expression_statement', 'children': ['280']}; {'id': '280', 'type': 'assignment', 'children': ['281', '282']}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'path_tuples'}; {'id': '282', 'type': 'call', 'children': ['283', '284']}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '284', 'type': 'argument_list', 'children': ['285']}; {'id': '285', 'type': 'call', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '287', 'type': 'argument_list', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'paths'}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'path_scores'}; {'id': '290', 'type': 'expression_statement', 'children': ['291']}; {'id': '291', 'type': 'assignment', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'sorted_by_length'}; {'id': '293', 'type': 'call', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '295', 'type': 'argument_list', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'path_tuples'}; {'id': '297', 'type': 'keyword_argument', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '299', 'type': 'lambda', 'children': ['300', '302']}; {'id': '300', 'type': 'lambda_parameters', 'children': ['301']}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '302', 'type': 'call', 'children': ['303', '304']}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '304', 'type': 'argument_list', 'children': ['305']}; {'id': '305', 'type': 'subscript', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '307', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '308', 'type': 'expression_statement', 'children': ['309']}; {'id': '309', 'type': 'assignment', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'scored_paths'}; {'id': '311', 'type': 'call', 'children': ['312', '313']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '313', 'type': 'argument_list', 'children': ['314', '315', '323']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'sorted_by_length'}; {'id': '315', 'type': 'keyword_argument', 'children': ['316', '317']}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '317', 'type': 'lambda', 'children': ['318', '320']}; {'id': '318', 'type': 'lambda_parameters', 'children': ['319']}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '320', 'type': 'subscript', 'children': ['321', '322']}; {'id': '321', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '322', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '323', 'type': 'keyword_argument', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '325', 'type': 'True', 'children': []}; {'id': '326', 'type': 'return_statement', 'children': ['327']}; {'id': '327', 'type': 'identifier', 'children': [], 'value': 'scored_paths'}
def score_paths(self, paths, agents_values, loss_of_function=False, sigma=0.15, include_final_node=False): obs_model = lambda x: scipy.stats.norm(x, sigma) obs_dict = {} for ag, val in agents_values.items(): obs_list = self.agent_to_obs[ag] if obs_list is not None: for obs in obs_list: obs_dict[obs] = val path_scores = [] for path in paths: logger.info('------') logger.info("Scoring path:") logger.info(path) path_score = 0 last_path_node_index = -1 if include_final_node else -2 for node, sign in path[:last_path_node_index]: for affected_obs, rule_obs_sign in self.rule_obs_dict[node]: flip_polarity = -1 if loss_of_function else 1 pred_sign = sign * rule_obs_sign * flip_polarity logger.info('%s %s: effect %s %s' % (node, sign, affected_obs, pred_sign)) measured_val = obs_dict.get(affected_obs) if measured_val: if pred_sign <= 0: prob_correct = obs_model(measured_val).logcdf(0) else: prob_correct = obs_model(measured_val).logsf(0) logger.info('Actual: %s, Log Probability: %s' % (measured_val, prob_correct)) path_score += prob_correct if not self.rule_obs_dict[node]: logger.info('%s %s' % (node, sign)) prob_correct = obs_model(0).logcdf(0) logger.info('Unmeasured node, Log Probability: %s' % (prob_correct)) path_score += prob_correct logger.info("Path score: %s" % path_score) path_scores.append(path_score) path_tuples = list(zip(paths, path_scores)) sorted_by_length = sorted(path_tuples, key=lambda x: len(x[0])) scored_paths = sorted(sorted_by_length, key=lambda x: x[1], reverse=True) return scored_paths
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'prune_influence_map'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '14', '21', '25', '63', '70', '78', '85', '89', '111', '118', '130', '144', '156', '160', '253', '265']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'im'}; {'id': '9', 'type': 'call', 'children': ['10', '13']}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'get_im'}; {'id': '13', 'type': 'argument_list', 'children': []}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'string', 'children': [], 'value': "'Removing self loops'"}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'edges_to_remove'}; {'id': '24', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '25', 'type': 'for_statement', 'children': ['26', '27', '32']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'im'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'edges'}; {'id': '31', 'type': 'argument_list', 'children': []}; {'id': '32', 'type': 'block', 'children': ['33']}; {'id': '33', 'type': 'if_statement', 'children': ['34', '41']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '38'], 'value': '=='}; {'id': '35', 'type': 'subscript', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '37', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '40', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '41', 'type': 'block', 'children': ['42', '50']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '47', 'type': 'argument_list', 'children': ['48', '49']}; {'id': '48', 'type': 'string', 'children': [], 'value': "'Removing self loop: %s'"}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'call', 'children': ['52', '55']}; {'id': '52', 'type': 'attribute', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'edges_to_remove'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'tuple', 'children': ['57', '60']}; {'id': '57', 'type': 'subscript', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '59', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '60', 'type': 'subscript', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '62', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'call', 'children': ['65', '68']}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'im'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'remove_edges_from'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'edges_to_remove'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'remove_im_params'}; {'id': '73', 'type': 'argument_list', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'im'}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}; {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'string', 'children': [], 'value': "'Get successorts of each node'"}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'succ_dict'}; {'id': '88', 'type': 'dictionary', 'children': []}; {'id': '89', 'type': 'for_statement', 'children': ['90', '91', '96']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'im'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '95', 'type': 'argument_list', 'children': []}; {'id': '96', 'type': 'block', 'children': ['97']}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '102']}; {'id': '99', 'type': 'subscript', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'succ_dict'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '102', 'type': 'call', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}; {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'im'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'successors'}; {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'call', 'children': ['113', '116']}; {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '116', 'type': 'argument_list', 'children': ['117']}; {'id': '117', 'type': 'string', 'children': [], 'value': "'Compare combinations of successors'"}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}; {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'group_key_fun'}; {'id': '121', 'type': 'lambda', 'children': ['122', '124']}; {'id': '122', 'type': 'lambda_parameters', 'children': ['123']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '124', 'type': 'call', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '126', 'type': 'argument_list', 'children': ['127']}; {'id': '127', 'type': 'subscript', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'succ_dict'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}; {'id': '131', 'type': 'assignment', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'nodes_sorted'}; {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '135', 'type': 'argument_list', 'children': ['136', '141']}; {'id': '136', 'type': 'call', 'children': ['137', '140']}; {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'im'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '140', 'type': 'argument_list', 'children': []}; {'id': '141', 'type': 'keyword_argument', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'group_key_fun'}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}; {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '147', 'type': 'call', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'itertools'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'groupby'}; {'id': '151', 'type': 'argument_list', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'nodes_sorted'}; {'id': '153', 'type': 'keyword_argument', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'group_key_fun'}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}; {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'edges_to_remove'}; {'id': '159', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '160', 'type': 'for_statement', 'children': ['161', '164', '165']}; {'id': '161', 'type': 'pattern_list', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'gix'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '165', 'type': 'block', 'children': ['166', '176']}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}; {'id': '167', 'type': 'assignment', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'combos'}; {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'itertools'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'combinations'}; {'id': '173', 'type': 'argument_list', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '175', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '176', 'type': 'for_statement', 'children': ['177', '182', '186']}; {'id': '177', 'type': 'pattern_list', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'ix'}; {'id': '179', 'type': 'tuple_pattern', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'p1'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'p2'}; {'id': '182', 'type': 'call', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'combos'}; {'id': '186', 'type': 'block', 'children': ['187']}; {'id': '187', 'type': 'if_statement', 'children': ['188', '222']}; {'id': '188', 'type': 'boolean_operator', 'children': ['189', '205', '206'], 'value': 'and'}; {'id': '189', 'type': 'comparison_operator', 'children': ['190', '200'], 'value': '=='}; {'id': '190', 'type': 'call', 'children': ['191', '196']}; {'id': '191', 'type': 'attribute', 'children': ['192', '195']}; {'id': '192', 'type': 'subscript', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'succ_dict'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'p1'}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'difference'}; {'id': '196', 'type': 'argument_list', 'children': ['197']}; {'id': '197', 'type': 'subscript', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'succ_dict'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'p2'}; {'id': '200', 'type': 'call', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '202', 'type': 'argument_list', 'children': ['203']}; {'id': '203', 'type': 'list', 'children': ['204'], 'value': '[p2]'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'p2'}; {'id': '205', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '206', 'type': 'comparison_operator', 'children': ['207', '217'], 'value': '=='}; {'id': '207', 'type': 'call', 'children': ['208', '213']}; {'id': '208', 'type': 'attribute', 'children': ['209', '212']}; {'id': '209', 'type': 'subscript', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'succ_dict'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'p2'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'difference'}; {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'subscript', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'succ_dict'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'p1'}; {'id': '217', 'type': 'call', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '219', 'type': 'argument_list', 'children': ['220']}; {'id': '220', 'type': 'list', 'children': ['221'], 'value': '[p1]'}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'p1'}; {'id': '222', 'type': 'block', 'children': ['223']}; {'id': '223', 'type': 'for_statement', 'children': ['224', '227', '234']}; {'id': '224', 'type': 'pattern_list', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '227', 'type': 'tuple', 'children': ['228', '231']}; {'id': '228', 'type': 'tuple', 'children': ['229', '230']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'p1'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'p2'}; {'id': '231', 'type': 'tuple', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'p2'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'p1'}; {'id': '234', 'type': 'block', 'children': ['235', '244']}; {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'call', 'children': ['237', '240']}; {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'edges_to_remove'}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '240', 'type': 'argument_list', 'children': ['241']}; {'id': '241', 'type': 'tuple', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '244', 'type': 'expression_statement', 'children': ['245']}; {'id': '245', 'type': 'call', 'children': ['246', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '249', 'type': 'argument_list', 'children': ['250', '251', '252']}; {'id': '250', 'type': 'string', 'children': [], 'value': "'Will remove edge (%s, %s)'"}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'call', 'children': ['255', '258']}; {'id': '255', 'type': 'attribute', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '258', 'type': 'argument_list', 'children': ['259']}; {'id': '259', 'type': 'binary_operator', 'children': ['260', '261'], 'value': '%'}; {'id': '260', 'type': 'string', 'children': [], 'value': "'Removing %d edges from influence map'"}; {'id': '261', 'type': 'call', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '263', 'type': 'argument_list', 'children': ['264']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'edges_to_remove'}; {'id': '265', 'type': 'expression_statement', 'children': ['266']}; {'id': '266', 'type': 'call', 'children': ['267', '270']}; {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'im'}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'remove_edges_from'}; {'id': '270', 'type': 'argument_list', 'children': ['271']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'edges_to_remove'}
def prune_influence_map(self): im = self.get_im() logger.info('Removing self loops') edges_to_remove = [] for e in im.edges(): if e[0] == e[1]: logger.info('Removing self loop: %s', e) edges_to_remove.append((e[0], e[1])) im.remove_edges_from(edges_to_remove) remove_im_params(self.model, im) logger.info('Get successorts of each node') succ_dict = {} for node in im.nodes(): succ_dict[node] = set(im.successors(node)) logger.info('Compare combinations of successors') group_key_fun = lambda x: len(succ_dict[x]) nodes_sorted = sorted(im.nodes(), key=group_key_fun) groups = itertools.groupby(nodes_sorted, key=group_key_fun) edges_to_remove = [] for gix, group in groups: combos = itertools.combinations(group, 2) for ix, (p1, p2) in enumerate(combos): if succ_dict[p1].difference(succ_dict[p2]) == set([p2]) and \ succ_dict[p2].difference(succ_dict[p1]) == set([p1]): for u, v in ((p1, p2), (p2, p1)): edges_to_remove.append((u, v)) logger.debug('Will remove edge (%s, %s)', u, v) logger.info('Removing %d edges from influence map' % len(edges_to_remove)) im.remove_edges_from(edges_to_remove)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'send_request'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'ndex_service_url'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'is_json'}; {'id': '8', 'type': 'True', 'children': []}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'use_get'}; {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '42', '48', '84', '97', '104', '108', '157', '164']}; {'id': '13', 'type': 'if_statement', 'children': ['14', '15', '28']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'use_get'}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'requests'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '23', 'type': 'argument_list', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'ndex_service_url'}; {'id': '25', 'type': 'keyword_argument', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '28', 'type': 'else_clause', 'children': ['29']}; {'id': '29', 'type': 'block', 'children': ['30']}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'requests'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'post'}; {'id': '37', 'type': 'argument_list', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'ndex_service_url'}; {'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'status_code'}; {'id': '48', 'type': 'if_statement', 'children': ['49', '52', '68']}; {'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': '=='}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '51', 'type': 'integer', 'children': [], 'value': '200'}; {'id': '52', 'type': 'block', 'children': ['53']}; {'id': '53', 'type': 'if_statement', 'children': ['54', '55', '62']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'is_json'}; {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'return_statement', 'children': ['57']}; {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '61', 'type': 'argument_list', 'children': []}; {'id': '62', 'type': 'else_clause', 'children': ['63']}; {'id': '63', 'type': 'block', 'children': ['64']}; {'id': '64', 'type': 'return_statement', 'children': ['65']}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'text'}; {'id': '68', 'type': 'elif_clause', 'children': ['69', '72']}; {'id': '69', 'type': 'comparison_operator', 'children': ['70', '71'], 'value': '!='}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '71', 'type': 'integer', 'children': [], 'value': '300'}; {'id': '72', 'type': 'block', 'children': ['73', '82']}; {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '78']}; {'id': '75', 'type': 'attribute', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '78', 'type': 'argument_list', 'children': ['79']}; {'id': '79', 'type': 'binary_operator', 'children': ['80', '81'], 'value': '%'}; {'id': '80', 'type': 'string', 'children': [], 'value': "'Request returned with code %d'"}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '82', 'type': 'return_statement', 'children': ['83']}; {'id': '83', 'type': 'None', 'children': []}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}; {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'task_id'}; {'id': '87', 'type': 'call', 'children': ['88', '95']}; {'id': '88', 'type': 'attribute', 'children': ['89', '94']}; {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '93', 'type': 'argument_list', 'children': []}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'string', 'children': [], 'value': "'task_id'"}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'call', 'children': ['99', '102']}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '102', 'type': 'argument_list', 'children': ['103']}; {'id': '103', 'type': 'string', 'children': [], 'value': "'NDEx task submitted...'"}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}; {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'time_used'}; {'id': '107', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '108', 'type': 'try_statement', 'children': ['109', '150']}; {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'while_statement', 'children': ['111', '114']}; {'id': '111', 'type': 'comparison_operator', 'children': ['112', '113'], 'value': '!='}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '113', 'type': 'integer', 'children': [], 'value': '200'}; {'id': '114', 'type': 'block', 'children': ['115', '128', '134']}; {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'assignment', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '118', 'type': 'call', 'children': ['119', '122']}; {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'requests'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}; {'id': '123', 'type': 'binary_operator', 'children': ['124', '127'], 'value': '+'}; {'id': '124', 'type': 'binary_operator', 'children': ['125', '126'], 'value': '+'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'ndex_base_url'}; {'id': '126', 'type': 'string', 'children': [], 'value': "'/task/'"}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'task_id'}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}; {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'status_code'}; {'id': '134', 'type': 'if_statement', 'children': ['135', '138']}; {'id': '135', 'type': 'comparison_operator', 'children': ['136', '137'], 'value': '!='}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '137', 'type': 'integer', 'children': [], 'value': '200'}; {'id': '138', 'type': 'block', 'children': ['139', '146']}; {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'call', 'children': ['141', '144']}; {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'sleep'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}; {'id': '145', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}; {'id': '147', 'type': 'augmented_assignment', 'children': ['148', '149'], 'value': '+='}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'time_used'}; {'id': '149', 'type': 'integer', 'children': [], 'value': '5'}; {'id': '150', 'type': 'except_clause', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '152', 'type': 'block', 'children': ['153', '155']}; {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '155', 'type': 'return_statement', 'children': ['156']}; {'id': '156', 'type': 'None', 'children': []}; {'id': '157', 'type': 'expression_statement', 'children': ['158']}; {'id': '158', 'type': 'call', 'children': ['159', '162']}; {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}; {'id': '163', 'type': 'string', 'children': [], 'value': "'NDEx task complete.'"}; {'id': '164', 'type': 'if_statement', 'children': ['165', '166', '173']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'is_json'}; {'id': '166', 'type': 'block', 'children': ['167']}; {'id': '167', 'type': 'return_statement', 'children': ['168']}; {'id': '168', 'type': 'call', 'children': ['169', '172']}; {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '172', 'type': 'argument_list', 'children': []}; {'id': '173', 'type': 'else_clause', 'children': ['174']}; {'id': '174', 'type': 'block', 'children': ['175']}; {'id': '175', 'type': 'return_statement', 'children': ['176']}; {'id': '176', 'type': 'attribute', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'text'}
def send_request(ndex_service_url, params, is_json=True, use_get=False): if use_get: res = requests.get(ndex_service_url, json=params) else: res = requests.post(ndex_service_url, json=params) status = res.status_code if status == 200: if is_json: return res.json() else: return res.text elif status != 300: logger.error('Request returned with code %d' % status) return None task_id = res.json().get('task_id') logger.info('NDEx task submitted...') time_used = 0 try: while status != 200: res = requests.get(ndex_base_url + '/task/' + task_id) status = res.status_code if status != 200: time.sleep(5) time_used += 5 except KeyError: next return None logger.info('NDEx task complete.') if is_json: return res.json() else: return res.text
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_hash'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'shallow'}; {'id': '7', 'type': 'True', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'refresh'}; {'id': '10', 'type': 'False', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12', '114']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '14', '52']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'shallow'}; {'id': '14', 'type': 'block', 'children': ['15', '46']}; {'id': '15', 'type': 'if_statement', 'children': ['16', '31']}; {'id': '16', 'type': 'boolean_operator', 'children': ['17', '29', '30'], 'value': 'or'}; {'id': '17', 'type': 'boolean_operator', 'children': ['18', '24'], 'value': 'or'}; {'id': '18', 'type': 'not_operator', 'children': ['19']}; {'id': '19', 'type': 'call', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '21', 'type': 'argument_list', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '23', 'type': 'string', 'children': [], 'value': "'_shallow_hash'"}; {'id': '24', 'type': 'comparison_operator', 'children': ['25', '28'], 'value': 'is'}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': '_shallow_hash'}; {'id': '28', 'type': 'None', 'children': []}; {'id': '29', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'refresh'}; {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': '_shallow_hash'}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'make_hash'}; {'id': '39', 'type': 'argument_list', 'children': ['40', '45']}; {'id': '40', 'type': 'call', 'children': ['41', '44']}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'matches_key'}; {'id': '44', 'type': 'argument_list', 'children': []}; {'id': '45', 'type': 'integer', 'children': [], 'value': '14'}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': '_shallow_hash'}; {'id': '52', 'type': 'else_clause', 'children': ['53']}; {'id': '53', 'type': 'block', 'children': ['54', '108']}; {'id': '54', 'type': 'if_statement', 'children': ['55', '70']}; {'id': '55', 'type': 'boolean_operator', 'children': ['56', '68', '69'], 'value': 'or'}; {'id': '56', 'type': 'boolean_operator', 'children': ['57', '63'], 'value': 'or'}; {'id': '57', 'type': 'not_operator', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '62', 'type': 'string', 'children': [], 'value': "'_full_hash'"}; {'id': '63', 'type': 'comparison_operator', 'children': ['64', '67'], 'value': 'is'}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': '_full_hash'}; {'id': '67', 'type': 'None', 'children': []}; {'id': '68', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'refresh'}; {'id': '70', 'type': 'block', 'children': ['71', '88']}; {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'ev_mk_list'}; {'id': '74', 'type': 'call', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}; {'id': '77', 'type': 'list_comprehension', 'children': ['78', '83']}; {'id': '78', 'type': 'call', 'children': ['79', '82']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'matches_key'}; {'id': '82', 'type': 'argument_list', 'children': []}; {'id': '83', 'type': 'for_in_clause', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'evidence'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'assignment', 'children': ['90', '93', '94']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': '_full_hash'}; {'id': '93', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '94', 'type': 'call', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'make_hash'}; {'id': '96', 'type': 'argument_list', 'children': ['97', '107']}; {'id': '97', 'type': 'binary_operator', 'children': ['98', '103'], 'value': '+'}; {'id': '98', 'type': 'call', 'children': ['99', '102']}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'matches_key'}; {'id': '102', 'type': 'argument_list', 'children': []}; {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'ev_mk_list'}; {'id': '107', 'type': 'integer', 'children': [], 'value': '16'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}; {'id': '109', 'type': 'assignment', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': '_full_hash'}; {'id': '114', 'type': 'return_statement', 'children': ['115']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'ret'}
def get_hash(self, shallow=True, refresh=False): if shallow: if not hasattr(self, '_shallow_hash') or self._shallow_hash is None\ or refresh: self._shallow_hash = make_hash(self.matches_key(), 14) ret = self._shallow_hash else: if not hasattr(self, '_full_hash') or self._full_hash is None \ or refresh: ev_mk_list = sorted([ev.matches_key() for ev in self.evidence]) self._full_hash = \ make_hash(self.matches_key() + str(ev_mk_list), 16) ret = self._full_hash return ret
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_json'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'use_sbo'}; {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '18', '31', '55', '64', '72', '97', '107', '129', '151', '200', '220']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'stmt_type'}; {'id': '12', 'type': 'attribute', 'children': ['13', '17']}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'all_stmts'}; {'id': '21', 'type': 'binary_operator', 'children': ['22', '28'], 'value': '+'}; {'id': '22', 'type': 'binary_operator', 'children': ['23', '25'], 'value': '+'}; {'id': '23', 'type': 'list', 'children': ['24'], 'value': '[self]'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'supports'}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'supported_by'}; {'id': '31', 'type': 'for_statement', 'children': ['32', '33', '34']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'all_stmts'}; {'id': '34', 'type': 'block', 'children': ['35']}; {'id': '35', 'type': 'if_statement', 'children': ['36', '42']}; {'id': '36', 'type': 'not_operator', 'children': ['37']}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '39', 'type': 'argument_list', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '41', 'type': 'string', 'children': [], 'value': "'uuid'"}; {'id': '42', 'type': 'block', 'children': ['43']}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '48', 'type': 'binary_operator', 'children': ['49', '50'], 'value': '%'}; {'id': '49', 'type': 'string', 'children': [], 'value': "'%s'"}; {'id': '50', 'type': 'call', 'children': ['51', '54']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'uuid4'}; {'id': '54', 'type': 'argument_list', 'children': []}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'json_dict'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': '_o'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'stmt_type'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'assignment', 'children': ['66', '69']}; {'id': '66', 'type': 'subscript', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'json_dict'}; {'id': '68', 'type': 'string', 'children': [], 'value': "'belief'"}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'belief'}; {'id': '72', 'type': 'if_statement', 'children': ['73', '76']}; {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'evidence'}; {'id': '76', 'type': 'block', 'children': ['77', '91']}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'evidence'}; {'id': '80', 'type': 'list_comprehension', 'children': ['81', '86']}; {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'to_json'}; {'id': '85', 'type': 'argument_list', 'children': []}; {'id': '86', 'type': 'for_in_clause', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'ev'}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'evidence'}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '96']}; {'id': '93', 'type': 'subscript', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'json_dict'}; {'id': '95', 'type': 'string', 'children': [], 'value': "'evidence'"}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'evidence'}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '102']}; {'id': '99', 'type': 'subscript', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'json_dict'}; {'id': '101', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '102', 'type': 'binary_operator', 'children': ['103', '104'], 'value': '%'}; {'id': '103', 'type': 'string', 'children': [], 'value': "'%s'"}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '107', 'type': 'if_statement', 'children': ['108', '111']}; {'id': '108', 'type': 'attribute', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'supports'}; {'id': '111', 'type': 'block', 'children': ['112']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}; {'id': '113', 'type': 'assignment', 'children': ['114', '117', '118']}; {'id': '114', 'type': 'subscript', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'json_dict'}; {'id': '116', 'type': 'string', 'children': [], 'value': "'supports'"}; {'id': '117', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '118', 'type': 'list_comprehension', 'children': ['119', '124']}; {'id': '119', 'type': 'binary_operator', 'children': ['120', '121'], 'value': '%'}; {'id': '120', 'type': 'string', 'children': [], 'value': "'%s'"}; {'id': '121', 'type': 'attribute', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '124', 'type': 'for_in_clause', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '126', 'type': 'attribute', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'supports'}; {'id': '129', 'type': 'if_statement', 'children': ['130', '133']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'supported_by'}; {'id': '133', 'type': 'block', 'children': ['134']}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}; {'id': '135', 'type': 'assignment', 'children': ['136', '139', '140']}; {'id': '136', 'type': 'subscript', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'json_dict'}; {'id': '138', 'type': 'string', 'children': [], 'value': "'supported_by'"}; {'id': '139', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '140', 'type': 'list_comprehension', 'children': ['141', '146']}; {'id': '141', 'type': 'binary_operator', 'children': ['142', '143'], 'value': '%'}; {'id': '142', 'type': 'string', 'children': [], 'value': "'%s'"}; {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '146', 'type': 'for_in_clause', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'st'}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'supported_by'}; {'id': '151', 'type': 'function_definition', 'children': ['152', '153', '155']}; {'id': '152', 'type': 'function_name', 'children': [], 'value': 'get_sbo_term'}; {'id': '153', 'type': 'parameters', 'children': ['154']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '155', 'type': 'block', 'children': ['156', '171', '198']}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}; {'id': '157', 'type': 'assignment', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'sbo_term'}; {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'stmt_sbo_map'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'call', 'children': ['165', '170']}; {'id': '165', 'type': 'attribute', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '170', 'type': 'argument_list', 'children': []}; {'id': '171', 'type': 'while_statement', 'children': ['172', '174']}; {'id': '172', 'type': 'not_operator', 'children': ['173']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'sbo_term'}; {'id': '174', 'type': 'block', 'children': ['175', '183']}; {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'assignment', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '178', 'type': 'subscript', 'children': ['179', '182']}; {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': '__bases__'}; {'id': '182', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'sbo_term'}; {'id': '186', 'type': 'call', 'children': ['187', '190']}; {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'stmt_sbo_map'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}; {'id': '191', 'type': 'call', 'children': ['192', '197']}; {'id': '192', 'type': 'attribute', 'children': ['193', '196']}; {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '195', 'type': 'identifier', 'children': [], 'value': '__name__'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'lower'}; {'id': '197', 'type': 'argument_list', 'children': []}; {'id': '198', 'type': 'return_statement', 'children': ['199']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'sbo_term'}; {'id': '200', 'type': 'if_statement', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'use_sbo'}; {'id': '202', 'type': 'block', 'children': ['203', '212']}; {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'assignment', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'sbo_term'}; {'id': '206', 'type': 'call', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'get_sbo_term'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}; {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': '__class__'}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}; {'id': '213', 'type': 'assignment', 'children': ['214', '217']}; {'id': '214', 'type': 'subscript', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'json_dict'}; {'id': '216', 'type': 'string', 'children': [], 'value': "'sbo'"}; {'id': '217', 'type': 'binary_operator', 'children': ['218', '219'], 'value': '%'}; {'id': '218', 'type': 'string', 'children': [], 'value': "'http://identifiers.org/sbo/SBO:%s'"}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'sbo_term'}; {'id': '220', 'type': 'return_statement', 'children': ['221']}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'json_dict'}
def to_json(self, use_sbo=False): stmt_type = type(self).__name__ all_stmts = [self] + self.supports + self.supported_by for st in all_stmts: if not hasattr(st, 'uuid'): st.uuid = '%s' % uuid.uuid4() json_dict = _o(type=stmt_type) json_dict['belief'] = self.belief if self.evidence: evidence = [ev.to_json() for ev in self.evidence] json_dict['evidence'] = evidence json_dict['id'] = '%s' % self.uuid if self.supports: json_dict['supports'] = \ ['%s' % st.uuid for st in self.supports] if self.supported_by: json_dict['supported_by'] = \ ['%s' % st.uuid for st in self.supported_by] def get_sbo_term(cls): sbo_term = stmt_sbo_map.get(cls.__name__.lower()) while not sbo_term: cls = cls.__bases__[0] sbo_term = stmt_sbo_map.get(cls.__name__.lower()) return sbo_term if use_sbo: sbo_term = get_sbo_term(self.__class__) json_dict['sbo'] = \ 'http://identifiers.org/sbo/SBO:%s' % sbo_term return json_dict
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'to_graph'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'block', 'children': ['6', '225', '233', '241', '253']}; {'id': '6', 'type': 'function_definition', 'children': ['7', '8', '12']}; {'id': '7', 'type': 'function_name', 'children': [], 'value': 'json_node'}; {'id': '8', 'type': 'parameters', 'children': ['9', '10', '11']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '12', 'type': 'block', 'children': ['13', '19', '28', '223']}; {'id': '13', 'type': 'if_statement', 'children': ['14', '16']}; {'id': '14', 'type': 'not_operator', 'children': ['15']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '16', 'type': 'block', 'children': ['17']}; {'id': '17', 'type': 'return_statement', 'children': ['18']}; {'id': '18', 'type': 'None', 'children': []}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'node_id'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'string', 'children': [], 'value': "'|'"}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '28', 'type': 'if_statement', 'children': ['29', '34', '82', '178']}; {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '34', 'type': 'block', 'children': ['35', '45']}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'add_node'}; {'id': '40', 'type': 'argument_list', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'node_id'}; {'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '44', 'type': 'string', 'children': [], 'value': "''"}; {'id': '45', 'type': 'for_statement', 'children': ['46', '49', '53']}; {'id': '46', 'type': 'pattern_list', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'sub_element'}; {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '53', 'type': 'block', 'children': ['54', '68']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}; {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'sub_id'}; {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'json_node'}; {'id': '59', 'type': 'argument_list', 'children': ['60', '61', '62']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'sub_element'}; {'id': '62', 'type': 'binary_operator', 'children': ['63', '64'], 'value': '+'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '64', 'type': 'list', 'children': ['65'], 'value': "['%s' % i]"}; {'id': '65', 'type': 'binary_operator', 'children': ['66', '67'], 'value': '%'}; {'id': '66', 'type': 'string', 'children': [], 'value': "'%s'"}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '68', 'type': 'if_statement', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'sub_id'}; {'id': '70', 'type': 'block', 'children': ['71']}; {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'call', 'children': ['73', '76']}; {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'add_edge'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '78', '79']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'node_id'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'sub_id'}; {'id': '79', 'type': 'keyword_argument', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '81', 'type': 'string', 'children': [], 'value': "''"}; {'id': '82', 'type': 'elif_clause', 'children': ['83', '88']}; {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '85', 'type': 'argument_list', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '88', 'type': 'block', 'children': ['89', '99']}; {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '94']}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'add_node'}; {'id': '94', 'type': 'argument_list', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'node_id'}; {'id': '96', 'type': 'keyword_argument', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '98', 'type': 'string', 'children': [], 'value': "''"}; {'id': '99', 'type': 'for_statement', 'children': ['100', '103', '108']}; {'id': '100', 'type': 'pattern_list', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '107', 'type': 'argument_list', 'children': []}; {'id': '108', 'type': 'block', 'children': ['109', '147', '161']}; {'id': '109', 'type': 'if_statement', 'children': ['110', '113', '115', '131']}; {'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': '=='}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '112', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'continue_statement', 'children': []}; {'id': '115', 'type': 'elif_clause', 'children': ['116', '119']}; {'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': '=='}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '118', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '119', 'type': 'block', 'children': ['120', '130']}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}; {'id': '121', 'type': 'assignment', 'children': ['122', '129']}; {'id': '122', 'type': 'subscript', 'children': ['123', '128']}; {'id': '123', 'type': 'subscript', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'node_id'}; {'id': '128', 'type': 'string', 'children': [], 'value': "'label'"}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '130', 'type': 'continue_statement', 'children': []}; {'id': '131', 'type': 'elif_clause', 'children': ['132', '135']}; {'id': '132', 'type': 'comparison_operator', 'children': ['133', '134'], 'value': '=='}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '134', 'type': 'string', 'children': [], 'value': "'type'"}; {'id': '135', 'type': 'block', 'children': ['136', '146']}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}; {'id': '137', 'type': 'assignment', 'children': ['138', '145']}; {'id': '138', 'type': 'subscript', 'children': ['139', '144']}; {'id': '139', 'type': 'subscript', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'node_id'}; {'id': '144', 'type': 'string', 'children': [], 'value': "'label'"}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '146', 'type': 'continue_statement', 'children': []}; {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'sub_id'}; {'id': '150', 'type': 'call', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'json_node'}; {'id': '152', 'type': 'argument_list', 'children': ['153', '154', '155']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '155', 'type': 'binary_operator', 'children': ['156', '157'], 'value': '+'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'prefix'}; {'id': '157', 'type': 'list', 'children': ['158'], 'value': "['%s' % k]"}; {'id': '158', 'type': 'binary_operator', 'children': ['159', '160'], 'value': '%'}; {'id': '159', 'type': 'string', 'children': [], 'value': "'%s'"}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '161', 'type': 'if_statement', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'sub_id'}; {'id': '163', 'type': 'block', 'children': ['164']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}; {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'add_edge'}; {'id': '169', 'type': 'argument_list', 'children': ['170', '171', '172']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'node_id'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'sub_id'}; {'id': '172', 'type': 'keyword_argument', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '174', 'type': '()', 'children': ['175']}; {'id': '175', 'type': 'binary_operator', 'children': ['176', '177'], 'value': '%'}; {'id': '176', 'type': 'string', 'children': [], 'value': "'%s'"}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '178', 'type': 'else_clause', 'children': ['179']}; {'id': '179', 'type': 'block', 'children': ['180', '207']}; {'id': '180', 'type': 'if_statement', 'children': ['181', '194']}; {'id': '181', 'type': 'boolean_operator', 'children': ['182', '187', '188'], 'value': 'and'}; {'id': '182', 'type': 'call', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '184', 'type': 'argument_list', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'basestring'}; {'id': '187', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '188', 'type': 'call', 'children': ['189', '192']}; {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '192', 'type': 'argument_list', 'children': ['193']}; {'id': '193', 'type': 'string', 'children': [], 'value': "'http'"}; {'id': '194', 'type': 'block', 'children': ['195']}; {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'assignment', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '198', 'type': 'subscript', 'children': ['199', '205']}; {'id': '199', 'type': 'call', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '205', 'type': 'unary_operator', 'children': ['206'], 'value': '-'}; {'id': '206', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'call', 'children': ['209', '212']}; {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'add_node'}; {'id': '212', 'type': 'argument_list', 'children': ['213', '214']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'node_id'}; {'id': '214', 'type': 'keyword_argument', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '216', 'type': '()', 'children': ['217']}; {'id': '217', 'type': 'binary_operator', 'children': ['218', '219'], 'value': '%'}; {'id': '218', 'type': 'string', 'children': [], 'value': "'%s'"}; {'id': '219', 'type': 'call', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'element'}; {'id': '223', 'type': 'return_statement', 'children': ['224']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'node_id'}; {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '228']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'jd'}; {'id': '228', 'type': 'call', 'children': ['229', '232']}; {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'to_json'}; {'id': '232', 'type': 'argument_list', 'children': []}; {'id': '233', 'type': 'expression_statement', 'children': ['234']}; {'id': '234', 'type': 'assignment', 'children': ['235', '236']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '236', 'type': 'call', 'children': ['237', '240']}; {'id': '237', 'type': 'attribute', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'networkx'}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'DiGraph'}; {'id': '240', 'type': 'argument_list', 'children': []}; {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'call', 'children': ['243', '244']}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'json_node'}; {'id': '244', 'type': 'argument_list', 'children': ['245', '246', '247']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'graph'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'jd'}; {'id': '247', 'type': 'list', 'children': ['248'], 'value': "['%s' % self.uuid]"}; {'id': '248', 'type': 'binary_operator', 'children': ['249', '250'], 'value': '%'}; {'id': '249', 'type': 'string', 'children': [], 'value': "'%s'"}; {'id': '250', 'type': 'attribute', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '253', 'type': 'return_statement', 'children': ['254']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'graph'}
def to_graph(self): def json_node(graph, element, prefix): if not element: return None node_id = '|'.join(prefix) if isinstance(element, list): graph.add_node(node_id, label='') for i, sub_element in enumerate(element): sub_id = json_node(graph, sub_element, prefix + ['%s' % i]) if sub_id: graph.add_edge(node_id, sub_id, label='') elif isinstance(element, dict): graph.add_node(node_id, label='') for k, v in element.items(): if k == 'id': continue elif k == 'name': graph.node[node_id]['label'] = v continue elif k == 'type': graph.node[node_id]['label'] = v continue sub_id = json_node(graph, v, prefix + ['%s' % k]) if sub_id: graph.add_edge(node_id, sub_id, label=('%s' % k)) else: if isinstance(element, basestring) and \ element.startswith('http'): element = element.split('/')[-1] graph.add_node(node_id, label=('%s' % str(element))) return node_id jd = self.to_json() graph = networkx.DiGraph() json_node(graph, jd, ['%s' % self.uuid]) return graph
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_bel_stmts'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'block', 'children': ['9', '24', '121', '147']}; {'id': '9', 'type': 'if_statement', 'children': ['10', '15']}; {'id': '10', 'type': 'comparison_operator', 'children': ['11', '14'], 'value': 'is'}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '14', 'type': 'None', 'children': []}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'bel_stmt_path'}; {'id': '19', 'type': 'binary_operator', 'children': ['20', '21'], 'value': '%'}; {'id': '20', 'type': 'string', 'children': [], 'value': "'%s_bel_stmts.pkl'"}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '39', '70']}; {'id': '25', 'type': 'boolean_operator', 'children': ['26', '31'], 'value': 'and'}; {'id': '26', 'type': 'comparison_operator', 'children': ['27', '30'], 'value': 'is'}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '30', 'type': 'None', 'children': []}; {'id': '31', 'type': 'call', 'children': ['32', '37']}; {'id': '32', 'type': 'attribute', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'bel_stmt_path'}; {'id': '39', 'type': 'block', 'children': ['40', '49']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '45', 'type': 'argument_list', 'children': ['46']}; {'id': '46', 'type': 'binary_operator', 'children': ['47', '48'], 'value': '%'}; {'id': '47', 'type': 'string', 'children': [], 'value': '"Loading BEL statements from %s"'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'bel_stmt_path'}; {'id': '49', 'type': 'with_statement', 'children': ['50', '60']}; {'id': '50', 'type': 'with_clause', 'children': ['51']}; {'id': '51', 'type': 'with_item', 'children': ['52']}; {'id': '52', 'type': 'as_pattern', 'children': ['53', '58']}; {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '55', 'type': 'argument_list', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'bel_stmt_path'}; {'id': '57', 'type': 'string', 'children': [], 'value': "'rb'"}; {'id': '58', 'type': 'as_pattern_target', 'children': ['59']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '60', 'type': 'block', 'children': ['61']}; {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'bel_statements'}; {'id': '64', 'type': 'call', 'children': ['65', '68']}; {'id': '65', 'type': 'attribute', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'pickle'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '70', 'type': 'else_clause', 'children': ['71']}; {'id': '71', 'type': 'block', 'children': ['72', '88', '94']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'assignment', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'bel_proc'}; {'id': '75', 'type': 'call', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'bel'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'process_pybel_neighborhood'}; {'id': '79', 'type': 'argument_list', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'gene_list'}; {'id': '83', 'type': 'keyword_argument', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'network_file'}; {'id': '85', 'type': 'attribute', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'bel_corpus'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'bel_statements'}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'bel_proc'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'statements'}; {'id': '94', 'type': 'if_statement', 'children': ['95', '100']}; {'id': '95', 'type': 'comparison_operator', 'children': ['96', '99'], 'value': 'is'}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '99', 'type': 'None', 'children': []}; {'id': '100', 'type': 'block', 'children': ['101']}; {'id': '101', 'type': 'with_statement', 'children': ['102', '112']}; {'id': '102', 'type': 'with_clause', 'children': ['103']}; {'id': '103', 'type': 'with_item', 'children': ['104']}; {'id': '104', 'type': 'as_pattern', 'children': ['105', '110']}; {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '107', 'type': 'argument_list', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'bel_stmt_path'}; {'id': '109', 'type': 'string', 'children': [], 'value': "'wb'"}; {'id': '110', 'type': 'as_pattern_target', 'children': ['111']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '112', 'type': 'block', 'children': ['113']}; {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '118']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'pickle'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'dump'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'bel_statements'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '121', 'type': 'if_statement', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '123', 'type': 'block', 'children': ['124']}; {'id': '124', 'type': 'if_statement', 'children': ['125', '133']}; {'id': '125', 'type': 'comparison_operator', 'children': ['126', '132'], 'value': '>'}; {'id': '126', 'type': 'call', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'gene_list'}; {'id': '132', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '133', 'type': 'block', 'children': ['134']}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}; {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'bel_statements'}; {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'ac'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'filter_gene_list'}; {'id': '141', 'type': 'argument_list', 'children': ['142', '143', '146']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'bel_statements'}; {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'gene_list'}; {'id': '146', 'type': 'string', 'children': [], 'value': "'all'"}; {'id': '147', 'type': 'return_statement', 'children': ['148']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'bel_statements'}
def get_bel_stmts(self, filter=False): if self.basename is not None: bel_stmt_path = '%s_bel_stmts.pkl' % self.basename if self.basename is not None and os.path.isfile(bel_stmt_path): logger.info("Loading BEL statements from %s" % bel_stmt_path) with open(bel_stmt_path, 'rb') as f: bel_statements = pickle.load(f) else: bel_proc = bel.process_pybel_neighborhood(self.gene_list, network_file=self.bel_corpus) bel_statements = bel_proc.statements if self.basename is not None: with open(bel_stmt_path, 'wb') as f: pickle.dump(bel_statements, f) if filter: if len(self.gene_list) > 1: bel_statements = ac.filter_gene_list(bel_statements, self.gene_list, 'all') return bel_statements
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_biopax_stmts'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '7', 'type': 'False', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '10', 'type': 'string', 'children': [], 'value': "'pathsbetween'"}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'database_filter'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'block', 'children': ['15', '38', '86', '237', '266', '306']}; {'id': '15', 'type': 'if_statement', 'children': ['16', '21']}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '20'], 'value': 'is'}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '20', 'type': 'None', 'children': []}; {'id': '21', 'type': 'block', 'children': ['22', '30']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'biopax_stmt_path'}; {'id': '25', 'type': 'binary_operator', 'children': ['26', '27'], 'value': '%'}; {'id': '26', 'type': 'string', 'children': [], 'value': "'%s_biopax_stmts.pkl'"}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'biopax_ras_owl_path'}; {'id': '33', 'type': 'binary_operator', 'children': ['34', '35'], 'value': '%'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'%s_pc_pathsbetween.owl'"}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '38', 'type': 'if_statement', 'children': ['39', '53']}; {'id': '39', 'type': 'boolean_operator', 'children': ['40', '45'], 'value': 'and'}; {'id': '40', 'type': 'comparison_operator', 'children': ['41', '44'], 'value': 'is'}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '44', 'type': 'None', 'children': []}; {'id': '45', 'type': 'call', 'children': ['46', '51']}; {'id': '46', 'type': 'attribute', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'biopax_stmt_path'}; {'id': '53', 'type': 'block', 'children': ['54', '63', '84']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}; {'id': '55', 'type': 'call', 'children': ['56', '59']}; {'id': '56', 'type': 'attribute', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '59', 'type': 'argument_list', 'children': ['60']}; {'id': '60', 'type': 'binary_operator', 'children': ['61', '62'], 'value': '%'}; {'id': '61', 'type': 'string', 'children': [], 'value': '"Loading Biopax statements from %s"'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'biopax_stmt_path'}; {'id': '63', 'type': 'with_statement', 'children': ['64', '74']}; {'id': '64', 'type': 'with_clause', 'children': ['65']}; {'id': '65', 'type': 'with_item', 'children': ['66']}; {'id': '66', 'type': 'as_pattern', 'children': ['67', '72']}; {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '69', 'type': 'argument_list', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'biopax_stmt_path'}; {'id': '71', 'type': 'string', 'children': [], 'value': "'rb'"}; {'id': '72', 'type': 'as_pattern_target', 'children': ['73']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '74', 'type': 'block', 'children': ['75']}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'bp_statements'}; {'id': '78', 'type': 'call', 'children': ['79', '82']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'pickle'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'load'}; {'id': '82', 'type': 'argument_list', 'children': ['83']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '84', 'type': 'return_statement', 'children': ['85']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'bp_statements'}; {'id': '86', 'type': 'if_statement', 'children': ['87', '101', '120']}; {'id': '87', 'type': 'boolean_operator', 'children': ['88', '93'], 'value': 'and'}; {'id': '88', 'type': 'comparison_operator', 'children': ['89', '92'], 'value': 'is'}; {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '92', 'type': 'None', 'children': []}; {'id': '93', 'type': 'call', 'children': ['94', '99']}; {'id': '94', 'type': 'attribute', 'children': ['95', '98']}; {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'isfile'}; {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'biopax_ras_owl_path'}; {'id': '101', 'type': 'block', 'children': ['102', '111']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'call', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'binary_operator', 'children': ['109', '110'], 'value': '%'}; {'id': '109', 'type': 'string', 'children': [], 'value': '"Loading Biopax from OWL file %s"'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'biopax_ras_owl_path'}; {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'bp'}; {'id': '114', 'type': 'call', 'children': ['115', '118']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'biopax'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'process_owl'}; {'id': '118', 'type': 'argument_list', 'children': ['119']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'biopax_ras_owl_path'}; {'id': '120', 'type': 'else_clause', 'children': ['121']}; {'id': '121', 'type': 'block', 'children': ['122', '149', '223']}; {'id': '122', 'type': 'if_statement', 'children': ['123', '137']}; {'id': '123', 'type': 'boolean_operator', 'children': ['124', '133'], 'value': 'and'}; {'id': '124', 'type': '()', 'children': ['125']}; {'id': '125', 'type': 'comparison_operator', 'children': ['126', '132'], 'value': '<'}; {'id': '126', 'type': 'call', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'gene_list'}; {'id': '132', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '133', 'type': '()', 'children': ['134']}; {'id': '134', 'type': 'comparison_operator', 'children': ['135', '136'], 'value': '=='}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '136', 'type': 'string', 'children': [], 'value': "'pathsbetween'"}; {'id': '137', 'type': 'block', 'children': ['138', '145']}; {'id': '138', 'type': 'expression_statement', 'children': ['139']}; {'id': '139', 'type': 'call', 'children': ['140', '143']}; {'id': '140', 'type': 'attribute', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '143', 'type': 'argument_list', 'children': ['144']}; {'id': '144', 'type': 'string', 'children': [], 'value': "'Using neighborhood query for one gene.'"}; {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '148', 'type': 'string', 'children': [], 'value': "'neighborhood'"}; {'id': '149', 'type': 'if_statement', 'children': ['150', '153', '191', '210']}; {'id': '150', 'type': 'comparison_operator', 'children': ['151', '152'], 'value': '=='}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '152', 'type': 'string', 'children': [], 'value': "'pathsbetween'"}; {'id': '153', 'type': 'block', 'children': ['154', '174']}; {'id': '154', 'type': 'if_statement', 'children': ['155', '163', '168']}; {'id': '155', 'type': 'comparison_operator', 'children': ['156', '162'], 'value': '>'}; {'id': '156', 'type': 'call', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}; {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'gene_list'}; {'id': '162', 'type': 'integer', 'children': [], 'value': '60'}; {'id': '163', 'type': 'block', 'children': ['164']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}; {'id': '165', 'type': 'assignment', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'block_size'}; {'id': '167', 'type': 'integer', 'children': [], 'value': '60'}; {'id': '168', 'type': 'else_clause', 'children': ['169']}; {'id': '169', 'type': 'block', 'children': ['170']}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}; {'id': '171', 'type': 'assignment', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'block_size'}; {'id': '173', 'type': 'None', 'children': []}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}; {'id': '175', 'type': 'assignment', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'bp'}; {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'biopax'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'process_pc_pathsbetween'}; {'id': '181', 'type': 'argument_list', 'children': ['182', '185', '188']}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'gene_list'}; {'id': '185', 'type': 'keyword_argument', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'database_filter'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'database_filter'}; {'id': '188', 'type': 'keyword_argument', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'block_size'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'block_size'}; {'id': '191', 'type': 'elif_clause', 'children': ['192', '195']}; {'id': '192', 'type': 'comparison_operator', 'children': ['193', '194'], 'value': '=='}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '194', 'type': 'string', 'children': [], 'value': "'neighborhood'"}; {'id': '195', 'type': 'block', 'children': ['196']}; {'id': '196', 'type': 'expression_statement', 'children': ['197']}; {'id': '197', 'type': 'assignment', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'bp'}; {'id': '199', 'type': 'call', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'biopax'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'process_pc_neighborhood'}; {'id': '203', 'type': 'argument_list', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'gene_list'}; {'id': '207', 'type': 'keyword_argument', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'database_filter'}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'database_filter'}; {'id': '210', 'type': 'else_clause', 'children': ['211']}; {'id': '211', 'type': 'block', 'children': ['212', '221']}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}; {'id': '213', 'type': 'call', 'children': ['214', '217']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '217', 'type': 'argument_list', 'children': ['218']}; {'id': '218', 'type': 'binary_operator', 'children': ['219', '220'], 'value': '%'}; {'id': '219', 'type': 'string', 'children': [], 'value': "'Invalid query type: %s'"}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'query'}; {'id': '221', 'type': 'return_statement', 'children': ['222']}; {'id': '222', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '223', 'type': 'if_statement', 'children': ['224', '229']}; {'id': '224', 'type': 'comparison_operator', 'children': ['225', '228'], 'value': 'is'}; {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '228', 'type': 'None', 'children': []}; {'id': '229', 'type': 'block', 'children': ['230']}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}; {'id': '231', 'type': 'call', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'bp'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'save_model'}; {'id': '235', 'type': 'argument_list', 'children': ['236']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'biopax_ras_owl_path'}; {'id': '237', 'type': 'if_statement', 'children': ['238', '243']}; {'id': '238', 'type': 'comparison_operator', 'children': ['239', '242'], 'value': 'is'}; {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '242', 'type': 'None', 'children': []}; {'id': '243', 'type': 'block', 'children': ['244']}; {'id': '244', 'type': 'with_statement', 'children': ['245', '255']}; {'id': '245', 'type': 'with_clause', 'children': ['246']}; {'id': '246', 'type': 'with_item', 'children': ['247']}; {'id': '247', 'type': 'as_pattern', 'children': ['248', '253']}; {'id': '248', 'type': 'call', 'children': ['249', '250']}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '250', 'type': 'argument_list', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'biopax_stmt_path'}; {'id': '252', 'type': 'string', 'children': [], 'value': "'wb'"}; {'id': '253', 'type': 'as_pattern_target', 'children': ['254']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '255', 'type': 'block', 'children': ['256']}; {'id': '256', 'type': 'expression_statement', 'children': ['257']}; {'id': '257', 'type': 'call', 'children': ['258', '261']}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'pickle'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'dump'}; {'id': '261', 'type': 'argument_list', 'children': ['262', '265']}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'bp'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'statements'}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '266', 'type': 'if_statement', 'children': ['267', '268', '298']}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'filter'}; {'id': '268', 'type': 'block', 'children': ['269', '283']}; {'id': '269', 'type': 'expression_statement', 'children': ['270']}; {'id': '270', 'type': 'assignment', 'children': ['271', '272']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'policy'}; {'id': '272', 'type': 'conditional_expression', 'children': ['273', '274', '282'], 'value': 'if'}; {'id': '273', 'type': 'string', 'children': [], 'value': "'one'"}; {'id': '274', 'type': 'comparison_operator', 'children': ['275', '281'], 'value': '>'}; {'id': '275', 'type': 'call', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '277', 'type': 'argument_list', 'children': ['278']}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'gene_list'}; {'id': '281', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '282', 'type': 'string', 'children': [], 'value': "'all'"}; {'id': '283', 'type': 'expression_statement', 'children': ['284']}; {'id': '284', 'type': 'assignment', 'children': ['285', '286']}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'stmts'}; {'id': '286', 'type': 'call', 'children': ['287', '290']}; {'id': '287', 'type': 'attribute', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'ac'}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'filter_gene_list'}; {'id': '290', 'type': 'argument_list', 'children': ['291', '294', '297']}; {'id': '291', 'type': 'attribute', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'bp'}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'statements'}; {'id': '294', 'type': 'attribute', 'children': ['295', '296']}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'gene_list'}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'policy'}; {'id': '298', 'type': 'else_clause', 'children': ['299']}; {'id': '299', 'type': 'block', 'children': ['300']}; {'id': '300', 'type': 'expression_statement', 'children': ['301']}; {'id': '301', 'type': 'assignment', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'stmts'}; {'id': '303', 'type': 'attribute', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'bp'}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'statements'}; {'id': '306', 'type': 'return_statement', 'children': ['307']}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'stmts'}
def get_biopax_stmts(self, filter=False, query='pathsbetween', database_filter=None): if self.basename is not None: biopax_stmt_path = '%s_biopax_stmts.pkl' % self.basename biopax_ras_owl_path = '%s_pc_pathsbetween.owl' % self.basename if self.basename is not None and os.path.isfile(biopax_stmt_path): logger.info("Loading Biopax statements from %s" % biopax_stmt_path) with open(biopax_stmt_path, 'rb') as f: bp_statements = pickle.load(f) return bp_statements if self.basename is not None and os.path.isfile(biopax_ras_owl_path): logger.info("Loading Biopax from OWL file %s" % biopax_ras_owl_path) bp = biopax.process_owl(biopax_ras_owl_path) else: if (len(self.gene_list) < 2) and (query == 'pathsbetween'): logger.warning('Using neighborhood query for one gene.') query = 'neighborhood' if query == 'pathsbetween': if len(self.gene_list) > 60: block_size = 60 else: block_size = None bp = biopax.process_pc_pathsbetween(self.gene_list, database_filter=database_filter, block_size=block_size) elif query == 'neighborhood': bp = biopax.process_pc_neighborhood(self.gene_list, database_filter=database_filter) else: logger.error('Invalid query type: %s' % query) return [] if self.basename is not None: bp.save_model(biopax_ras_owl_path) if self.basename is not None: with open(biopax_stmt_path, 'wb') as f: pickle.dump(bp.statements, f) if filter: policy = 'one' if len(self.gene_list) > 1 else 'all' stmts = ac.filter_gene_list(bp.statements, self.gene_list, policy) else: stmts = bp.statements return stmts
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'run_preassembly'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'stmts'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'print_summary'}; {'id': '8', 'type': 'True', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10', '18', '25', '31', '38', '51', '55', '87', '93', '101', '108', '114', '120', '126', '134', '144', '152', '160', '168', '178', '188', '269', '306']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'pa1'}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'Preassembler'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'hierarchies'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'stmts'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'string', 'children': [], 'value': '"Combining duplicates"'}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'pa1'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'combine_duplicates'}; {'id': '30', 'type': 'argument_list', 'children': []}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'call', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}; {'id': '37', 'type': 'string', 'children': [], 'value': '"Mapping sites"'}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '43']}; {'id': '40', 'type': 'tuple_pattern', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'valid'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'mapped'}; {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'sm'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'map_sites'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'pa1'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'unique_stmts'}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'correctly_mapped_stmts'}; {'id': '54', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '55', 'type': 'for_statement', 'children': ['56', '57', '58']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'ms'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'mapped'}; {'id': '58', 'type': 'block', 'children': ['59']}; {'id': '59', 'type': 'if_statement', 'children': ['60', '77']}; {'id': '60', 'type': 'call', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '62', 'type': 'argument_list', 'children': ['63']}; {'id': '63', 'type': 'list_comprehension', 'children': ['64', '72']}; {'id': '64', 'type': 'conditional_expression', 'children': ['65', '66', '71'], 'value': 'if'}; {'id': '65', 'type': 'True', 'children': []}; {'id': '66', 'type': 'comparison_operator', 'children': ['67', '70'], 'value': 'is'}; {'id': '67', 'type': 'subscript', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'mm'}; {'id': '69', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '70', 'type': 'None', 'children': []}; {'id': '71', 'type': 'False', 'children': []}; {'id': '72', 'type': 'for_in_clause', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'mm'}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'ms'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'mapped_mods'}; {'id': '77', 'type': 'block', 'children': ['78']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}; {'id': '79', 'type': 'call', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'correctly_mapped_stmts'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'ms'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'mapped_stmt'}; {'id': '87', 'type': 'expression_statement', 'children': ['88']}; {'id': '88', 'type': 'assignment', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'mapped_stmts'}; {'id': '90', 'type': 'binary_operator', 'children': ['91', '92'], 'value': '+'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'valid'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'correctly_mapped_stmts'}; {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'pa2'}; {'id': '96', 'type': 'call', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'Preassembler'}; {'id': '98', 'type': 'argument_list', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'hierarchies'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'mapped_stmts'}; {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '106']}; {'id': '103', 'type': 'attribute', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '106', 'type': 'argument_list', 'children': ['107']}; {'id': '107', 'type': 'string', 'children': [], 'value': '"Combining duplicates again"'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}; {'id': '109', 'type': 'call', 'children': ['110', '113']}; {'id': '110', 'type': 'attribute', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'pa2'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'combine_duplicates'}; {'id': '113', 'type': 'argument_list', 'children': []}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}; {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'pa2'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'combine_related'}; {'id': '119', 'type': 'argument_list', 'children': []}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}; {'id': '121', 'type': 'assignment', 'children': ['122', '125']}; {'id': '122', 'type': 'attribute', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '125', 'type': 'dictionary', 'children': []}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}; {'id': '127', 'type': 'assignment', 'children': ['128', '133']}; {'id': '128', 'type': 'subscript', 'children': ['129', '132']}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '132', 'type': 'string', 'children': [], 'value': "'raw'"}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'stmts'}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}; {'id': '135', 'type': 'assignment', 'children': ['136', '141']}; {'id': '136', 'type': 'subscript', 'children': ['137', '140']}; {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '140', 'type': 'string', 'children': [], 'value': "'duplicates1'"}; {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'pa1'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'unique_stmts'}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}; {'id': '145', 'type': 'assignment', 'children': ['146', '151']}; {'id': '146', 'type': 'subscript', 'children': ['147', '150']}; {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '150', 'type': 'string', 'children': [], 'value': "'valid'"}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'valid'}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}; {'id': '153', 'type': 'assignment', 'children': ['154', '159']}; {'id': '154', 'type': 'subscript', 'children': ['155', '158']}; {'id': '155', 'type': 'attribute', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '158', 'type': 'string', 'children': [], 'value': "'mapped'"}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'mapped'}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}; {'id': '161', 'type': 'assignment', 'children': ['162', '167']}; {'id': '162', 'type': 'subscript', 'children': ['163', '166']}; {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '166', 'type': 'string', 'children': [], 'value': "'mapped_stmts'"}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'mapped_stmts'}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}; {'id': '169', 'type': 'assignment', 'children': ['170', '175']}; {'id': '170', 'type': 'subscript', 'children': ['171', '174']}; {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '174', 'type': 'string', 'children': [], 'value': "'duplicates2'"}; {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'pa2'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'unique_stmts'}; {'id': '178', 'type': 'expression_statement', 'children': ['179']}; {'id': '179', 'type': 'assignment', 'children': ['180', '185']}; {'id': '180', 'type': 'subscript', 'children': ['181', '184']}; {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '184', 'type': 'string', 'children': [], 'value': "'related2'"}; {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'pa2'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'related_stmts'}; {'id': '188', 'type': 'if_statement', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'print_summary'}; {'id': '190', 'type': 'block', 'children': ['191', '203', '217', '229', '241', '255']}; {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'call', 'children': ['193', '196']}; {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '196', 'type': 'argument_list', 'children': ['197']}; {'id': '197', 'type': 'binary_operator', 'children': ['198', '199'], 'value': '%'}; {'id': '198', 'type': 'string', 'children': [], 'value': '"\\nStarting number of statements: %d"'}; {'id': '199', 'type': 'call', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '201', 'type': 'argument_list', 'children': ['202']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'stmts'}; {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'call', 'children': ['205', '208']}; {'id': '205', 'type': 'attribute', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '208', 'type': 'argument_list', 'children': ['209']}; {'id': '209', 'type': 'binary_operator', 'children': ['210', '211'], 'value': '%'}; {'id': '210', 'type': 'string', 'children': [], 'value': '"After duplicate removal: %d"'}; {'id': '211', 'type': 'call', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'pa1'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'unique_stmts'}; {'id': '217', 'type': 'expression_statement', 'children': ['218']}; {'id': '218', 'type': 'call', 'children': ['219', '222']}; {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '222', 'type': 'argument_list', 'children': ['223']}; {'id': '223', 'type': 'binary_operator', 'children': ['224', '225'], 'value': '%'}; {'id': '224', 'type': 'string', 'children': [], 'value': '"Unique statements with valid sites: %d"'}; {'id': '225', 'type': 'call', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '227', 'type': 'argument_list', 'children': ['228']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'valid'}; {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'call', 'children': ['231', '234']}; {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '234', 'type': 'argument_list', 'children': ['235']}; {'id': '235', 'type': 'binary_operator', 'children': ['236', '237'], 'value': '%'}; {'id': '236', 'type': 'string', 'children': [], 'value': '"Unique statements with invalid sites: %d"'}; {'id': '237', 'type': 'call', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '239', 'type': 'argument_list', 'children': ['240']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'mapped'}; {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'call', 'children': ['243', '246']}; {'id': '243', 'type': 'attribute', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}; {'id': '247', 'type': 'binary_operator', 'children': ['248', '249'], 'value': '%'}; {'id': '248', 'type': 'string', 'children': [], 'value': '"After post-mapping duplicate removal: %d"'}; {'id': '249', 'type': 'call', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '251', 'type': 'argument_list', 'children': ['252']}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'pa2'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'unique_stmts'}; {'id': '255', 'type': 'expression_statement', 'children': ['256']}; {'id': '256', 'type': 'call', 'children': ['257', '260']}; {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '260', 'type': 'argument_list', 'children': ['261']}; {'id': '261', 'type': 'binary_operator', 'children': ['262', '263'], 'value': '%'}; {'id': '262', 'type': 'string', 'children': [], 'value': '"After combining related statements: %d"'}; {'id': '263', 'type': 'call', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '265', 'type': 'argument_list', 'children': ['266']}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'pa2'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'related_stmts'}; {'id': '269', 'type': 'if_statement', 'children': ['270', '275']}; {'id': '270', 'type': 'comparison_operator', 'children': ['271', '274'], 'value': 'is'}; {'id': '271', 'type': 'attribute', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '274', 'type': 'None', 'children': []}; {'id': '275', 'type': 'block', 'children': ['276', '284']}; {'id': '276', 'type': 'expression_statement', 'children': ['277']}; {'id': '277', 'type': 'assignment', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'results_filename'}; {'id': '279', 'type': 'binary_operator', 'children': ['280', '281'], 'value': '%'}; {'id': '280', 'type': 'string', 'children': [], 'value': "'%s_results.pkl'"}; {'id': '281', 'type': 'attribute', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'basename'}; {'id': '284', 'type': 'with_statement', 'children': ['285', '295']}; {'id': '285', 'type': 'with_clause', 'children': ['286']}; {'id': '286', 'type': 'with_item', 'children': ['287']}; {'id': '287', 'type': 'as_pattern', 'children': ['288', '293']}; {'id': '288', 'type': 'call', 'children': ['289', '290']}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'open'}; {'id': '290', 'type': 'argument_list', 'children': ['291', '292']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'results_filename'}; {'id': '292', 'type': 'string', 'children': [], 'value': "'wb'"}; {'id': '293', 'type': 'as_pattern_target', 'children': ['294']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '295', 'type': 'block', 'children': ['296']}; {'id': '296', 'type': 'expression_statement', 'children': ['297']}; {'id': '297', 'type': 'call', 'children': ['298', '301']}; {'id': '298', 'type': 'attribute', 'children': ['299', '300']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'pickle'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'dump'}; {'id': '301', 'type': 'argument_list', 'children': ['302', '305']}; {'id': '302', 'type': 'attribute', 'children': ['303', '304']}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'f'}; {'id': '306', 'type': 'return_statement', 'children': ['307']}; {'id': '307', 'type': 'attribute', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'results'}
def run_preassembly(self, stmts, print_summary=True): pa1 = Preassembler(hierarchies, stmts) logger.info("Combining duplicates") pa1.combine_duplicates() logger.info("Mapping sites") (valid, mapped) = sm.map_sites(pa1.unique_stmts) correctly_mapped_stmts = [] for ms in mapped: if all([True if mm[1] is not None else False for mm in ms.mapped_mods]): correctly_mapped_stmts.append(ms.mapped_stmt) mapped_stmts = valid + correctly_mapped_stmts pa2 = Preassembler(hierarchies, mapped_stmts) logger.info("Combining duplicates again") pa2.combine_duplicates() pa2.combine_related() self.results = {} self.results['raw'] = stmts self.results['duplicates1'] = pa1.unique_stmts self.results['valid'] = valid self.results['mapped'] = mapped self.results['mapped_stmts'] = mapped_stmts self.results['duplicates2'] = pa2.unique_stmts self.results['related2'] = pa2.related_stmts if print_summary: logger.info("\nStarting number of statements: %d" % len(stmts)) logger.info("After duplicate removal: %d" % len(pa1.unique_stmts)) logger.info("Unique statements with valid sites: %d" % len(valid)) logger.info("Unique statements with invalid sites: %d" % len(mapped)) logger.info("After post-mapping duplicate removal: %d" % len(pa2.unique_stmts)) logger.info("After combining related statements: %d" % len(pa2.related_stmts)) if self.basename is not None: results_filename = '%s_results.pkl' % self.basename with open(results_filename, 'wb') as f: pickle.dump(self.results, f) return self.results
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_get_grounding'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '5', 'type': 'block', 'children': ['6', '15', '24', '30', '100', '117', '121', '146', '186', '195']}; {'id': '6', 'type': 'expression_statement', 'children': ['7']}; {'id': '7', 'type': 'assignment', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '9', 'type': 'dictionary', 'children': ['10']}; {'id': '10', 'type': 'pair', 'children': ['11', '12']}; {'id': '11', 'type': 'string', 'children': [], 'value': "'TEXT'"}; {'id': '12', 'type': 'subscript', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '14', 'type': 'string', 'children': [], 'value': "'text'"}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'groundings'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'entity'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'string', 'children': [], 'value': "'grounding'"}; {'id': '24', 'type': 'if_statement', 'children': ['25', '27']}; {'id': '25', 'type': 'not_operator', 'children': ['26']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'groundings'}; {'id': '27', 'type': 'block', 'children': ['28']}; {'id': '28', 'type': 'return_statement', 'children': ['29']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '30', 'type': 'function_definition', 'children': ['31', '32', '34']}; {'id': '31', 'type': 'function_name', 'children': [], 'value': 'get_ont_concept'}; {'id': '32', 'type': 'parameters', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'concept'}; {'id': '34', 'type': 'block', 'children': ['35', '98']}; {'id': '35', 'type': 'if_statement', 'children': ['36', '42']}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'concept'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '42', 'type': 'block', 'children': ['43', '51', '61']}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'concept'}; {'id': '46', 'type': 'subscript', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'concept'}; {'id': '48', 'type': 'slice', 'children': ['49', '50']}; {'id': '49', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '50', 'type': 'colon', 'children': []}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'concept'}; {'id': '54', 'type': 'call', 'children': ['55', '58']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'concept'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'replace'}; {'id': '58', 'type': 'argument_list', 'children': ['59', '60']}; {'id': '59', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '60', 'type': 'string', 'children': [], 'value': "'_'"}; {'id': '61', 'type': 'while_statement', 'children': ['62', '65']}; {'id': '62', 'type': 'comparison_operator', 'children': ['63', '64'], 'value': 'not'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'concept'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'hume_onto_entries'}; {'id': '65', 'type': 'block', 'children': ['66', '75', '84']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '69', 'type': 'call', 'children': ['70', '73']}; {'id': '70', 'type': 'attribute', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'concept'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '75', 'type': 'if_statement', 'children': ['76', '82']}; {'id': '76', 'type': 'comparison_operator', 'children': ['77', '81'], 'value': '=='}; {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '81', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '82', 'type': 'block', 'children': ['83']}; {'id': '83', 'type': 'break_statement', 'children': []}; {'id': '84', 'type': 'expression_statement', 'children': ['85']}; {'id': '85', 'type': 'assignment', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'concept'}; {'id': '87', 'type': 'call', 'children': ['88', '91']}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'subscript', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'parts'}; {'id': '94', 'type': 'slice', 'children': ['95', '96']}; {'id': '95', 'type': 'colon', 'children': []}; {'id': '96', 'type': 'unary_operator', 'children': ['97'], 'value': '-'}; {'id': '97', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '98', 'type': 'return_statement', 'children': ['99']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'concept'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}; {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'raw_grounding_entries'}; {'id': '103', 'type': 'list_comprehension', 'children': ['104', '114']}; {'id': '104', 'type': 'tuple', 'children': ['105', '111']}; {'id': '105', 'type': 'call', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'get_ont_concept'}; {'id': '107', 'type': 'argument_list', 'children': ['108']}; {'id': '108', 'type': 'subscript', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '110', 'type': 'string', 'children': [], 'value': "'ontologyConcept'"}; {'id': '111', 'type': 'subscript', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '113', 'type': 'string', 'children': [], 'value': "'value'"}; {'id': '114', 'type': 'for_in_clause', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'g'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'groundings'}; {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'grounding_dict'}; {'id': '120', 'type': 'dictionary', 'children': []}; {'id': '121', 'type': 'for_statement', 'children': ['122', '125', '126']}; {'id': '122', 'type': 'pattern_list', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'cat'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'raw_grounding_entries'}; {'id': '126', 'type': 'block', 'children': ['127']}; {'id': '127', 'type': 'if_statement', 'children': ['128', '139']}; {'id': '128', 'type': 'boolean_operator', 'children': ['129', '133'], 'value': 'or'}; {'id': '129', 'type': '()', 'children': ['130']}; {'id': '130', 'type': 'comparison_operator', 'children': ['131', '132'], 'value': 'not'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'cat'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'grounding_dict'}; {'id': '133', 'type': '()', 'children': ['134']}; {'id': '134', 'type': 'comparison_operator', 'children': ['135', '136'], 'value': '>'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '136', 'type': 'subscript', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'grounding_dict'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'cat'}; {'id': '139', 'type': 'block', 'children': ['140']}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}; {'id': '141', 'type': 'assignment', 'children': ['142', '145']}; {'id': '142', 'type': 'subscript', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'grounding_dict'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'cat'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}; {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'grounding_entries'}; {'id': '149', 'type': 'call', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '151', 'type': 'argument_list', 'children': ['152', '163', '183']}; {'id': '152', 'type': 'call', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}; {'id': '155', 'type': 'call', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '157', 'type': 'argument_list', 'children': ['158']}; {'id': '158', 'type': 'call', 'children': ['159', '162']}; {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'grounding_dict'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '162', 'type': 'argument_list', 'children': []}; {'id': '163', 'type': 'keyword_argument', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '165', 'type': 'lambda', 'children': ['166', '168']}; {'id': '166', 'type': 'lambda_parameters', 'children': ['167']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '168', 'type': 'tuple', 'children': ['169', '172', '180']}; {'id': '169', 'type': 'subscript', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '171', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '172', 'type': 'call', 'children': ['173', '178']}; {'id': '173', 'type': 'attribute', 'children': ['174', '177']}; {'id': '174', 'type': 'subscript', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '176', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}; {'id': '179', 'type': 'string', 'children': [], 'value': "'/'"}; {'id': '180', 'type': 'subscript', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '182', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '183', 'type': 'keyword_argument', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'reverse'}; {'id': '185', 'type': 'True', 'children': []}; {'id': '186', 'type': 'if_statement', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'grounding_entries'}; {'id': '188', 'type': 'block', 'children': ['189']}; {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '194']}; {'id': '191', 'type': 'subscript', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '193', 'type': 'string', 'children': [], 'value': "'HUME'"}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'grounding_entries'}; {'id': '195', 'type': 'return_statement', 'children': ['196']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'db_refs'}
def _get_grounding(entity): db_refs = {'TEXT': entity['text']} groundings = entity.get('grounding') if not groundings: return db_refs def get_ont_concept(concept): if concept.startswith('/'): concept = concept[1:] concept = concept.replace(' ', '_') while concept not in hume_onto_entries: parts = concept.split('/') if len(parts) == 1: break concept = '/'.join(parts[:-1]) return concept raw_grounding_entries = [(get_ont_concept(g['ontologyConcept']), g['value']) for g in groundings] grounding_dict = {} for cat, score in raw_grounding_entries: if (cat not in grounding_dict) or (score > grounding_dict[cat]): grounding_dict[cat] = score grounding_entries = sorted(list(set(grounding_dict.items())), key=lambda x: (x[1], x[0].count('/'), x[0]), reverse=True) if grounding_entries: db_refs['HUME'] = grounding_entries return db_refs
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_is_statement_in_list'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'new_stmt'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'old_stmt_list'}; {'id': '6', 'type': 'block', 'children': ['7', '252']}; {'id': '7', 'type': 'for_statement', 'children': ['8', '9', '10']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'old_stmt'}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'old_stmt_list'}; {'id': '10', 'type': 'block', 'children': ['11']}; {'id': '11', 'type': 'if_statement', 'children': ['12', '18', '21', '181']}; {'id': '12', 'type': 'call', 'children': ['13', '16']}; {'id': '13', 'type': 'attribute', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'old_stmt'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'equals'}; {'id': '16', 'type': 'argument_list', 'children': ['17']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'new_stmt'}; {'id': '18', 'type': 'block', 'children': ['19']}; {'id': '19', 'type': 'return_statement', 'children': ['20']}; {'id': '20', 'type': 'True', 'children': []}; {'id': '21', 'type': 'elif_clause', 'children': ['22', '35']}; {'id': '22', 'type': 'boolean_operator', 'children': ['23', '29'], 'value': 'and'}; {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'old_stmt'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'evidence_equals'}; {'id': '27', 'type': 'argument_list', 'children': ['28']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'new_stmt'}; {'id': '29', 'type': 'call', 'children': ['30', '33']}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'old_stmt'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'matches'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'new_stmt'}; {'id': '35', 'type': 'block', 'children': ['36', '77', '179']}; {'id': '36', 'type': 'if_statement', 'children': ['37', '42', '59']}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '39', 'type': 'argument_list', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'new_stmt'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'Complex'}; {'id': '42', 'type': 'block', 'children': ['43']}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'agent_pairs'}; {'id': '46', 'type': 'call', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '48', 'type': 'argument_list', 'children': ['49', '54']}; {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'old_stmt'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'sorted_members'}; {'id': '53', 'type': 'argument_list', 'children': []}; {'id': '54', 'type': 'call', 'children': ['55', '58']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'new_stmt'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'sorted_members'}; {'id': '58', 'type': 'argument_list', 'children': []}; {'id': '59', 'type': 'else_clause', 'children': ['60']}; {'id': '60', 'type': 'block', 'children': ['61']}; {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'agent_pairs'}; {'id': '64', 'type': 'call', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '66', 'type': 'argument_list', 'children': ['67', '72']}; {'id': '67', 'type': 'call', 'children': ['68', '71']}; {'id': '68', 'type': 'attribute', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'old_stmt'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'agent_list'}; {'id': '71', 'type': 'argument_list', 'children': []}; {'id': '72', 'type': 'call', 'children': ['73', '76']}; {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'new_stmt'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'agent_list'}; {'id': '76', 'type': 'argument_list', 'children': []}; {'id': '77', 'type': 'for_statement', 'children': ['78', '81', '82']}; {'id': '78', 'type': 'pattern_list', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'ag_old'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'ag_new'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'agent_pairs'}; {'id': '82', 'type': 'block', 'children': ['83', '96', '109', '115', '122', '140', '154', '168', '177']}; {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 's_old'}; {'id': '86', 'type': 'call', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '88', 'type': 'argument_list', 'children': ['89']}; {'id': '89', 'type': 'call', 'children': ['90', '95']}; {'id': '90', 'type': 'attribute', 'children': ['91', '94']}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'ag_old'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '95', 'type': 'argument_list', 'children': []}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}; {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 's_new'}; {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'call', 'children': ['103', '108']}; {'id': '103', 'type': 'attribute', 'children': ['104', '107']}; {'id': '104', 'type': 'attribute', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'ag_new'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '108', 'type': 'argument_list', 'children': []}; {'id': '109', 'type': 'if_statement', 'children': ['110', '113']}; {'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': '=='}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 's_old'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 's_new'}; {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'continue_statement', 'children': []}; {'id': '115', 'type': 'if_statement', 'children': ['116', '119']}; {'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': '>'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 's_old'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 's_new'}; {'id': '119', 'type': 'block', 'children': ['120']}; {'id': '120', 'type': 'return_statement', 'children': ['121']}; {'id': '121', 'type': 'True', 'children': []}; {'id': '122', 'type': 'if_statement', 'children': ['123', '126']}; {'id': '123', 'type': 'comparison_operator', 'children': ['124', '125'], 'value': '>'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 's_new'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 's_old'}; {'id': '126', 'type': 'block', 'children': ['127', '138']}; {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '134']}; {'id': '129', 'type': 'attribute', 'children': ['130', '133']}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'ag_old'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}; {'id': '135', 'type': 'attribute', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'ag_new'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '138', 'type': 'return_statement', 'children': ['139']}; {'id': '139', 'type': 'True', 'children': []}; {'id': '140', 'type': 'if_statement', 'children': ['141', '147']}; {'id': '141', 'type': 'call', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': '_fix_different_refs'}; {'id': '143', 'type': 'argument_list', 'children': ['144', '145', '146']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'ag_old'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'ag_new'}; {'id': '146', 'type': 'string', 'children': [], 'value': "'CHEBI'"}; {'id': '147', 'type': 'block', 'children': ['148']}; {'id': '148', 'type': 'return_statement', 'children': ['149']}; {'id': '149', 'type': 'call', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': '_is_statement_in_list'}; {'id': '151', 'type': 'argument_list', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'new_stmt'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'old_stmt_list'}; {'id': '154', 'type': 'if_statement', 'children': ['155', '161']}; {'id': '155', 'type': 'call', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': '_fix_different_refs'}; {'id': '157', 'type': 'argument_list', 'children': ['158', '159', '160']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'ag_old'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'ag_new'}; {'id': '160', 'type': 'string', 'children': [], 'value': "'UMLS'"}; {'id': '161', 'type': 'block', 'children': ['162']}; {'id': '162', 'type': 'return_statement', 'children': ['163']}; {'id': '163', 'type': 'call', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': '_is_statement_in_list'}; {'id': '165', 'type': 'argument_list', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'new_stmt'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'old_stmt_list'}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}; {'id': '169', 'type': 'call', 'children': ['170', '173']}; {'id': '170', 'type': 'attribute', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'concatenated_string', 'children': ['175', '176']}; {'id': '175', 'type': 'string', 'children': [], 'value': '"Found an unexpected kind of duplicate. "'}; {'id': '176', 'type': 'string', 'children': [], 'value': '"Ignoring it."'}; {'id': '177', 'type': 'return_statement', 'children': ['178']}; {'id': '178', 'type': 'True', 'children': []}; {'id': '179', 'type': 'return_statement', 'children': ['180']}; {'id': '180', 'type': 'True', 'children': []}; {'id': '181', 'type': 'elif_clause', 'children': ['182', '197']}; {'id': '182', 'type': 'comparison_operator', 'children': ['183', '190'], 'value': '=='}; {'id': '183', 'type': 'call', 'children': ['184', '187']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'old_stmt'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'get_hash'}; {'id': '187', 'type': 'argument_list', 'children': ['188', '189']}; {'id': '188', 'type': 'True', 'children': []}; {'id': '189', 'type': 'True', 'children': []}; {'id': '190', 'type': 'call', 'children': ['191', '194']}; {'id': '191', 'type': 'attribute', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'new_stmt'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'get_hash'}; {'id': '194', 'type': 'argument_list', 'children': ['195', '196']}; {'id': '195', 'type': 'True', 'children': []}; {'id': '196', 'type': 'True', 'children': []}; {'id': '197', 'type': 'block', 'children': ['198', '206', '214', '235']}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}; {'id': '199', 'type': 'assignment', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'e_old'}; {'id': '201', 'type': 'subscript', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'old_stmt'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'evidence'}; {'id': '205', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}; {'id': '207', 'type': 'assignment', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'e_new'}; {'id': '209', 'type': 'subscript', 'children': ['210', '213']}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'new_stmt'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'evidence'}; {'id': '213', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '214', 'type': 'if_statement', 'children': ['215', '222']}; {'id': '215', 'type': 'comparison_operator', 'children': ['216', '221'], 'value': 'is'}; {'id': '216', 'type': 'subscript', 'children': ['217', '220']}; {'id': '217', 'type': 'attribute', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'e_old'}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '220', 'type': 'string', 'children': [], 'value': "'last_verb'"}; {'id': '221', 'type': 'None', 'children': []}; {'id': '222', 'type': 'block', 'children': ['223']}; {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'assignment', 'children': ['225', '230']}; {'id': '225', 'type': 'subscript', 'children': ['226', '229']}; {'id': '226', 'type': 'attribute', 'children': ['227', '228']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'e_old'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '229', 'type': 'string', 'children': [], 'value': "'last_verb'"}; {'id': '230', 'type': 'subscript', 'children': ['231', '234']}; {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'e_new'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'annotations'}; {'id': '234', 'type': 'string', 'children': [], 'value': "'last_verb'"}; {'id': '235', 'type': 'if_statement', 'children': ['236', '249']}; {'id': '236', 'type': 'comparison_operator', 'children': ['237', '243'], 'value': '=='}; {'id': '237', 'type': 'call', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'e_old'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'get_source_hash'}; {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'True', 'children': []}; {'id': '243', 'type': 'call', 'children': ['244', '247']}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'e_new'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'get_source_hash'}; {'id': '247', 'type': 'argument_list', 'children': ['248']}; {'id': '248', 'type': 'True', 'children': []}; {'id': '249', 'type': 'block', 'children': ['250']}; {'id': '250', 'type': 'return_statement', 'children': ['251']}; {'id': '251', 'type': 'True', 'children': []}; {'id': '252', 'type': 'return_statement', 'children': ['253']}; {'id': '253', 'type': 'False', 'children': []}
def _is_statement_in_list(new_stmt, old_stmt_list): for old_stmt in old_stmt_list: if old_stmt.equals(new_stmt): return True elif old_stmt.evidence_equals(new_stmt) and old_stmt.matches(new_stmt): if isinstance(new_stmt, Complex): agent_pairs = zip(old_stmt.sorted_members(), new_stmt.sorted_members()) else: agent_pairs = zip(old_stmt.agent_list(), new_stmt.agent_list()) for ag_old, ag_new in agent_pairs: s_old = set(ag_old.db_refs.items()) s_new = set(ag_new.db_refs.items()) if s_old == s_new: continue if s_old > s_new: return True if s_new > s_old: ag_old.db_refs.update(ag_new.db_refs) return True if _fix_different_refs(ag_old, ag_new, 'CHEBI'): return _is_statement_in_list(new_stmt, old_stmt_list) if _fix_different_refs(ag_old, ag_new, 'UMLS'): return _is_statement_in_list(new_stmt, old_stmt_list) logger.warning("Found an unexpected kind of duplicate. " "Ignoring it.") return True return True elif old_stmt.get_hash(True, True) == new_stmt.get_hash(True, True): e_old = old_stmt.evidence[0] e_new = new_stmt.evidence[0] if e_old.annotations['last_verb'] is None: e_old.annotations['last_verb'] = e_new.annotations['last_verb'] if e_old.get_source_hash(True) == e_new.get_source_hash(True): return True return False
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '5']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_urn_to_db_refs'}; {'id': '3', 'type': 'parameters', 'children': ['4']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'urn'}; {'id': '5', 'type': 'block', 'children': ['6', '15', '24', '33', '43', '47', '51', '227', '233', '263', '305', '311', '324', '351']}; {'id': '6', 'type': 'if_statement', 'children': ['7', '10']}; {'id': '7', 'type': 'comparison_operator', 'children': ['8', '9'], 'value': 'is'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'urn'}; {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11']}; {'id': '11', 'type': 'return_statement', 'children': ['12']}; {'id': '12', 'type': 'expression_list', 'children': ['13', '14']}; {'id': '13', 'type': 'dictionary', 'children': []}; {'id': '14', 'type': 'None', 'children': []}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'URN_PATT'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'match'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'urn'}; {'id': '24', 'type': 'if_statement', 'children': ['25', '28']}; {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'is'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '27', 'type': 'None', 'children': []}; {'id': '28', 'type': 'block', 'children': ['29']}; {'id': '29', 'type': 'return_statement', 'children': ['30']}; {'id': '30', 'type': 'expression_list', 'children': ['31', '32']}; {'id': '31', 'type': 'None', 'children': []}; {'id': '32', 'type': 'None', 'children': []}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '38']}; {'id': '35', 'type': 'pattern_list', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'urn_type'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'urn_id'}; {'id': '38', 'type': 'call', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '42', 'type': 'argument_list', 'children': []}; {'id': '43', 'type': 'expression_statement', 'children': ['44']}; {'id': '44', 'type': 'assignment', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '46', 'type': 'dictionary', 'children': []}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'db_name'}; {'id': '50', 'type': 'None', 'children': []}; {'id': '51', 'type': 'if_statement', 'children': ['52', '55', '81', '129', '201', '214']}; {'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': '=='}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'urn_type'}; {'id': '54', 'type': 'string', 'children': [], 'value': "'agi-cas'"}; {'id': '55', 'type': 'block', 'children': ['56', '63']}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'chebi_id'}; {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'get_chebi_id_from_cas'}; {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'urn_id'}; {'id': '63', 'type': 'if_statement', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'chebi_id'}; {'id': '65', 'type': 'block', 'children': ['66', '74']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'assignment', 'children': ['68', '71']}; {'id': '68', 'type': 'subscript', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '70', 'type': 'string', 'children': [], 'value': "'CHEBI'"}; {'id': '71', 'type': 'binary_operator', 'children': ['72', '73'], 'value': '%'}; {'id': '72', 'type': 'string', 'children': [], 'value': "'CHEBI:%s'"}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'chebi_id'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}; {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'db_name'}; {'id': '77', 'type': 'call', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'get_chebi_name_from_id'}; {'id': '79', 'type': 'argument_list', 'children': ['80']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'chebi_id'}; {'id': '81', 'type': 'elif_clause', 'children': ['82', '85']}; {'id': '82', 'type': 'comparison_operator', 'children': ['83', '84'], 'value': '=='}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'urn_type'}; {'id': '84', 'type': 'string', 'children': [], 'value': "'agi-llid'"}; {'id': '85', 'type': 'block', 'children': ['86', '93']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}; {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'hgnc_id'}; {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'get_hgnc_from_entrez'}; {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'urn_id'}; {'id': '93', 'type': 'if_statement', 'children': ['94', '97']}; {'id': '94', 'type': 'comparison_operator', 'children': ['95', '96'], 'value': 'is'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'hgnc_id'}; {'id': '96', 'type': 'None', 'children': []}; {'id': '97', 'type': 'block', 'children': ['98', '104', '111', '122']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'assignment', 'children': ['100', '103']}; {'id': '100', 'type': 'subscript', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '102', 'type': 'string', 'children': [], 'value': "'HGNC'"}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'hgnc_id'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}; {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'}; {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'get_uniprot_id'}; {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'hgnc_id'}; {'id': '111', 'type': 'if_statement', 'children': ['112', '115']}; {'id': '112', 'type': 'comparison_operator', 'children': ['113', '114'], 'value': 'is'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'}; {'id': '114', 'type': 'None', 'children': []}; {'id': '115', 'type': 'block', 'children': ['116']}; {'id': '116', 'type': 'expression_statement', 'children': ['117']}; {'id': '117', 'type': 'assignment', 'children': ['118', '121']}; {'id': '118', 'type': 'subscript', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '120', 'type': 'string', 'children': [], 'value': "'UP'"}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'uniprot_id'}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}; {'id': '123', 'type': 'assignment', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'db_name'}; {'id': '125', 'type': 'call', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'get_hgnc_name'}; {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'hgnc_id'}; {'id': '129', 'type': 'elif_clause', 'children': ['130', '137']}; {'id': '130', 'type': 'comparison_operator', 'children': ['131', '132'], 'value': 'in'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'urn_type'}; {'id': '132', 'type': 'list', 'children': ['133', '134', '135', '136'], 'value': "['agi-meshdis', 'agi-ncimorgan', 'agi-ncimtissue',\n 'agi-ncimcelltype']"}; {'id': '133', 'type': 'string', 'children': [], 'value': "'agi-meshdis'"}; {'id': '134', 'type': 'string', 'children': [], 'value': "'agi-ncimorgan'"}; {'id': '135', 'type': 'string', 'children': [], 'value': "'agi-ncimtissue'"}; {'id': '136', 'type': 'string', 'children': [], 'value': "'agi-ncimcelltype'"}; {'id': '137', 'type': 'block', 'children': ['138']}; {'id': '138', 'type': 'if_statement', 'children': ['139', '155', '162']}; {'id': '139', 'type': 'boolean_operator', 'children': ['140', '146'], 'value': 'and'}; {'id': '140', 'type': 'call', 'children': ['141', '144']}; {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'urn_id'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}; {'id': '145', 'type': 'string', 'children': [], 'value': "'C'"}; {'id': '146', 'type': 'call', 'children': ['147', '154']}; {'id': '147', 'type': 'attribute', 'children': ['148', '153']}; {'id': '148', 'type': 'subscript', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'urn_id'}; {'id': '150', 'type': 'slice', 'children': ['151', '152']}; {'id': '151', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '152', 'type': 'colon', 'children': []}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'isdigit'}; {'id': '154', 'type': 'argument_list', 'children': []}; {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'expression_statement', 'children': ['157']}; {'id': '157', 'type': 'assignment', 'children': ['158', '161']}; {'id': '158', 'type': 'subscript', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '160', 'type': 'string', 'children': [], 'value': "'UMLS'"}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'urn_id'}; {'id': '162', 'type': 'else_clause', 'children': ['163']}; {'id': '163', 'type': 'block', 'children': ['164', '171', '182']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}; {'id': '165', 'type': 'assignment', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'urn_mesh_name'}; {'id': '167', 'type': 'call', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'unquote'}; {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'urn_id'}; {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'assignment', 'children': ['173', '176']}; {'id': '173', 'type': 'pattern_list', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'mesh_id'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'mesh_name'}; {'id': '176', 'type': 'call', 'children': ['177', '180']}; {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'mesh_client'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'get_mesh_id_name'}; {'id': '180', 'type': 'argument_list', 'children': ['181']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'urn_mesh_name'}; {'id': '182', 'type': 'if_statement', 'children': ['183', '184', '195']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'mesh_id'}; {'id': '184', 'type': 'block', 'children': ['185', '191']}; {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '190']}; {'id': '187', 'type': 'subscript', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '189', 'type': 'string', 'children': [], 'value': "'MESH'"}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'mesh_id'}; {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'db_name'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'mesh_name'}; {'id': '195', 'type': 'else_clause', 'children': ['196']}; {'id': '196', 'type': 'block', 'children': ['197']}; {'id': '197', 'type': 'expression_statement', 'children': ['198']}; {'id': '198', 'type': 'assignment', 'children': ['199', '200']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'db_name'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'urn_mesh_name'}; {'id': '201', 'type': 'elif_clause', 'children': ['202', '205']}; {'id': '202', 'type': 'comparison_operator', 'children': ['203', '204'], 'value': '=='}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'urn_type'}; {'id': '204', 'type': 'string', 'children': [], 'value': "'agi-gocomplex'"}; {'id': '205', 'type': 'block', 'children': ['206']}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}; {'id': '207', 'type': 'assignment', 'children': ['208', '211']}; {'id': '208', 'type': 'subscript', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '210', 'type': 'string', 'children': [], 'value': "'GO'"}; {'id': '211', 'type': 'binary_operator', 'children': ['212', '213'], 'value': '%'}; {'id': '212', 'type': 'string', 'children': [], 'value': "'GO:%s'"}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'urn_id'}; {'id': '214', 'type': 'elif_clause', 'children': ['215', '218']}; {'id': '215', 'type': 'comparison_operator', 'children': ['216', '217'], 'value': '=='}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'urn_type'}; {'id': '217', 'type': 'string', 'children': [], 'value': "'agi-go'"}; {'id': '218', 'type': 'block', 'children': ['219']}; {'id': '219', 'type': 'expression_statement', 'children': ['220']}; {'id': '220', 'type': 'assignment', 'children': ['221', '224']}; {'id': '221', 'type': 'subscript', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '223', 'type': 'string', 'children': [], 'value': "'GO'"}; {'id': '224', 'type': 'binary_operator', 'children': ['225', '226'], 'value': '%'}; {'id': '225', 'type': 'string', 'children': [], 'value': "'GO:%s'"}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'urn_id'}; {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '230']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'db_sometimes_maps_to_famplex'}; {'id': '230', 'type': 'list', 'children': ['231', '232'], 'value': "['GO', 'MESH']"}; {'id': '231', 'type': 'string', 'children': [], 'value': "'GO'"}; {'id': '232', 'type': 'string', 'children': [], 'value': "'MESH'"}; {'id': '233', 'type': 'for_statement', 'children': ['234', '235', '236']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'db_sometimes_maps_to_famplex'}; {'id': '236', 'type': 'block', 'children': ['237']}; {'id': '237', 'type': 'if_statement', 'children': ['238', '241']}; {'id': '238', 'type': 'comparison_operator', 'children': ['239', '240'], 'value': 'in'}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '241', 'type': 'block', 'children': ['242', '250']}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}; {'id': '243', 'type': 'assignment', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '245', 'type': 'tuple', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '247', 'type': 'subscript', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '250', 'type': 'if_statement', 'children': ['251', '254']}; {'id': '251', 'type': 'comparison_operator', 'children': ['252', '253'], 'value': 'in'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'famplex_map'}; {'id': '254', 'type': 'block', 'children': ['255']}; {'id': '255', 'type': 'expression_statement', 'children': ['256']}; {'id': '256', 'type': 'assignment', 'children': ['257', '260']}; {'id': '257', 'type': 'subscript', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '259', 'type': 'string', 'children': [], 'value': "'FPLX'"}; {'id': '260', 'type': 'subscript', 'children': ['261', '262']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'famplex_map'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '263', 'type': 'if_statement', 'children': ['264', '270']}; {'id': '264', 'type': 'call', 'children': ['265', '268']}; {'id': '265', 'type': 'attribute', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'urn'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'startswith'}; {'id': '268', 'type': 'argument_list', 'children': ['269']}; {'id': '269', 'type': 'string', 'children': [], 'value': "'urn:agi-enz'"}; {'id': '270', 'type': 'block', 'children': ['271', '280', '286', '292']}; {'id': '271', 'type': 'expression_statement', 'children': ['272']}; {'id': '272', 'type': 'assignment', 'children': ['273', '274']}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'tokens'}; {'id': '274', 'type': 'call', 'children': ['275', '278']}; {'id': '275', 'type': 'attribute', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'urn'}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '278', 'type': 'argument_list', 'children': ['279']}; {'id': '279', 'type': 'string', 'children': [], 'value': "':'"}; {'id': '280', 'type': 'expression_statement', 'children': ['281']}; {'id': '281', 'type': 'assignment', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'eccode'}; {'id': '283', 'type': 'subscript', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'tokens'}; {'id': '285', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '286', 'type': 'expression_statement', 'children': ['287']}; {'id': '287', 'type': 'assignment', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '289', 'type': 'tuple', 'children': ['290', '291']}; {'id': '290', 'type': 'string', 'children': [], 'value': "'ECCODE'"}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'eccode'}; {'id': '292', 'type': 'if_statement', 'children': ['293', '296']}; {'id': '293', 'type': 'comparison_operator', 'children': ['294', '295'], 'value': 'in'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'famplex_map'}; {'id': '296', 'type': 'block', 'children': ['297']}; {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'assignment', 'children': ['299', '302']}; {'id': '299', 'type': 'subscript', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '301', 'type': 'string', 'children': [], 'value': "'FPLX'"}; {'id': '302', 'type': 'subscript', 'children': ['303', '304']}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'famplex_map'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '305', 'type': 'expression_statement', 'children': ['306']}; {'id': '306', 'type': 'assignment', 'children': ['307', '308']}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '308', 'type': 'tuple', 'children': ['309', '310']}; {'id': '309', 'type': 'string', 'children': [], 'value': "'MEDSCAN'"}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'urn'}; {'id': '311', 'type': 'if_statement', 'children': ['312', '315']}; {'id': '312', 'type': 'comparison_operator', 'children': ['313', '314'], 'value': 'in'}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'famplex_map'}; {'id': '315', 'type': 'block', 'children': ['316']}; {'id': '316', 'type': 'expression_statement', 'children': ['317']}; {'id': '317', 'type': 'assignment', 'children': ['318', '321']}; {'id': '318', 'type': 'subscript', 'children': ['319', '320']}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '320', 'type': 'string', 'children': [], 'value': "'FPLX'"}; {'id': '321', 'type': 'subscript', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'famplex_map'}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '324', 'type': 'if_statement', 'children': ['325', '328', '335']}; {'id': '325', 'type': 'comparison_operator', 'children': ['326', '327'], 'value': 'in'}; {'id': '326', 'type': 'string', 'children': [], 'value': "'FPLX'"}; {'id': '327', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '328', 'type': 'block', 'children': ['329']}; {'id': '329', 'type': 'expression_statement', 'children': ['330']}; {'id': '330', 'type': 'assignment', 'children': ['331', '332']}; {'id': '331', 'type': 'identifier', 'children': [], 'value': 'db_name'}; {'id': '332', 'type': 'subscript', 'children': ['333', '334']}; {'id': '333', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '334', 'type': 'string', 'children': [], 'value': "'FPLX'"}; {'id': '335', 'type': 'elif_clause', 'children': ['336', '339']}; {'id': '336', 'type': 'comparison_operator', 'children': ['337', '338'], 'value': 'in'}; {'id': '337', 'type': 'string', 'children': [], 'value': "'GO'"}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '339', 'type': 'block', 'children': ['340']}; {'id': '340', 'type': 'expression_statement', 'children': ['341']}; {'id': '341', 'type': 'assignment', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'db_name'}; {'id': '343', 'type': 'call', 'children': ['344', '347']}; {'id': '344', 'type': 'attribute', 'children': ['345', '346']}; {'id': '345', 'type': 'identifier', 'children': [], 'value': 'go_client'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'get_go_label'}; {'id': '347', 'type': 'argument_list', 'children': ['348']}; {'id': '348', 'type': 'subscript', 'children': ['349', '350']}; {'id': '349', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '350', 'type': 'string', 'children': [], 'value': "'GO'"}; {'id': '351', 'type': 'return_statement', 'children': ['352']}; {'id': '352', 'type': 'expression_list', 'children': ['353', '354']}; {'id': '353', 'type': 'identifier', 'children': [], 'value': 'db_refs'}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'db_name'}
def _urn_to_db_refs(urn): if urn is None: return {}, None m = URN_PATT.match(urn) if m is None: return None, None urn_type, urn_id = m.groups() db_refs = {} db_name = None if urn_type == 'agi-cas': chebi_id = get_chebi_id_from_cas(urn_id) if chebi_id: db_refs['CHEBI'] = 'CHEBI:%s' % chebi_id db_name = get_chebi_name_from_id(chebi_id) elif urn_type == 'agi-llid': hgnc_id = get_hgnc_from_entrez(urn_id) if hgnc_id is not None: db_refs['HGNC'] = hgnc_id uniprot_id = get_uniprot_id(hgnc_id) if uniprot_id is not None: db_refs['UP'] = uniprot_id db_name = get_hgnc_name(hgnc_id) elif urn_type in ['agi-meshdis', 'agi-ncimorgan', 'agi-ncimtissue', 'agi-ncimcelltype']: if urn_id.startswith('C') and urn_id[1:].isdigit(): db_refs['UMLS'] = urn_id else: urn_mesh_name = unquote(urn_id) mesh_id, mesh_name = mesh_client.get_mesh_id_name(urn_mesh_name) if mesh_id: db_refs['MESH'] = mesh_id db_name = mesh_name else: db_name = urn_mesh_name elif urn_type == 'agi-gocomplex': db_refs['GO'] = 'GO:%s' % urn_id elif urn_type == 'agi-go': db_refs['GO'] = 'GO:%s' % urn_id db_sometimes_maps_to_famplex = ['GO', 'MESH'] for db in db_sometimes_maps_to_famplex: if db in db_refs: key = (db, db_refs[db]) if key in famplex_map: db_refs['FPLX'] = famplex_map[key] if urn.startswith('urn:agi-enz'): tokens = urn.split(':') eccode = tokens[2] key = ('ECCODE', eccode) if key in famplex_map: db_refs['FPLX'] = famplex_map[key] key = ('MEDSCAN', urn) if key in famplex_map: db_refs['FPLX'] = famplex_map[key] if 'FPLX' in db_refs: db_name = db_refs['FPLX'] elif 'GO' in db_refs: db_name = go_client.get_go_label(db_refs['GO']) return db_refs, db_name
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'symmetricsys'}; {'id': '3', 'type': 'parameters', 'children': ['4', '7', '10', '13']}; {'id': '4', 'type': 'default_parameter', 'children': ['5', '6']}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'dep_tr'}; {'id': '6', 'type': 'None', 'children': []}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'indep_tr'}; {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'SuperClass'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'TransformedSys'}; {'id': '13', 'type': 'dictionary_splat_pattern', 'children': ['14']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '15', 'type': 'block', 'children': ['16', '43', '70', '240']}; {'id': '16', 'type': 'if_statement', 'children': ['17', '20']}; {'id': '17', 'type': 'comparison_operator', 'children': ['18', '19'], 'value': 'is'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'dep_tr'}; {'id': '19', 'type': 'None', 'children': []}; {'id': '20', 'type': 'block', 'children': ['21']}; {'id': '21', 'type': 'if_statement', 'children': ['22', '37']}; {'id': '22', 'type': 'boolean_operator', 'children': ['23', '30'], 'value': 'or'}; {'id': '23', 'type': 'not_operator', 'children': ['24']}; {'id': '24', 'type': 'call', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'callable'}; {'id': '26', 'type': 'argument_list', 'children': ['27']}; {'id': '27', 'type': 'subscript', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'dep_tr'}; {'id': '29', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '30', 'type': 'not_operator', 'children': ['31']}; {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'callable'}; {'id': '33', 'type': 'argument_list', 'children': ['34']}; {'id': '34', 'type': 'subscript', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'dep_tr'}; {'id': '36', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'raise_statement', 'children': ['39']}; {'id': '39', 'type': 'call', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '41', 'type': 'argument_list', 'children': ['42']}; {'id': '42', 'type': 'string', 'children': [], 'value': '"Exceptected dep_tr to be a pair of callables"'}; {'id': '43', 'type': 'if_statement', 'children': ['44', '47']}; {'id': '44', 'type': 'comparison_operator', 'children': ['45', '46'], 'value': 'is'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'indep_tr'}; {'id': '46', 'type': 'None', 'children': []}; {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'if_statement', 'children': ['49', '64']}; {'id': '49', 'type': 'boolean_operator', 'children': ['50', '57'], 'value': 'or'}; {'id': '50', 'type': 'not_operator', 'children': ['51']}; {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'callable'}; {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'subscript', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'indep_tr'}; {'id': '56', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '57', 'type': 'not_operator', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'callable'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'indep_tr'}; {'id': '63', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '64', 'type': 'block', 'children': ['65']}; {'id': '65', 'type': 'raise_statement', 'children': ['66']}; {'id': '66', 'type': 'call', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}; {'id': '69', 'type': 'string', 'children': [], 'value': '"Exceptected indep_tr to be a pair of callables"'}; {'id': '70', 'type': 'class_definition', 'children': ['71', '72', '74']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': '_SymmetricSys'}; {'id': '72', 'type': 'argument_list', 'children': ['73']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'SuperClass'}; {'id': '74', 'type': 'block', 'children': ['75', '183']}; {'id': '75', 'type': 'function_definition', 'children': ['76', '77', '85']}; {'id': '76', 'type': 'function_name', 'children': [], 'value': '__init__'}; {'id': '77', 'type': 'parameters', 'children': ['78', '79', '80', '83']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'dep_exprs'}; {'id': '80', 'type': 'default_parameter', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'indep'}; {'id': '82', 'type': 'None', 'children': []}; {'id': '83', 'type': 'dictionary_splat_pattern', 'children': ['84']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'inner_kwargs'}; {'id': '85', 'type': 'block', 'children': ['86', '94', '101', '111']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}; {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'new_kwargs'}; {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '93', 'type': 'argument_list', 'children': []}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}; {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'new_kwargs'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '99', 'type': 'argument_list', 'children': ['100']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'inner_kwargs'}; {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '106']}; {'id': '103', 'type': 'pattern_list', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'dep'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'exprs'}; {'id': '106', 'type': 'call', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}; {'id': '109', 'type': 'list_splat', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'dep_exprs'}; {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'call', 'children': ['113', '120']}; {'id': '113', 'type': 'attribute', 'children': ['114', '119']}; {'id': '114', 'type': 'call', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'super'}; {'id': '116', 'type': 'argument_list', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': '_SymmetricSys'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': '__init__'}; {'id': '120', 'type': 'argument_list', 'children': ['121', '126', '127', '160', '181']}; {'id': '121', 'type': 'call', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '123', 'type': 'argument_list', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'dep'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'exprs'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'indep'}; {'id': '127', 'type': 'keyword_argument', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'dep_transf'}; {'id': '129', 'type': 'conditional_expression', 'children': ['130', '156', '159'], 'value': 'if'}; {'id': '130', 'type': 'call', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '132', 'type': 'argument_list', 'children': ['133']}; {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '135', 'type': 'argument_list', 'children': ['136', '146']}; {'id': '136', 'type': 'call', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}; {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '141', 'type': 'argument_list', 'children': ['142', '145']}; {'id': '142', 'type': 'subscript', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'dep_tr'}; {'id': '144', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'dep'}; {'id': '146', 'type': 'call', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}; {'id': '149', 'type': 'call', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '151', 'type': 'argument_list', 'children': ['152', '155']}; {'id': '152', 'type': 'subscript', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'dep_tr'}; {'id': '154', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'dep'}; {'id': '156', 'type': 'comparison_operator', 'children': ['157', '158'], 'value': 'is'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'dep_tr'}; {'id': '158', 'type': 'None', 'children': []}; {'id': '159', 'type': 'None', 'children': []}; {'id': '160', 'type': 'keyword_argument', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'indep_transf'}; {'id': '162', 'type': '()', 'children': ['163']}; {'id': '163', 'type': 'conditional_expression', 'children': ['164', '177', '180'], 'value': 'if'}; {'id': '164', 'type': 'tuple', 'children': ['165', '171']}; {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'subscript', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'indep_tr'}; {'id': '168', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'indep'}; {'id': '171', 'type': 'call', 'children': ['172', '175']}; {'id': '172', 'type': 'subscript', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'indep_tr'}; {'id': '174', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'indep'}; {'id': '177', 'type': 'comparison_operator', 'children': ['178', '179'], 'value': 'is'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'indep_tr'}; {'id': '179', 'type': 'None', 'children': []}; {'id': '180', 'type': 'None', 'children': []}; {'id': '181', 'type': 'dictionary_splat', 'children': ['182']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'new_kwargs'}; {'id': '183', 'type': 'decorated_definition', 'children': ['184', '186']}; {'id': '184', 'type': 'decorator', 'children': ['185']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'classmethod'}; {'id': '186', 'type': 'function_definition', 'children': ['187', '188', '199']}; {'id': '187', 'type': 'function_name', 'children': [], 'value': 'from_callback'}; {'id': '188', 'type': 'parameters', 'children': ['189', '190', '191', '194', '197']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'cb'}; {'id': '191', 'type': 'default_parameter', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'ny'}; {'id': '193', 'type': 'None', 'children': []}; {'id': '194', 'type': 'default_parameter', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'nparams'}; {'id': '196', 'type': 'None', 'children': []}; {'id': '197', 'type': 'dictionary_splat_pattern', 'children': ['198']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'inner_kwargs'}; {'id': '199', 'type': 'block', 'children': ['200', '208', '215']}; {'id': '200', 'type': 'expression_statement', 'children': ['201']}; {'id': '201', 'type': 'assignment', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'new_kwargs'}; {'id': '203', 'type': 'call', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '207', 'type': 'argument_list', 'children': []}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}; {'id': '209', 'type': 'call', 'children': ['210', '213']}; {'id': '210', 'type': 'attribute', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'new_kwargs'}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'inner_kwargs'}; {'id': '215', 'type': 'return_statement', 'children': ['216']}; {'id': '216', 'type': 'call', 'children': ['217', '220']}; {'id': '217', 'type': 'attribute', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'SuperClass'}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'from_callback'}; {'id': '220', 'type': 'argument_list', 'children': ['221', '222', '223', '224', '235', '238']}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'cb'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'ny'}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'nparams'}; {'id': '224', 'type': 'keyword_argument', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'dep_transf_cbs'}; {'id': '226', 'type': 'conditional_expression', 'children': ['227', '231', '234'], 'value': 'if'}; {'id': '227', 'type': 'call', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'repeat'}; {'id': '229', 'type': 'argument_list', 'children': ['230']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'dep_tr'}; {'id': '231', 'type': 'comparison_operator', 'children': ['232', '233'], 'value': 'is'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'dep_tr'}; {'id': '233', 'type': 'None', 'children': []}; {'id': '234', 'type': 'None', 'children': []}; {'id': '235', 'type': 'keyword_argument', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'indep_transf_cbs'}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'indep_tr'}; {'id': '238', 'type': 'dictionary_splat', 'children': ['239']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'new_kwargs'}; {'id': '240', 'type': 'return_statement', 'children': ['241']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': '_SymmetricSys'}
def symmetricsys(dep_tr=None, indep_tr=None, SuperClass=TransformedSys, **kwargs): if dep_tr is not None: if not callable(dep_tr[0]) or not callable(dep_tr[1]): raise ValueError("Exceptected dep_tr to be a pair of callables") if indep_tr is not None: if not callable(indep_tr[0]) or not callable(indep_tr[1]): raise ValueError("Exceptected indep_tr to be a pair of callables") class _SymmetricSys(SuperClass): def __init__(self, dep_exprs, indep=None, **inner_kwargs): new_kwargs = kwargs.copy() new_kwargs.update(inner_kwargs) dep, exprs = zip(*dep_exprs) super(_SymmetricSys, self).__init__( zip(dep, exprs), indep, dep_transf=list(zip( list(map(dep_tr[0], dep)), list(map(dep_tr[1], dep)) )) if dep_tr is not None else None, indep_transf=((indep_tr[0](indep), indep_tr[1](indep)) if indep_tr is not None else None), **new_kwargs) @classmethod def from_callback(cls, cb, ny=None, nparams=None, **inner_kwargs): new_kwargs = kwargs.copy() new_kwargs.update(inner_kwargs) return SuperClass.from_callback( cb, ny, nparams, dep_transf_cbs=repeat(dep_tr) if dep_tr is not None else None, indep_transf_cbs=indep_tr, **new_kwargs) return _SymmetricSys
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'from_other'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'ori'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '8', 'type': 'block', 'children': ['9', '45', '66', '87', '120', '153', '172', '185', '193', '217']}; {'id': '9', 'type': 'for_statement', 'children': ['10', '11', '20']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '11', 'type': 'binary_operator', 'children': ['12', '15'], 'value': '+'}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_attrs_to_copy'}; {'id': '15', 'type': 'tuple', 'children': ['16', '17', '18', '19']}; {'id': '16', 'type': 'string', 'children': [], 'value': "'params'"}; {'id': '17', 'type': 'string', 'children': [], 'value': "'roots'"}; {'id': '18', 'type': 'string', 'children': [], 'value': "'init_indep'"}; {'id': '19', 'type': 'string', 'children': [], 'value': "'init_dep'"}; {'id': '20', 'type': 'block', 'children': ['21']}; {'id': '21', 'type': 'if_statement', 'children': ['22', '25']}; {'id': '22', 'type': 'comparison_operator', 'children': ['23', '24'], 'value': 'not'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '25', 'type': 'block', 'children': ['26', '34']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'ori'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '34', 'type': 'if_statement', 'children': ['35', '38']}; {'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'is'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '37', 'type': 'None', 'children': []}; {'id': '38', 'type': 'block', 'children': ['39']}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '44']}; {'id': '41', 'type': 'subscript', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '45', 'type': 'if_statement', 'children': ['46', '57']}; {'id': '46', 'type': 'boolean_operator', 'children': ['47', '50'], 'value': 'and'}; {'id': '47', 'type': 'comparison_operator', 'children': ['48', '49'], 'value': 'not'}; {'id': '48', 'type': 'string', 'children': [], 'value': "'lower_bounds'"}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '50', 'type': 'comparison_operator', 'children': ['51', '56'], 'value': 'is'}; {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '53', 'type': 'argument_list', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'ori'}; {'id': '55', 'type': 'string', 'children': [], 'value': "'lower_bounds'"}; {'id': '56', 'type': 'None', 'children': []}; {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'assignment', 'children': ['60', '63']}; {'id': '60', 'type': 'subscript', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '62', 'type': 'string', 'children': [], 'value': "'lower_bounds'"}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'ori'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'lower_bounds'}; {'id': '66', 'type': 'if_statement', 'children': ['67', '78']}; {'id': '67', 'type': 'boolean_operator', 'children': ['68', '71'], 'value': 'and'}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': 'not'}; {'id': '69', 'type': 'string', 'children': [], 'value': "'upper_bounds'"}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '71', 'type': 'comparison_operator', 'children': ['72', '77'], 'value': 'is'}; {'id': '72', 'type': 'call', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '74', 'type': 'argument_list', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'ori'}; {'id': '76', 'type': 'string', 'children': [], 'value': "'upper_bounds'"}; {'id': '77', 'type': 'None', 'children': []}; {'id': '78', 'type': 'block', 'children': ['79']}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '84']}; {'id': '81', 'type': 'subscript', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '83', 'type': 'string', 'children': [], 'value': "'upper_bounds'"}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'ori'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'upper_bounds'}; {'id': '87', 'type': 'if_statement', 'children': ['88', '96']}; {'id': '88', 'type': 'comparison_operator', 'children': ['89', '95'], 'value': '>'}; {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'ori'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'pre_processors'}; {'id': '95', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '96', 'type': 'block', 'children': ['97', '108']}; {'id': '97', 'type': 'if_statement', 'children': ['98', '101']}; {'id': '98', 'type': 'comparison_operator', 'children': ['99', '100'], 'value': 'not'}; {'id': '99', 'type': 'string', 'children': [], 'value': "'pre_processors'"}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '101', 'type': 'block', 'children': ['102']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'assignment', 'children': ['104', '107']}; {'id': '104', 'type': 'subscript', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '106', 'type': 'string', 'children': [], 'value': "'pre_processors'"}; {'id': '107', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}; {'id': '109', 'type': 'assignment', 'children': ['110', '113']}; {'id': '110', 'type': 'subscript', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '112', 'type': 'string', 'children': [], 'value': "'pre_processors'"}; {'id': '113', 'type': 'binary_operator', 'children': ['114', '117'], 'value': '+'}; {'id': '114', 'type': 'subscript', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '116', 'type': 'string', 'children': [], 'value': "'pre_processors'"}; {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'ori'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'pre_processors'}; {'id': '120', 'type': 'if_statement', 'children': ['121', '129']}; {'id': '121', 'type': 'comparison_operator', 'children': ['122', '128'], 'value': '>'}; {'id': '122', 'type': 'call', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}; {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'ori'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'post_processors'}; {'id': '128', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '129', 'type': 'block', 'children': ['130', '141']}; {'id': '130', 'type': 'if_statement', 'children': ['131', '134']}; {'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': 'not'}; {'id': '132', 'type': 'string', 'children': [], 'value': "'post_processors'"}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '134', 'type': 'block', 'children': ['135']}; {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'assignment', 'children': ['137', '140']}; {'id': '137', 'type': 'subscript', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '139', 'type': 'string', 'children': [], 'value': "'post_processors'"}; {'id': '140', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '146']}; {'id': '143', 'type': 'subscript', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '145', 'type': 'string', 'children': [], 'value': "'post_processors'"}; {'id': '146', 'type': 'binary_operator', 'children': ['147', '150'], 'value': '+'}; {'id': '147', 'type': 'attribute', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'ori'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'post_processors'}; {'id': '150', 'type': 'subscript', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '152', 'type': 'string', 'children': [], 'value': "'post_processors'"}; {'id': '153', 'type': 'if_statement', 'children': ['154', '157']}; {'id': '154', 'type': 'comparison_operator', 'children': ['155', '156'], 'value': 'not'}; {'id': '155', 'type': 'string', 'children': [], 'value': "'dep_exprs'"}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '157', 'type': 'block', 'children': ['158']}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}; {'id': '159', 'type': 'assignment', 'children': ['160', '163']}; {'id': '160', 'type': 'subscript', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '162', 'type': 'string', 'children': [], 'value': "'dep_exprs'"}; {'id': '163', 'type': 'call', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '165', 'type': 'argument_list', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'ori'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'dep'}; {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'ori'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'exprs'}; {'id': '172', 'type': 'if_statement', 'children': ['173', '176']}; {'id': '173', 'type': 'comparison_operator', 'children': ['174', '175'], 'value': 'not'}; {'id': '174', 'type': 'string', 'children': [], 'value': "'indep'"}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '176', 'type': 'block', 'children': ['177']}; {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'assignment', 'children': ['179', '182']}; {'id': '179', 'type': 'subscript', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '181', 'type': 'string', 'children': [], 'value': "'indep'"}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'ori'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'indep'}; {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'assignment', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '188', 'type': 'call', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}; {'id': '191', 'type': 'dictionary_splat', 'children': ['192']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '193', 'type': 'for_statement', 'children': ['194', '195', '198']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '195', 'type': 'attribute', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'ori'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': '_attrs_to_copy'}; {'id': '198', 'type': 'block', 'children': ['199']}; {'id': '199', 'type': 'if_statement', 'children': ['200', '205']}; {'id': '200', 'type': 'comparison_operator', 'children': ['201', '202'], 'value': 'not'}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': '_attrs_to_copy'}; {'id': '205', 'type': 'block', 'children': ['206']}; {'id': '206', 'type': 'expression_statement', 'children': ['207']}; {'id': '207', 'type': 'call', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'setattr'}; {'id': '209', 'type': 'argument_list', 'children': ['210', '211', '212']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'instance'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '212', 'type': 'call', 'children': ['213', '214']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '214', 'type': 'argument_list', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'ori'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'attr'}; {'id': '217', 'type': 'return_statement', 'children': ['218']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'instance'}
def from_other(cls, ori, **kwargs): for k in cls._attrs_to_copy + ('params', 'roots', 'init_indep', 'init_dep'): if k not in kwargs: val = getattr(ori, k) if val is not None: kwargs[k] = val if 'lower_bounds' not in kwargs and getattr(ori, 'lower_bounds') is not None: kwargs['lower_bounds'] = ori.lower_bounds if 'upper_bounds' not in kwargs and getattr(ori, 'upper_bounds') is not None: kwargs['upper_bounds'] = ori.upper_bounds if len(ori.pre_processors) > 0: if 'pre_processors' not in kwargs: kwargs['pre_processors'] = [] kwargs['pre_processors'] = kwargs['pre_processors'] + ori.pre_processors if len(ori.post_processors) > 0: if 'post_processors' not in kwargs: kwargs['post_processors'] = [] kwargs['post_processors'] = ori.post_processors + kwargs['post_processors'] if 'dep_exprs' not in kwargs: kwargs['dep_exprs'] = zip(ori.dep, ori.exprs) if 'indep' not in kwargs: kwargs['indep'] = ori.indep instance = cls(**kwargs) for attr in ori._attrs_to_copy: if attr not in cls._attrs_to_copy: setattr(instance, attr, getattr(ori, attr)) return instance
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'from_linear_invariants'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'ori_sys'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'preferred'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'dictionary_splat_pattern', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '11', 'type': 'block', 'children': ['12', '18', '29', '39', '56', '87', '117', '152', '156', '220', '299', '307', '359', '385']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': '_be'}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'ori_sys'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'be'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': '_be'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'Matrix'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'attribute', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'ori_sys'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'linear_invariants'}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '34']}; {'id': '31', 'type': 'pattern_list', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'rA'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'pivots'}; {'id': '34', 'type': 'call', 'children': ['35', '38']}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'rref'}; {'id': '38', 'type': 'argument_list', 'children': []}; {'id': '39', 'type': 'if_statement', 'children': ['40', '50']}; {'id': '40', 'type': 'comparison_operator', 'children': ['41', '45'], 'value': '<'}; {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'pivots'}; {'id': '45', 'type': 'subscript', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '49', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '50', 'type': 'block', 'children': ['51']}; {'id': '51', 'type': 'raise_statement', 'children': ['52']}; {'id': '52', 'type': 'call', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'NotImplementedError'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}; {'id': '55', 'type': 'string', 'children': [], 'value': '"Linear invariants contain linear dependencies."'}; {'id': '56', 'type': 'expression_statement', 'children': ['57']}; {'id': '57', 'type': 'assignment', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'per_row_cols'}; {'id': '59', 'type': 'list_comprehension', 'children': ['60', '79']}; {'id': '60', 'type': 'tuple', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'ri'}; {'id': '62', 'type': 'list_comprehension', 'children': ['63', '64', '72']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'ci'}; {'id': '64', 'type': 'for_in_clause', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'ci'}; {'id': '66', 'type': 'call', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '72', 'type': 'if_clause', 'children': ['73']}; {'id': '73', 'type': 'comparison_operator', 'children': ['74', '78'], 'value': '!='}; {'id': '74', 'type': 'subscript', 'children': ['75', '76', '77']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'ri'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'ci'}; {'id': '78', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '79', 'type': 'for_in_clause', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'ri'}; {'id': '81', 'type': 'call', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '83', 'type': 'argument_list', 'children': ['84']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '87', 'type': 'if_statement', 'children': ['88', '91']}; {'id': '88', 'type': 'comparison_operator', 'children': ['89', '90'], 'value': 'is'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'preferred'}; {'id': '90', 'type': 'None', 'children': []}; {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}; {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'preferred'}; {'id': '95', 'type': 'conditional_expression', 'children': ['96', '105', '108'], 'value': 'if'}; {'id': '96', 'type': 'subscript', 'children': ['97', '100']}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'ori_sys'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '100', 'type': 'slice', 'children': ['101', '102']}; {'id': '101', 'type': 'colon', 'children': []}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'ori_sys'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'dep_by_name'}; {'id': '108', 'type': 'call', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}; {'id': '111', 'type': 'call', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '113', 'type': 'argument_list', 'children': ['114']}; {'id': '114', 'type': 'attribute', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'assignment', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'targets'}; {'id': '120', 'type': 'list_comprehension', 'children': ['121', '149']}; {'id': '121', 'type': 'conditional_expression', 'children': ['122', '130', '133'], 'value': 'if'}; {'id': '122', 'type': 'call', 'children': ['123', '128']}; {'id': '123', 'type': 'attribute', 'children': ['124', '127']}; {'id': '124', 'type': 'attribute', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'ori_sys'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'dep'}; {'id': '130', 'type': 'attribute', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'ori_sys'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'dep_by_name'}; {'id': '133', 'type': '()', 'children': ['134']}; {'id': '134', 'type': 'conditional_expression', 'children': ['135', '136', '141'], 'value': 'if'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'dep'}; {'id': '136', 'type': 'call', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '138', 'type': 'argument_list', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'dep'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '141', 'type': 'call', 'children': ['142', '147']}; {'id': '142', 'type': 'attribute', 'children': ['143', '146']}; {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'ori_sys'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'dep'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'dep'}; {'id': '149', 'type': 'for_in_clause', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'dep'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'preferred'}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}; {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'row_tgt'}; {'id': '155', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '156', 'type': 'for_statement', 'children': ['157', '160', '175', '211']}; {'id': '157', 'type': 'pattern_list', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'ri'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'colids'}; {'id': '160', 'type': 'call', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '162', 'type': 'argument_list', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'per_row_cols'}; {'id': '164', 'type': 'keyword_argument', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '166', 'type': 'lambda', 'children': ['167', '169']}; {'id': '167', 'type': 'lambda_parameters', 'children': ['168']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'subscript', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '174', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '175', 'type': 'block', 'children': ['176', '202']}; {'id': '176', 'type': 'for_statement', 'children': ['177', '178', '179']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'tgt'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'targets'}; {'id': '179', 'type': 'block', 'children': ['180']}; {'id': '180', 'type': 'if_statement', 'children': ['181', '184']}; {'id': '181', 'type': 'comparison_operator', 'children': ['182', '183'], 'value': 'in'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'tgt'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'colids'}; {'id': '184', 'type': 'block', 'children': ['185', '194', '201']}; {'id': '185', 'type': 'expression_statement', 'children': ['186']}; {'id': '186', 'type': 'call', 'children': ['187', '190']}; {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'row_tgt'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '190', 'type': 'argument_list', 'children': ['191']}; {'id': '191', 'type': 'tuple', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'ri'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'tgt'}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}; {'id': '195', 'type': 'call', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'targets'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'remove'}; {'id': '199', 'type': 'argument_list', 'children': ['200']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'tgt'}; {'id': '201', 'type': 'break_statement', 'children': []}; {'id': '202', 'type': 'if_statement', 'children': ['203', '209']}; {'id': '203', 'type': 'comparison_operator', 'children': ['204', '208'], 'value': '=='}; {'id': '204', 'type': 'call', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '206', 'type': 'argument_list', 'children': ['207']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'targets'}; {'id': '208', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '209', 'type': 'block', 'children': ['210']}; {'id': '210', 'type': 'break_statement', 'children': []}; {'id': '211', 'type': 'else_clause', 'children': ['212']}; {'id': '212', 'type': 'block', 'children': ['213']}; {'id': '213', 'type': 'raise_statement', 'children': ['214']}; {'id': '214', 'type': 'call', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '216', 'type': 'argument_list', 'children': ['217']}; {'id': '217', 'type': 'binary_operator', 'children': ['218', '219'], 'value': '%'}; {'id': '218', 'type': 'string', 'children': [], 'value': '"Could not find a solutions for: %s"'}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'targets'}; {'id': '220', 'type': 'function_definition', 'children': ['221', '222', '227']}; {'id': '221', 'type': 'function_name', 'children': [], 'value': 'analytic_factory'}; {'id': '222', 'type': 'parameters', 'children': ['223', '224', '225', '226']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'x0'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'y0'}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'p0'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'be'}; {'id': '227', 'type': 'block', 'children': ['228']}; {'id': '228', 'type': 'return_statement', 'children': ['229']}; {'id': '229', 'type': 'dictionary_comprehension', 'children': ['230', '294']}; {'id': '230', 'type': 'pair', 'children': ['231', '236']}; {'id': '231', 'type': 'subscript', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'ori_sys'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'dep'}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'tgt'}; {'id': '236', 'type': 'binary_operator', 'children': ['237', '249'], 'value': '-'}; {'id': '237', 'type': 'subscript', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'y0'}; {'id': '239', 'type': 'conditional_expression', 'children': ['240', '245', '248'], 'value': 'if'}; {'id': '240', 'type': 'subscript', 'children': ['241', '244']}; {'id': '241', 'type': 'attribute', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'ori_sys'}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'dep'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'tgt'}; {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'ori_sys'}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'dep_by_name'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'tgt'}; {'id': '249', 'type': 'binary_operator', 'children': ['250', '290'], 'value': '/'}; {'id': '250', 'type': 'call', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '252', 'type': 'argument_list', 'children': ['253']}; {'id': '253', 'type': 'list_comprehension', 'children': ['254', '278', '286']}; {'id': '254', 'type': 'binary_operator', 'children': ['255', '259'], 'value': '*'}; {'id': '255', 'type': 'subscript', 'children': ['256', '257', '258']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'ri'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'ci'}; {'id': '259', 'type': '()', 'children': ['260']}; {'id': '260', 'type': 'binary_operator', 'children': ['261', '266'], 'value': '-'}; {'id': '261', 'type': 'subscript', 'children': ['262', '265']}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'ori_sys'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'dep'}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'ci'}; {'id': '266', 'type': 'subscript', 'children': ['267', '268']}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'y0'}; {'id': '268', 'type': 'conditional_expression', 'children': ['269', '274', '277'], 'value': 'if'}; {'id': '269', 'type': 'subscript', 'children': ['270', '273']}; {'id': '270', 'type': 'attribute', 'children': ['271', '272']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'ori_sys'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'dep'}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'ci'}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'ori_sys'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'dep_by_name'}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'ci'}; {'id': '278', 'type': 'for_in_clause', 'children': ['279', '280']}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'ci'}; {'id': '280', 'type': 'call', 'children': ['281', '282']}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '282', 'type': 'argument_list', 'children': ['283']}; {'id': '283', 'type': 'attribute', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '286', 'type': 'if_clause', 'children': ['287']}; {'id': '287', 'type': 'comparison_operator', 'children': ['288', '289'], 'value': '!='}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'ci'}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'tgt'}; {'id': '290', 'type': 'subscript', 'children': ['291', '292', '293']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'ri'}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'tgt'}; {'id': '294', 'type': 'for_in_clause', 'children': ['295', '298']}; {'id': '295', 'type': 'pattern_list', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'ri'}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'tgt'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'row_tgt'}; {'id': '299', 'type': 'expression_statement', 'children': ['300']}; {'id': '300', 'type': 'assignment', 'children': ['301', '302']}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'ori_li_nms'}; {'id': '302', 'type': 'boolean_operator', 'children': ['303', '306'], 'value': 'or'}; {'id': '303', 'type': 'attribute', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'ori_sys'}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'linear_invariant_names'}; {'id': '306', 'type': 'tuple', 'children': []}; {'id': '307', 'type': 'expression_statement', 'children': ['308']}; {'id': '308', 'type': 'assignment', 'children': ['309', '310']}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'new_lin_invar'}; {'id': '310', 'type': 'list_comprehension', 'children': ['311', '334', '346']}; {'id': '311', 'type': 'list_comprehension', 'children': ['312', '313', '321']}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'cell'}; {'id': '313', 'type': 'for_in_clause', 'children': ['314', '317']}; {'id': '314', 'type': 'pattern_list', 'children': ['315', '316']}; {'id': '315', 'type': 'identifier', 'children': [], 'value': 'ci'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'cell'}; {'id': '317', 'type': 'call', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '319', 'type': 'argument_list', 'children': ['320']}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '321', 'type': 'if_clause', 'children': ['322']}; {'id': '322', 'type': 'comparison_operator', 'children': ['323', '324'], 'value': 'not'}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'ci'}; {'id': '324', 'type': 'subscript', 'children': ['325', '333']}; {'id': '325', 'type': 'call', 'children': ['326', '327']}; {'id': '326', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '327', 'type': 'argument_list', 'children': ['328']}; {'id': '328', 'type': 'call', 'children': ['329', '330']}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '330', 'type': 'argument_list', 'children': ['331']}; {'id': '331', 'type': 'list_splat', 'children': ['332']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'row_tgt'}; {'id': '333', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '334', 'type': 'for_in_clause', 'children': ['335', '338']}; {'id': '335', 'type': 'pattern_list', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'ri'}; {'id': '337', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '338', 'type': 'call', 'children': ['339', '340']}; {'id': '339', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '340', 'type': 'argument_list', 'children': ['341']}; {'id': '341', 'type': 'call', 'children': ['342', '345']}; {'id': '342', 'type': 'attribute', 'children': ['343', '344']}; {'id': '343', 'type': 'identifier', 'children': [], 'value': 'A'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'tolist'}; {'id': '345', 'type': 'argument_list', 'children': []}; {'id': '346', 'type': 'if_clause', 'children': ['347']}; {'id': '347', 'type': 'comparison_operator', 'children': ['348', '349'], 'value': 'not'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': 'ri'}; {'id': '349', 'type': 'subscript', 'children': ['350', '358']}; {'id': '350', 'type': 'call', 'children': ['351', '352']}; {'id': '351', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '352', 'type': 'argument_list', 'children': ['353']}; {'id': '353', 'type': 'call', 'children': ['354', '355']}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '355', 'type': 'argument_list', 'children': ['356']}; {'id': '356', 'type': 'list_splat', 'children': ['357']}; {'id': '357', 'type': 'identifier', 'children': [], 'value': 'row_tgt'}; {'id': '358', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '359', 'type': 'expression_statement', 'children': ['360']}; {'id': '360', 'type': 'assignment', 'children': ['361', '362']}; {'id': '361', 'type': 'identifier', 'children': [], 'value': 'new_lin_i_nms'}; {'id': '362', 'type': 'list_comprehension', 'children': ['363', '364', '372']}; {'id': '363', 'type': 'identifier', 'children': [], 'value': 'nam'}; {'id': '364', 'type': 'for_in_clause', 'children': ['365', '368']}; {'id': '365', 'type': 'pattern_list', 'children': ['366', '367']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'ri'}; {'id': '367', 'type': 'identifier', 'children': [], 'value': 'nam'}; {'id': '368', 'type': 'call', 'children': ['369', '370']}; {'id': '369', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '370', 'type': 'argument_list', 'children': ['371']}; {'id': '371', 'type': 'identifier', 'children': [], 'value': 'ori_li_nms'}; {'id': '372', 'type': 'if_clause', 'children': ['373']}; {'id': '373', 'type': 'comparison_operator', 'children': ['374', '375'], 'value': 'not'}; {'id': '374', 'type': 'identifier', 'children': [], 'value': 'ri'}; {'id': '375', 'type': 'subscript', 'children': ['376', '384']}; {'id': '376', 'type': 'call', 'children': ['377', '378']}; {'id': '377', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '378', 'type': 'argument_list', 'children': ['379']}; {'id': '379', 'type': 'call', 'children': ['380', '381']}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '381', 'type': 'argument_list', 'children': ['382']}; {'id': '382', 'type': 'list_splat', 'children': ['383']}; {'id': '383', 'type': 'identifier', 'children': [], 'value': 'row_tgt'}; {'id': '384', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '385', 'type': 'return_statement', 'children': ['386']}; {'id': '386', 'type': 'call', 'children': ['387', '388']}; {'id': '387', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '388', 'type': 'argument_list', 'children': ['389', '390', '391', '394', '397']}; {'id': '389', 'type': 'identifier', 'children': [], 'value': 'ori_sys'}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'analytic_factory'}; {'id': '391', 'type': 'keyword_argument', 'children': ['392', '393']}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'linear_invariants'}; {'id': '393', 'type': 'identifier', 'children': [], 'value': 'new_lin_invar'}; {'id': '394', 'type': 'keyword_argument', 'children': ['395', '396']}; {'id': '395', 'type': 'identifier', 'children': [], 'value': 'linear_invariant_names'}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'new_lin_i_nms'}; {'id': '397', 'type': 'dictionary_splat', 'children': ['398']}; {'id': '398', 'type': 'identifier', 'children': [], 'value': 'kwargs'}
def from_linear_invariants(cls, ori_sys, preferred=None, **kwargs): _be = ori_sys.be A = _be.Matrix(ori_sys.linear_invariants) rA, pivots = A.rref() if len(pivots) < A.shape[0]: raise NotImplementedError("Linear invariants contain linear dependencies.") per_row_cols = [(ri, [ci for ci in range(A.cols) if A[ri, ci] != 0]) for ri in range(A.rows)] if preferred is None: preferred = ori_sys.names[:A.rows] if ori_sys.dep_by_name else list(range(A.rows)) targets = [ ori_sys.names.index(dep) if ori_sys.dep_by_name else ( dep if isinstance(dep, int) else ori_sys.dep.index(dep)) for dep in preferred] row_tgt = [] for ri, colids in sorted(per_row_cols, key=lambda k: len(k[1])): for tgt in targets: if tgt in colids: row_tgt.append((ri, tgt)) targets.remove(tgt) break if len(targets) == 0: break else: raise ValueError("Could not find a solutions for: %s" % targets) def analytic_factory(x0, y0, p0, be): return { ori_sys.dep[tgt]: y0[ori_sys.dep[tgt] if ori_sys.dep_by_name else tgt] - sum( [A[ri, ci]*(ori_sys.dep[ci] - y0[ori_sys.dep[ci] if ori_sys.dep_by_name else ci]) for ci in range(A.cols) if ci != tgt])/A[ri, tgt] for ri, tgt in row_tgt } ori_li_nms = ori_sys.linear_invariant_names or () new_lin_invar = [[cell for ci, cell in enumerate(row) if ci not in list(zip(*row_tgt))[1]] for ri, row in enumerate(A.tolist()) if ri not in list(zip(*row_tgt))[0]] new_lin_i_nms = [nam for ri, nam in enumerate(ori_li_nms) if ri not in list(zip(*row_tgt))[0]] return cls(ori_sys, analytic_factory, linear_invariants=new_lin_invar, linear_invariant_names=new_lin_i_nms, **kwargs)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '23']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'chained_parameter_variation'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8', '11', '14', '17', '20']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'subject'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'durations'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'y0'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'varied_params'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'default_params'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'integrate_kwargs'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'x0'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'npoints'}; {'id': '19', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '22', 'type': 'None', 'children': []}; {'id': '23', 'type': 'block', 'children': ['24', '32', '37', '63', '96', '102', '108', '160', '169', '300']}; {'id': '24', 'type': 'assert_statement', 'children': ['25', '31']}; {'id': '25', 'type': 'comparison_operator', 'children': ['26', '30'], 'value': '>'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'durations'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '31', 'type': 'string', 'children': [], 'value': "'need at least 1 duration (preferably many)'"}; {'id': '32', 'type': 'assert_statement', 'children': ['33', '36']}; {'id': '33', 'type': 'comparison_operator', 'children': ['34', '35'], 'value': '>'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'npoints'}; {'id': '35', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '36', 'type': 'string', 'children': [], 'value': "'need at least 1 point per duration'"}; {'id': '37', 'type': 'for_statement', 'children': ['38', '41', '46']}; {'id': '38', 'type': 'pattern_list', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'varied_params'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '45', 'type': 'argument_list', 'children': []}; {'id': '46', 'type': 'block', 'children': ['47']}; {'id': '47', 'type': 'if_statement', 'children': ['48', '57']}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '53'], 'value': '!='}; {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'durations'}; {'id': '57', 'type': 'block', 'children': ['58']}; {'id': '58', 'type': 'raise_statement', 'children': ['59']}; {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'string', 'children': [], 'value': '"Mismathced lengths of durations and varied_params"'}; {'id': '63', 'type': 'if_statement', 'children': ['64', '69', '84']}; {'id': '64', 'type': 'call', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '66', 'type': 'argument_list', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'subject'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'ODESys'}; {'id': '69', 'type': 'block', 'children': ['70', '76']}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'assignment', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'integrate'}; {'id': '73', 'type': 'attribute', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'subject'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'integrate'}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}; {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '79', 'type': 'boolean_operator', 'children': ['80', '81'], 'value': 'or'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '81', 'type': 'attribute', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'subject'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '84', 'type': 'else_clause', 'children': ['85']}; {'id': '85', 'type': 'block', 'children': ['86', '90']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}; {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'integrate'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'subject'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}; {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '93', 'type': 'boolean_operator', 'children': ['94', '95'], 'value': 'or'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}; {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'default_params'}; {'id': '99', 'type': 'boolean_operator', 'children': ['100', '101'], 'value': 'or'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'default_params'}; {'id': '101', 'type': 'dictionary', 'children': []}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'integrate_kwargs'}; {'id': '105', 'type': 'boolean_operator', 'children': ['106', '107'], 'value': 'or'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'integrate_kwargs'}; {'id': '107', 'type': 'dictionary', 'children': []}; {'id': '108', 'type': 'function_definition', 'children': ['109', '110', '113']}; {'id': '109', 'type': 'function_name', 'children': [], 'value': '_get_idx'}; {'id': '110', 'type': 'parameters', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'cont'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'if_statement', 'children': ['115', '120', '154']}; {'id': '115', 'type': 'call', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '117', 'type': 'argument_list', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'cont'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '120', 'type': 'block', 'children': ['121']}; {'id': '121', 'type': 'return_statement', 'children': ['122']}; {'id': '122', 'type': 'dictionary_comprehension', 'children': ['123', '145']}; {'id': '123', 'type': 'pair', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '125', 'type': '()', 'children': ['126']}; {'id': '126', 'type': 'conditional_expression', 'children': ['127', '130', '144'], 'value': 'if'}; {'id': '127', 'type': 'subscript', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '130', 'type': 'boolean_operator', 'children': ['131', '136'], 'value': 'and'}; {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '133', 'type': 'argument_list', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '135', 'type': 'string', 'children': [], 'value': "'__len__'"}; {'id': '136', 'type': 'comparison_operator', 'children': ['137', '143'], 'value': '>'}; {'id': '137', 'type': 'call', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '139', 'type': 'argument_list', 'children': ['140', '141', '142']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '141', 'type': 'string', 'children': [], 'value': "'ndim'"}; {'id': '142', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '143', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '145', 'type': 'for_in_clause', 'children': ['146', '149']}; {'id': '146', 'type': 'pattern_list', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '149', 'type': 'call', 'children': ['150', '153']}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'cont'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '153', 'type': 'argument_list', 'children': []}; {'id': '154', 'type': 'else_clause', 'children': ['155']}; {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'return_statement', 'children': ['157']}; {'id': '157', 'type': 'subscript', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'cont'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}; {'id': '161', 'type': 'assignment', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'durations'}; {'id': '163', 'type': 'call', 'children': ['164', '167']}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'cumsum'}; {'id': '167', 'type': 'argument_list', 'children': ['168']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'durations'}; {'id': '169', 'type': 'for_statement', 'children': ['170', '171', '178']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'idx_dur'}; {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'call', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '176', 'type': 'argument_list', 'children': ['177']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'durations'}; {'id': '178', 'type': 'block', 'children': ['179', '188', '206']}; {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'assignment', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '182', 'type': 'call', 'children': ['183', '186']}; {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '186', 'type': 'argument_list', 'children': ['187']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'default_params'}; {'id': '188', 'type': 'for_statement', 'children': ['189', '192', '197']}; {'id': '189', 'type': 'pattern_list', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '192', 'type': 'call', 'children': ['193', '196']}; {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'varied_params'}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '196', 'type': 'argument_list', 'children': []}; {'id': '197', 'type': 'block', 'children': ['198']}; {'id': '198', 'type': 'expression_statement', 'children': ['199']}; {'id': '199', 'type': 'assignment', 'children': ['200', '203']}; {'id': '200', 'type': 'subscript', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '203', 'type': 'subscript', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'idx_dur'}; {'id': '206', 'type': 'if_statement', 'children': ['207', '210', '246']}; {'id': '207', 'type': 'comparison_operator', 'children': ['208', '209'], 'value': '=='}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'idx_dur'}; {'id': '209', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '210', 'type': 'block', 'children': ['211', '224']}; {'id': '211', 'type': 'if_statement', 'children': ['212', '215']}; {'id': '212', 'type': 'comparison_operator', 'children': ['213', '214'], 'value': 'is'}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'x0'}; {'id': '214', 'type': 'None', 'children': []}; {'id': '215', 'type': 'block', 'children': ['216']}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}; {'id': '217', 'type': 'assignment', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'x0'}; {'id': '219', 'type': 'binary_operator', 'children': ['220', '223'], 'value': '*'}; {'id': '220', 'type': 'subscript', 'children': ['221', '222']}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'durations'}; {'id': '222', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '223', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}; {'id': '225', 'type': 'assignment', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '227', 'type': 'call', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'integrate'}; {'id': '229', 'type': 'argument_list', 'children': ['230', '242', '243', '244']}; {'id': '230', 'type': 'call', 'children': ['231', '234']}; {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'linspace'}; {'id': '234', 'type': 'argument_list', 'children': ['235', '236', '239']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'x0'}; {'id': '236', 'type': 'subscript', 'children': ['237', '238']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'durations'}; {'id': '238', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '239', 'type': 'binary_operator', 'children': ['240', '241'], 'value': '+'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'npoints'}; {'id': '241', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'y0'}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '244', 'type': 'dictionary_splat', 'children': ['245']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'integrate_kwargs'}; {'id': '246', 'type': 'else_clause', 'children': ['247']}; {'id': '247', 'type': 'block', 'children': ['248']}; {'id': '248', 'type': 'if_statement', 'children': ['249', '254', '270']}; {'id': '249', 'type': 'call', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '251', 'type': 'argument_list', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'Result'}; {'id': '254', 'type': 'block', 'children': ['255']}; {'id': '255', 'type': 'expression_statement', 'children': ['256']}; {'id': '256', 'type': 'call', 'children': ['257', '260']}; {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'extend_by_integration'}; {'id': '260', 'type': 'argument_list', 'children': ['261', '264', '265', '268']}; {'id': '261', 'type': 'subscript', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'durations'}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'idx_dur'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '265', 'type': 'keyword_argument', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'npoints'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'npoints'}; {'id': '268', 'type': 'dictionary_splat', 'children': ['269']}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'integrate_kwargs'}; {'id': '270', 'type': 'else_clause', 'children': ['271']}; {'id': '271', 'type': 'block', 'children': ['272']}; {'id': '272', 'type': 'for_statement', 'children': ['273', '276', '280']}; {'id': '273', 'type': 'pattern_list', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'idx_res'}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '276', 'type': 'call', 'children': ['277', '278']}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '278', 'type': 'argument_list', 'children': ['279']}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'out'}; {'id': '280', 'type': 'block', 'children': ['281']}; {'id': '281', 'type': 'expression_statement', 'children': ['282']}; {'id': '282', 'type': 'call', 'children': ['283', '286']}; {'id': '283', 'type': 'attribute', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'r'}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'extend_by_integration'}; {'id': '286', 'type': 'argument_list', 'children': ['287', '290', '295', '298']}; {'id': '287', 'type': 'subscript', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'durations'}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'idx_dur'}; {'id': '290', 'type': 'call', 'children': ['291', '292']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': '_get_idx'}; {'id': '292', 'type': 'argument_list', 'children': ['293', '294']}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'idx_res'}; {'id': '295', 'type': 'keyword_argument', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'npoints'}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'npoints'}; {'id': '298', 'type': 'dictionary_splat', 'children': ['299']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'integrate_kwargs'}; {'id': '300', 'type': 'return_statement', 'children': ['301']}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'out'}
def chained_parameter_variation(subject, durations, y0, varied_params, default_params=None, integrate_kwargs=None, x0=None, npoints=1, numpy=None): assert len(durations) > 0, 'need at least 1 duration (preferably many)' assert npoints > 0, 'need at least 1 point per duration' for k, v in varied_params.items(): if len(v) != len(durations): raise ValueError("Mismathced lengths of durations and varied_params") if isinstance(subject, ODESys): integrate = subject.integrate numpy = numpy or subject.numpy else: integrate = subject numpy = numpy or np default_params = default_params or {} integrate_kwargs = integrate_kwargs or {} def _get_idx(cont, idx): if isinstance(cont, dict): return {k: (v[idx] if hasattr(v, '__len__') and getattr(v, 'ndim', 1) > 0 else v) for k, v in cont.items()} else: return cont[idx] durations = numpy.cumsum(durations) for idx_dur in range(len(durations)): params = copy.copy(default_params) for k, v in varied_params.items(): params[k] = v[idx_dur] if idx_dur == 0: if x0 is None: x0 = durations[0]*0 out = integrate(numpy.linspace(x0, durations[0], npoints + 1), y0, params, **integrate_kwargs) else: if isinstance(out, Result): out.extend_by_integration(durations[idx_dur], params, npoints=npoints, **integrate_kwargs) else: for idx_res, r in enumerate(out): r.extend_by_integration(durations[idx_dur], _get_idx(params, idx_res), npoints=npoints, **integrate_kwargs) return out
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'integrate'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'y0'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '9', 'type': 'tuple', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'atol'}; {'id': '12', 'type': 'float', 'children': [], 'value': '1e-8'}; {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'rtol'}; {'id': '15', 'type': 'float', 'children': [], 'value': '1e-8'}; {'id': '16', 'type': 'dictionary_splat_pattern', 'children': ['17']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '18', 'type': 'block', 'children': ['19', '30', '45', '55', '86', '108', '132', '161', '167', '177', '194', '212', '218', '272', '408']}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'arrs'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'to_arrays'}; {'id': '26', 'type': 'argument_list', 'children': ['27', '28', '29']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'y0'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '36']}; {'id': '32', 'type': 'pattern_list', 'children': ['33', '34', '35']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': '_x'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': '_y'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': '_p'}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': '_arrs'}; {'id': '38', 'type': 'call', 'children': ['39', '42']}; {'id': '39', 'type': 'attribute', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'pre_process'}; {'id': '42', 'type': 'argument_list', 'children': ['43']}; {'id': '43', 'type': 'list_splat', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'arrs'}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'assignment', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'ndims'}; {'id': '48', 'type': 'list_comprehension', 'children': ['49', '52']}; {'id': '49', 'type': 'attribute', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'ndim'}; {'id': '52', 'type': 'for_in_clause', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'a'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': '_arrs'}; {'id': '55', 'type': 'if_statement', 'children': ['56', '62', '67', '79']}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': '=='}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'ndims'}; {'id': '58', 'type': 'list', 'children': ['59', '60', '61'], 'value': '[1, 1, 1]'}; {'id': '59', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '60', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '61', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '62', 'type': 'block', 'children': ['63']}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'twodim'}; {'id': '66', 'type': 'False', 'children': []}; {'id': '67', 'type': 'elif_clause', 'children': ['68', '74']}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '70'], 'value': '=='}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'ndims'}; {'id': '70', 'type': 'list', 'children': ['71', '72', '73'], 'value': '[2, 2, 2]'}; {'id': '71', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '72', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '73', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '74', 'type': 'block', 'children': ['75']}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'twodim'}; {'id': '78', 'type': 'True', 'children': []}; {'id': '79', 'type': 'else_clause', 'children': ['80']}; {'id': '80', 'type': 'block', 'children': ['81']}; {'id': '81', 'type': 'raise_statement', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '84', 'type': 'argument_list', 'children': ['85']}; {'id': '85', 'type': 'string', 'children': [], 'value': '"Pre-processor made ndims inconsistent?"'}; {'id': '86', 'type': 'if_statement', 'children': ['87', '90']}; {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'append_iv'}; {'id': '90', 'type': 'block', 'children': ['91']}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': '_p'}; {'id': '94', 'type': 'call', 'children': ['95', '100']}; {'id': '95', 'type': 'attribute', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'concatenate'}; {'id': '100', 'type': 'argument_list', 'children': ['101', '104']}; {'id': '101', 'type': 'tuple', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': '_p'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': '_y'}; {'id': '104', 'type': 'keyword_argument', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '106', 'type': 'unary_operator', 'children': ['107'], 'value': '-'}; {'id': '107', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '108', 'type': 'if_statement', 'children': ['109', '114']}; {'id': '109', 'type': 'call', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '111', 'type': 'argument_list', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '113', 'type': 'string', 'children': [], 'value': "'ny'"}; {'id': '114', 'type': 'block', 'children': ['115']}; {'id': '115', 'type': 'if_statement', 'children': ['116', '126']}; {'id': '116', 'type': 'comparison_operator', 'children': ['117', '123'], 'value': '!='}; {'id': '117', 'type': 'subscript', 'children': ['118', '121']}; {'id': '118', 'type': 'attribute', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': '_y'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '121', 'type': 'unary_operator', 'children': ['122'], 'value': '-'}; {'id': '122', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'ny'}; {'id': '126', 'type': 'block', 'children': ['127']}; {'id': '127', 'type': 'raise_statement', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '130', 'type': 'argument_list', 'children': ['131']}; {'id': '131', 'type': 'string', 'children': [], 'value': '"Incorrect shape of intern_y0"'}; {'id': '132', 'type': 'if_statement', 'children': ['133', '138', '153']}; {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '135', 'type': 'argument_list', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'atol'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '138', 'type': 'block', 'children': ['139']}; {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '144']}; {'id': '141', 'type': 'subscript', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '143', 'type': 'string', 'children': [], 'value': "'atol'"}; {'id': '144', 'type': 'list_comprehension', 'children': ['145', '148']}; {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'atol'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '148', 'type': 'for_in_clause', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '150', 'type': 'attribute', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '153', 'type': 'else_clause', 'children': ['154']}; {'id': '154', 'type': 'block', 'children': ['155']}; {'id': '155', 'type': 'expression_statement', 'children': ['156']}; {'id': '156', 'type': 'assignment', 'children': ['157', '160']}; {'id': '157', 'type': 'subscript', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '159', 'type': 'string', 'children': [], 'value': "'atol'"}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'atol'}; {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '166']}; {'id': '163', 'type': 'subscript', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '165', 'type': 'string', 'children': [], 'value': "'rtol'"}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'rtol'}; {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'assignment', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'integrator'}; {'id': '170', 'type': 'call', 'children': ['171', '174']}; {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '174', 'type': 'argument_list', 'children': ['175', '176']}; {'id': '175', 'type': 'string', 'children': [], 'value': "'integrator'"}; {'id': '176', 'type': 'None', 'children': []}; {'id': '177', 'type': 'if_statement', 'children': ['178', '181']}; {'id': '178', 'type': 'comparison_operator', 'children': ['179', '180'], 'value': 'is'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'integrator'}; {'id': '180', 'type': 'None', 'children': []}; {'id': '181', 'type': 'block', 'children': ['182']}; {'id': '182', 'type': 'expression_statement', 'children': ['183']}; {'id': '183', 'type': 'assignment', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'integrator'}; {'id': '185', 'type': 'call', 'children': ['186', '191']}; {'id': '186', 'type': 'attribute', 'children': ['187', '190']}; {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'environ'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '191', 'type': 'argument_list', 'children': ['192', '193']}; {'id': '192', 'type': 'string', 'children': [], 'value': "'PYODESYS_INTEGRATOR'"}; {'id': '193', 'type': 'string', 'children': [], 'value': "'scipy'"}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}; {'id': '195', 'type': 'assignment', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '197', 'type': 'call', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '199', 'type': 'argument_list', 'children': ['200']}; {'id': '200', 'type': 'call', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '202', 'type': 'argument_list', 'children': ['203', '208']}; {'id': '203', 'type': 'attribute', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'numpy'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'atleast_2d'}; {'id': '208', 'type': 'tuple', 'children': ['209', '210', '211']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': '_x'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': '_y'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': '_p'}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}; {'id': '213', 'type': 'assignment', 'children': ['214', '217']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': '_current_integration_kwargs'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '218', 'type': 'if_statement', 'children': ['219', '224', '241']}; {'id': '219', 'type': 'call', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '221', 'type': 'argument_list', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'integrator'}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '224', 'type': 'block', 'children': ['225']}; {'id': '225', 'type': 'expression_statement', 'children': ['226']}; {'id': '226', 'type': 'assignment', 'children': ['227', '228']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'nfo'}; {'id': '228', 'type': 'call', 'children': ['229', '236']}; {'id': '229', 'type': 'call', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '231', 'type': 'argument_list', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '233', 'type': 'binary_operator', 'children': ['234', '235'], 'value': '+'}; {'id': '234', 'type': 'string', 'children': [], 'value': "'_integrate_'"}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'integrator'}; {'id': '236', 'type': 'argument_list', 'children': ['237', '239']}; {'id': '237', 'type': 'list_splat', 'children': ['238']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '239', 'type': 'dictionary_splat', 'children': ['240']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '241', 'type': 'else_clause', 'children': ['242']}; {'id': '242', 'type': 'block', 'children': ['243', '254']}; {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'assignment', 'children': ['245', '248']}; {'id': '245', 'type': 'subscript', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '247', 'type': 'string', 'children': [], 'value': "'with_jacobian'"}; {'id': '248', 'type': 'call', 'children': ['249', '250']}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '250', 'type': 'argument_list', 'children': ['251', '252', '253']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'integrator'}; {'id': '252', 'type': 'string', 'children': [], 'value': "'with_jacobian'"}; {'id': '253', 'type': 'None', 'children': []}; {'id': '254', 'type': 'expression_statement', 'children': ['255']}; {'id': '255', 'type': 'assignment', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'nfo'}; {'id': '257', 'type': 'call', 'children': ['258', '261']}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': '_integrate'}; {'id': '261', 'type': 'argument_list', 'children': ['262', '265', '268', '270']}; {'id': '262', 'type': 'attribute', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'integrator'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'integrate_adaptive'}; {'id': '265', 'type': 'attribute', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'integrator'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'integrate_predefined'}; {'id': '268', 'type': 'list_splat', 'children': ['269']}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '270', 'type': 'dictionary_splat', 'children': ['271']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '272', 'type': 'if_statement', 'children': ['273', '274', '343']}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'twodim'}; {'id': '274', 'type': 'block', 'children': ['275', '285', '295', '305']}; {'id': '275', 'type': 'expression_statement', 'children': ['276']}; {'id': '276', 'type': 'assignment', 'children': ['277', '278']}; {'id': '277', 'type': 'identifier', 'children': [], 'value': '_xout'}; {'id': '278', 'type': 'list_comprehension', 'children': ['279', '282']}; {'id': '279', 'type': 'subscript', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '281', 'type': 'string', 'children': [], 'value': "'internal_xout'"}; {'id': '282', 'type': 'for_in_clause', 'children': ['283', '284']}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'nfo'}; {'id': '285', 'type': 'expression_statement', 'children': ['286']}; {'id': '286', 'type': 'assignment', 'children': ['287', '288']}; {'id': '287', 'type': 'identifier', 'children': [], 'value': '_yout'}; {'id': '288', 'type': 'list_comprehension', 'children': ['289', '292']}; {'id': '289', 'type': 'subscript', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '291', 'type': 'string', 'children': [], 'value': "'internal_yout'"}; {'id': '292', 'type': 'for_in_clause', 'children': ['293', '294']}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'nfo'}; {'id': '295', 'type': 'expression_statement', 'children': ['296']}; {'id': '296', 'type': 'assignment', 'children': ['297', '298']}; {'id': '297', 'type': 'identifier', 'children': [], 'value': '_params'}; {'id': '298', 'type': 'list_comprehension', 'children': ['299', '302']}; {'id': '299', 'type': 'subscript', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '301', 'type': 'string', 'children': [], 'value': "'internal_params'"}; {'id': '302', 'type': 'for_in_clause', 'children': ['303', '304']}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'nfo'}; {'id': '305', 'type': 'expression_statement', 'children': ['306']}; {'id': '306', 'type': 'assignment', 'children': ['307', '308']}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '308', 'type': 'list_comprehension', 'children': ['309', '334']}; {'id': '309', 'type': 'call', 'children': ['310', '311']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'Result'}; {'id': '311', 'type': 'argument_list', 'children': ['312']}; {'id': '312', 'type': 'list_splat', 'children': ['313']}; {'id': '313', 'type': '()', 'children': ['314']}; {'id': '314', 'type': 'binary_operator', 'children': ['315', '329'], 'value': '+'}; {'id': '315', 'type': 'call', 'children': ['316', '319']}; {'id': '316', 'type': 'attribute', 'children': ['317', '318']}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'post_process'}; {'id': '319', 'type': 'argument_list', 'children': ['320', '323', '326']}; {'id': '320', 'type': 'subscript', 'children': ['321', '322']}; {'id': '321', 'type': 'identifier', 'children': [], 'value': '_xout'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '323', 'type': 'subscript', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': '_yout'}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '326', 'type': 'subscript', 'children': ['327', '328']}; {'id': '327', 'type': 'identifier', 'children': [], 'value': '_params'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '329', 'type': 'tuple', 'children': ['330', '333']}; {'id': '330', 'type': 'subscript', 'children': ['331', '332']}; {'id': '331', 'type': 'identifier', 'children': [], 'value': 'nfo'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '333', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '334', 'type': 'for_in_clause', 'children': ['335', '336']}; {'id': '335', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '336', 'type': 'call', 'children': ['337', '338']}; {'id': '337', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '338', 'type': 'argument_list', 'children': ['339']}; {'id': '339', 'type': 'call', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '341', 'type': 'argument_list', 'children': ['342']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'nfo'}; {'id': '343', 'type': 'else_clause', 'children': ['344']}; {'id': '344', 'type': 'block', 'children': ['345', '353', '361', '382', '388']}; {'id': '345', 'type': 'expression_statement', 'children': ['346']}; {'id': '346', 'type': 'assignment', 'children': ['347', '348']}; {'id': '347', 'type': 'identifier', 'children': [], 'value': '_xout'}; {'id': '348', 'type': 'subscript', 'children': ['349', '352']}; {'id': '349', 'type': 'subscript', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'nfo'}; {'id': '351', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '352', 'type': 'string', 'children': [], 'value': "'internal_xout'"}; {'id': '353', 'type': 'expression_statement', 'children': ['354']}; {'id': '354', 'type': 'assignment', 'children': ['355', '356']}; {'id': '355', 'type': 'identifier', 'children': [], 'value': '_yout'}; {'id': '356', 'type': 'subscript', 'children': ['357', '360']}; {'id': '357', 'type': 'subscript', 'children': ['358', '359']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'nfo'}; {'id': '359', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '360', 'type': 'string', 'children': [], 'value': "'internal_yout'"}; {'id': '361', 'type': 'expression_statement', 'children': ['362']}; {'id': '362', 'type': 'assignment', 'children': ['363', '366']}; {'id': '363', 'type': 'attribute', 'children': ['364', '365']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '365', 'type': 'identifier', 'children': [], 'value': '_internal'}; {'id': '366', 'type': 'expression_list', 'children': ['367', '372', '377']}; {'id': '367', 'type': 'call', 'children': ['368', '371']}; {'id': '368', 'type': 'attribute', 'children': ['369', '370']}; {'id': '369', 'type': 'identifier', 'children': [], 'value': '_xout'}; {'id': '370', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '371', 'type': 'argument_list', 'children': []}; {'id': '372', 'type': 'call', 'children': ['373', '376']}; {'id': '373', 'type': 'attribute', 'children': ['374', '375']}; {'id': '374', 'type': 'identifier', 'children': [], 'value': '_yout'}; {'id': '375', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '376', 'type': 'argument_list', 'children': []}; {'id': '377', 'type': 'call', 'children': ['378', '381']}; {'id': '378', 'type': 'attribute', 'children': ['379', '380']}; {'id': '379', 'type': 'identifier', 'children': [], 'value': '_p'}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '381', 'type': 'argument_list', 'children': []}; {'id': '382', 'type': 'expression_statement', 'children': ['383']}; {'id': '383', 'type': 'assignment', 'children': ['384', '385']}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'nfo'}; {'id': '385', 'type': 'subscript', 'children': ['386', '387']}; {'id': '386', 'type': 'identifier', 'children': [], 'value': 'nfo'}; {'id': '387', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '388', 'type': 'expression_statement', 'children': ['389']}; {'id': '389', 'type': 'assignment', 'children': ['390', '391']}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'res'}; {'id': '391', 'type': 'call', 'children': ['392', '393']}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'Result'}; {'id': '393', 'type': 'argument_list', 'children': ['394']}; {'id': '394', 'type': 'list_splat', 'children': ['395']}; {'id': '395', 'type': '()', 'children': ['396']}; {'id': '396', 'type': 'binary_operator', 'children': ['397', '405'], 'value': '+'}; {'id': '397', 'type': 'call', 'children': ['398', '401']}; {'id': '398', 'type': 'attribute', 'children': ['399', '400']}; {'id': '399', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '400', 'type': 'identifier', 'children': [], 'value': 'post_process'}; {'id': '401', 'type': 'argument_list', 'children': ['402', '403', '404']}; {'id': '402', 'type': 'identifier', 'children': [], 'value': '_xout'}; {'id': '403', 'type': 'identifier', 'children': [], 'value': '_yout'}; {'id': '404', 'type': 'identifier', 'children': [], 'value': '_p'}; {'id': '405', 'type': 'tuple', 'children': ['406', '407']}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'nfo'}; {'id': '407', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '408', 'type': 'return_statement', 'children': ['409']}; {'id': '409', 'type': 'identifier', 'children': [], 'value': 'res'}
def integrate(self, x, y0, params=(), atol=1e-8, rtol=1e-8, **kwargs): arrs = self.to_arrays(x, y0, params) _x, _y, _p = _arrs = self.pre_process(*arrs) ndims = [a.ndim for a in _arrs] if ndims == [1, 1, 1]: twodim = False elif ndims == [2, 2, 2]: twodim = True else: raise ValueError("Pre-processor made ndims inconsistent?") if self.append_iv: _p = self.numpy.concatenate((_p, _y), axis=-1) if hasattr(self, 'ny'): if _y.shape[-1] != self.ny: raise ValueError("Incorrect shape of intern_y0") if isinstance(atol, dict): kwargs['atol'] = [atol[k] for k in self.names] else: kwargs['atol'] = atol kwargs['rtol'] = rtol integrator = kwargs.pop('integrator', None) if integrator is None: integrator = os.environ.get('PYODESYS_INTEGRATOR', 'scipy') args = tuple(map(self.numpy.atleast_2d, (_x, _y, _p))) self._current_integration_kwargs = kwargs if isinstance(integrator, str): nfo = getattr(self, '_integrate_' + integrator)(*args, **kwargs) else: kwargs['with_jacobian'] = getattr(integrator, 'with_jacobian', None) nfo = self._integrate(integrator.integrate_adaptive, integrator.integrate_predefined, *args, **kwargs) if twodim: _xout = [d['internal_xout'] for d in nfo] _yout = [d['internal_yout'] for d in nfo] _params = [d['internal_params'] for d in nfo] res = [Result(*(self.post_process(_xout[i], _yout[i], _params[i]) + (nfo[i], self))) for i in range(len(nfo))] else: _xout = nfo[0]['internal_xout'] _yout = nfo[0]['internal_yout'] self._internal = _xout.copy(), _yout.copy(), _p.copy() nfo = nfo[0] res = Result(*(self.post_process(_xout, _yout, _p) + (nfo, self))) return res
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sort_data'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '6', 'type': 'block', 'children': ['7']}; {'id': '7', 'type': 'return_statement', 'children': ['8']}; {'id': '8', 'type': 'call', 'children': ['9', '22']}; {'id': '9', 'type': 'attribute', 'children': ['10', '21']}; {'id': '10', 'type': 'subscript', 'children': ['11', '17']}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'sort_values'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '17', 'type': 'binary_operator', 'children': ['18', '19'], 'value': '+'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '19', 'type': 'list', 'children': ['20'], 'value': "['value']"}; {'id': '20', 'type': 'string', 'children': [], 'value': "'value'"}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'reset_index'}; {'id': '22', 'type': 'argument_list', 'children': ['23']}; {'id': '23', 'type': 'keyword_argument', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'drop'}; {'id': '25', 'type': 'True', 'children': []}
def sort_data(data, cols): return data.sort_values(cols)[cols + ['value']].reset_index(drop=True)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'filter_by_meta'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'join_meta'}; {'id': '8', 'type': 'False', 'children': []}; {'id': '9', 'type': 'dictionary_splat_pattern', 'children': ['10']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '11', 'type': 'block', 'children': ['12', '40', '68', '83', '87', '158', '164', '172', '194', '207', '224', '232', '245', '253', '265', '280', '293']}; {'id': '12', 'type': 'if_statement', 'children': ['13', '34']}; {'id': '13', 'type': 'not_operator', 'children': ['14']}; {'id': '14', 'type': 'call', 'children': ['15', '21']}; {'id': '15', 'type': 'attribute', 'children': ['16', '20']}; {'id': '16', 'type': 'call', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '18', 'type': 'argument_list', 'children': ['19']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'META_IDX'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'issubset'}; {'id': '21', 'type': 'argument_list', 'children': ['22']}; {'id': '22', 'type': 'binary_operator', 'children': ['23', '28'], 'value': '+'}; {'id': '23', 'type': 'attribute', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'attribute', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '34', 'type': 'block', 'children': ['35']}; {'id': '35', 'type': 'raise_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}; {'id': '39', 'type': 'string', 'children': [], 'value': "'missing required index dimensions or columns!'"}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'DataFrame'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '67']}; {'id': '49', 'type': 'attribute', 'children': ['50', '66']}; {'id': '50', 'type': 'subscript', 'children': ['51', '54']}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'binary_operator', 'children': ['58', '62'], 'value': '-'}; {'id': '58', 'type': 'call', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '62', 'type': 'call', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'META_IDX'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '67', 'type': 'argument_list', 'children': []}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'keep'}; {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'binary_operator', 'children': ['77', '79'], 'value': '*'}; {'id': '77', 'type': 'list', 'children': ['78'], 'value': '[True]'}; {'id': '78', 'type': 'True', 'children': []}; {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'apply_filter'}; {'id': '86', 'type': 'False', 'children': []}; {'id': '87', 'type': 'for_statement', 'children': ['88', '91', '96']}; {'id': '88', 'type': 'pattern_list', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '95', 'type': 'argument_list', 'children': []}; {'id': '96', 'type': 'block', 'children': ['97', '152']}; {'id': '97', 'type': 'if_statement', 'children': ['98', '105', '137']}; {'id': '98', 'type': 'boolean_operator', 'children': ['99', '102'], 'value': 'and'}; {'id': '99', 'type': 'comparison_operator', 'children': ['100', '101'], 'value': 'in'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'META_IDX'}; {'id': '102', 'type': 'comparison_operator', 'children': ['103', '104'], 'value': 'is'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '104', 'type': 'None', 'children': []}; {'id': '105', 'type': 'block', 'children': ['106', '122', '133']}; {'id': '106', 'type': 'expression_statement', 'children': ['107']}; {'id': '107', 'type': 'assignment', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': '_col'}; {'id': '109', 'type': 'call', 'children': ['110', '115']}; {'id': '110', 'type': 'attribute', 'children': ['111', '114']}; {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'get_level_values'}; {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'conditional_expression', 'children': ['117', '118', '121'], 'value': 'if'}; {'id': '117', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': 'is'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '120', 'type': 'string', 'children': [], 'value': "'model'"}; {'id': '121', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}; {'id': '123', 'type': 'augmented_assignment', 'children': ['124', '125'], 'value': '&='}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'keep'}; {'id': '125', 'type': 'call', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'pattern_match'}; {'id': '127', 'type': 'argument_list', 'children': ['128', '129', '130']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': '_col'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '130', 'type': 'keyword_argument', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'has_nan'}; {'id': '132', 'type': 'False', 'children': []}; {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'apply_filter'}; {'id': '136', 'type': 'True', 'children': []}; {'id': '137', 'type': 'elif_clause', 'children': ['138', '141']}; {'id': '138', 'type': 'comparison_operator', 'children': ['139', '140'], 'value': 'is'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '140', 'type': 'None', 'children': []}; {'id': '141', 'type': 'block', 'children': ['142']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}; {'id': '143', 'type': 'augmented_assignment', 'children': ['144', '145'], 'value': '&='}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'keep'}; {'id': '145', 'type': 'call', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'pattern_match'}; {'id': '147', 'type': 'argument_list', 'children': ['148', '151']}; {'id': '148', 'type': 'subscript', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}; {'id': '153', 'type': 'augmented_assignment', 'children': ['154', '155'], 'value': '|='}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'apply_filter'}; {'id': '155', 'type': 'comparison_operator', 'children': ['156', '157'], 'value': 'is'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '157', 'type': 'None', 'children': []}; {'id': '158', 'type': 'expression_statement', 'children': ['159']}; {'id': '159', 'type': 'assignment', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '161', 'type': 'subscript', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'keep'}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}; {'id': '165', 'type': 'assignment', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '171', 'type': 'argument_list', 'children': []}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}; {'id': '173', 'type': 'assignment', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '175', 'type': 'conditional_expression', 'children': ['176', '184', '193'], 'value': 'if'}; {'id': '176', 'type': 'call', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '178', 'type': 'argument_list', 'children': ['179']}; {'id': '179', 'type': 'attribute', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '184', 'type': 'not_operator', 'children': ['185']}; {'id': '185', 'type': 'comparison_operator', 'children': ['186', '191'], 'value': '=='}; {'id': '186', 'type': 'attribute', 'children': ['187', '190']}; {'id': '187', 'type': 'attribute', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '191', 'type': 'list', 'children': ['192'], 'value': '[None]'}; {'id': '192', 'type': 'None', 'children': []}; {'id': '193', 'type': 'None', 'children': []}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}; {'id': '195', 'type': 'assignment', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '197', 'type': 'call', 'children': ['198', '205']}; {'id': '198', 'type': 'attribute', 'children': ['199', '204']}; {'id': '199', 'type': 'call', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'reset_index'}; {'id': '203', 'type': 'argument_list', 'children': []}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'set_index'}; {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'META_IDX'}; {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'assignment', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '210', 'type': 'subscript', 'children': ['211', '214']}; {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'loc'}; {'id': '214', 'type': 'call', 'children': ['215', '220']}; {'id': '215', 'type': 'attribute', 'children': ['216', '219']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'intersection'}; {'id': '220', 'type': 'argument_list', 'children': ['221']}; {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}; {'id': '225', 'type': 'assignment', 'children': ['226', '231']}; {'id': '226', 'type': 'attribute', 'children': ['227', '230']}; {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'META_IDX'}; {'id': '232', 'type': 'if_statement', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'apply_filter'}; {'id': '234', 'type': 'block', 'children': ['235']}; {'id': '235', 'type': 'expression_statement', 'children': ['236']}; {'id': '236', 'type': 'assignment', 'children': ['237', '238']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '238', 'type': 'subscript', 'children': ['239', '242']}; {'id': '239', 'type': 'attribute', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'loc'}; {'id': '242', 'type': 'attribute', 'children': ['243', '244']}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'assignment', 'children': ['247', '252']}; {'id': '247', 'type': 'attribute', 'children': ['248', '251']}; {'id': '248', 'type': 'attribute', 'children': ['249', '250']}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'META_IDX'}; {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'assignment', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '256', 'type': 'conditional_expression', 'children': ['257', '263', '264'], 'value': 'if'}; {'id': '257', 'type': 'call', 'children': ['258', '261']}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '261', 'type': 'argument_list', 'children': ['262']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'join_meta'}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '265', 'type': 'expression_statement', 'children': ['266']}; {'id': '266', 'type': 'assignment', 'children': ['267', '268']}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '268', 'type': 'call', 'children': ['269', '276']}; {'id': '269', 'type': 'attribute', 'children': ['270', '275']}; {'id': '270', 'type': 'call', 'children': ['271', '274']}; {'id': '271', 'type': 'attribute', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'reset_index'}; {'id': '274', 'type': 'argument_list', 'children': []}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'set_index'}; {'id': '276', 'type': 'argument_list', 'children': ['277']}; {'id': '277', 'type': 'boolean_operator', 'children': ['278', '279'], 'value': 'or'}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '279', 'type': 'string', 'children': [], 'value': "'index'"}; {'id': '280', 'type': 'if_statement', 'children': ['281', '284']}; {'id': '281', 'type': 'comparison_operator', 'children': ['282', '283'], 'value': 'is'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '283', 'type': 'None', 'children': []}; {'id': '284', 'type': 'block', 'children': ['285']}; {'id': '285', 'type': 'expression_statement', 'children': ['286']}; {'id': '286', 'type': 'assignment', 'children': ['287', '292']}; {'id': '287', 'type': 'attribute', 'children': ['288', '291']}; {'id': '288', 'type': 'attribute', 'children': ['289', '290']}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '292', 'type': 'None', 'children': []}; {'id': '293', 'type': 'return_statement', 'children': ['294']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'data'}
def filter_by_meta(data, df, join_meta=False, **kwargs): if not set(META_IDX).issubset(data.index.names + list(data.columns)): raise ValueError('missing required index dimensions or columns!') meta = pd.DataFrame(df.meta[list(set(kwargs) - set(META_IDX))].copy()) keep = np.array([True] * len(meta)) apply_filter = False for col, values in kwargs.items(): if col in META_IDX and values is not None: _col = meta.index.get_level_values(0 if col is 'model' else 1) keep &= pattern_match(_col, values, has_nan=False) apply_filter = True elif values is not None: keep &= pattern_match(meta[col], values) apply_filter |= values is not None meta = meta[keep] data = data.copy() idx = list(data.index.names) if not data.index.names == [None] else None data = data.reset_index().set_index(META_IDX) meta = meta.loc[meta.index.intersection(data.index)] meta.index.names = META_IDX if apply_filter: data = data.loc[meta.index] data.index.names = META_IDX data = data.join(meta) if join_meta else data data = data.reset_index().set_index(idx or 'index') if idx is None: data.index.name = None return data
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '14']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'append'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'ignore_meta_conflict'}; {'id': '8', 'type': 'False', 'children': []}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'inplace'}; {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'dictionary_splat_pattern', 'children': ['13']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '14', 'type': 'block', 'children': ['15', '36', '50', '63', '80', '97', '266', '322', '352', '370', '385', '401']}; {'id': '15', 'type': 'if_statement', 'children': ['16', '22']}; {'id': '16', 'type': 'not_operator', 'children': ['17']}; {'id': '17', 'type': 'call', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '19', 'type': 'argument_list', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'IamDataFrame'}; {'id': '22', 'type': 'block', 'children': ['23', '32']}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'IamDataFrame'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '30', 'type': 'dictionary_splat', 'children': ['31']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'ignore_meta_conflict'}; {'id': '35', 'type': 'True', 'children': []}; {'id': '36', 'type': 'if_statement', 'children': ['37', '44']}; {'id': '37', 'type': 'comparison_operator', 'children': ['38', '41'], 'value': 'is'}; {'id': '38', 'type': 'attribute', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'time_col'}; {'id': '41', 'type': 'attribute', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'time_col'}; {'id': '44', 'type': 'block', 'children': ['45']}; {'id': '45', 'type': 'raise_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'string', 'children': [], 'value': "'incompatible time format (years vs. datetime)!'"}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '53', 'type': 'conditional_expression', 'children': ['54', '60', '62'], 'value': 'if'}; {'id': '54', 'type': 'call', 'children': ['55', '58']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'deepcopy'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '60', 'type': 'not_operator', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'inplace'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'diff'}; {'id': '66', 'type': 'call', 'children': ['67', '74']}; {'id': '67', 'type': 'attribute', 'children': ['68', '73']}; {'id': '68', 'type': 'attribute', 'children': ['69', '72']}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'difference'}; {'id': '74', 'type': 'argument_list', 'children': ['75']}; {'id': '75', 'type': 'attribute', 'children': ['76', '79']}; {'id': '76', 'type': 'attribute', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}; {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'intersect'}; {'id': '83', 'type': 'call', 'children': ['84', '91']}; {'id': '84', 'type': 'attribute', 'children': ['85', '90']}; {'id': '85', 'type': 'attribute', 'children': ['86', '89']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'intersection'}; {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'attribute', 'children': ['93', '96']}; {'id': '93', 'type': 'attribute', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '97', 'type': 'if_statement', 'children': ['98', '102']}; {'id': '98', 'type': 'not_operator', 'children': ['99']}; {'id': '99', 'type': 'attribute', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'intersect'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'empty'}; {'id': '102', 'type': 'block', 'children': ['103', '213', '233', '244']}; {'id': '103', 'type': 'if_statement', 'children': ['104', '106']}; {'id': '104', 'type': 'not_operator', 'children': ['105']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'ignore_meta_conflict'}; {'id': '106', 'type': 'block', 'children': ['107', '127']}; {'id': '107', 'type': 'expression_statement', 'children': ['108']}; {'id': '108', 'type': 'assignment', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '110', 'type': 'list_comprehension', 'children': ['111', '112', '119']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '112', 'type': 'for_in_clause', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '114', 'type': 'attribute', 'children': ['115', '118']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '119', 'type': 'if_clause', 'children': ['120']}; {'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': 'in'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '122', 'type': 'attribute', 'children': ['123', '126']}; {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '127', 'type': 'if_statement', 'children': ['128', '149']}; {'id': '128', 'type': 'not_operator', 'children': ['129']}; {'id': '129', 'type': 'call', 'children': ['130', '140']}; {'id': '130', 'type': 'attribute', 'children': ['131', '139']}; {'id': '131', 'type': 'subscript', 'children': ['132', '137', '138']}; {'id': '132', 'type': 'attribute', 'children': ['133', '136']}; {'id': '133', 'type': 'attribute', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'loc'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'intersect'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'equals'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}; {'id': '141', 'type': 'subscript', 'children': ['142', '147', '148']}; {'id': '142', 'type': 'attribute', 'children': ['143', '146']}; {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'loc'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'intersect'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '149', 'type': 'block', 'children': ['150', '186', '208']}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}; {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'conflict_idx'}; {'id': '153', 'type': '()', 'children': ['154']}; {'id': '154', 'type': 'call', 'children': ['155', '185']}; {'id': '155', 'type': 'attribute', 'children': ['156', '184']}; {'id': '156', 'type': 'attribute', 'children': ['157', '183']}; {'id': '157', 'type': 'call', 'children': ['158', '182']}; {'id': '158', 'type': 'attribute', 'children': ['159', '181']}; {'id': '159', 'type': 'call', 'children': ['160', '163']}; {'id': '160', 'type': 'attribute', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'concat'}; {'id': '163', 'type': 'argument_list', 'children': ['164']}; {'id': '164', 'type': 'list', 'children': ['165', '173'], 'value': '[ret.meta.loc[intersect, cols],\n other.meta.loc[intersect, cols]]'}; {'id': '165', 'type': 'subscript', 'children': ['166', '171', '172']}; {'id': '166', 'type': 'attribute', 'children': ['167', '170']}; {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'loc'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'intersect'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '173', 'type': 'subscript', 'children': ['174', '179', '180']}; {'id': '174', 'type': 'attribute', 'children': ['175', '178']}; {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'loc'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'intersect'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'drop_duplicates'}; {'id': '182', 'type': 'argument_list', 'children': []}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'drop_duplicates'}; {'id': '185', 'type': 'argument_list', 'children': []}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}; {'id': '187', 'type': 'assignment', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '189', 'type': 'call', 'children': ['190', '193']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}; {'id': '191', 'type': 'string', 'children': [], 'value': "'conflict in `meta` for scenarios {}'"}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '193', 'type': 'argument_list', 'children': ['194']}; {'id': '194', 'type': 'list_comprehension', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '196', 'type': 'for_in_clause', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '198', 'type': 'attribute', 'children': ['199', '207']}; {'id': '199', 'type': 'call', 'children': ['200', '203']}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'DataFrame'}; {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'keyword_argument', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'conflict_idx'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '208', 'type': 'raise_statement', 'children': ['209']}; {'id': '209', 'type': 'call', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '211', 'type': 'argument_list', 'children': ['212']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '213', 'type': 'expression_statement', 'children': ['214']}; {'id': '214', 'type': 'assignment', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '216', 'type': 'list_comprehension', 'children': ['217', '218', '225']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '218', 'type': 'for_in_clause', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '220', 'type': 'attribute', 'children': ['221', '224']}; {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '225', 'type': 'if_clause', 'children': ['226']}; {'id': '226', 'type': 'comparison_operator', 'children': ['227', '228'], 'value': 'not'}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '228', 'type': 'attribute', 'children': ['229', '232']}; {'id': '229', 'type': 'attribute', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '233', 'type': 'expression_statement', 'children': ['234']}; {'id': '234', 'type': 'assignment', 'children': ['235', '236']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': '_meta'}; {'id': '236', 'type': 'subscript', 'children': ['237', '242', '243']}; {'id': '237', 'type': 'attribute', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'loc'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'intersect'}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '244', 'type': 'expression_statement', 'children': ['245']}; {'id': '245', 'type': 'assignment', 'children': ['246', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '249', 'type': 'call', 'children': ['250', '255']}; {'id': '250', 'type': 'attribute', 'children': ['251', '254']}; {'id': '251', 'type': 'attribute', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'merge'}; {'id': '255', 'type': 'argument_list', 'children': ['256', '257', '260', '263']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': '_meta'}; {'id': '257', 'type': 'keyword_argument', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'how'}; {'id': '259', 'type': 'string', 'children': [], 'value': "'outer'"}; {'id': '260', 'type': 'keyword_argument', 'children': ['261', '262']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'left_index'}; {'id': '262', 'type': 'True', 'children': []}; {'id': '263', 'type': 'keyword_argument', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'right_index'}; {'id': '265', 'type': 'True', 'children': []}; {'id': '266', 'type': 'if_statement', 'children': ['267', '271']}; {'id': '267', 'type': 'not_operator', 'children': ['268']}; {'id': '268', 'type': 'attribute', 'children': ['269', '270']}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'diff'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'empty'}; {'id': '271', 'type': 'block', 'children': ['272', '299']}; {'id': '272', 'type': 'expression_statement', 'children': ['273']}; {'id': '273', 'type': 'assignment', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'sort_kwarg'}; {'id': '275', 'type': 'conditional_expression', 'children': ['276', '277', '292', '293'], 'value': 'if'}; {'id': '276', 'type': 'dictionary', 'children': []}; {'id': '277', 'type': 'comparison_operator', 'children': ['278', '291'], 'value': '<'}; {'id': '278', 'type': 'call', 'children': ['279', '280']}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '280', 'type': 'argument_list', 'children': ['281']}; {'id': '281', 'type': 'subscript', 'children': ['282', '290']}; {'id': '282', 'type': 'call', 'children': ['283', '288']}; {'id': '283', 'type': 'attribute', 'children': ['284', '287']}; {'id': '284', 'type': 'attribute', 'children': ['285', '286']}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': '__version__'}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'split'}; {'id': '288', 'type': 'argument_list', 'children': ['289']}; {'id': '289', 'type': 'string', 'children': [], 'value': "'.'"}; {'id': '290', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '291', 'type': 'integer', 'children': [], 'value': '23'}; {'id': '292', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '293', 'type': 'call', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '295', 'type': 'argument_list', 'children': ['296']}; {'id': '296', 'type': 'keyword_argument', 'children': ['297', '298']}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'sort'}; {'id': '298', 'type': 'False', 'children': []}; {'id': '299', 'type': 'expression_statement', 'children': ['300']}; {'id': '300', 'type': 'assignment', 'children': ['301', '304']}; {'id': '301', 'type': 'attribute', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '304', 'type': 'call', 'children': ['305', '310']}; {'id': '305', 'type': 'attribute', 'children': ['306', '309']}; {'id': '306', 'type': 'attribute', 'children': ['307', '308']}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '310', 'type': 'argument_list', 'children': ['311', '320']}; {'id': '311', 'type': 'subscript', 'children': ['312', '317', '318']}; {'id': '312', 'type': 'attribute', 'children': ['313', '316']}; {'id': '313', 'type': 'attribute', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '315', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '316', 'type': 'identifier', 'children': [], 'value': 'loc'}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'diff'}; {'id': '318', 'type': 'slice', 'children': ['319']}; {'id': '319', 'type': 'colon', 'children': []}; {'id': '320', 'type': 'dictionary_splat', 'children': ['321']}; {'id': '321', 'type': 'identifier', 'children': [], 'value': 'sort_kwarg'}; {'id': '322', 'type': 'expression_statement', 'children': ['323']}; {'id': '323', 'type': 'assignment', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': '_data'}; {'id': '325', 'type': 'call', 'children': ['326', '338']}; {'id': '326', 'type': 'attribute', 'children': ['327', '337']}; {'id': '327', 'type': 'call', 'children': ['328', '333']}; {'id': '328', 'type': 'attribute', 'children': ['329', '332']}; {'id': '329', 'type': 'attribute', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '331', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'set_index'}; {'id': '333', 'type': 'argument_list', 'children': ['334']}; {'id': '334', 'type': 'attribute', 'children': ['335', '336']}; {'id': '335', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '336', 'type': 'identifier', 'children': [], 'value': '_LONG_IDX'}; {'id': '337', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '338', 'type': 'argument_list', 'children': ['339', '349']}; {'id': '339', 'type': 'call', 'children': ['340', '345']}; {'id': '340', 'type': 'attribute', 'children': ['341', '344']}; {'id': '341', 'type': 'attribute', 'children': ['342', '343']}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '343', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'set_index'}; {'id': '345', 'type': 'argument_list', 'children': ['346']}; {'id': '346', 'type': 'attribute', 'children': ['347', '348']}; {'id': '347', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '348', 'type': 'identifier', 'children': [], 'value': '_LONG_IDX'}; {'id': '349', 'type': 'keyword_argument', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'verify_integrity'}; {'id': '351', 'type': 'True', 'children': []}; {'id': '352', 'type': 'expression_statement', 'children': ['353']}; {'id': '353', 'type': 'augmented_assignment', 'children': ['354', '357'], 'value': '+='}; {'id': '354', 'type': 'attribute', 'children': ['355', '356']}; {'id': '355', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'extra_cols'}; {'id': '357', 'type': 'list_comprehension', 'children': ['358', '359', '364']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '359', 'type': 'for_in_clause', 'children': ['360', '361']}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '361', 'type': 'attribute', 'children': ['362', '363']}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'other'}; {'id': '363', 'type': 'identifier', 'children': [], 'value': 'extra_cols'}; {'id': '364', 'type': 'if_clause', 'children': ['365']}; {'id': '365', 'type': 'comparison_operator', 'children': ['366', '367'], 'value': 'not'}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '367', 'type': 'attribute', 'children': ['368', '369']}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '369', 'type': 'identifier', 'children': [], 'value': 'extra_cols'}; {'id': '370', 'type': 'expression_statement', 'children': ['371']}; {'id': '371', 'type': 'assignment', 'children': ['372', '375']}; {'id': '372', 'type': 'attribute', 'children': ['373', '374']}; {'id': '373', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '374', 'type': 'identifier', 'children': [], 'value': '_LONG_IDX'}; {'id': '375', 'type': 'binary_operator', 'children': ['376', '382'], 'value': '+'}; {'id': '376', 'type': 'binary_operator', 'children': ['377', '378'], 'value': '+'}; {'id': '377', 'type': 'identifier', 'children': [], 'value': 'IAMC_IDX'}; {'id': '378', 'type': 'list', 'children': ['379'], 'value': '[ret.time_col]'}; {'id': '379', 'type': 'attribute', 'children': ['380', '381']}; {'id': '380', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '381', 'type': 'identifier', 'children': [], 'value': 'time_col'}; {'id': '382', 'type': 'attribute', 'children': ['383', '384']}; {'id': '383', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'extra_cols'}; {'id': '385', 'type': 'expression_statement', 'children': ['386']}; {'id': '386', 'type': 'assignment', 'children': ['387', '390']}; {'id': '387', 'type': 'attribute', 'children': ['388', '389']}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '389', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '390', 'type': 'call', 'children': ['391', '392']}; {'id': '391', 'type': 'identifier', 'children': [], 'value': 'sort_data'}; {'id': '392', 'type': 'argument_list', 'children': ['393', '398']}; {'id': '393', 'type': 'call', 'children': ['394', '397']}; {'id': '394', 'type': 'attribute', 'children': ['395', '396']}; {'id': '395', 'type': 'identifier', 'children': [], 'value': '_data'}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'reset_index'}; {'id': '397', 'type': 'argument_list', 'children': []}; {'id': '398', 'type': 'attribute', 'children': ['399', '400']}; {'id': '399', 'type': 'identifier', 'children': [], 'value': 'ret'}; {'id': '400', 'type': 'identifier', 'children': [], 'value': '_LONG_IDX'}; {'id': '401', 'type': 'if_statement', 'children': ['402', '404']}; {'id': '402', 'type': 'not_operator', 'children': ['403']}; {'id': '403', 'type': 'identifier', 'children': [], 'value': 'inplace'}; {'id': '404', 'type': 'block', 'children': ['405']}; {'id': '405', 'type': 'return_statement', 'children': ['406']}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'ret'}
def append(self, other, ignore_meta_conflict=False, inplace=False, **kwargs): if not isinstance(other, IamDataFrame): other = IamDataFrame(other, **kwargs) ignore_meta_conflict = True if self.time_col is not other.time_col: raise ValueError('incompatible time format (years vs. datetime)!') ret = copy.deepcopy(self) if not inplace else self diff = other.meta.index.difference(ret.meta.index) intersect = other.meta.index.intersection(ret.meta.index) if not intersect.empty: if not ignore_meta_conflict: cols = [i for i in other.meta.columns if i in ret.meta.columns] if not ret.meta.loc[intersect, cols].equals( other.meta.loc[intersect, cols]): conflict_idx = ( pd.concat([ret.meta.loc[intersect, cols], other.meta.loc[intersect, cols]] ).drop_duplicates() .index.drop_duplicates() ) msg = 'conflict in `meta` for scenarios {}'.format( [i for i in pd.DataFrame(index=conflict_idx).index]) raise ValueError(msg) cols = [i for i in other.meta.columns if i not in ret.meta.columns] _meta = other.meta.loc[intersect, cols] ret.meta = ret.meta.merge(_meta, how='outer', left_index=True, right_index=True) if not diff.empty: sort_kwarg = {} if int(pd.__version__.split('.')[1]) < 23 \ else dict(sort=False) ret.meta = ret.meta.append(other.meta.loc[diff, :], **sort_kwarg) _data = ret.data.set_index(ret._LONG_IDX).append( other.data.set_index(other._LONG_IDX), verify_integrity=True) ret.extra_cols += [i for i in other.extra_cols if i not in ret.extra_cols] ret._LONG_IDX = IAMC_IDX + [ret.time_col] + ret.extra_cols ret.data = sort_data(_data.reset_index(), ret._LONG_IDX) if not inplace: return ret
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '19']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'pivot_table'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '9', 'type': 'string', 'children': [], 'value': "'value'"}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'aggfunc'}; {'id': '12', 'type': 'string', 'children': [], 'value': "'count'"}; {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'fill_value'}; {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'style'}; {'id': '18', 'type': 'None', 'children': []}; {'id': '19', 'type': 'block', 'children': ['20', '31', '42', '48', '149', '172']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '23', 'type': 'conditional_expression', 'children': ['24', '26', '30'], 'value': 'if'}; {'id': '24', 'type': 'list', 'children': ['25'], 'value': '[index]'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'isstr'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '34', 'type': 'conditional_expression', 'children': ['35', '37', '41'], 'value': 'if'}; {'id': '35', 'type': 'list', 'children': ['36'], 'value': '[columns]'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'isstr'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '48', 'type': 'if_statement', 'children': ['49', '53']}; {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'isstr'}; {'id': '51', 'type': 'argument_list', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'aggfunc'}; {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'if_statement', 'children': ['55', '58', '83', '129']}; {'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': '=='}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'aggfunc'}; {'id': '57', 'type': 'string', 'children': [], 'value': "'count'"}; {'id': '58', 'type': 'block', 'children': ['59', '79']}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '62', 'type': 'call', 'children': ['63', '78']}; {'id': '63', 'type': 'attribute', 'children': ['64', '77']}; {'id': '64', 'type': 'call', 'children': ['65', '70']}; {'id': '65', 'type': 'attribute', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'groupby'}; {'id': '70', 'type': 'argument_list', 'children': ['71', '74']}; {'id': '71', 'type': 'binary_operator', 'children': ['72', '73'], 'value': '+'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'as_index'}; {'id': '76', 'type': 'False', 'children': []}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '78', 'type': 'argument_list', 'children': []}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'fill_value'}; {'id': '82', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '83', 'type': 'elif_clause', 'children': ['84', '87']}; {'id': '84', 'type': 'comparison_operator', 'children': ['85', '86'], 'value': '=='}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'aggfunc'}; {'id': '86', 'type': 'string', 'children': [], 'value': "'mean'"}; {'id': '87', 'type': 'block', 'children': ['88', '114', '120']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '91', 'type': 'call', 'children': ['92', '112']}; {'id': '92', 'type': 'attribute', 'children': ['93', '110', '111']}; {'id': '93', 'type': 'call', 'children': ['94', '109']}; {'id': '94', 'type': 'attribute', 'children': ['95', '108']}; {'id': '95', 'type': 'call', 'children': ['96', '101']}; {'id': '96', 'type': 'attribute', 'children': ['97', '100']}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'groupby'}; {'id': '101', 'type': 'argument_list', 'children': ['102', '105']}; {'id': '102', 'type': 'binary_operator', 'children': ['103', '104'], 'value': '+'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '105', 'type': 'keyword_argument', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'as_index'}; {'id': '107', 'type': 'False', 'children': []}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'mean'}; {'id': '109', 'type': 'argument_list', 'children': []}; {'id': '110', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'round'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}; {'id': '113', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}; {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'aggfunc'}; {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}; {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'fill_value'}; {'id': '123', 'type': 'conditional_expression', 'children': ['124', '125', '128'], 'value': 'if'}; {'id': '124', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '125', 'type': 'comparison_operator', 'children': ['126', '127'], 'value': '=='}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'style'}; {'id': '127', 'type': 'string', 'children': [], 'value': "'heatmap'"}; {'id': '128', 'type': 'string', 'children': [], 'value': '""'}; {'id': '129', 'type': 'elif_clause', 'children': ['130', '133']}; {'id': '130', 'type': 'comparison_operator', 'children': ['131', '132'], 'value': '=='}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'aggfunc'}; {'id': '132', 'type': 'string', 'children': [], 'value': "'sum'"}; {'id': '133', 'type': 'block', 'children': ['134', '140']}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}; {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'aggfunc'}; {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}; {'id': '141', 'type': 'assignment', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'fill_value'}; {'id': '143', 'type': 'conditional_expression', 'children': ['144', '145', '148'], 'value': 'if'}; {'id': '144', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '145', 'type': 'comparison_operator', 'children': ['146', '147'], 'value': '=='}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'style'}; {'id': '147', 'type': 'string', 'children': [], 'value': "'heatmap'"}; {'id': '148', 'type': 'string', 'children': [], 'value': '""'}; {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'assignment', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '152', 'type': 'call', 'children': ['153', '156']}; {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'pivot_table'}; {'id': '156', 'type': 'argument_list', 'children': ['157', '160', '163', '166', '169']}; {'id': '157', 'type': 'keyword_argument', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '160', 'type': 'keyword_argument', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '163', 'type': 'keyword_argument', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '166', 'type': 'keyword_argument', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'aggfunc'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'aggfunc'}; {'id': '169', 'type': 'keyword_argument', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'fill_value'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'fill_value'}; {'id': '172', 'type': 'return_statement', 'children': ['173']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'df'}
def pivot_table(self, index, columns, values='value', aggfunc='count', fill_value=None, style=None): index = [index] if isstr(index) else index columns = [columns] if isstr(columns) else columns df = self.data if isstr(aggfunc): if aggfunc == 'count': df = self.data.groupby(index + columns, as_index=False).count() fill_value = 0 elif aggfunc == 'mean': df = self.data.groupby(index + columns, as_index=False).mean()\ .round(2) aggfunc = np.sum fill_value = 0 if style == 'heatmap' else "" elif aggfunc == 'sum': aggfunc = np.sum fill_value = 0 if style == 'heatmap' else "" df = df.pivot_table(values=values, index=index, columns=columns, aggfunc=aggfunc, fill_value=fill_value) return df
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'check_internal_consistency'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '7', 'type': 'block', 'children': ['8', '12', '68']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'inconsistent_vars'}; {'id': '11', 'type': 'dictionary', 'children': []}; {'id': '12', 'type': 'for_statement', 'children': ['13', '14', '19']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'variable'}; {'id': '14', 'type': 'call', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '18', 'type': 'argument_list', 'children': []}; {'id': '19', 'type': 'block', 'children': ['20', '31', '44', '55']}; {'id': '20', 'type': 'expression_statement', 'children': ['21']}; {'id': '21', 'type': 'assignment', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'diff_agg'}; {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'check_aggregate'}; {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'variable'}; {'id': '29', 'type': 'dictionary_splat', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '31', 'type': 'if_statement', 'children': ['32', '35']}; {'id': '32', 'type': 'comparison_operator', 'children': ['33', '34'], 'value': 'is'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'diff_agg'}; {'id': '34', 'type': 'None', 'children': []}; {'id': '35', 'type': 'block', 'children': ['36']}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'assignment', 'children': ['38', '43']}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'inconsistent_vars'}; {'id': '40', 'type': 'binary_operator', 'children': ['41', '42'], 'value': '+'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'variable'}; {'id': '42', 'type': 'string', 'children': [], 'value': '"-aggregate"'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'diff_agg'}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'diff_regional'}; {'id': '47', 'type': 'call', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'check_aggregate_region'}; {'id': '51', 'type': 'argument_list', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'variable'}; {'id': '53', 'type': 'dictionary_splat', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '55', 'type': 'if_statement', 'children': ['56', '59']}; {'id': '56', 'type': 'comparison_operator', 'children': ['57', '58'], 'value': 'is'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'diff_regional'}; {'id': '58', 'type': 'None', 'children': []}; {'id': '59', 'type': 'block', 'children': ['60']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}; {'id': '61', 'type': 'assignment', 'children': ['62', '67']}; {'id': '62', 'type': 'subscript', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'inconsistent_vars'}; {'id': '64', 'type': 'binary_operator', 'children': ['65', '66'], 'value': '+'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'variable'}; {'id': '66', 'type': 'string', 'children': [], 'value': '"-regional"'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'diff_regional'}; {'id': '68', 'type': 'return_statement', 'children': ['69']}; {'id': '69', 'type': 'conditional_expression', 'children': ['70', '71', '72'], 'value': 'if'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'inconsistent_vars'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'inconsistent_vars'}; {'id': '72', 'type': 'None', 'children': []}
def check_internal_consistency(self, **kwargs): inconsistent_vars = {} for variable in self.variables(): diff_agg = self.check_aggregate(variable, **kwargs) if diff_agg is not None: inconsistent_vars[variable + "-aggregate"] = diff_agg diff_regional = self.check_aggregate_region(variable, **kwargs) if diff_regional is not None: inconsistent_vars[variable + "-regional"] = diff_regional return inconsistent_vars if inconsistent_vars else None
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_apply_filters'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'dictionary_splat_pattern', 'children': ['6']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'filters'}; {'id': '7', 'type': 'block', 'children': ['8', '18', '35', '432']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'regexp'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'filters'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '17']}; {'id': '16', 'type': 'string', 'children': [], 'value': "'regexp'"}; {'id': '17', 'type': 'False', 'children': []}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'keep'}; {'id': '21', 'type': 'call', 'children': ['22', '25']}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'binary_operator', 'children': ['27', '29'], 'value': '*'}; {'id': '27', 'type': 'list', 'children': ['28'], 'value': '[True]'}; {'id': '28', 'type': 'True', 'children': []}; {'id': '29', 'type': 'call', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '31', 'type': 'argument_list', 'children': ['32']}; {'id': '32', 'type': 'attribute', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '35', 'type': 'for_statement', 'children': ['36', '39', '44']}; {'id': '36', 'type': 'pattern_list', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '39', 'type': 'call', 'children': ['40', '43']}; {'id': '40', 'type': 'attribute', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'filters'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '43', 'type': 'argument_list', 'children': []}; {'id': '44', 'type': 'block', 'children': ['45', '51', '428']}; {'id': '45', 'type': 'if_statement', 'children': ['46', '49']}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': 'is'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '48', 'type': 'None', 'children': []}; {'id': '49', 'type': 'block', 'children': ['50']}; {'id': '50', 'type': 'continue_statement', 'children': []}; {'id': '51', 'type': 'if_statement', 'children': ['52', '59', '106', '136', '179', '212', '310', '343', '366', '397', '421']}; {'id': '52', 'type': 'comparison_operator', 'children': ['53', '54'], 'value': 'in'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '54', 'type': 'attribute', 'children': ['55', '58']}; {'id': '55', 'type': 'attribute', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '59', 'type': 'block', 'children': ['60', '75', '85']}; {'id': '60', 'type': 'expression_statement', 'children': ['61']}; {'id': '61', 'type': 'assignment', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'matches'}; {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'pattern_match'}; {'id': '65', 'type': 'argument_list', 'children': ['66', '71', '72']}; {'id': '66', 'type': 'subscript', 'children': ['67', '70']}; {'id': '67', 'type': 'attribute', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '72', 'type': 'keyword_argument', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'regexp'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'regexp'}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'cat_idx'}; {'id': '78', 'type': 'attribute', 'children': ['79', '84']}; {'id': '79', 'type': 'subscript', 'children': ['80', '83']}; {'id': '80', 'type': 'attribute', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'matches'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'keep_col'}; {'id': '88', 'type': '()', 'children': ['89']}; {'id': '89', 'type': 'call', 'children': ['90', '104']}; {'id': '90', 'type': 'attribute', 'children': ['91', '103']}; {'id': '91', 'type': 'attribute', 'children': ['92', '102']}; {'id': '92', 'type': 'call', 'children': ['93', '100']}; {'id': '93', 'type': 'attribute', 'children': ['94', '99']}; {'id': '94', 'type': 'subscript', 'children': ['95', '98']}; {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'META_IDX'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'set_index'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'META_IDX'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'isin'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'cat_idx'}; {'id': '106', 'type': 'elif_clause', 'children': ['107', '110']}; {'id': '107', 'type': 'comparison_operator', 'children': ['108', '109'], 'value': '=='}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '109', 'type': 'string', 'children': [], 'value': "'variable'"}; {'id': '110', 'type': 'block', 'children': ['111', '122']}; {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '114', 'type': 'conditional_expression', 'children': ['115', '118', '121'], 'value': 'if'}; {'id': '115', 'type': 'subscript', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'filters'}; {'id': '117', 'type': 'string', 'children': [], 'value': "'level'"}; {'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': 'in'}; {'id': '119', 'type': 'string', 'children': [], 'value': "'level'"}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'filters'}; {'id': '121', 'type': 'None', 'children': []}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}; {'id': '123', 'type': 'assignment', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'keep_col'}; {'id': '125', 'type': 'call', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'pattern_match'}; {'id': '127', 'type': 'argument_list', 'children': ['128', '133', '134', '135']}; {'id': '128', 'type': 'subscript', 'children': ['129', '132']}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'regexp'}; {'id': '136', 'type': 'elif_clause', 'children': ['137', '140']}; {'id': '137', 'type': 'comparison_operator', 'children': ['138', '139'], 'value': '=='}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '139', 'type': 'string', 'children': [], 'value': "'year'"}; {'id': '140', 'type': 'block', 'children': ['141', '171']}; {'id': '141', 'type': 'expression_statement', 'children': ['142']}; {'id': '142', 'type': 'assignment', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': '_data'}; {'id': '144', 'type': 'conditional_expression', 'children': ['145', '150', '155', '156'], 'value': 'if'}; {'id': '145', 'type': 'subscript', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '150', 'type': 'comparison_operator', 'children': ['151', '154'], 'value': 'is'}; {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'time_col'}; {'id': '154', 'type': 'string', 'children': [], 'value': "'time'"}; {'id': '155', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '156', 'type': 'call', 'children': ['157', '164']}; {'id': '157', 'type': 'attribute', 'children': ['158', '163']}; {'id': '158', 'type': 'subscript', 'children': ['159', '162']}; {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '162', 'type': 'string', 'children': [], 'value': "'time'"}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'apply'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}; {'id': '165', 'type': 'lambda', 'children': ['166', '168']}; {'id': '166', 'type': 'lambda_parameters', 'children': ['167']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'year'}; {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'assignment', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'keep_col'}; {'id': '174', 'type': 'call', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'years_match'}; {'id': '176', 'type': 'argument_list', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': '_data'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '179', 'type': 'elif_clause', 'children': ['180', '189']}; {'id': '180', 'type': 'boolean_operator', 'children': ['181', '184'], 'value': 'and'}; {'id': '181', 'type': 'comparison_operator', 'children': ['182', '183'], 'value': '=='}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '183', 'type': 'string', 'children': [], 'value': "'month'"}; {'id': '184', 'type': 'comparison_operator', 'children': ['185', '188'], 'value': 'is'}; {'id': '185', 'type': 'attribute', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'time_col'}; {'id': '188', 'type': 'string', 'children': [], 'value': "'time'"}; {'id': '189', 'type': 'block', 'children': ['190']}; {'id': '190', 'type': 'expression_statement', 'children': ['191']}; {'id': '191', 'type': 'assignment', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'keep_col'}; {'id': '193', 'type': 'call', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'month_match'}; {'id': '195', 'type': 'argument_list', 'children': ['196', '211']}; {'id': '196', 'type': 'call', 'children': ['197', '204']}; {'id': '197', 'type': 'attribute', 'children': ['198', '203']}; {'id': '198', 'type': 'subscript', 'children': ['199', '202']}; {'id': '199', 'type': 'attribute', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '202', 'type': 'string', 'children': [], 'value': "'time'"}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'apply'}; {'id': '204', 'type': 'argument_list', 'children': ['205']}; {'id': '205', 'type': 'lambda', 'children': ['206', '208']}; {'id': '206', 'type': 'lambda_parameters', 'children': ['207']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '208', 'type': 'attribute', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'month'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '212', 'type': 'elif_clause', 'children': ['213', '222']}; {'id': '213', 'type': 'boolean_operator', 'children': ['214', '217'], 'value': 'and'}; {'id': '214', 'type': 'comparison_operator', 'children': ['215', '216'], 'value': '=='}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '216', 'type': 'string', 'children': [], 'value': "'day'"}; {'id': '217', 'type': 'comparison_operator', 'children': ['218', '221'], 'value': 'is'}; {'id': '218', 'type': 'attribute', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'time_col'}; {'id': '221', 'type': 'string', 'children': [], 'value': "'time'"}; {'id': '222', 'type': 'block', 'children': ['223', '259', '302']}; {'id': '223', 'type': 'if_statement', 'children': ['224', '229', '234', '253']}; {'id': '224', 'type': 'call', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '226', 'type': 'argument_list', 'children': ['227', '228']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '229', 'type': 'block', 'children': ['230']}; {'id': '230', 'type': 'expression_statement', 'children': ['231']}; {'id': '231', 'type': 'assignment', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'wday'}; {'id': '233', 'type': 'True', 'children': []}; {'id': '234', 'type': 'elif_clause', 'children': ['235', '248']}; {'id': '235', 'type': 'boolean_operator', 'children': ['236', '241'], 'value': 'and'}; {'id': '236', 'type': 'call', 'children': ['237', '238']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '238', 'type': 'argument_list', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '241', 'type': 'call', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '243', 'type': 'argument_list', 'children': ['244', '247']}; {'id': '244', 'type': 'subscript', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '246', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '248', 'type': 'block', 'children': ['249']}; {'id': '249', 'type': 'expression_statement', 'children': ['250']}; {'id': '250', 'type': 'assignment', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'wday'}; {'id': '252', 'type': 'True', 'children': []}; {'id': '253', 'type': 'else_clause', 'children': ['254']}; {'id': '254', 'type': 'block', 'children': ['255']}; {'id': '255', 'type': 'expression_statement', 'children': ['256']}; {'id': '256', 'type': 'assignment', 'children': ['257', '258']}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'wday'}; {'id': '258', 'type': 'False', 'children': []}; {'id': '259', 'type': 'if_statement', 'children': ['260', '261', '282']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'wday'}; {'id': '261', 'type': 'block', 'children': ['262']}; {'id': '262', 'type': 'expression_statement', 'children': ['263']}; {'id': '263', 'type': 'assignment', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'days'}; {'id': '265', 'type': 'call', 'children': ['266', '273']}; {'id': '266', 'type': 'attribute', 'children': ['267', '272']}; {'id': '267', 'type': 'subscript', 'children': ['268', '271']}; {'id': '268', 'type': 'attribute', 'children': ['269', '270']}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '271', 'type': 'string', 'children': [], 'value': "'time'"}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'apply'}; {'id': '273', 'type': 'argument_list', 'children': ['274']}; {'id': '274', 'type': 'lambda', 'children': ['275', '277']}; {'id': '275', 'type': 'lambda_parameters', 'children': ['276']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '277', 'type': 'call', 'children': ['278', '281']}; {'id': '278', 'type': 'attribute', 'children': ['279', '280']}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'weekday'}; {'id': '281', 'type': 'argument_list', 'children': []}; {'id': '282', 'type': 'else_clause', 'children': ['283']}; {'id': '283', 'type': 'block', 'children': ['284']}; {'id': '284', 'type': 'expression_statement', 'children': ['285']}; {'id': '285', 'type': 'assignment', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'days'}; {'id': '287', 'type': 'call', 'children': ['288', '295']}; {'id': '288', 'type': 'attribute', 'children': ['289', '294']}; {'id': '289', 'type': 'subscript', 'children': ['290', '293']}; {'id': '290', 'type': 'attribute', 'children': ['291', '292']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '293', 'type': 'string', 'children': [], 'value': "'time'"}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'apply'}; {'id': '295', 'type': 'argument_list', 'children': ['296']}; {'id': '296', 'type': 'lambda', 'children': ['297', '299']}; {'id': '297', 'type': 'lambda_parameters', 'children': ['298']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '299', 'type': 'attribute', 'children': ['300', '301']}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'day'}; {'id': '302', 'type': 'expression_statement', 'children': ['303']}; {'id': '303', 'type': 'assignment', 'children': ['304', '305']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'keep_col'}; {'id': '305', 'type': 'call', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'day_match'}; {'id': '307', 'type': 'argument_list', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'days'}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '310', 'type': 'elif_clause', 'children': ['311', '320']}; {'id': '311', 'type': 'boolean_operator', 'children': ['312', '315'], 'value': 'and'}; {'id': '312', 'type': 'comparison_operator', 'children': ['313', '314'], 'value': '=='}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '314', 'type': 'string', 'children': [], 'value': "'hour'"}; {'id': '315', 'type': 'comparison_operator', 'children': ['316', '319'], 'value': 'is'}; {'id': '316', 'type': 'attribute', 'children': ['317', '318']}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'time_col'}; {'id': '319', 'type': 'string', 'children': [], 'value': "'time'"}; {'id': '320', 'type': 'block', 'children': ['321']}; {'id': '321', 'type': 'expression_statement', 'children': ['322']}; {'id': '322', 'type': 'assignment', 'children': ['323', '324']}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'keep_col'}; {'id': '324', 'type': 'call', 'children': ['325', '326']}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'hour_match'}; {'id': '326', 'type': 'argument_list', 'children': ['327', '342']}; {'id': '327', 'type': 'call', 'children': ['328', '335']}; {'id': '328', 'type': 'attribute', 'children': ['329', '334']}; {'id': '329', 'type': 'subscript', 'children': ['330', '333']}; {'id': '330', 'type': 'attribute', 'children': ['331', '332']}; {'id': '331', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '333', 'type': 'string', 'children': [], 'value': "'time'"}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'apply'}; {'id': '335', 'type': 'argument_list', 'children': ['336']}; {'id': '336', 'type': 'lambda', 'children': ['337', '339']}; {'id': '337', 'type': 'lambda_parameters', 'children': ['338']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '339', 'type': 'attribute', 'children': ['340', '341']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '341', 'type': 'identifier', 'children': [], 'value': 'hour'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '343', 'type': 'elif_clause', 'children': ['344', '353']}; {'id': '344', 'type': 'boolean_operator', 'children': ['345', '348'], 'value': 'and'}; {'id': '345', 'type': 'comparison_operator', 'children': ['346', '347'], 'value': '=='}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '347', 'type': 'string', 'children': [], 'value': "'time'"}; {'id': '348', 'type': 'comparison_operator', 'children': ['349', '352'], 'value': 'is'}; {'id': '349', 'type': 'attribute', 'children': ['350', '351']}; {'id': '350', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '351', 'type': 'identifier', 'children': [], 'value': 'time_col'}; {'id': '352', 'type': 'string', 'children': [], 'value': "'time'"}; {'id': '353', 'type': 'block', 'children': ['354']}; {'id': '354', 'type': 'expression_statement', 'children': ['355']}; {'id': '355', 'type': 'assignment', 'children': ['356', '357']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'keep_col'}; {'id': '357', 'type': 'call', 'children': ['358', '359']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'datetime_match'}; {'id': '359', 'type': 'argument_list', 'children': ['360', '365']}; {'id': '360', 'type': 'subscript', 'children': ['361', '364']}; {'id': '361', 'type': 'attribute', 'children': ['362', '363']}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '363', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '365', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '366', 'type': 'elif_clause', 'children': ['367', '370']}; {'id': '367', 'type': 'comparison_operator', 'children': ['368', '369'], 'value': '=='}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '369', 'type': 'string', 'children': [], 'value': "'level'"}; {'id': '370', 'type': 'block', 'children': ['371']}; {'id': '371', 'type': 'if_statement', 'children': ['372', '379', '394']}; {'id': '372', 'type': 'comparison_operator', 'children': ['373', '374'], 'value': 'not'}; {'id': '373', 'type': 'string', 'children': [], 'value': "'variable'"}; {'id': '374', 'type': 'call', 'children': ['375', '378']}; {'id': '375', 'type': 'attribute', 'children': ['376', '377']}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'filters'}; {'id': '377', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '378', 'type': 'argument_list', 'children': []}; {'id': '379', 'type': 'block', 'children': ['380']}; {'id': '380', 'type': 'expression_statement', 'children': ['381']}; {'id': '381', 'type': 'assignment', 'children': ['382', '383']}; {'id': '382', 'type': 'identifier', 'children': [], 'value': 'keep_col'}; {'id': '383', 'type': 'call', 'children': ['384', '385']}; {'id': '384', 'type': 'identifier', 'children': [], 'value': 'find_depth'}; {'id': '385', 'type': 'argument_list', 'children': ['386', '391']}; {'id': '386', 'type': 'subscript', 'children': ['387', '390']}; {'id': '387', 'type': 'attribute', 'children': ['388', '389']}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '389', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '390', 'type': 'string', 'children': [], 'value': "'variable'"}; {'id': '391', 'type': 'keyword_argument', 'children': ['392', '393']}; {'id': '392', 'type': 'identifier', 'children': [], 'value': 'level'}; {'id': '393', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '394', 'type': 'else_clause', 'children': ['395']}; {'id': '395', 'type': 'block', 'children': ['396']}; {'id': '396', 'type': 'continue_statement', 'children': []}; {'id': '397', 'type': 'elif_clause', 'children': ['398', '405']}; {'id': '398', 'type': 'comparison_operator', 'children': ['399', '400'], 'value': 'in'}; {'id': '399', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '400', 'type': 'attribute', 'children': ['401', '404']}; {'id': '401', 'type': 'attribute', 'children': ['402', '403']}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '403', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '404', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '405', 'type': 'block', 'children': ['406']}; {'id': '406', 'type': 'expression_statement', 'children': ['407']}; {'id': '407', 'type': 'assignment', 'children': ['408', '409']}; {'id': '408', 'type': 'identifier', 'children': [], 'value': 'keep_col'}; {'id': '409', 'type': 'call', 'children': ['410', '411']}; {'id': '410', 'type': 'identifier', 'children': [], 'value': 'pattern_match'}; {'id': '411', 'type': 'argument_list', 'children': ['412', '417', '418']}; {'id': '412', 'type': 'subscript', 'children': ['413', '416']}; {'id': '413', 'type': 'attribute', 'children': ['414', '415']}; {'id': '414', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '415', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '416', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '417', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '418', 'type': 'keyword_argument', 'children': ['419', '420']}; {'id': '419', 'type': 'identifier', 'children': [], 'value': 'regexp'}; {'id': '420', 'type': 'identifier', 'children': [], 'value': 'regexp'}; {'id': '421', 'type': 'else_clause', 'children': ['422']}; {'id': '422', 'type': 'block', 'children': ['423']}; {'id': '423', 'type': 'expression_statement', 'children': ['424']}; {'id': '424', 'type': 'call', 'children': ['425', '426']}; {'id': '425', 'type': 'identifier', 'children': [], 'value': '_raise_filter_error'}; {'id': '426', 'type': 'argument_list', 'children': ['427']}; {'id': '427', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '428', 'type': 'expression_statement', 'children': ['429']}; {'id': '429', 'type': 'augmented_assignment', 'children': ['430', '431'], 'value': '&='}; {'id': '430', 'type': 'identifier', 'children': [], 'value': 'keep'}; {'id': '431', 'type': 'identifier', 'children': [], 'value': 'keep_col'}; {'id': '432', 'type': 'return_statement', 'children': ['433']}; {'id': '433', 'type': 'identifier', 'children': [], 'value': 'keep'}
def _apply_filters(self, **filters): regexp = filters.pop('regexp', False) keep = np.array([True] * len(self.data)) for col, values in filters.items(): if values is None: continue if col in self.meta.columns: matches = pattern_match(self.meta[col], values, regexp=regexp) cat_idx = self.meta[matches].index keep_col = (self.data[META_IDX].set_index(META_IDX) .index.isin(cat_idx)) elif col == 'variable': level = filters['level'] if 'level' in filters else None keep_col = pattern_match(self.data[col], values, level, regexp) elif col == 'year': _data = self.data[col] if self.time_col is not 'time' \ else self.data['time'].apply(lambda x: x.year) keep_col = years_match(_data, values) elif col == 'month' and self.time_col is 'time': keep_col = month_match(self.data['time'] .apply(lambda x: x.month), values) elif col == 'day' and self.time_col is 'time': if isinstance(values, str): wday = True elif isinstance(values, list) and isinstance(values[0], str): wday = True else: wday = False if wday: days = self.data['time'].apply(lambda x: x.weekday()) else: days = self.data['time'].apply(lambda x: x.day) keep_col = day_match(days, values) elif col == 'hour' and self.time_col is 'time': keep_col = hour_match(self.data['time'] .apply(lambda x: x.hour), values) elif col == 'time' and self.time_col is 'time': keep_col = datetime_match(self.data[col], values) elif col == 'level': if 'variable' not in filters.keys(): keep_col = find_depth(self.data['variable'], level=values) else: continue elif col in self.data.columns: keep_col = pattern_match(self.data[col], values, regexp=regexp) else: _raise_filter_error(col) keep &= keep_col return keep
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'load_metadata'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '6', 'type': 'list_splat_pattern', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '8', 'type': 'dictionary_splat_pattern', 'children': ['9']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '10', 'type': 'block', 'children': ['11', '31', '96', '103', '135', '145', '160', '172', '201', '211', '219', '223', '255', '287']}; {'id': '11', 'type': 'if_statement', 'children': ['12', '21']}; {'id': '12', 'type': 'not_operator', 'children': ['13']}; {'id': '13', 'type': 'call', 'children': ['14', '19']}; {'id': '14', 'type': 'attribute', 'children': ['15', '18']}; {'id': '15', 'type': 'attribute', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'os'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'exists'}; {'id': '19', 'type': 'argument_list', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '21', 'type': 'block', 'children': ['22']}; {'id': '22', 'type': 'raise_statement', 'children': ['23']}; {'id': '23', 'type': 'call', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '25', 'type': 'argument_list', 'children': ['26']}; {'id': '26', 'type': 'binary_operator', 'children': ['27', '30'], 'value': '+'}; {'id': '27', 'type': 'binary_operator', 'children': ['28', '29'], 'value': '+'}; {'id': '28', 'type': 'string', 'children': [], 'value': '"no metadata file \'"'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '30', 'type': 'string', 'children': [], 'value': '"\' found!"'}; {'id': '31', 'type': 'if_statement', 'children': ['32', '38', '52']}; {'id': '32', 'type': 'call', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'endswith'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}; {'id': '37', 'type': 'string', 'children': [], 'value': "'csv'"}; {'id': '38', 'type': 'block', 'children': ['39']}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '42', 'type': 'call', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'read_csv'}; {'id': '46', 'type': 'argument_list', 'children': ['47', '48', '50']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '48', 'type': 'list_splat', 'children': ['49']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '50', 'type': 'dictionary_splat', 'children': ['51']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '52', 'type': 'else_clause', 'children': ['53']}; {'id': '53', 'type': 'block', 'children': ['54', '63', '83']}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}; {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'xl'}; {'id': '57', 'type': 'call', 'children': ['58', '61']}; {'id': '58', 'type': 'attribute', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'ExcelFile'}; {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '63', 'type': 'if_statement', 'children': ['64', '76']}; {'id': '64', 'type': 'boolean_operator', 'children': ['65', '73'], 'value': 'and'}; {'id': '65', 'type': 'comparison_operator', 'children': ['66', '72'], 'value': '>'}; {'id': '66', 'type': 'call', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '68', 'type': 'argument_list', 'children': ['69']}; {'id': '69', 'type': 'attribute', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'xl'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'sheet_names'}; {'id': '72', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': 'not'}; {'id': '74', 'type': 'string', 'children': [], 'value': "'sheet_name'"}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '76', 'type': 'block', 'children': ['77']}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '82']}; {'id': '79', 'type': 'subscript', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '81', 'type': 'string', 'children': [], 'value': "'sheet_name'"}; {'id': '82', 'type': 'string', 'children': [], 'value': "'meta'"}; {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '86', 'type': 'call', 'children': ['87', '90']}; {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'pd'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'read_excel'}; {'id': '90', 'type': 'argument_list', 'children': ['91', '92', '94']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '92', 'type': 'list_splat', 'children': ['93']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '94', 'type': 'dictionary_splat', 'children': ['95']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}; {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'req_cols'}; {'id': '99', 'type': 'list', 'children': ['100', '101', '102'], 'value': "['model', 'scenario', 'exclude']"}; {'id': '100', 'type': 'string', 'children': [], 'value': "'model'"}; {'id': '101', 'type': 'string', 'children': [], 'value': "'scenario'"}; {'id': '102', 'type': 'string', 'children': [], 'value': "'exclude'"}; {'id': '103', 'type': 'if_statement', 'children': ['104', '119']}; {'id': '104', 'type': 'not_operator', 'children': ['105']}; {'id': '105', 'type': 'call', 'children': ['106', '112']}; {'id': '106', 'type': 'attribute', 'children': ['107', '111']}; {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'req_cols'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'issubset'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}; {'id': '113', 'type': 'call', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '115', 'type': 'argument_list', 'children': ['116']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '119', 'type': 'block', 'children': ['120', '124']}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}; {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '123', 'type': 'string', 'children': [], 'value': "'File `{}` does not have required columns ({})!'"}; {'id': '124', 'type': 'raise_statement', 'children': ['125']}; {'id': '125', 'type': 'call', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '127', 'type': 'argument_list', 'children': ['128']}; {'id': '128', 'type': 'call', 'children': ['129', '132']}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '132', 'type': 'argument_list', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'path'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'req_cols'}; {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'call', 'children': ['137', '140']}; {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'set_index'}; {'id': '140', 'type': 'argument_list', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'META_IDX'}; {'id': '142', 'type': 'keyword_argument', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'inplace'}; {'id': '144', 'type': 'True', 'children': []}; {'id': '145', 'type': 'expression_statement', 'children': ['146']}; {'id': '146', 'type': 'assignment', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '148', 'type': 'call', 'children': ['149', '156']}; {'id': '149', 'type': 'attribute', 'children': ['150', '155']}; {'id': '150', 'type': 'attribute', 'children': ['151', '154']}; {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'intersection'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}; {'id': '157', 'type': 'attribute', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}; {'id': '161', 'type': 'assignment', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'n_invalid'}; {'id': '163', 'type': 'binary_operator', 'children': ['164', '168'], 'value': '-'}; {'id': '164', 'type': 'call', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '168', 'type': 'call', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '170', 'type': 'argument_list', 'children': ['171']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '172', 'type': 'if_statement', 'children': ['173', '176']}; {'id': '173', 'type': 'comparison_operator', 'children': ['174', '175'], 'value': '>'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'n_invalid'}; {'id': '175', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '176', 'type': 'block', 'children': ['177', '181']}; {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'assignment', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '180', 'type': 'string', 'children': [], 'value': "'Ignoring {} scenario{} from imported metadata'"}; {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'call', 'children': ['183', '188']}; {'id': '183', 'type': 'attribute', 'children': ['184', '187']}; {'id': '184', 'type': 'call', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '186', 'type': 'argument_list', 'children': []}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '188', 'type': 'argument_list', 'children': ['189']}; {'id': '189', 'type': 'call', 'children': ['190', '193']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '193', 'type': 'argument_list', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'n_invalid'}; {'id': '195', 'type': 'conditional_expression', 'children': ['196', '197', '200'], 'value': 'if'}; {'id': '196', 'type': 'string', 'children': [], 'value': "'s'"}; {'id': '197', 'type': 'comparison_operator', 'children': ['198', '199'], 'value': '>'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'n_invalid'}; {'id': '199', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '200', 'type': 'string', 'children': [], 'value': "''"}; {'id': '201', 'type': 'if_statement', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'empty'}; {'id': '205', 'type': 'block', 'children': ['206']}; {'id': '206', 'type': 'raise_statement', 'children': ['207']}; {'id': '207', 'type': 'call', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '209', 'type': 'argument_list', 'children': ['210']}; {'id': '210', 'type': 'string', 'children': [], 'value': "'No valid scenarios in imported metadata file!'"}; {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'assignment', 'children': ['213', '214']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '214', 'type': 'subscript', 'children': ['215', '218']}; {'id': '215', 'type': 'attribute', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'loc'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'idx'}; {'id': '219', 'type': 'expression_statement', 'children': ['220']}; {'id': '220', 'type': 'assignment', 'children': ['221', '222']}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '222', 'type': 'string', 'children': [], 'value': "'Importing metadata for {} scenario{} (for total of {})'"}; {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'call', 'children': ['225', '230']}; {'id': '225', 'type': 'attribute', 'children': ['226', '229']}; {'id': '226', 'type': 'call', 'children': ['227', '228']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '228', 'type': 'argument_list', 'children': []}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '230', 'type': 'argument_list', 'children': ['231']}; {'id': '231', 'type': 'call', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '235', 'type': 'argument_list', 'children': ['236', '240', '249']}; {'id': '236', 'type': 'call', 'children': ['237', '238']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '238', 'type': 'argument_list', 'children': ['239']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '240', 'type': 'conditional_expression', 'children': ['241', '242', '248'], 'value': 'if'}; {'id': '241', 'type': 'string', 'children': [], 'value': "'s'"}; {'id': '242', 'type': 'comparison_operator', 'children': ['243', '247'], 'value': '>'}; {'id': '243', 'type': 'call', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '245', 'type': 'argument_list', 'children': ['246']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '247', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '248', 'type': 'string', 'children': [], 'value': "''"}; {'id': '249', 'type': 'call', 'children': ['250', '251']}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '251', 'type': 'argument_list', 'children': ['252']}; {'id': '252', 'type': 'attribute', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '255', 'type': 'for_statement', 'children': ['256', '257', '260']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '260', 'type': 'block', 'children': ['261', '268']}; {'id': '261', 'type': 'expression_statement', 'children': ['262']}; {'id': '262', 'type': 'call', 'children': ['263', '266']}; {'id': '263', 'type': 'attribute', 'children': ['264', '265']}; {'id': '264', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '265', 'type': 'identifier', 'children': [], 'value': '_new_meta_column'}; {'id': '266', 'type': 'argument_list', 'children': ['267']}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '268', 'type': 'expression_statement', 'children': ['269']}; {'id': '269', 'type': 'assignment', 'children': ['270', '275']}; {'id': '270', 'type': 'subscript', 'children': ['271', '274']}; {'id': '271', 'type': 'attribute', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '275', 'type': 'call', 'children': ['276', '281']}; {'id': '276', 'type': 'attribute', 'children': ['277', '280']}; {'id': '277', 'type': 'subscript', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'combine_first'}; {'id': '281', 'type': 'argument_list', 'children': ['282']}; {'id': '282', 'type': 'subscript', 'children': ['283', '286']}; {'id': '283', 'type': 'attribute', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '287', 'type': 'expression_statement', 'children': ['288']}; {'id': '288', 'type': 'assignment', 'children': ['289', '294']}; {'id': '289', 'type': 'attribute', 'children': ['290', '293']}; {'id': '290', 'type': 'attribute', 'children': ['291', '292']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '294', 'type': 'call', 'children': ['295', '302']}; {'id': '295', 'type': 'attribute', 'children': ['296', '301']}; {'id': '296', 'type': 'attribute', 'children': ['297', '300']}; {'id': '297', 'type': 'attribute', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'meta'}; {'id': '300', 'type': 'identifier', 'children': [], 'value': 'exclude'}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'astype'}; {'id': '302', 'type': 'argument_list', 'children': ['303']}; {'id': '303', 'type': 'string', 'children': [], 'value': "'bool'"}
def load_metadata(self, path, *args, **kwargs): if not os.path.exists(path): raise ValueError("no metadata file '" + path + "' found!") if path.endswith('csv'): df = pd.read_csv(path, *args, **kwargs) else: xl = pd.ExcelFile(path) if len(xl.sheet_names) > 1 and 'sheet_name' not in kwargs: kwargs['sheet_name'] = 'meta' df = pd.read_excel(path, *args, **kwargs) req_cols = ['model', 'scenario', 'exclude'] if not set(req_cols).issubset(set(df.columns)): e = 'File `{}` does not have required columns ({})!' raise ValueError(e.format(path, req_cols)) df.set_index(META_IDX, inplace=True) idx = self.meta.index.intersection(df.index) n_invalid = len(df) - len(idx) if n_invalid > 0: msg = 'Ignoring {} scenario{} from imported metadata' logger().info(msg.format(n_invalid, 's' if n_invalid > 1 else '')) if idx.empty: raise ValueError('No valid scenarios in imported metadata file!') df = df.loc[idx] msg = 'Importing metadata for {} scenario{} (for total of {})' logger().info(msg.format(len(df), 's' if len(df) > 1 else '', len(self.meta))) for col in df.columns: self._new_meta_column(col) self.meta[col] = df[col].combine_first(self.meta[col]) self.meta.exclude = self.meta.exclude.astype('bool')
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '17']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'assign_style_props'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'marker'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'linestyle'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'cmap'}; {'id': '16', 'type': 'None', 'children': []}; {'id': '17', 'type': 'block', 'children': ['18', '32', '75', '90', '94', '100', '113', '205', '304']}; {'id': '18', 'type': 'if_statement', 'children': ['19', '26']}; {'id': '19', 'type': 'boolean_operator', 'children': ['20', '23'], 'value': 'and'}; {'id': '20', 'type': 'comparison_operator', 'children': ['21', '22'], 'value': 'is'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '22', 'type': 'None', 'children': []}; {'id': '23', 'type': 'comparison_operator', 'children': ['24', '25'], 'value': 'is'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'cmap'}; {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'block', 'children': ['27']}; {'id': '27', 'type': 'raise_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '30', 'type': 'argument_list', 'children': ['31']}; {'id': '31', 'type': 'string', 'children': [], 'value': "'`cmap` must be provided with the `color` argument'"}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '35', 'type': 'conditional_expression', 'children': ['36', '46', '51', '52'], 'value': 'if'}; {'id': '36', 'type': 'call', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}; {'id': '39', 'type': 'call', 'children': ['40', '45']}; {'id': '40', 'type': 'attribute', 'children': ['41', '44']}; {'id': '41', 'type': 'subscript', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '45', 'type': 'argument_list', 'children': []}; {'id': '46', 'type': 'comparison_operator', 'children': ['47', '48'], 'value': 'in'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '51', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}; {'id': '55', 'type': 'call', 'children': ['56', '74']}; {'id': '56', 'type': 'attribute', 'children': ['57', '73']}; {'id': '57', 'type': 'subscript', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'binary_operator', 'children': ['63', '69'], 'value': '&'}; {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'IAMC_IDX'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'drop_duplicates'}; {'id': '74', 'type': 'argument_list', 'children': []}; {'id': '75', 'type': 'expression_statement', 'children': ['76']}; {'id': '76', 'type': 'assignment', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '78', 'type': 'call', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'default_props'}; {'id': '80', 'type': 'argument_list', 'children': ['81', '84', '87']}; {'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'reset'}; {'id': '83', 'type': 'True', 'children': []}; {'id': '84', 'type': 'keyword_argument', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'num_colors'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '87', 'type': 'keyword_argument', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'colormap'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'cmap'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}; {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'props'}; {'id': '93', 'type': 'dictionary', 'children': []}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}; {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'rc'}; {'id': '97', 'type': 'call', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'run_control'}; {'id': '99', 'type': 'argument_list', 'children': []}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}; {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'kinds'}; {'id': '103', 'type': 'list', 'children': ['104', '107', '110'], 'value': "[('color', color), ('marker', marker), ('linestyle', linestyle)]"}; {'id': '104', 'type': 'tuple', 'children': ['105', '106']}; {'id': '105', 'type': 'string', 'children': [], 'value': "'color'"}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '107', 'type': 'tuple', 'children': ['108', '109']}; {'id': '108', 'type': 'string', 'children': [], 'value': "'marker'"}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'marker'}; {'id': '110', 'type': 'tuple', 'children': ['111', '112']}; {'id': '111', 'type': 'string', 'children': [], 'value': "'linestyle'"}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'linestyle'}; {'id': '113', 'type': 'for_statement', 'children': ['114', '117', '118']}; {'id': '114', 'type': 'pattern_list', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'kind'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'kinds'}; {'id': '118', 'type': 'block', 'children': ['119', '125']}; {'id': '119', 'type': 'expression_statement', 'children': ['120']}; {'id': '120', 'type': 'assignment', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'rc_has_kind'}; {'id': '122', 'type': 'comparison_operator', 'children': ['123', '124'], 'value': 'in'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'kind'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'rc'}; {'id': '125', 'type': 'if_statement', 'children': ['126', '131']}; {'id': '126', 'type': 'comparison_operator', 'children': ['127', '128'], 'value': 'in'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'columns'}; {'id': '131', 'type': 'block', 'children': ['132', '142', '146', '199']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}; {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'rc_has_var'}; {'id': '135', 'type': 'boolean_operator', 'children': ['136', '137'], 'value': 'and'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'rc_has_kind'}; {'id': '137', 'type': 'comparison_operator', 'children': ['138', '139'], 'value': 'in'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '139', 'type': 'subscript', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'rc'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'kind'}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}; {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'props_for_kind'}; {'id': '145', 'type': 'dictionary', 'children': []}; {'id': '146', 'type': 'for_statement', 'children': ['147', '148', '155']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '148', 'type': 'call', 'children': ['149', '154']}; {'id': '149', 'type': 'attribute', 'children': ['150', '153']}; {'id': '150', 'type': 'subscript', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'unique'}; {'id': '154', 'type': 'argument_list', 'children': []}; {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'if_statement', 'children': ['157', '166', '186']}; {'id': '157', 'type': 'boolean_operator', 'children': ['158', '159'], 'value': 'and'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'rc_has_var'}; {'id': '159', 'type': 'comparison_operator', 'children': ['160', '161'], 'value': 'in'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '161', 'type': 'subscript', 'children': ['162', '165']}; {'id': '162', 'type': 'subscript', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'rc'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'kind'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '166', 'type': 'block', 'children': ['167', '179']}; {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'assignment', 'children': ['169', '172']}; {'id': '169', 'type': 'subscript', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'props_for_kind'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '172', 'type': 'subscript', 'children': ['173', '178']}; {'id': '173', 'type': 'subscript', 'children': ['174', '177']}; {'id': '174', 'type': 'subscript', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'rc'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'kind'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '179', 'type': 'expression_statement', 'children': ['180']}; {'id': '180', 'type': 'call', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}; {'id': '183', 'type': 'subscript', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'kind'}; {'id': '186', 'type': 'else_clause', 'children': ['187']}; {'id': '187', 'type': 'block', 'children': ['188']}; {'id': '188', 'type': 'expression_statement', 'children': ['189']}; {'id': '189', 'type': 'assignment', 'children': ['190', '193']}; {'id': '190', 'type': 'subscript', 'children': ['191', '192']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'props_for_kind'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'val'}; {'id': '193', 'type': 'call', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'subscript', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'defaults'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'kind'}; {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '204']}; {'id': '201', 'type': 'subscript', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'props'}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'kind'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'props_for_kind'}; {'id': '205', 'type': 'if_statement', 'children': ['206', '209']}; {'id': '206', 'type': 'comparison_operator', 'children': ['207', '208'], 'value': 'in'}; {'id': '207', 'type': 'string', 'children': [], 'value': "'color'"}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'props'}; {'id': '209', 'type': 'block', 'children': ['210', '216', '227', '244']}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}; {'id': '211', 'type': 'assignment', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '213', 'type': 'subscript', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'props'}; {'id': '215', 'type': 'string', 'children': [], 'value': "'color'"}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}; {'id': '217', 'type': 'assignment', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '219', 'type': 'call', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'call', 'children': ['223', '226']}; {'id': '223', 'type': 'attribute', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '226', 'type': 'argument_list', 'children': []}; {'id': '227', 'type': 'expression_statement', 'children': ['228']}; {'id': '228', 'type': 'assignment', 'children': ['229', '230']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'overlap_idx'}; {'id': '230', 'type': 'call', 'children': ['231', '234']}; {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'in1d'}; {'id': '234', 'type': 'argument_list', 'children': ['235', '236']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '236', 'type': 'call', 'children': ['237', '238']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '238', 'type': 'argument_list', 'children': ['239']}; {'id': '239', 'type': 'call', 'children': ['240', '243']}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'PYAM_COLORS'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '243', 'type': 'argument_list', 'children': []}; {'id': '244', 'type': 'if_statement', 'children': ['245', '250']}; {'id': '245', 'type': 'call', 'children': ['246', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'overlap_idx'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '249', 'type': 'argument_list', 'children': []}; {'id': '250', 'type': 'block', 'children': ['251', '269', '280', '298']}; {'id': '251', 'type': 'expression_statement', 'children': ['252']}; {'id': '252', 'type': 'assignment', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '254', 'type': 'subscript', 'children': ['255', '268']}; {'id': '255', 'type': 'call', 'children': ['256', '259']}; {'id': '256', 'type': 'attribute', 'children': ['257', '258']}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '259', 'type': 'argument_list', 'children': ['260']}; {'id': '260', 'type': 'call', 'children': ['261', '262']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '262', 'type': 'argument_list', 'children': ['263']}; {'id': '263', 'type': 'call', 'children': ['264', '267']}; {'id': '264', 'type': 'attribute', 'children': ['265', '266']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '267', 'type': 'argument_list', 'children': []}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'overlap_idx'}; {'id': '269', 'type': 'expression_statement', 'children': ['270']}; {'id': '270', 'type': 'assignment', 'children': ['271', '272']}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '272', 'type': 'subscript', 'children': ['273', '279']}; {'id': '273', 'type': 'call', 'children': ['274', '277']}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '277', 'type': 'argument_list', 'children': ['278']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'overlap_idx'}; {'id': '280', 'type': 'for_statement', 'children': ['281', '284', '289']}; {'id': '281', 'type': 'pattern_list', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '284', 'type': 'call', 'children': ['285', '286']}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '286', 'type': 'argument_list', 'children': ['287', '288']}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '289', 'type': 'block', 'children': ['290']}; {'id': '290', 'type': 'expression_statement', 'children': ['291']}; {'id': '291', 'type': 'assignment', 'children': ['292', '295']}; {'id': '292', 'type': 'subscript', 'children': ['293', '294']}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '295', 'type': 'subscript', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'PYAM_COLORS'}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '298', 'type': 'expression_statement', 'children': ['299']}; {'id': '299', 'type': 'assignment', 'children': ['300', '303']}; {'id': '300', 'type': 'subscript', 'children': ['301', '302']}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'props'}; {'id': '302', 'type': 'string', 'children': [], 'value': "'color'"}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '304', 'type': 'return_statement', 'children': ['305']}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'props'}
def assign_style_props(df, color=None, marker=None, linestyle=None, cmap=None): if color is None and cmap is not None: raise ValueError('`cmap` must be provided with the `color` argument') n = len(df[color].unique()) if color in df.columns else \ len(df[list(set(df.columns) & set(IAMC_IDX))].drop_duplicates()) defaults = default_props(reset=True, num_colors=n, colormap=cmap) props = {} rc = run_control() kinds = [('color', color), ('marker', marker), ('linestyle', linestyle)] for kind, var in kinds: rc_has_kind = kind in rc if var in df.columns: rc_has_var = rc_has_kind and var in rc[kind] props_for_kind = {} for val in df[var].unique(): if rc_has_var and val in rc[kind][var]: props_for_kind[val] = rc[kind][var][val] next(defaults[kind]) else: props_for_kind[val] = next(defaults[kind]) props[kind] = props_for_kind if 'color' in props: d = props['color'] values = list(d.values()) overlap_idx = np.in1d(values, list(PYAM_COLORS.keys())) if overlap_idx.any(): keys = np.array(list(d.keys()))[overlap_idx] values = np.array(values)[overlap_idx] for k, v in zip(keys, values): d[k] = PYAM_COLORS[v] props['color'] = d return props
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '38']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'scatter'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10', '13', '16', '19', '22', '25', '28', '33', '36']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'legend'}; {'id': '12', 'type': 'None', 'children': []}; {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'default_parameter', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '18', 'type': 'None', 'children': []}; {'id': '19', 'type': 'default_parameter', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'marker'}; {'id': '21', 'type': 'string', 'children': [], 'value': "'o'"}; {'id': '22', 'type': 'default_parameter', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'linestyle'}; {'id': '24', 'type': 'None', 'children': []}; {'id': '25', 'type': 'default_parameter', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'cmap'}; {'id': '27', 'type': 'None', 'children': []}; {'id': '28', 'type': 'default_parameter', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'groupby'}; {'id': '30', 'type': 'list', 'children': ['31', '32'], 'value': "['model', 'scenario']"}; {'id': '31', 'type': 'string', 'children': [], 'value': "'model'"}; {'id': '32', 'type': 'string', 'children': [], 'value': "'scenario'"}; {'id': '33', 'type': 'default_parameter', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'with_lines'}; {'id': '35', 'type': 'False', 'children': []}; {'id': '36', 'type': 'dictionary_splat_pattern', 'children': ['37']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '38', 'type': 'block', 'children': ['39', '54', '73', '82', '86', '259', '269', '319', '343', '350', '357', '367']}; {'id': '39', 'type': 'if_statement', 'children': ['40', '43']}; {'id': '40', 'type': 'comparison_operator', 'children': ['41', '42'], 'value': 'is'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '42', 'type': 'None', 'children': []}; {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'assignment', 'children': ['46', '49']}; {'id': '46', 'type': 'pattern_list', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'fig'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '49', 'type': 'call', 'children': ['50', '53']}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'plt'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'subplots'}; {'id': '53', 'type': 'argument_list', 'children': []}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}; {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'props'}; {'id': '57', 'type': 'call', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'assign_style_props'}; {'id': '59', 'type': 'argument_list', 'children': ['60', '61', '64', '67', '70']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'marker'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'marker'}; {'id': '67', 'type': 'keyword_argument', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'linestyle'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'linestyle'}; {'id': '70', 'type': 'keyword_argument', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'cmap'}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'cmap'}; {'id': '73', 'type': 'expression_statement', 'children': ['74']}; {'id': '74', 'type': 'assignment', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '76', 'type': 'call', 'children': ['77', '80']}; {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'df'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'groupby'}; {'id': '80', 'type': 'argument_list', 'children': ['81']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'groupby'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}; {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'legend_data'}; {'id': '85', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '86', 'type': 'for_statement', 'children': ['87', '90', '91']}; {'id': '87', 'type': 'pattern_list', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'groups'}; {'id': '91', 'type': 'block', 'children': ['92', '96', '100', '178', '212', '219']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}; {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'pargs'}; {'id': '95', 'type': 'dictionary', 'children': []}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}; {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '99', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '100', 'type': 'for_statement', 'children': ['101', '105', '118']}; {'id': '101', 'type': 'pattern_list', 'children': ['102', '103', '104']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'kind'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '105', 'type': 'list', 'children': ['106', '110', '114'], 'value': "[('c', 'color', color),\n ('marker', 'marker', marker),\n ('linestyle', 'linestyle', linestyle)]"}; {'id': '106', 'type': 'tuple', 'children': ['107', '108', '109']}; {'id': '107', 'type': 'string', 'children': [], 'value': "'c'"}; {'id': '108', 'type': 'string', 'children': [], 'value': "'color'"}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'color'}; {'id': '110', 'type': 'tuple', 'children': ['111', '112', '113']}; {'id': '111', 'type': 'string', 'children': [], 'value': "'marker'"}; {'id': '112', 'type': 'string', 'children': [], 'value': "'marker'"}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'marker'}; {'id': '114', 'type': 'tuple', 'children': ['115', '116', '117']}; {'id': '115', 'type': 'string', 'children': [], 'value': "'linestyle'"}; {'id': '116', 'type': 'string', 'children': [], 'value': "'linestyle'"}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'linestyle'}; {'id': '118', 'type': 'block', 'children': ['119']}; {'id': '119', 'type': 'if_statement', 'children': ['120', '123', '170']}; {'id': '120', 'type': 'comparison_operator', 'children': ['121', '122'], 'value': 'in'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'kind'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'props'}; {'id': '123', 'type': 'block', 'children': ['124', '134', '150']}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}; {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '127', 'type': 'subscript', 'children': ['128', '133']}; {'id': '128', 'type': 'attribute', 'children': ['129', '132']}; {'id': '129', 'type': 'subscript', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '133', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}; {'id': '135', 'type': 'assignment', 'children': ['136', '139']}; {'id': '136', 'type': 'subscript', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'pargs'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '139', 'type': 'subscript', 'children': ['140', '143']}; {'id': '140', 'type': 'subscript', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'props'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'kind'}; {'id': '143', 'type': 'subscript', 'children': ['144', '149']}; {'id': '144', 'type': 'attribute', 'children': ['145', '148']}; {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'values'}; {'id': '149', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}; {'id': '151', 'type': 'call', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'call', 'children': ['157', '168']}; {'id': '157', 'type': 'attribute', 'children': ['158', '167']}; {'id': '158', 'type': 'call', 'children': ['159', '165']}; {'id': '159', 'type': 'attribute', 'children': ['160', '164']}; {'id': '160', 'type': 'call', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'repr'}; {'id': '162', 'type': 'argument_list', 'children': ['163']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'lstrip'}; {'id': '165', 'type': 'argument_list', 'children': ['166']}; {'id': '166', 'type': 'string', 'children': [], 'value': '"u\'"'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'strip'}; {'id': '168', 'type': 'argument_list', 'children': ['169']}; {'id': '169', 'type': 'string', 'children': [], 'value': '"\'"'}; {'id': '170', 'type': 'else_clause', 'children': ['171']}; {'id': '171', 'type': 'block', 'children': ['172']}; {'id': '172', 'type': 'expression_statement', 'children': ['173']}; {'id': '173', 'type': 'assignment', 'children': ['174', '177']}; {'id': '174', 'type': 'subscript', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'pargs'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'var'}; {'id': '178', 'type': 'if_statement', 'children': ['179', '185', '198']}; {'id': '179', 'type': 'comparison_operator', 'children': ['180', '184'], 'value': '>'}; {'id': '180', 'type': 'call', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '184', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '185', 'type': 'block', 'children': ['186']}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}; {'id': '187', 'type': 'call', 'children': ['188', '191']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'legend_data'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'call', 'children': ['193', '196']}; {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '196', 'type': 'argument_list', 'children': ['197']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '198', 'type': 'else_clause', 'children': ['199']}; {'id': '199', 'type': 'block', 'children': ['200']}; {'id': '200', 'type': 'expression_statement', 'children': ['201']}; {'id': '201', 'type': 'call', 'children': ['202', '205']}; {'id': '202', 'type': 'attribute', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'legend_data'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'call', 'children': ['207', '210']}; {'id': '207', 'type': 'attribute', 'children': ['208', '209']}; {'id': '208', 'type': 'string', 'children': [], 'value': "' '"}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'join'}; {'id': '210', 'type': 'argument_list', 'children': ['211']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}; {'id': '213', 'type': 'call', 'children': ['214', '217']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '217', 'type': 'argument_list', 'children': ['218']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'pargs'}; {'id': '219', 'type': 'if_statement', 'children': ['220', '221', '236']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'with_lines'}; {'id': '221', 'type': 'block', 'children': ['222']}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}; {'id': '223', 'type': 'call', 'children': ['224', '227']}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'plot'}; {'id': '227', 'type': 'argument_list', 'children': ['228', '231', '234']}; {'id': '228', 'type': 'subscript', 'children': ['229', '230']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '231', 'type': 'subscript', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '234', 'type': 'dictionary_splat', 'children': ['235']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '236', 'type': 'else_clause', 'children': ['237']}; {'id': '237', 'type': 'block', 'children': ['238', '245']}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}; {'id': '239', 'type': 'call', 'children': ['240', '243']}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'string', 'children': [], 'value': "'linestyle'"}; {'id': '245', 'type': 'expression_statement', 'children': ['246']}; {'id': '246', 'type': 'call', 'children': ['247', '250']}; {'id': '247', 'type': 'attribute', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'scatter'}; {'id': '250', 'type': 'argument_list', 'children': ['251', '254', '257']}; {'id': '251', 'type': 'subscript', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '254', 'type': 'subscript', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '257', 'type': 'dictionary_splat', 'children': ['258']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'assignment', 'children': ['261', '264']}; {'id': '261', 'type': 'pattern_list', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'handles'}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '264', 'type': 'call', 'children': ['265', '268']}; {'id': '265', 'type': 'attribute', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'get_legend_handles_labels'}; {'id': '268', 'type': 'argument_list', 'children': []}; {'id': '269', 'type': 'if_statement', 'children': ['270', '279']}; {'id': '270', 'type': 'comparison_operator', 'children': ['271', '272'], 'value': '!='}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'legend_data'}; {'id': '272', 'type': 'binary_operator', 'children': ['273', '275'], 'value': '*'}; {'id': '273', 'type': 'list', 'children': ['274'], 'value': "['']"}; {'id': '274', 'type': 'string', 'children': [], 'value': "''"}; {'id': '275', 'type': 'call', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '277', 'type': 'argument_list', 'children': ['278']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'legend_data'}; {'id': '279', 'type': 'block', 'children': ['280', '296', '309']}; {'id': '280', 'type': 'expression_statement', 'children': ['281']}; {'id': '281', 'type': 'assignment', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '283', 'type': 'call', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'sorted'}; {'id': '285', 'type': 'argument_list', 'children': ['286']}; {'id': '286', 'type': 'call', 'children': ['287', '288']}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '288', 'type': 'argument_list', 'children': ['289']}; {'id': '289', 'type': 'call', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '291', 'type': 'argument_list', 'children': ['292']}; {'id': '292', 'type': 'call', 'children': ['293', '294']}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '294', 'type': 'argument_list', 'children': ['295']}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'legend_data'}; {'id': '296', 'type': 'expression_statement', 'children': ['297']}; {'id': '297', 'type': 'assignment', 'children': ['298', '299']}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'idxs'}; {'id': '299', 'type': 'list_comprehension', 'children': ['300', '306']}; {'id': '300', 'type': 'call', 'children': ['301', '304']}; {'id': '301', 'type': 'attribute', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'legend_data'}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '304', 'type': 'argument_list', 'children': ['305']}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '306', 'type': 'for_in_clause', 'children': ['307', '308']}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '309', 'type': 'expression_statement', 'children': ['310']}; {'id': '310', 'type': 'assignment', 'children': ['311', '312']}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'handles'}; {'id': '312', 'type': 'list_comprehension', 'children': ['313', '316']}; {'id': '313', 'type': 'subscript', 'children': ['314', '315']}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'handles'}; {'id': '315', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '316', 'type': 'for_in_clause', 'children': ['317', '318']}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'idxs'}; {'id': '319', 'type': 'if_statement', 'children': ['320', '334']}; {'id': '320', 'type': 'boolean_operator', 'children': ['321', '331'], 'value': 'or'}; {'id': '321', 'type': 'boolean_operator', 'children': ['322', '325'], 'value': 'and'}; {'id': '322', 'type': 'comparison_operator', 'children': ['323', '324'], 'value': 'is'}; {'id': '323', 'type': 'identifier', 'children': [], 'value': 'legend'}; {'id': '324', 'type': 'None', 'children': []}; {'id': '325', 'type': 'comparison_operator', 'children': ['326', '330'], 'value': '<'}; {'id': '326', 'type': 'call', 'children': ['327', '328']}; {'id': '327', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '328', 'type': 'argument_list', 'children': ['329']}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '330', 'type': 'integer', 'children': [], 'value': '13'}; {'id': '331', 'type': 'comparison_operator', 'children': ['332', '333'], 'value': 'is'}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'legend'}; {'id': '333', 'type': 'False', 'children': []}; {'id': '334', 'type': 'block', 'children': ['335']}; {'id': '335', 'type': 'expression_statement', 'children': ['336']}; {'id': '336', 'type': 'call', 'children': ['337', '338']}; {'id': '337', 'type': 'identifier', 'children': [], 'value': '_add_legend'}; {'id': '338', 'type': 'argument_list', 'children': ['339', '340', '341', '342']}; {'id': '339', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'handles'}; {'id': '341', 'type': 'identifier', 'children': [], 'value': 'labels'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'legend'}; {'id': '343', 'type': 'expression_statement', 'children': ['344']}; {'id': '344', 'type': 'call', 'children': ['345', '348']}; {'id': '345', 'type': 'attribute', 'children': ['346', '347']}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '347', 'type': 'identifier', 'children': [], 'value': 'set_xlabel'}; {'id': '348', 'type': 'argument_list', 'children': ['349']}; {'id': '349', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '350', 'type': 'expression_statement', 'children': ['351']}; {'id': '351', 'type': 'call', 'children': ['352', '355']}; {'id': '352', 'type': 'attribute', 'children': ['353', '354']}; {'id': '353', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'set_ylabel'}; {'id': '355', 'type': 'argument_list', 'children': ['356']}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '357', 'type': 'if_statement', 'children': ['358', '359']}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '359', 'type': 'block', 'children': ['360']}; {'id': '360', 'type': 'expression_statement', 'children': ['361']}; {'id': '361', 'type': 'call', 'children': ['362', '365']}; {'id': '362', 'type': 'attribute', 'children': ['363', '364']}; {'id': '363', 'type': 'identifier', 'children': [], 'value': 'ax'}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'set_title'}; {'id': '365', 'type': 'argument_list', 'children': ['366']}; {'id': '366', 'type': 'identifier', 'children': [], 'value': 'title'}; {'id': '367', 'type': 'return_statement', 'children': ['368']}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'ax'}
def scatter(df, x, y, ax=None, legend=None, title=None, color=None, marker='o', linestyle=None, cmap=None, groupby=['model', 'scenario'], with_lines=False, **kwargs): if ax is None: fig, ax = plt.subplots() props = assign_style_props(df, color=color, marker=marker, linestyle=linestyle, cmap=cmap) groups = df.groupby(groupby) legend_data = [] for name, group in groups: pargs = {} labels = [] for key, kind, var in [('c', 'color', color), ('marker', 'marker', marker), ('linestyle', 'linestyle', linestyle)]: if kind in props: label = group[var].values[0] pargs[key] = props[kind][group[var].values[0]] labels.append(repr(label).lstrip("u'").strip("'")) else: pargs[key] = var if len(labels) > 0: legend_data.append(' '.join(labels)) else: legend_data.append(' '.join(name)) kwargs.update(pargs) if with_lines: ax.plot(group[x], group[y], **kwargs) else: kwargs.pop('linestyle') ax.scatter(group[x], group[y], **kwargs) handles, labels = ax.get_legend_handles_labels() if legend_data != [''] * len(legend_data): labels = sorted(list(set(tuple(legend_data)))) idxs = [legend_data.index(d) for d in labels] handles = [handles[i] for i in idxs] if legend is None and len(labels) < 13 or legend is not False: _add_legend(ax, handles, labels, legend) ax.set_xlabel(x) ax.set_ylabel(y) if title: ax.set_title(title) return ax
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '22']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'config_create'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'kernel'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'devices'}; {'id': '13', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'disks'}; {'id': '16', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'volumes'}; {'id': '19', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '20', 'type': 'dictionary_splat_pattern', 'children': ['21']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '22', 'type': 'block', 'children': ['23', '30', '41', '59', '78', '93', '226', '235', '297', '338', '345', '369', '375', '389', '405']}; {'id': '23', 'type': 'import_from_statement', 'children': ['24', '28']}; {'id': '24', 'type': 'relative_import', 'children': ['25', '26']}; {'id': '25', 'type': 'import_prefix', 'children': []}; {'id': '26', 'type': 'dotted_name', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'volume'}; {'id': '28', 'type': 'dotted_name', 'children': ['29']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'Volume'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'hypervisor_prefix'}; {'id': '33', 'type': 'conditional_expression', 'children': ['34', '35', '40'], 'value': 'if'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'sd'"}; {'id': '35', 'type': 'comparison_operator', 'children': ['36', '39'], 'value': '=='}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'hypervisor'}; {'id': '39', 'type': 'string', 'children': [], 'value': "'kvm'"}; {'id': '40', 'type': 'string', 'children': [], 'value': "'xvd'"}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'device_names'}; {'id': '44', 'type': 'list_comprehension', 'children': ['45', '52']}; {'id': '45', 'type': 'binary_operator', 'children': ['46', '47'], 'value': '+'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'hypervisor_prefix'}; {'id': '47', 'type': 'subscript', 'children': ['48', '51']}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'string'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'ascii_lowercase'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '52', 'type': 'for_in_clause', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '58']}; {'id': '57', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '58', 'type': 'integer', 'children': [], 'value': '8'}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'device_map'}; {'id': '62', 'type': 'dictionary_comprehension', 'children': ['63', '68']}; {'id': '63', 'type': 'pair', 'children': ['64', '67']}; {'id': '64', 'type': 'subscript', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'device_names'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '67', 'type': 'None', 'children': []}; {'id': '68', 'type': 'for_in_clause', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '70', 'type': 'call', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '74']}; {'id': '73', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '74', 'type': 'call', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '76', 'type': 'argument_list', 'children': ['77']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'device_names'}; {'id': '78', 'type': 'if_statement', 'children': ['79', '85']}; {'id': '79', 'type': 'boolean_operator', 'children': ['80', '81'], 'value': 'and'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'devices'}; {'id': '81', 'type': '()', 'children': ['82']}; {'id': '82', 'type': 'boolean_operator', 'children': ['83', '84'], 'value': 'or'}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'disks'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'volumes'}; {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'raise_statement', 'children': ['87']}; {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'concatenated_string', 'children': ['91', '92']}; {'id': '91', 'type': 'string', 'children': [], 'value': '\'You may not call config_create with "devices" and \''}; {'id': '92', 'type': 'string', 'children': [], 'value': '\'either of "disks" or "volumes" specified!\''}; {'id': '93', 'type': 'if_statement', 'children': ['94', '96']}; {'id': '94', 'type': 'not_operator', 'children': ['95']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'devices'}; {'id': '96', 'type': 'block', 'children': ['97', '110', '123', '127', '178']}; {'id': '97', 'type': 'if_statement', 'children': ['98', '104']}; {'id': '98', 'type': 'not_operator', 'children': ['99']}; {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '101', 'type': 'argument_list', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'disks'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '104', 'type': 'block', 'children': ['105']}; {'id': '105', 'type': 'expression_statement', 'children': ['106']}; {'id': '106', 'type': 'assignment', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'disks'}; {'id': '108', 'type': 'list', 'children': ['109'], 'value': '[disks]'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'disks'}; {'id': '110', 'type': 'if_statement', 'children': ['111', '117']}; {'id': '111', 'type': 'not_operator', 'children': ['112']}; {'id': '112', 'type': 'call', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '114', 'type': 'argument_list', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'volumes'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}; {'id': '119', 'type': 'assignment', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'volumes'}; {'id': '121', 'type': 'list', 'children': ['122'], 'value': '[volumes]'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'volumes'}; {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'devices'}; {'id': '126', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '127', 'type': 'for_statement', 'children': ['128', '129', '130']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'disks'}; {'id': '130', 'type': 'block', 'children': ['131']}; {'id': '131', 'type': 'if_statement', 'children': ['132', '135', '143', '157']}; {'id': '132', 'type': 'comparison_operator', 'children': ['133', '134'], 'value': 'is'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '134', 'type': 'None', 'children': []}; {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}; {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'devices'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'None', 'children': []}; {'id': '143', 'type': 'elif_clause', 'children': ['144', '149']}; {'id': '144', 'type': 'call', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '146', 'type': 'argument_list', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'Disk'}; {'id': '149', 'type': 'block', 'children': ['150']}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}; {'id': '151', 'type': 'call', 'children': ['152', '155']}; {'id': '152', 'type': 'attribute', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'devices'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '157', 'type': 'else_clause', 'children': ['158']}; {'id': '158', 'type': 'block', 'children': ['159']}; {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'call', 'children': ['161', '164']}; {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'devices'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}; {'id': '165', 'type': 'call', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'Disk'}; {'id': '167', 'type': 'argument_list', 'children': ['168', '171', '175']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': '_client'}; {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '173', 'type': 'argument_list', 'children': ['174']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '175', 'type': 'attribute', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '178', 'type': 'for_statement', 'children': ['179', '180', '181']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'volumes'}; {'id': '181', 'type': 'block', 'children': ['182']}; {'id': '182', 'type': 'if_statement', 'children': ['183', '186', '194', '208']}; {'id': '183', 'type': 'comparison_operator', 'children': ['184', '185'], 'value': 'is'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '185', 'type': 'None', 'children': []}; {'id': '186', 'type': 'block', 'children': ['187']}; {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'call', 'children': ['189', '192']}; {'id': '189', 'type': 'attribute', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'devices'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '192', 'type': 'argument_list', 'children': ['193']}; {'id': '193', 'type': 'None', 'children': []}; {'id': '194', 'type': 'elif_clause', 'children': ['195', '200']}; {'id': '195', 'type': 'call', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '197', 'type': 'argument_list', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'Volume'}; {'id': '200', 'type': 'block', 'children': ['201']}; {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'call', 'children': ['203', '206']}; {'id': '203', 'type': 'attribute', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'devices'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '206', 'type': 'argument_list', 'children': ['207']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '208', 'type': 'else_clause', 'children': ['209']}; {'id': '209', 'type': 'block', 'children': ['210']}; {'id': '210', 'type': 'expression_statement', 'children': ['211']}; {'id': '211', 'type': 'call', 'children': ['212', '215']}; {'id': '212', 'type': 'attribute', 'children': ['213', '214']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'devices'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '215', 'type': 'argument_list', 'children': ['216']}; {'id': '216', 'type': 'call', 'children': ['217', '218']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'Volume'}; {'id': '218', 'type': 'argument_list', 'children': ['219', '222']}; {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '221', 'type': 'identifier', 'children': [], 'value': '_client'}; {'id': '222', 'type': 'call', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '224', 'type': 'argument_list', 'children': ['225']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '226', 'type': 'if_statement', 'children': ['227', '229']}; {'id': '227', 'type': 'not_operator', 'children': ['228']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'devices'}; {'id': '229', 'type': 'block', 'children': ['230']}; {'id': '230', 'type': 'raise_statement', 'children': ['231']}; {'id': '231', 'type': 'call', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '233', 'type': 'argument_list', 'children': ['234']}; {'id': '234', 'type': 'string', 'children': [], 'value': "'Must include at least one disk or volume!'"}; {'id': '235', 'type': 'for_statement', 'children': ['236', '239', '243']}; {'id': '236', 'type': 'pattern_list', 'children': ['237', '238']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '239', 'type': 'call', 'children': ['240', '241']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'enumerate'}; {'id': '241', 'type': 'argument_list', 'children': ['242']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'devices'}; {'id': '243', 'type': 'block', 'children': ['244']}; {'id': '244', 'type': 'if_statement', 'children': ['245', '248', '250', '270', '290']}; {'id': '245', 'type': 'comparison_operator', 'children': ['246', '247'], 'value': 'is'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '247', 'type': 'None', 'children': []}; {'id': '248', 'type': 'block', 'children': ['249']}; {'id': '249', 'type': 'pass_statement', 'children': []}; {'id': '250', 'type': 'elif_clause', 'children': ['251', '256']}; {'id': '251', 'type': 'call', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '253', 'type': 'argument_list', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'Disk'}; {'id': '256', 'type': 'block', 'children': ['257']}; {'id': '257', 'type': 'expression_statement', 'children': ['258']}; {'id': '258', 'type': 'assignment', 'children': ['259', '264']}; {'id': '259', 'type': 'subscript', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'device_map'}; {'id': '261', 'type': 'subscript', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'device_names'}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '264', 'type': 'dictionary', 'children': ['265']}; {'id': '265', 'type': 'pair', 'children': ['266', '267']}; {'id': '266', 'type': 'string', 'children': [], 'value': "'disk_id'"}; {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '270', 'type': 'elif_clause', 'children': ['271', '276']}; {'id': '271', 'type': 'call', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '273', 'type': 'argument_list', 'children': ['274', '275']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'Volume'}; {'id': '276', 'type': 'block', 'children': ['277']}; {'id': '277', 'type': 'expression_statement', 'children': ['278']}; {'id': '278', 'type': 'assignment', 'children': ['279', '284']}; {'id': '279', 'type': 'subscript', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'device_map'}; {'id': '281', 'type': 'subscript', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'device_names'}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'i'}; {'id': '284', 'type': 'dictionary', 'children': ['285']}; {'id': '285', 'type': 'pair', 'children': ['286', '287']}; {'id': '286', 'type': 'string', 'children': [], 'value': "'volume_id'"}; {'id': '287', 'type': 'attribute', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '290', 'type': 'else_clause', 'children': ['291']}; {'id': '291', 'type': 'block', 'children': ['292']}; {'id': '292', 'type': 'raise_statement', 'children': ['293']}; {'id': '293', 'type': 'call', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '295', 'type': 'argument_list', 'children': ['296']}; {'id': '296', 'type': 'string', 'children': [], 'value': "'Disk or Volume expected!'"}; {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'assignment', 'children': ['299', '300']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '300', 'type': 'dictionary', 'children': ['301', '316', '335']}; {'id': '301', 'type': 'pair', 'children': ['302', '303']}; {'id': '302', 'type': 'string', 'children': [], 'value': "'kernel'"}; {'id': '303', 'type': 'conditional_expression', 'children': ['304', '307', '315'], 'value': 'if'}; {'id': '304', 'type': 'attribute', 'children': ['305', '306']}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'kernel'}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '307', 'type': 'call', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'issubclass'}; {'id': '309', 'type': 'argument_list', 'children': ['310', '314']}; {'id': '310', 'type': 'call', 'children': ['311', '312']}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '312', 'type': 'argument_list', 'children': ['313']}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'kernel'}; {'id': '314', 'type': 'identifier', 'children': [], 'value': 'Base'}; {'id': '315', 'type': 'identifier', 'children': [], 'value': 'kernel'}; {'id': '316', 'type': 'pair', 'children': ['317', '318']}; {'id': '317', 'type': 'string', 'children': [], 'value': "'label'"}; {'id': '318', 'type': 'conditional_expression', 'children': ['319', '320', '321'], 'value': 'if'}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '320', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '321', 'type': 'call', 'children': ['322', '325']}; {'id': '322', 'type': 'attribute', 'children': ['323', '324']}; {'id': '323', 'type': 'string', 'children': [], 'value': '"{}_config_{}"'}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '325', 'type': 'argument_list', 'children': ['326', '329']}; {'id': '326', 'type': 'attribute', 'children': ['327', '328']}; {'id': '327', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '329', 'type': 'call', 'children': ['330', '331']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '331', 'type': 'argument_list', 'children': ['332']}; {'id': '332', 'type': 'attribute', 'children': ['333', '334']}; {'id': '333', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'configs'}; {'id': '335', 'type': 'pair', 'children': ['336', '337']}; {'id': '336', 'type': 'string', 'children': [], 'value': "'devices'"}; {'id': '337', 'type': 'identifier', 'children': [], 'value': 'device_map'}; {'id': '338', 'type': 'expression_statement', 'children': ['339']}; {'id': '339', 'type': 'call', 'children': ['340', '343']}; {'id': '340', 'type': 'attribute', 'children': ['341', '342']}; {'id': '341', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '342', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '343', 'type': 'argument_list', 'children': ['344']}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '345', 'type': 'expression_statement', 'children': ['346']}; {'id': '346', 'type': 'assignment', 'children': ['347', '348']}; {'id': '347', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '348', 'type': 'call', 'children': ['349', '354']}; {'id': '349', 'type': 'attribute', 'children': ['350', '353']}; {'id': '350', 'type': 'attribute', 'children': ['351', '352']}; {'id': '351', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '352', 'type': 'identifier', 'children': [], 'value': '_client'}; {'id': '353', 'type': 'identifier', 'children': [], 'value': 'post'}; {'id': '354', 'type': 'argument_list', 'children': ['355', '363', '366']}; {'id': '355', 'type': 'call', 'children': ['356', '359']}; {'id': '356', 'type': 'attribute', 'children': ['357', '358']}; {'id': '357', 'type': 'string', 'children': [], 'value': '"{}/configs"'}; {'id': '358', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '359', 'type': 'argument_list', 'children': ['360']}; {'id': '360', 'type': 'attribute', 'children': ['361', '362']}; {'id': '361', 'type': 'identifier', 'children': [], 'value': 'Instance'}; {'id': '362', 'type': 'identifier', 'children': [], 'value': 'api_endpoint'}; {'id': '363', 'type': 'keyword_argument', 'children': ['364', '365']}; {'id': '364', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '365', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '366', 'type': 'keyword_argument', 'children': ['367', '368']}; {'id': '367', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '369', 'type': 'expression_statement', 'children': ['370']}; {'id': '370', 'type': 'call', 'children': ['371', '374']}; {'id': '371', 'type': 'attribute', 'children': ['372', '373']}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '373', 'type': 'identifier', 'children': [], 'value': 'invalidate'}; {'id': '374', 'type': 'argument_list', 'children': []}; {'id': '375', 'type': 'if_statement', 'children': ['376', '380']}; {'id': '376', 'type': 'not_operator', 'children': ['377']}; {'id': '377', 'type': 'comparison_operator', 'children': ['378', '379'], 'value': 'in'}; {'id': '378', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '379', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '380', 'type': 'block', 'children': ['381']}; {'id': '381', 'type': 'raise_statement', 'children': ['382']}; {'id': '382', 'type': 'call', 'children': ['383', '384']}; {'id': '383', 'type': 'identifier', 'children': [], 'value': 'UnexpectedResponseError'}; {'id': '384', 'type': 'argument_list', 'children': ['385', '386']}; {'id': '385', 'type': 'string', 'children': [], 'value': "'Unexpected response creating config!'"}; {'id': '386', 'type': 'keyword_argument', 'children': ['387', '388']}; {'id': '387', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '389', 'type': 'expression_statement', 'children': ['390']}; {'id': '390', 'type': 'assignment', 'children': ['391', '392']}; {'id': '391', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '392', 'type': 'call', 'children': ['393', '394']}; {'id': '393', 'type': 'identifier', 'children': [], 'value': 'Config'}; {'id': '394', 'type': 'argument_list', 'children': ['395', '398', '401', '404']}; {'id': '395', 'type': 'attribute', 'children': ['396', '397']}; {'id': '396', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '397', 'type': 'identifier', 'children': [], 'value': '_client'}; {'id': '398', 'type': 'subscript', 'children': ['399', '400']}; {'id': '399', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '400', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '401', 'type': 'attribute', 'children': ['402', '403']}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '403', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '404', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '405', 'type': 'return_statement', 'children': ['406']}; {'id': '406', 'type': 'identifier', 'children': [], 'value': 'c'}
def config_create(self, kernel=None, label=None, devices=[], disks=[], volumes=[], **kwargs): from .volume import Volume hypervisor_prefix = 'sd' if self.hypervisor == 'kvm' else 'xvd' device_names = [hypervisor_prefix + string.ascii_lowercase[i] for i in range(0, 8)] device_map = {device_names[i]: None for i in range(0, len(device_names))} if devices and (disks or volumes): raise ValueError('You may not call config_create with "devices" and ' 'either of "disks" or "volumes" specified!') if not devices: if not isinstance(disks, list): disks = [disks] if not isinstance(volumes, list): volumes = [volumes] devices = [] for d in disks: if d is None: devices.append(None) elif isinstance(d, Disk): devices.append(d) else: devices.append(Disk(self._client, int(d), self.id)) for v in volumes: if v is None: devices.append(None) elif isinstance(v, Volume): devices.append(v) else: devices.append(Volume(self._client, int(v))) if not devices: raise ValueError('Must include at least one disk or volume!') for i, d in enumerate(devices): if d is None: pass elif isinstance(d, Disk): device_map[device_names[i]] = {'disk_id': d.id } elif isinstance(d, Volume): device_map[device_names[i]] = {'volume_id': d.id } else: raise TypeError('Disk or Volume expected!') params = { 'kernel': kernel.id if issubclass(type(kernel), Base) else kernel, 'label': label if label else "{}_config_{}".format(self.label, len(self.configs)), 'devices': device_map, } params.update(kwargs) result = self._client.post("{}/configs".format(Instance.api_endpoint), model=self, data=params) self.invalidate() if not 'id' in result: raise UnexpectedResponseError('Unexpected response creating config!', json=result) c = Config(self._client, result['id'], self.id, result) return c
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '29']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'clone'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '11', '14', '17', '20', '23', '26']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'to_linode'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'region'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'default_parameter', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '13', 'type': 'None', 'children': []}; {'id': '14', 'type': 'default_parameter', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'configs'}; {'id': '16', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '17', 'type': 'default_parameter', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'disks'}; {'id': '19', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '20', 'type': 'default_parameter', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '22', 'type': 'None', 'children': []}; {'id': '23', 'type': 'default_parameter', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '25', 'type': 'None', 'children': []}; {'id': '26', 'type': 'default_parameter', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'with_backups'}; {'id': '28', 'type': 'None', 'children': []}; {'id': '29', 'type': 'block', 'children': ['30', '40', '51', '71', '91', '111', '131', '201', '225', '239', '252']}; {'id': '30', 'type': 'if_statement', 'children': ['31', '34']}; {'id': '31', 'type': 'boolean_operator', 'children': ['32', '33'], 'value': 'and'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'to_linode'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'region'}; {'id': '34', 'type': 'block', 'children': ['35']}; {'id': '35', 'type': 'raise_statement', 'children': ['36']}; {'id': '36', 'type': 'call', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '38', 'type': 'argument_list', 'children': ['39']}; {'id': '39', 'type': 'string', 'children': [], 'value': '\'You may only specify one of "to_linode" and "region"\''}; {'id': '40', 'type': 'if_statement', 'children': ['41', '45']}; {'id': '41', 'type': 'boolean_operator', 'children': ['42', '43'], 'value': 'and'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'region'}; {'id': '43', 'type': 'not_operator', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '45', 'type': 'block', 'children': ['46']}; {'id': '46', 'type': 'raise_statement', 'children': ['47']}; {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'string', 'children': [], 'value': '\'Specifying a region requires a "service" as well\''}; {'id': '51', 'type': 'if_statement', 'children': ['52', '65']}; {'id': '52', 'type': 'boolean_operator', 'children': ['53', '59'], 'value': 'and'}; {'id': '53', 'type': 'not_operator', 'children': ['54']}; {'id': '54', 'type': 'call', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '56', 'type': 'argument_list', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'configs'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '59', 'type': 'not_operator', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'configs'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'PaginatedList'}; {'id': '65', 'type': 'block', 'children': ['66']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'configs'}; {'id': '69', 'type': 'list', 'children': ['70'], 'value': '[configs]'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'configs'}; {'id': '71', 'type': 'if_statement', 'children': ['72', '85']}; {'id': '72', 'type': 'boolean_operator', 'children': ['73', '79'], 'value': 'and'}; {'id': '73', 'type': 'not_operator', 'children': ['74']}; {'id': '74', 'type': 'call', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '76', 'type': 'argument_list', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'disks'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '79', 'type': 'not_operator', 'children': ['80']}; {'id': '80', 'type': 'call', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '82', 'type': 'argument_list', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'disks'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'PaginatedList'}; {'id': '85', 'type': 'block', 'children': ['86']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}; {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'disks'}; {'id': '89', 'type': 'list', 'children': ['90'], 'value': '[disks]'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'disks'}; {'id': '91', 'type': 'expression_statement', 'children': ['92']}; {'id': '92', 'type': 'assignment', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'cids'}; {'id': '94', 'type': 'list_comprehension', 'children': ['95', '108']}; {'id': '95', 'type': 'conditional_expression', 'children': ['96', '99', '107'], 'value': 'if'}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '99', 'type': 'call', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'issubclass'}; {'id': '101', 'type': 'argument_list', 'children': ['102', '106']}; {'id': '102', 'type': 'call', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'Base'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '108', 'type': 'for_in_clause', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'c'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'configs'}; {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'dids'}; {'id': '114', 'type': 'list_comprehension', 'children': ['115', '128']}; {'id': '115', 'type': 'conditional_expression', 'children': ['116', '119', '127'], 'value': 'if'}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '119', 'type': 'call', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'issubclass'}; {'id': '121', 'type': 'argument_list', 'children': ['122', '126']}; {'id': '122', 'type': 'call', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'Base'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '128', 'type': 'for_in_clause', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'disks'}; {'id': '131', 'type': 'expression_statement', 'children': ['132']}; {'id': '132', 'type': 'assignment', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '134', 'type': 'dictionary', 'children': ['135', '150', '165', '180', '186', '192', '195', '198']}; {'id': '135', 'type': 'pair', 'children': ['136', '137']}; {'id': '136', 'type': 'string', 'children': [], 'value': '"linode_id"'}; {'id': '137', 'type': 'conditional_expression', 'children': ['138', '141', '149'], 'value': 'if'}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'to_linode'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '141', 'type': 'call', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'issubclass'}; {'id': '143', 'type': 'argument_list', 'children': ['144', '148']}; {'id': '144', 'type': 'call', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '146', 'type': 'argument_list', 'children': ['147']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'to_linode'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'Base'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'to_linode'}; {'id': '150', 'type': 'pair', 'children': ['151', '152']}; {'id': '151', 'type': 'string', 'children': [], 'value': '"region"'}; {'id': '152', 'type': 'conditional_expression', 'children': ['153', '156', '164'], 'value': 'if'}; {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'region'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '156', 'type': 'call', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'issubclass'}; {'id': '158', 'type': 'argument_list', 'children': ['159', '163']}; {'id': '159', 'type': 'call', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'region'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'Base'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'region'}; {'id': '165', 'type': 'pair', 'children': ['166', '167']}; {'id': '166', 'type': 'string', 'children': [], 'value': '"type"'}; {'id': '167', 'type': 'conditional_expression', 'children': ['168', '171', '179'], 'value': 'if'}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '171', 'type': 'call', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'issubclass'}; {'id': '173', 'type': 'argument_list', 'children': ['174', '178']}; {'id': '174', 'type': 'call', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '176', 'type': 'argument_list', 'children': ['177']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'Base'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'service'}; {'id': '180', 'type': 'pair', 'children': ['181', '182']}; {'id': '181', 'type': 'string', 'children': [], 'value': '"configs"'}; {'id': '182', 'type': 'conditional_expression', 'children': ['183', '184', '185'], 'value': 'if'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'cids'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'cids'}; {'id': '185', 'type': 'None', 'children': []}; {'id': '186', 'type': 'pair', 'children': ['187', '188']}; {'id': '187', 'type': 'string', 'children': [], 'value': '"disks"'}; {'id': '188', 'type': 'conditional_expression', 'children': ['189', '190', '191'], 'value': 'if'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'dids'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'dids'}; {'id': '191', 'type': 'None', 'children': []}; {'id': '192', 'type': 'pair', 'children': ['193', '194']}; {'id': '193', 'type': 'string', 'children': [], 'value': '"label"'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '195', 'type': 'pair', 'children': ['196', '197']}; {'id': '196', 'type': 'string', 'children': [], 'value': '"group"'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'group'}; {'id': '198', 'type': 'pair', 'children': ['199', '200']}; {'id': '199', 'type': 'string', 'children': [], 'value': '"with_backups"'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'with_backups'}; {'id': '201', 'type': 'expression_statement', 'children': ['202']}; {'id': '202', 'type': 'assignment', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '204', 'type': 'call', 'children': ['205', '210']}; {'id': '205', 'type': 'attribute', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': '_client'}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'post'}; {'id': '210', 'type': 'argument_list', 'children': ['211', '219', '222']}; {'id': '211', 'type': 'call', 'children': ['212', '215']}; {'id': '212', 'type': 'attribute', 'children': ['213', '214']}; {'id': '213', 'type': 'string', 'children': [], 'value': "'{}/clone'"}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '215', 'type': 'argument_list', 'children': ['216']}; {'id': '216', 'type': 'attribute', 'children': ['217', '218']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'Instance'}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'api_endpoint'}; {'id': '219', 'type': 'keyword_argument', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '222', 'type': 'keyword_argument', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '225', 'type': 'if_statement', 'children': ['226', '230']}; {'id': '226', 'type': 'not_operator', 'children': ['227']}; {'id': '227', 'type': 'comparison_operator', 'children': ['228', '229'], 'value': 'in'}; {'id': '228', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '230', 'type': 'block', 'children': ['231']}; {'id': '231', 'type': 'raise_statement', 'children': ['232']}; {'id': '232', 'type': 'call', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'UnexpectedResponseError'}; {'id': '234', 'type': 'argument_list', 'children': ['235', '236']}; {'id': '235', 'type': 'string', 'children': [], 'value': "'Unexpected response cloning Instance!'"}; {'id': '236', 'type': 'keyword_argument', 'children': ['237', '238']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '239', 'type': 'expression_statement', 'children': ['240']}; {'id': '240', 'type': 'assignment', 'children': ['241', '242']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'l'}; {'id': '242', 'type': 'call', 'children': ['243', '244']}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'Instance'}; {'id': '244', 'type': 'argument_list', 'children': ['245', '248', '251']}; {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '247', 'type': 'identifier', 'children': [], 'value': '_client'}; {'id': '248', 'type': 'subscript', 'children': ['249', '250']}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '250', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '252', 'type': 'return_statement', 'children': ['253']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'l'}
def clone(self, to_linode=None, region=None, service=None, configs=[], disks=[], label=None, group=None, with_backups=None): if to_linode and region: raise ValueError('You may only specify one of "to_linode" and "region"') if region and not service: raise ValueError('Specifying a region requires a "service" as well') if not isinstance(configs, list) and not isinstance(configs, PaginatedList): configs = [configs] if not isinstance(disks, list) and not isinstance(disks, PaginatedList): disks = [disks] cids = [ c.id if issubclass(type(c), Base) else c for c in configs ] dids = [ d.id if issubclass(type(d), Base) else d for d in disks ] params = { "linode_id": to_linode.id if issubclass(type(to_linode), Base) else to_linode, "region": region.id if issubclass(type(region), Base) else region, "type": service.id if issubclass(type(service), Base) else service, "configs": cids if cids else None, "disks": dids if dids else None, "label": label, "group": group, "with_backups": with_backups, } result = self._client.post('{}/clone'.format(Instance.api_endpoint), model=self, data=params) if not 'id' in result: raise UnexpectedResponseError('Unexpected response cloning Instance!', json=result) l = Instance(self._client, result['id'], result) return l
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_populate'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '6', 'type': 'block', 'children': ['7', '12', '20', '404', '412']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '10']}; {'id': '8', 'type': 'not_operator', 'children': ['9']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '10', 'type': 'block', 'children': ['11']}; {'id': '11', 'type': 'return_statement', 'children': []}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'call', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': '_set'}; {'id': '17', 'type': 'argument_list', 'children': ['18', '19']}; {'id': '18', 'type': 'string', 'children': [], 'value': "'_raw_json'"}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '20', 'type': 'for_statement', 'children': ['21', '22', '23']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'if_statement', 'children': ['25', '53']}; {'id': '25', 'type': 'comparison_operator', 'children': ['26', '27'], 'value': 'in'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '27', 'type': 'generator_expression', 'children': ['28', '29', '41']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '29', 'type': 'for_in_clause', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '31', 'type': 'call', 'children': ['32', '40']}; {'id': '32', 'type': 'attribute', 'children': ['33', '39']}; {'id': '33', 'type': 'attribute', 'children': ['34', '38']}; {'id': '34', 'type': 'call', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '40', 'type': 'argument_list', 'children': []}; {'id': '41', 'type': 'if_clause', 'children': ['42']}; {'id': '42', 'type': 'not_operator', 'children': ['43']}; {'id': '43', 'type': 'attribute', 'children': ['44', '52']}; {'id': '44', 'type': 'subscript', 'children': ['45', '51']}; {'id': '45', 'type': 'attribute', 'children': ['46', '50']}; {'id': '46', 'type': 'call', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'identifier'}; {'id': '53', 'type': 'block', 'children': ['54']}; {'id': '54', 'type': 'if_statement', 'children': ['55', '73', '236', '281', '305', '336', '392']}; {'id': '55', 'type': 'boolean_operator', 'children': ['56', '66', '67'], 'value': 'and'}; {'id': '56', 'type': 'attribute', 'children': ['57', '65']}; {'id': '57', 'type': 'subscript', 'children': ['58', '64']}; {'id': '58', 'type': 'attribute', 'children': ['59', '63']}; {'id': '59', 'type': 'call', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '61', 'type': 'argument_list', 'children': ['62']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'relationship'}; {'id': '66', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '67', 'type': 'not_operator', 'children': ['68']}; {'id': '68', 'type': 'comparison_operator', 'children': ['69', '72'], 'value': 'is'}; {'id': '69', 'type': 'subscript', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '72', 'type': 'None', 'children': []}; {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'if_statement', 'children': ['75', '82', '154']}; {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '77', 'type': 'argument_list', 'children': ['78', '81']}; {'id': '78', 'type': 'subscript', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '82', 'type': 'block', 'children': ['83', '87', '146']}; {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'assignment', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'objs'}; {'id': '86', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '87', 'type': 'for_statement', 'children': ['88', '89', '92']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '89', 'type': 'subscript', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '92', 'type': 'block', 'children': ['93', '100', '113', '129', '139']}; {'id': '93', 'type': 'if_statement', 'children': ['94', '98']}; {'id': '94', 'type': 'not_operator', 'children': ['95']}; {'id': '95', 'type': 'comparison_operator', 'children': ['96', '97'], 'value': 'in'}; {'id': '96', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '98', 'type': 'block', 'children': ['99']}; {'id': '99', 'type': 'continue_statement', 'children': []}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}; {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'new_class'}; {'id': '103', 'type': 'attribute', 'children': ['104', '112']}; {'id': '104', 'type': 'subscript', 'children': ['105', '111']}; {'id': '105', 'type': 'attribute', 'children': ['106', '110']}; {'id': '106', 'type': 'call', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '108', 'type': 'argument_list', 'children': ['109']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'relationship'}; {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '116', 'type': 'call', 'children': ['117', '120']}; {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'new_class'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'make_instance'}; {'id': '120', 'type': 'argument_list', 'children': ['121', '124']}; {'id': '121', 'type': 'subscript', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '123', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '124', 'type': 'call', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '126', 'type': 'argument_list', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '128', 'type': 'string', 'children': [], 'value': "'_client'"}; {'id': '129', 'type': 'if_statement', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '131', 'type': 'block', 'children': ['132']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}; {'id': '133', 'type': 'call', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': '_populate'}; {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'd'}; {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'call', 'children': ['141', '144']}; {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'objs'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}; {'id': '147', 'type': 'call', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': '_set'}; {'id': '151', 'type': 'argument_list', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'objs'}; {'id': '154', 'type': 'else_clause', 'children': ['155']}; {'id': '155', 'type': 'block', 'children': ['156', '181', '194', '208', '228']}; {'id': '156', 'type': 'if_statement', 'children': ['157', '164', '173']}; {'id': '157', 'type': 'call', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '159', 'type': 'argument_list', 'children': ['160', '163']}; {'id': '160', 'type': 'subscript', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '164', 'type': 'block', 'children': ['165']}; {'id': '165', 'type': 'expression_statement', 'children': ['166']}; {'id': '166', 'type': 'assignment', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'related_id'}; {'id': '168', 'type': 'subscript', 'children': ['169', '172']}; {'id': '169', 'type': 'subscript', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '172', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '173', 'type': 'else_clause', 'children': ['174']}; {'id': '174', 'type': 'block', 'children': ['175']}; {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'assignment', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'related_id'}; {'id': '178', 'type': 'subscript', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '181', 'type': 'expression_statement', 'children': ['182']}; {'id': '182', 'type': 'assignment', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'new_class'}; {'id': '184', 'type': 'attribute', 'children': ['185', '193']}; {'id': '185', 'type': 'subscript', 'children': ['186', '192']}; {'id': '186', 'type': 'attribute', 'children': ['187', '191']}; {'id': '187', 'type': 'call', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '189', 'type': 'argument_list', 'children': ['190']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'relationship'}; {'id': '194', 'type': 'expression_statement', 'children': ['195']}; {'id': '195', 'type': 'assignment', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '197', 'type': 'call', 'children': ['198', '201']}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'new_class'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'make_instance'}; {'id': '201', 'type': 'argument_list', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'related_id'}; {'id': '203', 'type': 'call', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '205', 'type': 'argument_list', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '207', 'type': 'string', 'children': [], 'value': "'_client'"}; {'id': '208', 'type': 'if_statement', 'children': ['209', '218']}; {'id': '209', 'type': 'boolean_operator', 'children': ['210', '211'], 'value': 'and'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '211', 'type': 'call', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '213', 'type': 'argument_list', 'children': ['214', '217']}; {'id': '214', 'type': 'subscript', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '218', 'type': 'block', 'children': ['219']}; {'id': '219', 'type': 'expression_statement', 'children': ['220']}; {'id': '220', 'type': 'call', 'children': ['221', '224']}; {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '223', 'type': 'identifier', 'children': [], 'value': '_populate'}; {'id': '224', 'type': 'argument_list', 'children': ['225']}; {'id': '225', 'type': 'subscript', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}; {'id': '229', 'type': 'call', 'children': ['230', '233']}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': '_set'}; {'id': '233', 'type': 'argument_list', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'obj'}; {'id': '236', 'type': 'elif_clause', 'children': ['237', '255']}; {'id': '237', 'type': 'boolean_operator', 'children': ['238', '248', '249'], 'value': 'and'}; {'id': '238', 'type': 'attribute', 'children': ['239', '247']}; {'id': '239', 'type': 'subscript', 'children': ['240', '246']}; {'id': '240', 'type': 'attribute', 'children': ['241', '245']}; {'id': '241', 'type': 'call', 'children': ['242', '243']}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '243', 'type': 'argument_list', 'children': ['244']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'slug_relationship'}; {'id': '248', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '249', 'type': 'not_operator', 'children': ['250']}; {'id': '250', 'type': 'comparison_operator', 'children': ['251', '254'], 'value': 'is'}; {'id': '251', 'type': 'subscript', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '254', 'type': 'None', 'children': []}; {'id': '255', 'type': 'block', 'children': ['256']}; {'id': '256', 'type': 'expression_statement', 'children': ['257']}; {'id': '257', 'type': 'call', 'children': ['258', '261']}; {'id': '258', 'type': 'attribute', 'children': ['259', '260']}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '260', 'type': 'identifier', 'children': [], 'value': '_set'}; {'id': '261', 'type': 'argument_list', 'children': ['262', '263']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '263', 'type': 'call', 'children': ['264', '274']}; {'id': '264', 'type': 'attribute', 'children': ['265', '273']}; {'id': '265', 'type': 'subscript', 'children': ['266', '272']}; {'id': '266', 'type': 'attribute', 'children': ['267', '271']}; {'id': '267', 'type': 'call', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '269', 'type': 'argument_list', 'children': ['270']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '271', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'slug_relationship'}; {'id': '274', 'type': 'argument_list', 'children': ['275', '278']}; {'id': '275', 'type': 'attribute', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '277', 'type': 'identifier', 'children': [], 'value': '_client'}; {'id': '278', 'type': 'subscript', 'children': ['279', '280']}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '281', 'type': 'elif_clause', 'children': ['282', '290']}; {'id': '282', 'type': 'comparison_operator', 'children': ['283', '289'], 'value': 'is'}; {'id': '283', 'type': 'call', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '285', 'type': 'argument_list', 'children': ['286']}; {'id': '286', 'type': 'subscript', 'children': ['287', '288']}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '290', 'type': 'block', 'children': ['291']}; {'id': '291', 'type': 'expression_statement', 'children': ['292']}; {'id': '292', 'type': 'call', 'children': ['293', '296']}; {'id': '293', 'type': 'attribute', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '295', 'type': 'identifier', 'children': [], 'value': '_set'}; {'id': '296', 'type': 'argument_list', 'children': ['297', '298']}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '298', 'type': 'call', 'children': ['299', '300']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'MappedObject'}; {'id': '300', 'type': 'argument_list', 'children': ['301']}; {'id': '301', 'type': 'dictionary_splat', 'children': ['302']}; {'id': '302', 'type': 'subscript', 'children': ['303', '304']}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '305', 'type': 'elif_clause', 'children': ['306', '314']}; {'id': '306', 'type': 'comparison_operator', 'children': ['307', '313'], 'value': 'is'}; {'id': '307', 'type': 'call', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '309', 'type': 'argument_list', 'children': ['310']}; {'id': '310', 'type': 'subscript', 'children': ['311', '312']}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '312', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '314', 'type': 'block', 'children': ['315', '326']}; {'id': '315', 'type': 'expression_statement', 'children': ['316']}; {'id': '316', 'type': 'assignment', 'children': ['317', '318']}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '318', 'type': 'call', 'children': ['319', '320']}; {'id': '319', 'type': 'identifier', 'children': [], 'value': 'MappedObject'}; {'id': '320', 'type': 'argument_list', 'children': ['321']}; {'id': '321', 'type': 'keyword_argument', 'children': ['322', '323']}; {'id': '322', 'type': 'identifier', 'children': [], 'value': '_list'}; {'id': '323', 'type': 'subscript', 'children': ['324', '325']}; {'id': '324', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '326', 'type': 'expression_statement', 'children': ['327']}; {'id': '327', 'type': 'call', 'children': ['328', '331']}; {'id': '328', 'type': 'attribute', 'children': ['329', '330']}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': '_set'}; {'id': '331', 'type': 'argument_list', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '333', 'type': 'attribute', 'children': ['334', '335']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'mapping'}; {'id': '335', 'type': 'identifier', 'children': [], 'value': '_list'}; {'id': '336', 'type': 'elif_clause', 'children': ['337', '347']}; {'id': '337', 'type': 'attribute', 'children': ['338', '346']}; {'id': '338', 'type': 'subscript', 'children': ['339', '345']}; {'id': '339', 'type': 'attribute', 'children': ['340', '344']}; {'id': '340', 'type': 'call', 'children': ['341', '342']}; {'id': '341', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '342', 'type': 'argument_list', 'children': ['343']}; {'id': '343', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '344', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '345', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'is_datetime'}; {'id': '347', 'type': 'block', 'children': ['348']}; {'id': '348', 'type': 'try_statement', 'children': ['349', '380']}; {'id': '349', 'type': 'block', 'children': ['350', '362']}; {'id': '350', 'type': 'expression_statement', 'children': ['351']}; {'id': '351', 'type': 'assignment', 'children': ['352', '353']}; {'id': '352', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '353', 'type': 'call', 'children': ['354', '357']}; {'id': '354', 'type': 'attribute', 'children': ['355', '356']}; {'id': '355', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '356', 'type': 'identifier', 'children': [], 'value': 'strptime'}; {'id': '357', 'type': 'argument_list', 'children': ['358', '361']}; {'id': '358', 'type': 'subscript', 'children': ['359', '360']}; {'id': '359', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '360', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '361', 'type': 'identifier', 'children': [], 'value': 'DATE_FORMAT'}; {'id': '362', 'type': 'expression_statement', 'children': ['363']}; {'id': '363', 'type': 'call', 'children': ['364', '367']}; {'id': '364', 'type': 'attribute', 'children': ['365', '366']}; {'id': '365', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '366', 'type': 'identifier', 'children': [], 'value': '_set'}; {'id': '367', 'type': 'argument_list', 'children': ['368', '369']}; {'id': '368', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '369', 'type': 'call', 'children': ['370', '373']}; {'id': '370', 'type': 'attribute', 'children': ['371', '372']}; {'id': '371', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '372', 'type': 'identifier', 'children': [], 'value': 'fromtimestamp'}; {'id': '373', 'type': 'argument_list', 'children': ['374']}; {'id': '374', 'type': 'call', 'children': ['375', '378']}; {'id': '375', 'type': 'attribute', 'children': ['376', '377']}; {'id': '376', 'type': 'identifier', 'children': [], 'value': 'time'}; {'id': '377', 'type': 'identifier', 'children': [], 'value': 'mktime'}; {'id': '378', 'type': 'argument_list', 'children': ['379']}; {'id': '379', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '380', 'type': 'except_clause', 'children': ['381']}; {'id': '381', 'type': 'block', 'children': ['382']}; {'id': '382', 'type': 'expression_statement', 'children': ['383']}; {'id': '383', 'type': 'call', 'children': ['384', '387']}; {'id': '384', 'type': 'attribute', 'children': ['385', '386']}; {'id': '385', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '386', 'type': 'identifier', 'children': [], 'value': '_set'}; {'id': '387', 'type': 'argument_list', 'children': ['388', '389']}; {'id': '388', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '389', 'type': 'subscript', 'children': ['390', '391']}; {'id': '390', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '391', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '392', 'type': 'else_clause', 'children': ['393']}; {'id': '393', 'type': 'block', 'children': ['394']}; {'id': '394', 'type': 'expression_statement', 'children': ['395']}; {'id': '395', 'type': 'call', 'children': ['396', '399']}; {'id': '396', 'type': 'attribute', 'children': ['397', '398']}; {'id': '397', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '398', 'type': 'identifier', 'children': [], 'value': '_set'}; {'id': '399', 'type': 'argument_list', 'children': ['400', '401']}; {'id': '400', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '401', 'type': 'subscript', 'children': ['402', '403']}; {'id': '402', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '403', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '404', 'type': 'expression_statement', 'children': ['405']}; {'id': '405', 'type': 'call', 'children': ['406', '409']}; {'id': '406', 'type': 'attribute', 'children': ['407', '408']}; {'id': '407', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '408', 'type': 'identifier', 'children': [], 'value': '_set'}; {'id': '409', 'type': 'argument_list', 'children': ['410', '411']}; {'id': '410', 'type': 'string', 'children': [], 'value': "'_populated'"}; {'id': '411', 'type': 'True', 'children': []}; {'id': '412', 'type': 'expression_statement', 'children': ['413']}; {'id': '413', 'type': 'call', 'children': ['414', '417']}; {'id': '414', 'type': 'attribute', 'children': ['415', '416']}; {'id': '415', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '416', 'type': 'identifier', 'children': [], 'value': '_set'}; {'id': '417', 'type': 'argument_list', 'children': ['418', '419']}; {'id': '418', 'type': 'string', 'children': [], 'value': "'_last_updated'"}; {'id': '419', 'type': 'call', 'children': ['420', '423']}; {'id': '420', 'type': 'attribute', 'children': ['421', '422']}; {'id': '421', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '422', 'type': 'identifier', 'children': [], 'value': 'now'}; {'id': '423', 'type': 'argument_list', 'children': []}
def _populate(self, json): if not json: return self._set('_raw_json', json) for key in json: if key in (k for k in type(self).properties.keys() if not type(self).properties[k].identifier): if type(self).properties[key].relationship \ and not json[key] is None: if isinstance(json[key], list): objs = [] for d in json[key]: if not 'id' in d: continue new_class = type(self).properties[key].relationship obj = new_class.make_instance(d['id'], getattr(self,'_client')) if obj: obj._populate(d) objs.append(obj) self._set(key, objs) else: if isinstance(json[key], dict): related_id = json[key]['id'] else: related_id = json[key] new_class = type(self).properties[key].relationship obj = new_class.make_instance(related_id, getattr(self,'_client')) if obj and isinstance(json[key], dict): obj._populate(json[key]) self._set(key, obj) elif type(self).properties[key].slug_relationship \ and not json[key] is None: self._set(key, type(self).properties[key].slug_relationship(self._client, json[key])) elif type(json[key]) is dict: self._set(key, MappedObject(**json[key])) elif type(json[key]) is list: mapping = MappedObject(_list=json[key]) self._set(key, mapping._list) elif type(self).properties[key].is_datetime: try: t = time.strptime(json[key], DATE_FORMAT) self._set(key, datetime.fromtimestamp(time.mktime(t))) except: self._set(key, json[key]) else: self._set(key, json[key]) self._set('_populated', True) self._set('_last_updated', datetime.now())
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': '_api_call'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'endpoint'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '14', 'type': 'None', 'children': []}; {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'filters'}; {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'block', 'children': ['19', '30', '39', '55', '67', '89', '103', '107', '121', '134', '146', '161', '246', '267']}; {'id': '19', 'type': 'if_statement', 'children': ['20', '24']}; {'id': '20', 'type': 'not_operator', 'children': ['21']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '24', 'type': 'block', 'children': ['25']}; {'id': '25', 'type': 'raise_statement', 'children': ['26']}; {'id': '26', 'type': 'call', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'string', 'children': [], 'value': '"You do not have an API token!"'}; {'id': '30', 'type': 'if_statement', 'children': ['31', '33']}; {'id': '31', 'type': 'not_operator', 'children': ['32']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '33', 'type': 'block', 'children': ['34']}; {'id': '34', 'type': 'raise_statement', 'children': ['35']}; {'id': '35', 'type': 'call', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '37', 'type': 'argument_list', 'children': ['38']}; {'id': '38', 'type': 'string', 'children': [], 'value': '"Method is required for API calls!"'}; {'id': '39', 'type': 'if_statement', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '41', 'type': 'block', 'children': ['42']}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'endpoint'}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'endpoint'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'dictionary_splat', 'children': ['51']}; {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'vars'}; {'id': '53', 'type': 'argument_list', 'children': ['54']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'assignment', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '58', 'type': 'call', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'string', 'children': [], 'value': "'{}{}'"}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '66']}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'base_url'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'endpoint'}; {'id': '67', 'type': 'expression_statement', 'children': ['68']}; {'id': '68', 'type': 'assignment', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '70', 'type': 'dictionary', 'children': ['71', '81', '84']}; {'id': '71', 'type': 'pair', 'children': ['72', '73']}; {'id': '72', 'type': 'string', 'children': [], 'value': "'Authorization'"}; {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'string', 'children': [], 'value': '"Bearer {}"'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'token'}; {'id': '81', 'type': 'pair', 'children': ['82', '83']}; {'id': '82', 'type': 'string', 'children': [], 'value': "'Content-Type'"}; {'id': '83', 'type': 'string', 'children': [], 'value': "'application/json'"}; {'id': '84', 'type': 'pair', 'children': ['85', '86']}; {'id': '85', 'type': 'string', 'children': [], 'value': "'User-Agent'"}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': '_user_agent'}; {'id': '89', 'type': 'if_statement', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'filters'}; {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}; {'id': '93', 'type': 'assignment', 'children': ['94', '97']}; {'id': '94', 'type': 'subscript', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '96', 'type': 'string', 'children': [], 'value': "'X-Filter'"}; {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'dumps'}; {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'filters'}; {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'assignment', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '106', 'type': 'None', 'children': []}; {'id': '107', 'type': 'if_statement', 'children': ['108', '111']}; {'id': '108', 'type': 'comparison_operator', 'children': ['109', '110'], 'value': 'is'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '110', 'type': 'None', 'children': []}; {'id': '111', 'type': 'block', 'children': ['112']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}; {'id': '113', 'type': 'assignment', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '115', 'type': 'call', 'children': ['116', '119']}; {'id': '116', 'type': 'attribute', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'dumps'}; {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '124', 'type': 'call', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'method'}; {'id': '126', 'type': 'argument_list', 'children': ['127', '128', '131']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '128', 'type': 'keyword_argument', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '131', 'type': 'keyword_argument', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}; {'id': '135', 'type': 'assignment', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '137', 'type': 'call', 'children': ['138', '143']}; {'id': '138', 'type': 'attribute', 'children': ['139', '142']}; {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'headers'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '143', 'type': 'argument_list', 'children': ['144', '145']}; {'id': '144', 'type': 'string', 'children': [], 'value': "'Warning'"}; {'id': '145', 'type': 'None', 'children': []}; {'id': '146', 'type': 'if_statement', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '148', 'type': 'block', 'children': ['149']}; {'id': '149', 'type': 'expression_statement', 'children': ['150']}; {'id': '150', 'type': 'call', 'children': ['151', '154']}; {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}; {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}; {'id': '157', 'type': 'string', 'children': [], 'value': "'Received warning from server: {}'"}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '161', 'type': 'if_statement', 'children': ['162', '168']}; {'id': '162', 'type': 'comparison_operator', 'children': ['163', '164', '167'], 'value': '<'}; {'id': '163', 'type': 'integer', 'children': [], 'value': '399'}; {'id': '164', 'type': 'attribute', 'children': ['165', '166']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'status_code'}; {'id': '167', 'type': 'integer', 'children': [], 'value': '600'}; {'id': '168', 'type': 'block', 'children': ['169', '173', '184', '233']}; {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '172', 'type': 'None', 'children': []}; {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'error_msg'}; {'id': '176', 'type': 'call', 'children': ['177', '180']}; {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'string', 'children': [], 'value': "'{}: '"}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '180', 'type': 'argument_list', 'children': ['181']}; {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'status_code'}; {'id': '184', 'type': 'try_statement', 'children': ['185', '230']}; {'id': '185', 'type': 'block', 'children': ['186', '194']}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}; {'id': '187', 'type': 'assignment', 'children': ['188', '189']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '189', 'type': 'call', 'children': ['190', '193']}; {'id': '190', 'type': 'attribute', 'children': ['191', '192']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '193', 'type': 'argument_list', 'children': []}; {'id': '194', 'type': 'if_statement', 'children': ['195', '202']}; {'id': '195', 'type': 'comparison_operator', 'children': ['196', '197'], 'value': 'in'}; {'id': '196', 'type': 'string', 'children': [], 'value': "'errors'"}; {'id': '197', 'type': 'call', 'children': ['198', '201']}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '201', 'type': 'argument_list', 'children': []}; {'id': '202', 'type': 'block', 'children': ['203']}; {'id': '203', 'type': 'for_statement', 'children': ['204', '205', '208']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '205', 'type': 'subscript', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '207', 'type': 'string', 'children': [], 'value': "'errors'"}; {'id': '208', 'type': 'block', 'children': ['209']}; {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'augmented_assignment', 'children': ['211', '212'], 'value': '+='}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'error_msg'}; {'id': '212', 'type': 'conditional_expression', 'children': ['213', '221', '222', '229'], 'value': 'if'}; {'id': '213', 'type': 'call', 'children': ['214', '217']}; {'id': '214', 'type': 'attribute', 'children': ['215', '216']}; {'id': '215', 'type': 'string', 'children': [], 'value': "'{}; '"}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '217', 'type': 'argument_list', 'children': ['218']}; {'id': '218', 'type': 'subscript', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '220', 'type': 'string', 'children': [], 'value': "'reason'"}; {'id': '221', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '222', 'type': 'comparison_operator', 'children': ['223', '224'], 'value': 'in'}; {'id': '223', 'type': 'string', 'children': [], 'value': "'reason'"}; {'id': '224', 'type': 'call', 'children': ['225', '228']}; {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '228', 'type': 'argument_list', 'children': []}; {'id': '229', 'type': 'string', 'children': [], 'value': "''"}; {'id': '230', 'type': 'except_clause', 'children': ['231']}; {'id': '231', 'type': 'block', 'children': ['232']}; {'id': '232', 'type': 'pass_statement', 'children': []}; {'id': '233', 'type': 'raise_statement', 'children': ['234']}; {'id': '234', 'type': 'call', 'children': ['235', '236']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'ApiError'}; {'id': '236', 'type': 'argument_list', 'children': ['237', '238', '243']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'error_msg'}; {'id': '238', 'type': 'keyword_argument', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '240', 'type': 'attribute', 'children': ['241', '242']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'status_code'}; {'id': '243', 'type': 'keyword_argument', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '246', 'type': 'if_statement', 'children': ['247', '252', '261']}; {'id': '247', 'type': 'comparison_operator', 'children': ['248', '251'], 'value': '!='}; {'id': '248', 'type': 'attribute', 'children': ['249', '250']}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '250', 'type': 'identifier', 'children': [], 'value': 'status_code'}; {'id': '251', 'type': 'integer', 'children': [], 'value': '204'}; {'id': '252', 'type': 'block', 'children': ['253']}; {'id': '253', 'type': 'expression_statement', 'children': ['254']}; {'id': '254', 'type': 'assignment', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '256', 'type': 'call', 'children': ['257', '260']}; {'id': '257', 'type': 'attribute', 'children': ['258', '259']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '260', 'type': 'argument_list', 'children': []}; {'id': '261', 'type': 'else_clause', 'children': ['262']}; {'id': '262', 'type': 'block', 'children': ['263']}; {'id': '263', 'type': 'expression_statement', 'children': ['264']}; {'id': '264', 'type': 'assignment', 'children': ['265', '266']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'j'}; {'id': '266', 'type': 'None', 'children': []}; {'id': '267', 'type': 'return_statement', 'children': ['268']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'j'}
def _api_call(self, endpoint, model=None, method=None, data=None, filters=None): if not self.token: raise RuntimeError("You do not have an API token!") if not method: raise ValueError("Method is required for API calls!") if model: endpoint = endpoint.format(**vars(model)) url = '{}{}'.format(self.base_url, endpoint) headers = { 'Authorization': "Bearer {}".format(self.token), 'Content-Type': 'application/json', 'User-Agent': self._user_agent, } if filters: headers['X-Filter'] = json.dumps(filters) body = None if data is not None: body = json.dumps(data) response = method(url, headers=headers, data=body) warning = response.headers.get('Warning', None) if warning: logger.warning('Received warning from server: {}'.format(warning)) if 399 < response.status_code < 600: j = None error_msg = '{}: '.format(response.status_code) try: j = response.json() if 'errors' in j.keys(): for e in j['errors']: error_msg += '{}; '.format(e['reason']) \ if 'reason' in e.keys() else '' except: pass raise ApiError(error_msg, status=response.status_code, json=j) if response.status_code != 204: j = response.json() else: j = None return j
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '21']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'tag_create'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12', '15', '18']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'instances'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'domains'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'nodebalancers'}; {'id': '14', 'type': 'None', 'children': []}; {'id': '15', 'type': 'default_parameter', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'volumes'}; {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'default_parameter', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'entities'}; {'id': '20', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '21', 'type': 'block', 'children': ['22', '34', '50', '90', '106', '147', '174', '186', '200', '211']}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '29']}; {'id': '24', 'type': 'pattern_list', 'children': ['25', '26', '27', '28']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'linode_ids'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'nodebalancer_ids'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'domain_ids'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'volume_ids'}; {'id': '29', 'type': 'expression_list', 'children': ['30', '31', '32', '33']}; {'id': '30', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '31', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '32', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '33', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'assignment', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'sorter'}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '39', 'type': 'argument_list', 'children': ['40', '45']}; {'id': '40', 'type': 'tuple', 'children': ['41', '42', '43', '44']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'linode_ids'}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'nodebalancer_ids'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'domain_ids'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'volume_ids'}; {'id': '45', 'type': 'tuple', 'children': ['46', '47', '48', '49']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'instances'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'nodebalancers'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'domains'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'volumes'}; {'id': '50', 'type': 'for_statement', 'children': ['51', '54', '55']}; {'id': '51', 'type': 'pattern_list', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'id_list'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'input_list'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'sorter'}; {'id': '55', 'type': 'block', 'children': ['56']}; {'id': '56', 'type': 'if_statement', 'children': ['57', '60']}; {'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': 'is'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'input_list'}; {'id': '59', 'type': 'None', 'children': []}; {'id': '60', 'type': 'block', 'children': ['61']}; {'id': '61', 'type': 'for_statement', 'children': ['62', '63', '64']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'cur'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'input_list'}; {'id': '64', 'type': 'block', 'children': ['65']}; {'id': '65', 'type': 'if_statement', 'children': ['66', '71', '79']}; {'id': '66', 'type': 'call', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '68', 'type': 'argument_list', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'cur'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '71', 'type': 'block', 'children': ['72']}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'id_list'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'cur'}; {'id': '79', 'type': 'else_clause', 'children': ['80']}; {'id': '80', 'type': 'block', 'children': ['81']}; {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'call', 'children': ['83', '86']}; {'id': '83', 'type': 'attribute', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'id_list'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '86', 'type': 'argument_list', 'children': ['87']}; {'id': '87', 'type': 'attribute', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'cur'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}; {'id': '91', 'type': 'assignment', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'type_map'}; {'id': '93', 'type': 'dictionary', 'children': ['94', '97', '100', '103']}; {'id': '94', 'type': 'pair', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'Instance'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'linode_ids'}; {'id': '97', 'type': 'pair', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'NodeBalancer'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'nodebalancer_ids'}; {'id': '100', 'type': 'pair', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'Domain'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'domain_ids'}; {'id': '103', 'type': 'pair', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'Volume'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'volume_ids'}; {'id': '106', 'type': 'for_statement', 'children': ['107', '108', '109']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'entities'}; {'id': '109', 'type': 'block', 'children': ['110']}; {'id': '110', 'type': 'if_statement', 'children': ['111', '117', '132']}; {'id': '111', 'type': 'comparison_operator', 'children': ['112', '116'], 'value': 'in'}; {'id': '112', 'type': 'call', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'type_map'}; {'id': '117', 'type': 'block', 'children': ['118']}; {'id': '118', 'type': 'expression_statement', 'children': ['119']}; {'id': '119', 'type': 'call', 'children': ['120', '128']}; {'id': '120', 'type': 'attribute', 'children': ['121', '127']}; {'id': '121', 'type': 'subscript', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'type_map'}; {'id': '123', 'type': 'call', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}; {'id': '129', 'type': 'attribute', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '132', 'type': 'else_clause', 'children': ['133']}; {'id': '133', 'type': 'block', 'children': ['134']}; {'id': '134', 'type': 'raise_statement', 'children': ['135']}; {'id': '135', 'type': 'call', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '137', 'type': 'argument_list', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '142']}; {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'string', 'children': [], 'value': "'Unsupported entity type {}'"}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '142', 'type': 'argument_list', 'children': ['143']}; {'id': '143', 'type': 'call', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '145', 'type': 'argument_list', 'children': ['146']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '147', 'type': 'expression_statement', 'children': ['148']}; {'id': '148', 'type': 'assignment', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '150', 'type': 'dictionary', 'children': ['151', '154', '159', '164', '169']}; {'id': '151', 'type': 'pair', 'children': ['152', '153']}; {'id': '152', 'type': 'string', 'children': [], 'value': "'label'"}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '154', 'type': 'pair', 'children': ['155', '156']}; {'id': '155', 'type': 'string', 'children': [], 'value': "'linodes'"}; {'id': '156', 'type': 'boolean_operator', 'children': ['157', '158'], 'value': 'or'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'linode_ids'}; {'id': '158', 'type': 'None', 'children': []}; {'id': '159', 'type': 'pair', 'children': ['160', '161']}; {'id': '160', 'type': 'string', 'children': [], 'value': "'nodebalancers'"}; {'id': '161', 'type': 'boolean_operator', 'children': ['162', '163'], 'value': 'or'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'nodebalancer_ids'}; {'id': '163', 'type': 'None', 'children': []}; {'id': '164', 'type': 'pair', 'children': ['165', '166']}; {'id': '165', 'type': 'string', 'children': [], 'value': "'domains'"}; {'id': '166', 'type': 'boolean_operator', 'children': ['167', '168'], 'value': 'or'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'domain_ids'}; {'id': '168', 'type': 'None', 'children': []}; {'id': '169', 'type': 'pair', 'children': ['170', '171']}; {'id': '170', 'type': 'string', 'children': [], 'value': "'volumes'"}; {'id': '171', 'type': 'boolean_operator', 'children': ['172', '173'], 'value': 'or'}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'volume_ids'}; {'id': '173', 'type': 'None', 'children': []}; {'id': '174', 'type': 'expression_statement', 'children': ['175']}; {'id': '175', 'type': 'assignment', 'children': ['176', '177']}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '177', 'type': 'call', 'children': ['178', '181']}; {'id': '178', 'type': 'attribute', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'post'}; {'id': '181', 'type': 'argument_list', 'children': ['182', '183']}; {'id': '182', 'type': 'string', 'children': [], 'value': "'/tags'"}; {'id': '183', 'type': 'keyword_argument', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '186', 'type': 'if_statement', 'children': ['187', '191']}; {'id': '187', 'type': 'not_operator', 'children': ['188']}; {'id': '188', 'type': 'comparison_operator', 'children': ['189', '190'], 'value': 'in'}; {'id': '189', 'type': 'string', 'children': [], 'value': "'label'"}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '191', 'type': 'block', 'children': ['192']}; {'id': '192', 'type': 'raise_statement', 'children': ['193']}; {'id': '193', 'type': 'call', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'UnexpectedResponseError'}; {'id': '195', 'type': 'argument_list', 'children': ['196', '197']}; {'id': '196', 'type': 'string', 'children': [], 'value': "'Unexpected response when creating Tag!'"}; {'id': '197', 'type': 'keyword_argument', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '200', 'type': 'expression_statement', 'children': ['201']}; {'id': '201', 'type': 'assignment', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '203', 'type': 'call', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'Tag'}; {'id': '205', 'type': 'argument_list', 'children': ['206', '207', '210']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '207', 'type': 'subscript', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '209', 'type': 'string', 'children': [], 'value': "'label'"}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'result'}; {'id': '211', 'type': 'return_statement', 'children': ['212']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 't'}
def tag_create(self, label, instances=None, domains=None, nodebalancers=None, volumes=None, entities=[]): linode_ids, nodebalancer_ids, domain_ids, volume_ids = [], [], [], [] sorter = zip((linode_ids, nodebalancer_ids, domain_ids, volume_ids), (instances, nodebalancers, domains, volumes)) for id_list, input_list in sorter: if input_list is not None: for cur in input_list: if isinstance(cur, int): id_list.append(cur) else: id_list.append(cur.id) type_map = { Instance: linode_ids, NodeBalancer: nodebalancer_ids, Domain: domain_ids, Volume: volume_ids, } for e in entities: if type(e) in type_map: type_map[type(e)].append(e.id) else: raise ValueError('Unsupported entity type {}'.format(type(e))) params = { 'label': label, 'linodes': linode_ids or None, 'nodebalancers': nodebalancer_ids or None, 'domains': domain_ids or None, 'volumes': volume_ids or None, } result = self.post('/tags', data=params) if not 'label' in result: raise UnexpectedResponseError('Unexpected response when creating Tag!', json=result) t = Tag(self, result['label'], result) return t
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'validate_anneal_schedule'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'anneal_schedule'}; {'id': '6', 'type': 'block', 'children': ['7', '19', '25', '49', '96', '116', '143', '161', '174', '184', '236', '242']}; {'id': '7', 'type': 'if_statement', 'children': ['8', '13']}; {'id': '8', 'type': 'comparison_operator', 'children': ['9', '10'], 'value': 'not'}; {'id': '9', 'type': 'string', 'children': [], 'value': "'anneal_schedule'"}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '13', 'type': 'block', 'children': ['14']}; {'id': '14', 'type': 'raise_statement', 'children': ['15']}; {'id': '15', 'type': 'call', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'}; {'id': '17', 'type': 'argument_list', 'children': ['18']}; {'id': '18', 'type': 'string', 'children': [], 'value': '"anneal_schedule is not an accepted parameter for this sampler"'}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '25', 'type': 'try_statement', 'children': ['26', '41']}; {'id': '26', 'type': 'block', 'children': ['27', '35']}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '32']}; {'id': '29', 'type': 'pattern_list', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'min_anneal_time'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'max_anneal_time'}; {'id': '32', 'type': 'subscript', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '34', 'type': 'string', 'children': [], 'value': "'annealing_time_range'"}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'assignment', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'max_anneal_schedule_points'}; {'id': '38', 'type': 'subscript', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'properties'}; {'id': '40', 'type': 'string', 'children': [], 'value': "'max_anneal_schedule_points'"}; {'id': '41', 'type': 'except_clause', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '43', 'type': 'block', 'children': ['44']}; {'id': '44', 'type': 'raise_statement', 'children': ['45']}; {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'RuntimeError'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'string', 'children': [], 'value': '"annealing_time_range and max_anneal_schedule_points are not properties of this solver"'}; {'id': '49', 'type': 'if_statement', 'children': ['50', '56', '62']}; {'id': '50', 'type': 'not_operator', 'children': ['51']}; {'id': '51', 'type': 'call', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '53', 'type': 'argument_list', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'anneal_schedule'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '56', 'type': 'block', 'children': ['57']}; {'id': '57', 'type': 'raise_statement', 'children': ['58']}; {'id': '58', 'type': 'call', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'TypeError'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'string', 'children': [], 'value': '"anneal_schedule should be a list"'}; {'id': '62', 'type': 'elif_clause', 'children': ['63', '76']}; {'id': '63', 'type': 'boolean_operator', 'children': ['64', '70'], 'value': 'or'}; {'id': '64', 'type': 'comparison_operator', 'children': ['65', '69'], 'value': '<'}; {'id': '65', 'type': 'call', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '67', 'type': 'argument_list', 'children': ['68']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'anneal_schedule'}; {'id': '69', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '70', 'type': 'comparison_operator', 'children': ['71', '75'], 'value': '>'}; {'id': '71', 'type': 'call', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '73', 'type': 'argument_list', 'children': ['74']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'anneal_schedule'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'max_anneal_schedule_points'}; {'id': '76', 'type': 'block', 'children': ['77', '91']}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'assignment', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '80', 'type': 'call', 'children': ['81', '85']}; {'id': '81', 'type': 'attribute', 'children': ['82', '84']}; {'id': '82', 'type': '()', 'children': ['83']}; {'id': '83', 'type': 'string', 'children': [], 'value': '"anneal_schedule must contain between 2 and {} points (contains {})"'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '85', 'type': 'argument_list', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'max_anneal_schedule_points'}; {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '89', 'type': 'argument_list', 'children': ['90']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'anneal_schedule'}; {'id': '91', 'type': 'raise_statement', 'children': ['92']}; {'id': '92', 'type': 'call', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '96', 'type': 'try_statement', 'children': ['97', '108']}; {'id': '97', 'type': 'block', 'children': ['98']}; {'id': '98', 'type': 'expression_statement', 'children': ['99']}; {'id': '99', 'type': 'assignment', 'children': ['100', '103']}; {'id': '100', 'type': 'pattern_list', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 't_list'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 's_list'}; {'id': '103', 'type': 'call', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'list_splat', 'children': ['107']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'anneal_schedule'}; {'id': '108', 'type': 'except_clause', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '110', 'type': 'block', 'children': ['111']}; {'id': '111', 'type': 'raise_statement', 'children': ['112']}; {'id': '112', 'type': 'call', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '114', 'type': 'argument_list', 'children': ['115']}; {'id': '115', 'type': 'string', 'children': [], 'value': '"anneal_schedule should be a list of 2-tuples"'}; {'id': '116', 'type': 'if_statement', 'children': ['117', '137']}; {'id': '117', 'type': 'not_operator', 'children': ['118']}; {'id': '118', 'type': 'call', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '120', 'type': 'generator_expression', 'children': ['121', '124']}; {'id': '121', 'type': 'comparison_operator', 'children': ['122', '123'], 'value': '<'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'tail_t'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'lead_t'}; {'id': '124', 'type': 'for_in_clause', 'children': ['125', '128']}; {'id': '125', 'type': 'pattern_list', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'tail_t'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'lead_t'}; {'id': '128', 'type': 'call', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '130', 'type': 'argument_list', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 't_list'}; {'id': '132', 'type': 'subscript', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 't_list'}; {'id': '134', 'type': 'slice', 'children': ['135', '136']}; {'id': '135', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '136', 'type': 'colon', 'children': []}; {'id': '137', 'type': 'block', 'children': ['138']}; {'id': '138', 'type': 'raise_statement', 'children': ['139']}; {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'string', 'children': [], 'value': '"Time t must increase for all points in the schedule"'}; {'id': '143', 'type': 'if_statement', 'children': ['144', '150']}; {'id': '144', 'type': 'comparison_operator', 'children': ['145', '149'], 'value': '>'}; {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 't_list'}; {'id': '147', 'type': 'unary_operator', 'children': ['148'], 'value': '-'}; {'id': '148', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'max_anneal_time'}; {'id': '150', 'type': 'block', 'children': ['151']}; {'id': '151', 'type': 'raise_statement', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '154']}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '154', 'type': 'argument_list', 'children': ['155']}; {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}; {'id': '157', 'type': 'string', 'children': [], 'value': '"schedule cannot be longer than the maximum anneal time of {}"'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'max_anneal_time'}; {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'assignment', 'children': ['163', '166']}; {'id': '163', 'type': 'pattern_list', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'start_s'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'end_s'}; {'id': '166', 'type': 'expression_list', 'children': ['167', '170']}; {'id': '167', 'type': 'subscript', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 's_list'}; {'id': '169', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '170', 'type': 'subscript', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 's_list'}; {'id': '172', 'type': 'unary_operator', 'children': ['173'], 'value': '-'}; {'id': '173', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '174', 'type': 'if_statement', 'children': ['175', '178']}; {'id': '175', 'type': 'comparison_operator', 'children': ['176', '177'], 'value': '!='}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'end_s'}; {'id': '177', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '178', 'type': 'block', 'children': ['179']}; {'id': '179', 'type': 'raise_statement', 'children': ['180']}; {'id': '180', 'type': 'call', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}; {'id': '183', 'type': 'string', 'children': [], 'value': '"In the final point, anneal fraction s must equal 1."'}; {'id': '184', 'type': 'if_statement', 'children': ['185', '188', '190', '222']}; {'id': '185', 'type': 'comparison_operator', 'children': ['186', '187'], 'value': '=='}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'start_s'}; {'id': '187', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '188', 'type': 'block', 'children': ['189']}; {'id': '189', 'type': 'pass_statement', 'children': []}; {'id': '190', 'type': 'elif_clause', 'children': ['191', '194']}; {'id': '191', 'type': 'comparison_operator', 'children': ['192', '193'], 'value': '=='}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'start_s'}; {'id': '193', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '194', 'type': 'block', 'children': ['195']}; {'id': '195', 'type': 'if_statement', 'children': ['196', '216']}; {'id': '196', 'type': 'not_operator', 'children': ['197']}; {'id': '197', 'type': 'call', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'all'}; {'id': '199', 'type': 'generator_expression', 'children': ['200', '203']}; {'id': '200', 'type': 'comparison_operator', 'children': ['201', '202'], 'value': '<='}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'tail_s'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'lead_s'}; {'id': '203', 'type': 'for_in_clause', 'children': ['204', '207']}; {'id': '204', 'type': 'pattern_list', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'tail_s'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'lead_s'}; {'id': '207', 'type': 'call', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '209', 'type': 'argument_list', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 's_list'}; {'id': '211', 'type': 'subscript', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 's_list'}; {'id': '213', 'type': 'slice', 'children': ['214', '215']}; {'id': '214', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '215', 'type': 'colon', 'children': []}; {'id': '216', 'type': 'block', 'children': ['217']}; {'id': '217', 'type': 'raise_statement', 'children': ['218']}; {'id': '218', 'type': 'call', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '220', 'type': 'argument_list', 'children': ['221']}; {'id': '221', 'type': 'string', 'children': [], 'value': '"For forward anneals, anneal fraction s must monotonically increase"'}; {'id': '222', 'type': 'else_clause', 'children': ['223']}; {'id': '223', 'type': 'block', 'children': ['224', '231']}; {'id': '224', 'type': 'expression_statement', 'children': ['225']}; {'id': '225', 'type': 'assignment', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '227', 'type': '()', 'children': ['228']}; {'id': '228', 'type': 'concatenated_string', 'children': ['229', '230']}; {'id': '229', 'type': 'string', 'children': [], 'value': '"In the first point, anneal fraction s must equal 0 for forward annealing or "'}; {'id': '230', 'type': 'string', 'children': [], 'value': '"1 for reverse annealing"'}; {'id': '231', 'type': 'raise_statement', 'children': ['232']}; {'id': '232', 'type': 'call', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '234', 'type': 'argument_list', 'children': ['235']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '236', 'type': 'expression_statement', 'children': ['237']}; {'id': '237', 'type': 'assignment', 'children': ['238', '239']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'max_slope'}; {'id': '239', 'type': 'binary_operator', 'children': ['240', '241'], 'value': '/'}; {'id': '240', 'type': 'float', 'children': [], 'value': '1.0'}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'min_anneal_time'}; {'id': '242', 'type': 'for_statement', 'children': ['243', '250', '259']}; {'id': '243', 'type': 'pattern_list', 'children': ['244', '247']}; {'id': '244', 'type': 'tuple_pattern', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 't0'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 's0'}; {'id': '247', 'type': 'tuple_pattern', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 't1'}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 's1'}; {'id': '250', 'type': 'call', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '252', 'type': 'argument_list', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'anneal_schedule'}; {'id': '254', 'type': 'subscript', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'anneal_schedule'}; {'id': '256', 'type': 'slice', 'children': ['257', '258']}; {'id': '257', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '258', 'type': 'colon', 'children': []}; {'id': '259', 'type': 'block', 'children': ['260']}; {'id': '260', 'type': 'if_statement', 'children': ['261', '275']}; {'id': '261', 'type': 'comparison_operator', 'children': ['262', '274'], 'value': '>'}; {'id': '262', 'type': 'call', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '264', 'type': 'argument_list', 'children': ['265']}; {'id': '265', 'type': 'binary_operator', 'children': ['266', '270'], 'value': '/'}; {'id': '266', 'type': '()', 'children': ['267']}; {'id': '267', 'type': 'binary_operator', 'children': ['268', '269'], 'value': '-'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 's0'}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 's1'}; {'id': '270', 'type': '()', 'children': ['271']}; {'id': '271', 'type': 'binary_operator', 'children': ['272', '273'], 'value': '-'}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 't0'}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 't1'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'max_slope'}; {'id': '275', 'type': 'block', 'children': ['276']}; {'id': '276', 'type': 'raise_statement', 'children': ['277']}; {'id': '277', 'type': 'call', 'children': ['278', '279']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '279', 'type': 'argument_list', 'children': ['280']}; {'id': '280', 'type': 'call', 'children': ['281', '284']}; {'id': '281', 'type': 'attribute', 'children': ['282', '283']}; {'id': '282', 'type': 'string', 'children': [], 'value': '"the maximum slope cannot exceed {}"'}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '284', 'type': 'argument_list', 'children': ['285']}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'max_slope'}
def validate_anneal_schedule(self, anneal_schedule): if 'anneal_schedule' not in self.parameters: raise RuntimeError("anneal_schedule is not an accepted parameter for this sampler") properties = self.properties try: min_anneal_time, max_anneal_time = properties['annealing_time_range'] max_anneal_schedule_points = properties['max_anneal_schedule_points'] except KeyError: raise RuntimeError("annealing_time_range and max_anneal_schedule_points are not properties of this solver") if not isinstance(anneal_schedule, list): raise TypeError("anneal_schedule should be a list") elif len(anneal_schedule) < 2 or len(anneal_schedule) > max_anneal_schedule_points: msg = ("anneal_schedule must contain between 2 and {} points (contains {})" ).format(max_anneal_schedule_points, len(anneal_schedule)) raise ValueError(msg) try: t_list, s_list = zip(*anneal_schedule) except ValueError: raise ValueError("anneal_schedule should be a list of 2-tuples") if not all(tail_t < lead_t for tail_t, lead_t in zip(t_list, t_list[1:])): raise ValueError("Time t must increase for all points in the schedule") if t_list[-1] > max_anneal_time: raise ValueError("schedule cannot be longer than the maximum anneal time of {}".format(max_anneal_time)) start_s, end_s = s_list[0], s_list[-1] if end_s != 1: raise ValueError("In the final point, anneal fraction s must equal 1.") if start_s == 1: pass elif start_s == 0: if not all(tail_s <= lead_s for tail_s, lead_s in zip(s_list, s_list[1:])): raise ValueError("For forward anneals, anneal fraction s must monotonically increase") else: msg = ("In the first point, anneal fraction s must equal 0 for forward annealing or " "1 for reverse annealing") raise ValueError(msg) max_slope = 1.0 / min_anneal_time for (t0, s0), (t1, s1) in zip(anneal_schedule, anneal_schedule[1:]): if abs((s0 - s1) / (t0 - t1)) > max_slope: raise ValueError("the maximum slope cannot exceed {}".format(max_slope))
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'target_to_source'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'target_adjacency'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'embedding'}; {'id': '6', 'type': 'block', 'children': ['7', '19', '23', '57', '112']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'source_adjacency'}; {'id': '10', 'type': 'dictionary_comprehension', 'children': ['11', '16']}; {'id': '11', 'type': 'pair', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '15', 'type': 'argument_list', 'children': []}; {'id': '16', 'type': 'for_in_clause', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'embedding'}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'reverse_embedding'}; {'id': '22', 'type': 'dictionary', 'children': []}; {'id': '23', 'type': 'for_statement', 'children': ['24', '27', '31']}; {'id': '24', 'type': 'pattern_list', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'chain'}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '29', 'type': 'argument_list', 'children': ['30']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'embedding'}; {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'for_statement', 'children': ['33', '34', '35']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'chain'}; {'id': '35', 'type': 'block', 'children': ['36', '51']}; {'id': '36', 'type': 'if_statement', 'children': ['37', '40']}; {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'in'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'reverse_embedding'}; {'id': '40', 'type': 'block', 'children': ['41']}; {'id': '41', 'type': 'raise_statement', 'children': ['42']}; {'id': '42', 'type': 'call', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '44', 'type': 'argument_list', 'children': ['45']}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'string', 'children': [], 'value': '"target node {} assigned to more than one source node"'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '56']}; {'id': '53', 'type': 'subscript', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'reverse_embedding'}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '57', 'type': 'for_statement', 'children': ['58', '61', '65']}; {'id': '58', 'type': 'pattern_list', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '61', 'type': 'call', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '63', 'type': 'argument_list', 'children': ['64']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'reverse_embedding'}; {'id': '65', 'type': 'block', 'children': ['66', '72']}; {'id': '66', 'type': 'expression_statement', 'children': ['67']}; {'id': '67', 'type': 'assignment', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'neighbors'}; {'id': '69', 'type': 'subscript', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'target_adjacency'}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '72', 'type': 'for_statement', 'children': ['73', '74', '75']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'neighbors'}; {'id': '75', 'type': 'block', 'children': ['76', '82', '88', '94', '103']}; {'id': '76', 'type': 'if_statement', 'children': ['77', '80']}; {'id': '77', 'type': 'comparison_operator', 'children': ['78', '79'], 'value': 'not'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'reverse_embedding'}; {'id': '80', 'type': 'block', 'children': ['81']}; {'id': '81', 'type': 'continue_statement', 'children': []}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}; {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '85', 'type': 'subscript', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'reverse_embedding'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '88', 'type': 'if_statement', 'children': ['89', '92']}; {'id': '89', 'type': 'comparison_operator', 'children': ['90', '91'], 'value': '=='}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '92', 'type': 'block', 'children': ['93']}; {'id': '93', 'type': 'continue_statement', 'children': []}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}; {'id': '95', 'type': 'call', 'children': ['96', '101']}; {'id': '96', 'type': 'attribute', 'children': ['97', '100']}; {'id': '97', 'type': 'subscript', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'source_adjacency'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '101', 'type': 'argument_list', 'children': ['102']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '110']}; {'id': '105', 'type': 'attribute', 'children': ['106', '109']}; {'id': '106', 'type': 'subscript', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'source_adjacency'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '110', 'type': 'argument_list', 'children': ['111']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '112', 'type': 'return_statement', 'children': ['113']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'source_adjacency'}
def target_to_source(target_adjacency, embedding): source_adjacency = {v: set() for v in embedding} reverse_embedding = {} for v, chain in iteritems(embedding): for u in chain: if u in reverse_embedding: raise ValueError("target node {} assigned to more than one source node".format(u)) reverse_embedding[u] = v for v, n in iteritems(reverse_embedding): neighbors = target_adjacency[v] for u in neighbors: if u not in reverse_embedding: continue m = reverse_embedding[u] if m == n: continue source_adjacency[n].add(m) source_adjacency[m].add(n) return source_adjacency
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '10']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'insert_graph'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cur'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'nodelist'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'edgelist'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'encoded_data'}; {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'block', 'children': ['11', '20', '34', '48', '69']}; {'id': '11', 'type': 'if_statement', 'children': ['12', '15']}; {'id': '12', 'type': 'comparison_operator', 'children': ['13', '14'], 'value': 'is'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'encoded_data'}; {'id': '14', 'type': 'None', 'children': []}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'encoded_data'}; {'id': '19', 'type': 'dictionary', 'children': []}; {'id': '20', 'type': 'if_statement', 'children': ['21', '24']}; {'id': '21', 'type': 'comparison_operator', 'children': ['22', '23'], 'value': 'not'}; {'id': '22', 'type': 'string', 'children': [], 'value': "'num_nodes'"}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'encoded_data'}; {'id': '24', 'type': 'block', 'children': ['25']}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '30']}; {'id': '27', 'type': 'subscript', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'encoded_data'}; {'id': '29', 'type': 'string', 'children': [], 'value': "'num_nodes'"}; {'id': '30', 'type': 'call', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '32', 'type': 'argument_list', 'children': ['33']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'nodelist'}; {'id': '34', 'type': 'if_statement', 'children': ['35', '38']}; {'id': '35', 'type': 'comparison_operator', 'children': ['36', '37'], 'value': 'not'}; {'id': '36', 'type': 'string', 'children': [], 'value': "'num_edges'"}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'encoded_data'}; {'id': '38', 'type': 'block', 'children': ['39']}; {'id': '39', 'type': 'expression_statement', 'children': ['40']}; {'id': '40', 'type': 'assignment', 'children': ['41', '44']}; {'id': '41', 'type': 'subscript', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'encoded_data'}; {'id': '43', 'type': 'string', 'children': [], 'value': "'num_edges'"}; {'id': '44', 'type': 'call', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'edgelist'}; {'id': '48', 'type': 'if_statement', 'children': ['49', '52']}; {'id': '49', 'type': 'comparison_operator', 'children': ['50', '51'], 'value': 'not'}; {'id': '50', 'type': 'string', 'children': [], 'value': "'edges'"}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'encoded_data'}; {'id': '52', 'type': 'block', 'children': ['53']}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '58']}; {'id': '55', 'type': 'subscript', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'encoded_data'}; {'id': '57', 'type': 'string', 'children': [], 'value': "'edges'"}; {'id': '58', 'type': 'call', 'children': ['59', '62']}; {'id': '59', 'type': 'attribute', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'dumps'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'edgelist'}; {'id': '64', 'type': 'keyword_argument', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'separators'}; {'id': '66', 'type': 'tuple', 'children': ['67', '68']}; {'id': '67', 'type': 'string', 'children': [], 'value': "','"}; {'id': '68', 'type': 'string', 'children': [], 'value': "':'"}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72', '73']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'insert'}; {'id': '72', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'cur'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'execute'}; {'id': '77', 'type': 'argument_list', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'insert'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'encoded_data'}
def insert_graph(cur, nodelist, edgelist, encoded_data=None): if encoded_data is None: encoded_data = {} if 'num_nodes' not in encoded_data: encoded_data['num_nodes'] = len(nodelist) if 'num_edges' not in encoded_data: encoded_data['num_edges'] = len(edgelist) if 'edges' not in encoded_data: encoded_data['edges'] = json.dumps(edgelist, separators=(',', ':')) insert = \ cur.execute(insert, encoded_data)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'draw_chimera_bqm'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'bqm'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'height'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12', '22', '32', '67', '79', '88', '97', '101', '105', '124', '143', '150', '159', '170', '183', '189', '195', '209', '218', '227', '239', '250', '254', '270', '291']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'linear'}; {'id': '15', 'type': 'call', 'children': ['16', '21']}; {'id': '16', 'type': 'attribute', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'bqm'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'linear'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '21', 'type': 'argument_list', 'children': []}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'quadratic'}; {'id': '25', 'type': 'call', 'children': ['26', '31']}; {'id': '26', 'type': 'attribute', 'children': ['27', '30']}; {'id': '27', 'type': 'attribute', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'bqm'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'quadratic'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'keys'}; {'id': '31', 'type': 'argument_list', 'children': []}; {'id': '32', 'type': 'if_statement', 'children': ['33', '40']}; {'id': '33', 'type': 'boolean_operator', 'children': ['34', '37'], 'value': 'and'}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'is'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '36', 'type': 'None', 'children': []}; {'id': '37', 'type': 'comparison_operator', 'children': ['38', '39'], 'value': 'is'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'height'}; {'id': '39', 'type': 'None', 'children': []}; {'id': '40', 'type': 'block', 'children': ['41', '59', '63']}; {'id': '41', 'type': 'expression_statement', 'children': ['42']}; {'id': '42', 'type': 'assignment', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'graph_size'}; {'id': '44', 'type': 'call', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'ceil'}; {'id': '46', 'type': 'argument_list', 'children': ['47']}; {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'sqrt'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'binary_operator', 'children': ['51', '58'], 'value': '/'}; {'id': '51', 'type': '()', 'children': ['52']}; {'id': '52', 'type': 'binary_operator', 'children': ['53', '57'], 'value': '+'}; {'id': '53', 'type': 'call', 'children': ['54', '55']}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'max'}; {'id': '55', 'type': 'argument_list', 'children': ['56']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'linear'}; {'id': '57', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '58', 'type': 'float', 'children': [], 'value': '8.0'}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'graph_size'}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'height'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'graph_size'}; {'id': '67', 'type': 'if_statement', 'children': ['68', '73']}; {'id': '68', 'type': 'boolean_operator', 'children': ['69', '71'], 'value': 'or'}; {'id': '69', 'type': 'not_operator', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '71', 'type': 'not_operator', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'height'}; {'id': '73', 'type': 'block', 'children': ['74']}; {'id': '74', 'type': 'raise_statement', 'children': ['75']}; {'id': '75', 'type': 'call', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '77', 'type': 'argument_list', 'children': ['78']}; {'id': '78', 'type': 'string', 'children': [], 'value': '"Both dimensions must be defined, not just one."'}; {'id': '79', 'type': 'expression_statement', 'children': ['80']}; {'id': '80', 'type': 'assignment', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'G0'}; {'id': '82', 'type': 'call', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'chimera_graph'}; {'id': '84', 'type': 'argument_list', 'children': ['85', '86', '87']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'height'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '87', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'G'}; {'id': '91', 'type': 'call', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'chimera_graph'}; {'id': '93', 'type': 'argument_list', 'children': ['94', '95', '96']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'height'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '96', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '97', 'type': 'expression_statement', 'children': ['98']}; {'id': '98', 'type': 'assignment', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'non_chimera_nodes'}; {'id': '100', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '101', 'type': 'expression_statement', 'children': ['102']}; {'id': '102', 'type': 'assignment', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'non_chimera_edges'}; {'id': '104', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '105', 'type': 'for_statement', 'children': ['106', '107', '108']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'linear'}; {'id': '108', 'type': 'block', 'children': ['109']}; {'id': '109', 'type': 'if_statement', 'children': ['110', '116']}; {'id': '110', 'type': 'not_operator', 'children': ['111']}; {'id': '111', 'type': 'comparison_operator', 'children': ['112', '113'], 'value': 'in'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'G'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '116', 'type': 'block', 'children': ['117']}; {'id': '117', 'type': 'expression_statement', 'children': ['118']}; {'id': '118', 'type': 'call', 'children': ['119', '122']}; {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'non_chimera_nodes'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '122', 'type': 'argument_list', 'children': ['123']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '124', 'type': 'for_statement', 'children': ['125', '126', '127']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'edge'}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'quadratic'}; {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'if_statement', 'children': ['129', '135']}; {'id': '129', 'type': 'not_operator', 'children': ['130']}; {'id': '130', 'type': 'comparison_operator', 'children': ['131', '132'], 'value': 'in'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'edge'}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'G'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'edges'}; {'id': '135', 'type': 'block', 'children': ['136']}; {'id': '136', 'type': 'expression_statement', 'children': ['137']}; {'id': '137', 'type': 'call', 'children': ['138', '141']}; {'id': '138', 'type': 'attribute', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'non_chimera_edges'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '141', 'type': 'argument_list', 'children': ['142']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'edge'}; {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'assignment', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'linear_set'}; {'id': '146', 'type': 'call', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'linear'}; {'id': '150', 'type': 'expression_statement', 'children': ['151']}; {'id': '151', 'type': 'assignment', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'g_node_set'}; {'id': '153', 'type': 'call', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '155', 'type': 'argument_list', 'children': ['156']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'G'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'quadratic_set'}; {'id': '162', 'type': 'call', 'children': ['163', '164']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}; {'id': '165', 'type': 'call', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '167', 'type': 'argument_list', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'frozenset'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'quadratic'}; {'id': '170', 'type': 'expression_statement', 'children': ['171']}; {'id': '171', 'type': 'assignment', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'g_edge_set'}; {'id': '173', 'type': 'call', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '175', 'type': 'argument_list', 'children': ['176']}; {'id': '176', 'type': 'call', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'map'}; {'id': '178', 'type': 'argument_list', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'frozenset'}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'G'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'edges'}; {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'non_chimera_nodes'}; {'id': '186', 'type': 'binary_operator', 'children': ['187', '188'], 'value': '-'}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'linear_set'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'g_node_set'}; {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '192']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'non_chimera_edges'}; {'id': '192', 'type': 'binary_operator', 'children': ['193', '194'], 'value': '-'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'quadratic_set'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'g_edge_set'}; {'id': '195', 'type': 'if_statement', 'children': ['196', '199']}; {'id': '196', 'type': 'boolean_operator', 'children': ['197', '198'], 'value': 'or'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'non_chimera_nodes'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'non_chimera_edges'}; {'id': '199', 'type': 'block', 'children': ['200']}; {'id': '200', 'type': 'raise_statement', 'children': ['201']}; {'id': '201', 'type': 'call', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '203', 'type': 'argument_list', 'children': ['204']}; {'id': '204', 'type': 'binary_operator', 'children': ['205', '206'], 'value': '%'}; {'id': '205', 'type': 'string', 'children': [], 'value': '"Input graph is not a chimera graph: Nodes: %s Edges: %s"'}; {'id': '206', 'type': 'tuple', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'non_chimera_nodes'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'non_chimera_edges'}; {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'assignment', 'children': ['211', '212']}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'remove_nodes'}; {'id': '212', 'type': 'call', 'children': ['213', '214']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '214', 'type': 'argument_list', 'children': ['215']}; {'id': '215', 'type': 'binary_operator', 'children': ['216', '217'], 'value': '-'}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'g_node_set'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'linear_set'}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}; {'id': '219', 'type': 'assignment', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'remove_edges'}; {'id': '221', 'type': 'call', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '223', 'type': 'argument_list', 'children': ['224']}; {'id': '224', 'type': 'binary_operator', 'children': ['225', '226'], 'value': '-'}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'g_edge_set'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'quadratic_set'}; {'id': '227', 'type': 'for_statement', 'children': ['228', '229', '230']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'edge'}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'remove_edges'}; {'id': '230', 'type': 'block', 'children': ['231']}; {'id': '231', 'type': 'expression_statement', 'children': ['232']}; {'id': '232', 'type': 'call', 'children': ['233', '236']}; {'id': '233', 'type': 'attribute', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'G'}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'remove_edge'}; {'id': '236', 'type': 'argument_list', 'children': ['237']}; {'id': '237', 'type': 'list_splat', 'children': ['238']}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'edge'}; {'id': '239', 'type': 'for_statement', 'children': ['240', '241', '242']}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'remove_nodes'}; {'id': '242', 'type': 'block', 'children': ['243']}; {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'call', 'children': ['245', '248']}; {'id': '245', 'type': 'attribute', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'G'}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'remove_node'}; {'id': '248', 'type': 'argument_list', 'children': ['249']}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'node'}; {'id': '250', 'type': 'expression_statement', 'children': ['251']}; {'id': '251', 'type': 'assignment', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'node_size'}; {'id': '253', 'type': 'integer', 'children': [], 'value': '100'}; {'id': '254', 'type': 'expression_statement', 'children': ['255']}; {'id': '255', 'type': 'call', 'children': ['256', '257']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'draw_chimera'}; {'id': '257', 'type': 'argument_list', 'children': ['258', '259', '264', '267']}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'G0'}; {'id': '259', 'type': 'keyword_argument', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'node_size'}; {'id': '261', 'type': 'binary_operator', 'children': ['262', '263'], 'value': '*'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'node_size'}; {'id': '263', 'type': 'float', 'children': [], 'value': '0.5'}; {'id': '264', 'type': 'keyword_argument', 'children': ['265', '266']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'node_color'}; {'id': '266', 'type': 'string', 'children': [], 'value': "'black'"}; {'id': '267', 'type': 'keyword_argument', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'edge_color'}; {'id': '269', 'type': 'string', 'children': [], 'value': "'black'"}; {'id': '270', 'type': 'expression_statement', 'children': ['271']}; {'id': '271', 'type': 'call', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'draw_chimera'}; {'id': '273', 'type': 'argument_list', 'children': ['274', '275', '278', '283', '288']}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'G'}; {'id': '275', 'type': 'keyword_argument', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'node_size'}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'node_size'}; {'id': '278', 'type': 'keyword_argument', 'children': ['279', '280']}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'linear_biases'}; {'id': '280', 'type': 'attribute', 'children': ['281', '282']}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'bqm'}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'linear'}; {'id': '283', 'type': 'keyword_argument', 'children': ['284', '285']}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'quadratic_biases'}; {'id': '285', 'type': 'attribute', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'bqm'}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'quadratic'}; {'id': '288', 'type': 'keyword_argument', 'children': ['289', '290']}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '290', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '291', 'type': 'return_statement', 'children': []}
def draw_chimera_bqm(bqm, width=None, height=None): linear = bqm.linear.keys() quadratic = bqm.quadratic.keys() if width is None and height is None: graph_size = ceil(sqrt((max(linear) + 1) / 8.0)) width = graph_size height = graph_size if not width or not height: raise Exception("Both dimensions must be defined, not just one.") G0 = chimera_graph(height, width, 4) G = chimera_graph(height, width, 4) non_chimera_nodes = [] non_chimera_edges = [] for node in linear: if not node in G.nodes: non_chimera_nodes.append(node) for edge in quadratic: if not edge in G.edges: non_chimera_edges.append(edge) linear_set = set(linear) g_node_set = set(G.nodes) quadratic_set = set(map(frozenset, quadratic)) g_edge_set = set(map(frozenset, G.edges)) non_chimera_nodes = linear_set - g_node_set non_chimera_edges = quadratic_set - g_edge_set if non_chimera_nodes or non_chimera_edges: raise Exception("Input graph is not a chimera graph: Nodes: %s Edges: %s" % (non_chimera_nodes, non_chimera_edges)) remove_nodes = list(g_node_set - linear_set) remove_edges = list(g_edge_set - quadratic_set) for edge in remove_edges: G.remove_edge(*edge) for node in remove_nodes: G.remove_node(node) node_size = 100 draw_chimera(G0, node_size=node_size*0.5, node_color='black', edge_color='black') draw_chimera(G, node_size=node_size, linear_biases=bqm.linear, quadratic_biases=bqm.quadratic, width=3) return
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'embed_bqm'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'source_bqm'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'embedding'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'target_adjacency'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'chain_strength'}; {'id': '9', 'type': 'float', 'children': [], 'value': '1.0'}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'smear_vartype'}; {'id': '12', 'type': 'None', 'children': []}; {'id': '13', 'type': 'block', 'children': ['14', '78', '89', '98', '174', '244', '312']}; {'id': '14', 'type': 'if_statement', 'children': ['15', '28', '46']}; {'id': '15', 'type': 'boolean_operator', 'children': ['16', '21'], 'value': 'and'}; {'id': '16', 'type': 'comparison_operator', 'children': ['17', '18'], 'value': 'is'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'smear_vartype'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'dimod'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'SPIN'}; {'id': '21', 'type': 'comparison_operator', 'children': ['22', '25'], 'value': 'is'}; {'id': '22', 'type': 'attribute', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'source_bqm'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'vartype'}; {'id': '25', 'type': 'attribute', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'dimod'}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'BINARY'}; {'id': '28', 'type': 'block', 'children': ['29']}; {'id': '29', 'type': 'return_statement', 'children': ['30']}; {'id': '30', 'type': 'attribute', 'children': ['31', '45']}; {'id': '31', 'type': 'call', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'embed_bqm'}; {'id': '33', 'type': 'argument_list', 'children': ['34', '37', '38', '39', '42']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'source_bqm'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'spin'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'embedding'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'target_adjacency'}; {'id': '39', 'type': 'keyword_argument', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'chain_strength'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'chain_strength'}; {'id': '42', 'type': 'keyword_argument', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'smear_vartype'}; {'id': '44', 'type': 'None', 'children': []}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'binary'}; {'id': '46', 'type': 'elif_clause', 'children': ['47', '60']}; {'id': '47', 'type': 'boolean_operator', 'children': ['48', '53'], 'value': 'and'}; {'id': '48', 'type': 'comparison_operator', 'children': ['49', '50'], 'value': 'is'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'smear_vartype'}; {'id': '50', 'type': 'attribute', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'dimod'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'BINARY'}; {'id': '53', 'type': 'comparison_operator', 'children': ['54', '57'], 'value': 'is'}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'source_bqm'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'vartype'}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'dimod'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'SPIN'}; {'id': '60', 'type': 'block', 'children': ['61']}; {'id': '61', 'type': 'return_statement', 'children': ['62']}; {'id': '62', 'type': 'attribute', 'children': ['63', '77']}; {'id': '63', 'type': 'call', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'embed_bqm'}; {'id': '65', 'type': 'argument_list', 'children': ['66', '69', '70', '71', '74']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'source_bqm'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'binary'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'embedding'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'target_adjacency'}; {'id': '71', 'type': 'keyword_argument', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'chain_strength'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'chain_strength'}; {'id': '74', 'type': 'keyword_argument', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'smear_vartype'}; {'id': '76', 'type': 'None', 'children': []}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'spin'}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}; {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'target_bqm'}; {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'source_bqm'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'empty'}; {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'attribute', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'source_bqm'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'vartype'}; {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'call', 'children': ['91', '94']}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'target_bqm'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'add_offset'}; {'id': '94', 'type': 'argument_list', 'children': ['95']}; {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'source_bqm'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '98', 'type': 'for_statement', 'children': ['99', '102', '108']}; {'id': '99', 'type': 'pattern_list', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'bias'}; {'id': '102', 'type': 'call', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '104', 'type': 'argument_list', 'children': ['105']}; {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'source_bqm'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'linear'}; {'id': '108', 'type': 'block', 'children': ['109', '127', '152', '161']}; {'id': '109', 'type': 'if_statement', 'children': ['110', '113', '120']}; {'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': 'in'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'embedding'}; {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}; {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'chain'}; {'id': '117', 'type': 'subscript', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'embedding'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '120', 'type': 'else_clause', 'children': ['121']}; {'id': '121', 'type': 'block', 'children': ['122']}; {'id': '122', 'type': 'raise_statement', 'children': ['123']}; {'id': '123', 'type': 'call', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'MissingChainError'}; {'id': '125', 'type': 'argument_list', 'children': ['126']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '127', 'type': 'if_statement', 'children': ['128', '137']}; {'id': '128', 'type': 'call', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'any'}; {'id': '130', 'type': 'generator_expression', 'children': ['131', '134']}; {'id': '131', 'type': 'comparison_operator', 'children': ['132', '133'], 'value': 'not'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'target_adjacency'}; {'id': '134', 'type': 'for_in_clause', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'chain'}; {'id': '137', 'type': 'block', 'children': ['138']}; {'id': '138', 'type': 'raise_statement', 'children': ['139']}; {'id': '139', 'type': 'call', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'InvalidNodeError'}; {'id': '141', 'type': 'argument_list', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '143', 'type': 'call', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'next'}; {'id': '145', 'type': 'generator_expression', 'children': ['146', '149']}; {'id': '146', 'type': 'comparison_operator', 'children': ['147', '148'], 'value': 'not'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'target_adjacency'}; {'id': '149', 'type': 'for_in_clause', 'children': ['150', '151']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'chain'}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}; {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '155', 'type': 'binary_operator', 'children': ['156', '157'], 'value': '/'}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'bias'}; {'id': '157', 'type': 'call', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'chain'}; {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'call', 'children': ['163', '166']}; {'id': '163', 'type': 'attribute', 'children': ['164', '165']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'target_bqm'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'add_variables_from'}; {'id': '166', 'type': 'argument_list', 'children': ['167']}; {'id': '167', 'type': 'dictionary_comprehension', 'children': ['168', '171']}; {'id': '168', 'type': 'pair', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '171', 'type': 'for_in_clause', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'chain'}; {'id': '174', 'type': 'for_statement', 'children': ['175', '180', '186']}; {'id': '175', 'type': 'pattern_list', 'children': ['176', '179']}; {'id': '176', 'type': 'tuple_pattern', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'bias'}; {'id': '180', 'type': 'call', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'iteritems'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}; {'id': '183', 'type': 'attribute', 'children': ['184', '185']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'source_bqm'}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'quadratic'}; {'id': '186', 'type': 'block', 'children': ['187', '210', '220', '229']}; {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'assignment', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'available_interactions'}; {'id': '190', 'type': 'set_comprehension', 'children': ['191', '194', '199', '204']}; {'id': '191', 'type': 'tuple', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '194', 'type': 'for_in_clause', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '196', 'type': 'subscript', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'embedding'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '199', 'type': 'for_in_clause', 'children': ['200', '201']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '201', 'type': 'subscript', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'embedding'}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '204', 'type': 'if_clause', 'children': ['205']}; {'id': '205', 'type': 'comparison_operator', 'children': ['206', '207'], 'value': 'in'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 's'}; {'id': '207', 'type': 'subscript', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'target_adjacency'}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '210', 'type': 'if_statement', 'children': ['211', '213']}; {'id': '211', 'type': 'not_operator', 'children': ['212']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'available_interactions'}; {'id': '213', 'type': 'block', 'children': ['214']}; {'id': '214', 'type': 'raise_statement', 'children': ['215']}; {'id': '215', 'type': 'call', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'MissingEdgeError'}; {'id': '217', 'type': 'argument_list', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '220', 'type': 'expression_statement', 'children': ['221']}; {'id': '221', 'type': 'assignment', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '223', 'type': 'binary_operator', 'children': ['224', '225'], 'value': '/'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'bias'}; {'id': '225', 'type': 'call', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '227', 'type': 'argument_list', 'children': ['228']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'available_interactions'}; {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'call', 'children': ['231', '234']}; {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'target_bqm'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'add_interactions_from'}; {'id': '234', 'type': 'generator_expression', 'children': ['235', '239']}; {'id': '235', 'type': 'tuple', 'children': ['236', '237', '238']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'b'}; {'id': '239', 'type': 'for_in_clause', 'children': ['240', '243']}; {'id': '240', 'type': 'pattern_list', 'children': ['241', '242']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'available_interactions'}; {'id': '244', 'type': 'for_statement', 'children': ['245', '246', '250']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'chain'}; {'id': '246', 'type': 'call', 'children': ['247', '248']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'itervalues'}; {'id': '248', 'type': 'argument_list', 'children': ['249']}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'embedding'}; {'id': '250', 'type': 'block', 'children': ['251', '273', '282', '294', '305']}; {'id': '251', 'type': 'if_statement', 'children': ['252', '258']}; {'id': '252', 'type': 'comparison_operator', 'children': ['253', '257'], 'value': '=='}; {'id': '253', 'type': 'call', 'children': ['254', '255']}; {'id': '254', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '255', 'type': 'argument_list', 'children': ['256']}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'chain'}; {'id': '257', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '258', 'type': 'block', 'children': ['259', '264', '272']}; {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'assignment', 'children': ['261', '263']}; {'id': '261', 'type': 'pattern_list', 'children': ['262']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'chain'}; {'id': '264', 'type': 'expression_statement', 'children': ['265']}; {'id': '265', 'type': 'call', 'children': ['266', '269']}; {'id': '266', 'type': 'attribute', 'children': ['267', '268']}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'target_bqm'}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'add_variable'}; {'id': '269', 'type': 'argument_list', 'children': ['270', '271']}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '271', 'type': 'float', 'children': [], 'value': '0.0'}; {'id': '272', 'type': 'continue_statement', 'children': []}; {'id': '273', 'type': 'expression_statement', 'children': ['274']}; {'id': '274', 'type': 'assignment', 'children': ['275', '276']}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'quadratic_chain_biases'}; {'id': '276', 'type': 'call', 'children': ['277', '278']}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'chain_to_quadratic'}; {'id': '278', 'type': 'argument_list', 'children': ['279', '280', '281']}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'chain'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'target_adjacency'}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'chain_strength'}; {'id': '282', 'type': 'expression_statement', 'children': ['283']}; {'id': '283', 'type': 'call', 'children': ['284', '287']}; {'id': '284', 'type': 'attribute', 'children': ['285', '286']}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'target_bqm'}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'add_interactions_from'}; {'id': '287', 'type': 'argument_list', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'quadratic_chain_biases'}; {'id': '289', 'type': 'keyword_argument', 'children': ['290', '291']}; {'id': '290', 'type': 'identifier', 'children': [], 'value': 'vartype'}; {'id': '291', 'type': 'attribute', 'children': ['292', '293']}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'dimod'}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'SPIN'}; {'id': '294', 'type': 'expression_statement', 'children': ['295']}; {'id': '295', 'type': 'assignment', 'children': ['296', '297']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'energy_diff'}; {'id': '297', 'type': 'unary_operator', 'children': ['298'], 'value': '-'}; {'id': '298', 'type': 'call', 'children': ['299', '300']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'sum'}; {'id': '300', 'type': 'argument_list', 'children': ['301']}; {'id': '301', 'type': 'call', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'itervalues'}; {'id': '303', 'type': 'argument_list', 'children': ['304']}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'quadratic_chain_biases'}; {'id': '305', 'type': 'expression_statement', 'children': ['306']}; {'id': '306', 'type': 'call', 'children': ['307', '310']}; {'id': '307', 'type': 'attribute', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'target_bqm'}; {'id': '309', 'type': 'identifier', 'children': [], 'value': 'add_offset'}; {'id': '310', 'type': 'argument_list', 'children': ['311']}; {'id': '311', 'type': 'identifier', 'children': [], 'value': 'energy_diff'}; {'id': '312', 'type': 'return_statement', 'children': ['313']}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'target_bqm'}
def embed_bqm(source_bqm, embedding, target_adjacency, chain_strength=1.0, smear_vartype=None): if smear_vartype is dimod.SPIN and source_bqm.vartype is dimod.BINARY: return embed_bqm(source_bqm.spin, embedding, target_adjacency, chain_strength=chain_strength, smear_vartype=None).binary elif smear_vartype is dimod.BINARY and source_bqm.vartype is dimod.SPIN: return embed_bqm(source_bqm.binary, embedding, target_adjacency, chain_strength=chain_strength, smear_vartype=None).spin target_bqm = source_bqm.empty(source_bqm.vartype) target_bqm.add_offset(source_bqm.offset) for v, bias in iteritems(source_bqm.linear): if v in embedding: chain = embedding[v] else: raise MissingChainError(v) if any(u not in target_adjacency for u in chain): raise InvalidNodeError(v, next(u not in target_adjacency for u in chain)) b = bias / len(chain) target_bqm.add_variables_from({u: b for u in chain}) for (u, v), bias in iteritems(source_bqm.quadratic): available_interactions = {(s, t) for s in embedding[u] for t in embedding[v] if s in target_adjacency[t]} if not available_interactions: raise MissingEdgeError(u, v) b = bias / len(available_interactions) target_bqm.add_interactions_from((u, v, b) for u, v in available_interactions) for chain in itervalues(embedding): if len(chain) == 1: v, = chain target_bqm.add_variable(v, 0.0) continue quadratic_chain_biases = chain_to_quadratic(chain, target_adjacency, chain_strength) target_bqm.add_interactions_from(quadratic_chain_biases, vartype=dimod.SPIN) energy_diff = -sum(itervalues(quadratic_chain_biases)) target_bqm.add_offset(energy_diff) return target_bqm
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'embed_ising'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'source_h'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'source_J'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'embedding'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'target_adjacency'}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'chain_strength'}; {'id': '10', 'type': 'float', 'children': [], 'value': '1.0'}; {'id': '11', 'type': 'block', 'children': ['12', '24', '36', '47']}; {'id': '12', 'type': 'expression_statement', 'children': ['13']}; {'id': '13', 'type': 'assignment', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'source_bqm'}; {'id': '15', 'type': 'call', 'children': ['16', '21']}; {'id': '16', 'type': 'attribute', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'dimod'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'BinaryQuadraticModel'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'from_ising'}; {'id': '21', 'type': 'argument_list', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'source_h'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'source_J'}; {'id': '24', 'type': 'expression_statement', 'children': ['25']}; {'id': '25', 'type': 'assignment', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'target_bqm'}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'embed_bqm'}; {'id': '29', 'type': 'argument_list', 'children': ['30', '31', '32', '33']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'source_bqm'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'embedding'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'target_adjacency'}; {'id': '33', 'type': 'keyword_argument', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'chain_strength'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'chain_strength'}; {'id': '36', 'type': 'expression_statement', 'children': ['37']}; {'id': '37', 'type': 'assignment', 'children': ['38', '42']}; {'id': '38', 'type': 'pattern_list', 'children': ['39', '40', '41']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'target_h'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'target_J'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': '__'}; {'id': '42', 'type': 'call', 'children': ['43', '46']}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'target_bqm'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'to_ising'}; {'id': '46', 'type': 'argument_list', 'children': []}; {'id': '47', 'type': 'return_statement', 'children': ['48']}; {'id': '48', 'type': 'expression_list', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'target_h'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'target_J'}
def embed_ising(source_h, source_J, embedding, target_adjacency, chain_strength=1.0): source_bqm = dimod.BinaryQuadraticModel.from_ising(source_h, source_J) target_bqm = embed_bqm(source_bqm, embedding, target_adjacency, chain_strength=chain_strength) target_h, target_J, __ = target_bqm.to_ising() return target_h, target_J
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'unembed_sampleset'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'target_sampleset'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'embedding'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'source_bqm'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'chain_break_method'}; {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'chain_break_fraction'}; {'id': '12', 'type': 'False', 'children': []}; {'id': '13', 'type': 'block', 'children': ['14', '23', '30', '50', '68', '74', '86', '212', '218', '240', '264']}; {'id': '14', 'type': 'if_statement', 'children': ['15', '18']}; {'id': '15', 'type': 'comparison_operator', 'children': ['16', '17'], 'value': 'is'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'chain_break_method'}; {'id': '17', 'type': 'None', 'children': []}; {'id': '18', 'type': 'block', 'children': ['19']}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'chain_break_method'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'majority_vote'}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '28', 'type': 'argument_list', 'children': ['29']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'source_bqm'}; {'id': '30', 'type': 'try_statement', 'children': ['31', '42']}; {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'chains'}; {'id': '35', 'type': 'list_comprehension', 'children': ['36', '39']}; {'id': '36', 'type': 'subscript', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'embedding'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '39', 'type': 'for_in_clause', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '42', 'type': 'except_clause', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '44', 'type': 'block', 'children': ['45']}; {'id': '45', 'type': 'raise_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '48', 'type': 'argument_list', 'children': ['49']}; {'id': '49', 'type': 'string', 'children': [], 'value': '"given bqm does not match the embedding"'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'chain_idxs'}; {'id': '53', 'type': 'list_comprehension', 'children': ['54', '65']}; {'id': '54', 'type': 'list_comprehension', 'children': ['55', '62']}; {'id': '55', 'type': 'subscript', 'children': ['56', '61']}; {'id': '56', 'type': 'attribute', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'target_sampleset'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '62', 'type': 'for_in_clause', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'chain'}; {'id': '65', 'type': 'for_in_clause', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'chain'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'chains'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'target_sampleset'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}; {'id': '75', 'type': 'assignment', 'children': ['76', '79']}; {'id': '76', 'type': 'pattern_list', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'unembedded'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'idxs'}; {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'chain_break_method'}; {'id': '81', 'type': 'argument_list', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'chain_idxs'}; {'id': '86', 'type': 'try_statement', 'children': ['87', '99']}; {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'energies'}; {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'source_bqm'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'energies'}; {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'tuple', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'unembedded'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '99', 'type': 'except_clause', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '101', 'type': 'block', 'children': ['102', '126', '161', '175', '194']}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'assignment', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'datatypes'}; {'id': '105', 'type': 'list', 'children': ['106', '121'], 'value': "[('sample', np.dtype(np.int8), (len(variables),)), ('energy', np.float)]"}; {'id': '106', 'type': 'tuple', 'children': ['107', '108', '116']}; {'id': '107', 'type': 'string', 'children': [], 'value': "'sample'"}; {'id': '108', 'type': 'call', 'children': ['109', '112']}; {'id': '109', 'type': 'attribute', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}; {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'int8'}; {'id': '116', 'type': 'tuple', 'children': ['117']}; {'id': '117', 'type': 'call', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '119', 'type': 'argument_list', 'children': ['120']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '121', 'type': 'tuple', 'children': ['122', '123']}; {'id': '122', 'type': 'string', 'children': [], 'value': "'energy'"}; {'id': '123', 'type': 'attribute', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'float'}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}; {'id': '127', 'type': 'call', 'children': ['128', '131']}; {'id': '128', 'type': 'attribute', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'datatypes'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '131', 'type': 'generator_expression', 'children': ['132', '148', '155']}; {'id': '132', 'type': 'tuple', 'children': ['133', '134', '139']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '134', 'type': 'attribute', 'children': ['135', '138']}; {'id': '135', 'type': 'subscript', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '139', 'type': 'subscript', 'children': ['140', '145']}; {'id': '140', 'type': 'attribute', 'children': ['141', '144']}; {'id': '141', 'type': 'subscript', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'shape'}; {'id': '145', 'type': 'slice', 'children': ['146', '147']}; {'id': '146', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '147', 'type': 'colon', 'children': []}; {'id': '148', 'type': 'for_in_clause', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '150', 'type': 'attribute', 'children': ['151', '154']}; {'id': '151', 'type': 'attribute', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '155', 'type': 'if_clause', 'children': ['156']}; {'id': '156', 'type': 'comparison_operator', 'children': ['157', '158'], 'value': 'not'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '158', 'type': 'set', 'children': ['159', '160']}; {'id': '159', 'type': 'string', 'children': [], 'value': "'sample'"}; {'id': '160', 'type': 'string', 'children': [], 'value': "'energy'"}; {'id': '161', 'type': 'if_statement', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'chain_break_fraction'}; {'id': '163', 'type': 'block', 'children': ['164']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}; {'id': '165', 'type': 'call', 'children': ['166', '169']}; {'id': '166', 'type': 'attribute', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'datatypes'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'tuple', 'children': ['171', '172']}; {'id': '171', 'type': 'string', 'children': [], 'value': "'chain_break_fraction'"}; {'id': '172', 'type': 'attribute', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'float64'}; {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'assignment', 'children': ['177', '178']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '178', 'type': 'call', 'children': ['179', '184']}; {'id': '179', 'type': 'attribute', 'children': ['180', '183']}; {'id': '180', 'type': 'attribute', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'rec'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'array'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}; {'id': '185', 'type': 'call', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'np'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'empty'}; {'id': '189', 'type': 'argument_list', 'children': ['190', '191']}; {'id': '190', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '191', 'type': 'keyword_argument', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'datatypes'}; {'id': '194', 'type': 'return_statement', 'children': ['195']}; {'id': '195', 'type': 'call', 'children': ['196', '199']}; {'id': '196', 'type': 'attribute', 'children': ['197', '198']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'dimod'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'SampleSet'}; {'id': '199', 'type': 'argument_list', 'children': ['200', '201', '202', '209']}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '202', 'type': 'call', 'children': ['203', '208']}; {'id': '203', 'type': 'attribute', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'target_sampleset'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '208', 'type': 'argument_list', 'children': []}; {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'target_sampleset'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'vartype'}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}; {'id': '213', 'type': 'assignment', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'reserved'}; {'id': '215', 'type': 'set', 'children': ['216', '217']}; {'id': '216', 'type': 'string', 'children': [], 'value': "'sample'"}; {'id': '217', 'type': 'string', 'children': [], 'value': "'energy'"}; {'id': '218', 'type': 'expression_statement', 'children': ['219']}; {'id': '219', 'type': 'assignment', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'vectors'}; {'id': '221', 'type': 'dictionary_comprehension', 'children': ['222', '229', '236']}; {'id': '222', 'type': 'pair', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '224', 'type': 'subscript', 'children': ['225', '228']}; {'id': '225', 'type': 'subscript', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'idxs'}; {'id': '229', 'type': 'for_in_clause', 'children': ['230', '231']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '231', 'type': 'attribute', 'children': ['232', '235']}; {'id': '232', 'type': 'attribute', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'dtype'}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'names'}; {'id': '236', 'type': 'if_clause', 'children': ['237']}; {'id': '237', 'type': 'comparison_operator', 'children': ['238', '239'], 'value': 'not'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'reserved'}; {'id': '240', 'type': 'if_statement', 'children': ['241', '242']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'chain_break_fraction'}; {'id': '242', 'type': 'block', 'children': ['243']}; {'id': '243', 'type': 'expression_statement', 'children': ['244']}; {'id': '244', 'type': 'assignment', 'children': ['245', '248']}; {'id': '245', 'type': 'subscript', 'children': ['246', '247']}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'vectors'}; {'id': '247', 'type': 'string', 'children': [], 'value': "'chain_break_fraction'"}; {'id': '248', 'type': 'subscript', 'children': ['249', '263']}; {'id': '249', 'type': 'call', 'children': ['250', '259']}; {'id': '250', 'type': 'attribute', 'children': ['251', '258']}; {'id': '251', 'type': 'call', 'children': ['252', '253']}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'broken_chains'}; {'id': '253', 'type': 'argument_list', 'children': ['254', '257']}; {'id': '254', 'type': 'attribute', 'children': ['255', '256']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'chain_idxs'}; {'id': '258', 'type': 'identifier', 'children': [], 'value': 'mean'}; {'id': '259', 'type': 'argument_list', 'children': ['260']}; {'id': '260', 'type': 'keyword_argument', 'children': ['261', '262']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'axis'}; {'id': '262', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'idxs'}; {'id': '264', 'type': 'return_statement', 'children': ['265']}; {'id': '265', 'type': 'call', 'children': ['266', '271']}; {'id': '266', 'type': 'attribute', 'children': ['267', '270']}; {'id': '267', 'type': 'attribute', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'dimod'}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'SampleSet'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'from_samples'}; {'id': '271', 'type': 'argument_list', 'children': ['272', '275', '278', '281', '290']}; {'id': '272', 'type': 'tuple', 'children': ['273', '274']}; {'id': '273', 'type': 'identifier', 'children': [], 'value': 'unembedded'}; {'id': '274', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '275', 'type': 'attribute', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'target_sampleset'}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'vartype'}; {'id': '278', 'type': 'keyword_argument', 'children': ['279', '280']}; {'id': '279', 'type': 'identifier', 'children': [], 'value': 'energy'}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'energies'}; {'id': '281', 'type': 'keyword_argument', 'children': ['282', '283']}; {'id': '282', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '283', 'type': 'call', 'children': ['284', '289']}; {'id': '284', 'type': 'attribute', 'children': ['285', '288']}; {'id': '285', 'type': 'attribute', 'children': ['286', '287']}; {'id': '286', 'type': 'identifier', 'children': [], 'value': 'target_sampleset'}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '289', 'type': 'argument_list', 'children': []}; {'id': '290', 'type': 'dictionary_splat', 'children': ['291']}; {'id': '291', 'type': 'identifier', 'children': [], 'value': 'vectors'}
def unembed_sampleset(target_sampleset, embedding, source_bqm, chain_break_method=None, chain_break_fraction=False): if chain_break_method is None: chain_break_method = majority_vote variables = list(source_bqm) try: chains = [embedding[v] for v in variables] except KeyError: raise ValueError("given bqm does not match the embedding") chain_idxs = [[target_sampleset.variables.index[v] for v in chain] for chain in chains] record = target_sampleset.record unembedded, idxs = chain_break_method(record.sample, chain_idxs) try: energies = source_bqm.energies((unembedded, variables)) except ValueError: datatypes = [('sample', np.dtype(np.int8), (len(variables),)), ('energy', np.float)] datatypes.extend((name, record[name].dtype, record[name].shape[1:]) for name in record.dtype.names if name not in {'sample', 'energy'}) if chain_break_fraction: datatypes.append(('chain_break_fraction', np.float64)) data = np.rec.array(np.empty(0, dtype=datatypes)) return dimod.SampleSet(data, variables, target_sampleset.info.copy(), target_sampleset.vartype) reserved = {'sample', 'energy'} vectors = {name: record[name][idxs] for name in record.dtype.names if name not in reserved} if chain_break_fraction: vectors['chain_break_fraction'] = broken_chains(record.sample, chain_idxs).mean(axis=1)[idxs] return dimod.SampleSet.from_samples((unembedded, variables), target_sampleset.vartype, energy=energies, info=target_sampleset.info.copy(), **vectors)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'nativeCliqueEmbed'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '6', 'type': 'block', 'children': ['7', '11', '23', '27', '31', '35', '153', '157', '193']}; {'id': '7', 'type': 'expression_statement', 'children': ['8']}; {'id': '8', 'type': 'assignment', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'maxCWR'}; {'id': '10', 'type': 'dictionary', 'children': []}; {'id': '11', 'type': 'expression_statement', 'children': ['12']}; {'id': '12', 'type': 'assignment', 'children': ['13', '16']}; {'id': '13', 'type': 'pattern_list', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'M'}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '16', 'type': 'expression_list', 'children': ['17', '20']}; {'id': '17', 'type': 'attribute', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'M'}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'maxscore'}; {'id': '26', 'type': 'None', 'children': []}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '30', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '31', 'type': 'expression_statement', 'children': ['32']}; {'id': '32', 'type': 'assignment', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '34', 'type': 'None', 'children': []}; {'id': '35', 'type': 'for_statement', 'children': ['36', '37', '43']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '37', 'type': 'call', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '39', 'type': 'argument_list', 'children': ['40']}; {'id': '40', 'type': 'binary_operator', 'children': ['41', '42'], 'value': '+'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '42', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '43', 'type': 'block', 'children': ['44', '52']}; {'id': '44', 'type': 'expression_statement', 'children': ['45']}; {'id': '45', 'type': 'assignment', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '47', 'type': 'binary_operator', 'children': ['48', '51'], 'value': '-'}; {'id': '48', 'type': 'binary_operator', 'children': ['49', '50'], 'value': '-'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'width'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '51', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '52', 'type': 'for_statement', 'children': ['53', '54', '60']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'ymin'}; {'id': '54', 'type': 'call', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'binary_operator', 'children': ['58', '59'], 'value': '-'}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '60', 'type': 'block', 'children': ['61', '67']}; {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'ymax'}; {'id': '64', 'type': 'binary_operator', 'children': ['65', '66'], 'value': '+'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'ymin'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'h'}; {'id': '67', 'type': 'for_statement', 'children': ['68', '69', '75']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'xmin'}; {'id': '69', 'type': 'call', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '71', 'type': 'argument_list', 'children': ['72']}; {'id': '72', 'type': 'binary_operator', 'children': ['73', '74'], 'value': '-'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'M'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '75', 'type': 'block', 'children': ['76', '82', '90', '102', '108', '134']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}; {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'xmax'}; {'id': '79', 'type': 'binary_operator', 'children': ['80', '81'], 'value': '+'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'xmin'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'w'}; {'id': '82', 'type': 'expression_statement', 'children': ['83']}; {'id': '83', 'type': 'assignment', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '85', 'type': 'tuple', 'children': ['86', '87', '88', '89']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'xmin'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'xmax'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'ymin'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'ymax'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}; {'id': '91', 'type': 'assignment', 'children': ['92', '95']}; {'id': '92', 'type': 'pattern_list', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'best'}; {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'attribute', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'maxCliqueWithRectangle'}; {'id': '99', 'type': 'argument_list', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'maxCWR'}; {'id': '102', 'type': 'expression_statement', 'children': ['103']}; {'id': '103', 'type': 'assignment', 'children': ['104', '107']}; {'id': '104', 'type': 'subscript', 'children': ['105', '106']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'maxCWR'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'best'}; {'id': '108', 'type': 'if_statement', 'children': ['109', '121']}; {'id': '109', 'type': 'boolean_operator', 'children': ['110', '113'], 'value': 'or'}; {'id': '110', 'type': 'comparison_operator', 'children': ['111', '112'], 'value': 'is'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'maxscore'}; {'id': '112', 'type': 'None', 'children': []}; {'id': '113', 'type': '()', 'children': ['114']}; {'id': '114', 'type': 'boolean_operator', 'children': ['115', '118'], 'value': 'and'}; {'id': '115', 'type': 'comparison_operator', 'children': ['116', '117'], 'value': 'is'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '117', 'type': 'None', 'children': []}; {'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': '<'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'maxscore'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '121', 'type': 'block', 'children': ['122', '126', '130']}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}; {'id': '123', 'type': 'assignment', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'maxscore'}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}; {'id': '127', 'type': 'assignment', 'children': ['128', '129']}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '129', 'type': 'None', 'children': []}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}; {'id': '131', 'type': 'assignment', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '133', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '134', 'type': 'if_statement', 'children': ['135', '138']}; {'id': '135', 'type': 'comparison_operator', 'children': ['136', '137'], 'value': '=='}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'maxscore'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '138', 'type': 'block', 'children': ['139']}; {'id': '139', 'type': 'expression_statement', 'children': ['140']}; {'id': '140', 'type': 'assignment', 'children': ['141', '144']}; {'id': '141', 'type': 'pattern_list', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '144', 'type': 'call', 'children': ['145', '146']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': '_accumulate_random'}; {'id': '146', 'type': 'argument_list', 'children': ['147', '148', '151', '152']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '148', 'type': 'subscript', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'best'}; {'id': '150', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'R'}; {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'clique'}; {'id': '156', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '157', 'type': 'while_statement', 'children': ['158', '161']}; {'id': '158', 'type': 'comparison_operator', 'children': ['159', '160'], 'value': 'in'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'maxCWR'}; {'id': '161', 'type': 'block', 'children': ['162', '172']}; {'id': '162', 'type': 'expression_statement', 'children': ['163']}; {'id': '163', 'type': 'assignment', 'children': ['164', '169']}; {'id': '164', 'type': 'pattern_list', 'children': ['165', '166', '167', '168']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'score'}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'ell'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'num'}; {'id': '169', 'type': 'subscript', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'maxCWR'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'key'}; {'id': '172', 'type': 'if_statement', 'children': ['173', '176']}; {'id': '173', 'type': 'comparison_operator', 'children': ['174', '175'], 'value': 'is'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'ell'}; {'id': '175', 'type': 'None', 'children': []}; {'id': '176', 'type': 'block', 'children': ['177', '186']}; {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'assignment', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'meb'}; {'id': '180', 'type': 'call', 'children': ['181', '184']}; {'id': '181', 'type': 'attribute', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'maximum_ell_bundle'}; {'id': '184', 'type': 'argument_list', 'children': ['185']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'ell'}; {'id': '186', 'type': 'expression_statement', 'children': ['187']}; {'id': '187', 'type': 'call', 'children': ['188', '191']}; {'id': '188', 'type': 'attribute', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'clique'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '191', 'type': 'argument_list', 'children': ['192']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'meb'}; {'id': '193', 'type': 'return_statement', 'children': ['194']}; {'id': '194', 'type': 'expression_list', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'maxscore'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'clique'}
def nativeCliqueEmbed(self, width): maxCWR = {} M, N = self.M, self.N maxscore = None count = 0 key = None for w in range(width + 2): h = width - w - 2 for ymin in range(N - h): ymax = ymin + h for xmin in range(M - w): xmax = xmin + w R = (xmin, xmax, ymin, ymax) score, best = self.maxCliqueWithRectangle(R, maxCWR) maxCWR[R] = best if maxscore is None or (score is not None and maxscore < score): maxscore = score key = None count = 0 if maxscore == score: count, key = _accumulate_random(count, best[3], key, R) clique = [] while key in maxCWR: score, ell, key, num = maxCWR[key] if ell is not None: meb = self.maximum_ell_bundle(ell) clique.extend(meb) return maxscore, clique
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '15']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_clique_embedding'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9', '12']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'default_parameter', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'target_edges'}; {'id': '14', 'type': 'None', 'children': []}; {'id': '15', 'type': 'block', 'children': ['16', '19', '25', '39', '152', '166']}; {'id': '16', 'type': 'import_statement', 'children': ['17']}; {'id': '17', 'type': 'dotted_name', 'children': ['18']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'random'}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '24']}; {'id': '21', 'type': 'pattern_list', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': '_'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '25', 'type': 'expression_statement', 'children': ['26']}; {'id': '26', 'type': 'assignment', 'children': ['27', '32']}; {'id': '27', 'type': 'pattern_list', 'children': ['28', '29', '30', '31']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'target_edges'}; {'id': '32', 'type': 'call', 'children': ['33', '34']}; {'id': '33', 'type': 'identifier', 'children': [], 'value': '_chimera_input'}; {'id': '34', 'type': 'argument_list', 'children': ['35', '36', '37', '38']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'target_edges'}; {'id': '39', 'type': 'if_statement', 'children': ['40', '46', '77', '126']}; {'id': '40', 'type': 'comparison_operator', 'children': ['41', '45'], 'value': '=='}; {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '45', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '46', 'type': 'block', 'children': ['47', '59', '71']}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'assignment', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'qubits'}; {'id': '50', 'type': 'call', 'children': ['51', '56']}; {'id': '51', 'type': 'attribute', 'children': ['52', '55']}; {'id': '52', 'type': 'call', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '54', 'type': 'argument_list', 'children': []}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'union'}; {'id': '56', 'type': 'argument_list', 'children': ['57']}; {'id': '57', 'type': 'list_splat', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'target_edges'}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'assignment', 'children': ['61', '62']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'qubit'}; {'id': '62', 'type': 'call', 'children': ['63', '66']}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'random'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'choice'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}; {'id': '67', 'type': 'call', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'qubits'}; {'id': '71', 'type': 'expression_statement', 'children': ['72']}; {'id': '72', 'type': 'assignment', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'embedding'}; {'id': '74', 'type': 'list', 'children': ['75'], 'value': '[[qubit]]'}; {'id': '75', 'type': 'list', 'children': ['76'], 'value': '[qubit]'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'qubit'}; {'id': '77', 'type': 'elif_clause', 'children': ['78', '84']}; {'id': '78', 'type': 'comparison_operator', 'children': ['79', '83'], 'value': '=='}; {'id': '79', 'type': 'call', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '83', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '84', 'type': 'block', 'children': ['85', '100', '114']}; {'id': '85', 'type': 'if_statement', 'children': ['86', '92']}; {'id': '86', 'type': 'not_operator', 'children': ['87']}; {'id': '87', 'type': 'call', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '89', 'type': 'argument_list', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'target_edges'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '92', 'type': 'block', 'children': ['93']}; {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'assignment', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'edges'}; {'id': '96', 'type': 'call', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'target_edges'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}; {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'edge'}; {'id': '103', 'type': 'subscript', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'edges'}; {'id': '105', 'type': 'call', 'children': ['106', '109']}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'random'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'randrange'}; {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'call', 'children': ['111', '112']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '112', 'type': 'argument_list', 'children': ['113']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'edges'}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}; {'id': '115', 'type': 'assignment', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'embedding'}; {'id': '117', 'type': 'list', 'children': ['118', '122'], 'value': '[[edge[0]], [edge[1]]]'}; {'id': '118', 'type': 'list', 'children': ['119'], 'value': '[edge[0]]'}; {'id': '119', 'type': 'subscript', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'edge'}; {'id': '121', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '122', 'type': 'list', 'children': ['123'], 'value': '[edge[1]]'}; {'id': '123', 'type': 'subscript', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'edge'}; {'id': '125', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '126', 'type': 'else_clause', 'children': ['127']}; {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}; {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'embedding'}; {'id': '131', 'type': 'call', 'children': ['132', '147']}; {'id': '132', 'type': 'attribute', 'children': ['133', '146']}; {'id': '133', 'type': 'call', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'processor'}; {'id': '135', 'type': 'argument_list', 'children': ['136', '137', '140', '143']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'target_edges'}; {'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'M'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '140', 'type': 'keyword_argument', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'N'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '143', 'type': 'keyword_argument', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'L'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'tightestNativeClique'}; {'id': '147', 'type': 'argument_list', 'children': ['148']}; {'id': '148', 'type': 'call', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '152', 'type': 'if_statement', 'children': ['153', '155']}; {'id': '153', 'type': 'not_operator', 'children': ['154']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'embedding'}; {'id': '155', 'type': 'block', 'children': ['156']}; {'id': '156', 'type': 'raise_statement', 'children': ['157']}; {'id': '157', 'type': 'call', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '159', 'type': 'argument_list', 'children': ['160']}; {'id': '160', 'type': 'call', 'children': ['161', '164']}; {'id': '161', 'type': 'attribute', 'children': ['162', '163']}; {'id': '162', 'type': 'string', 'children': [], 'value': '"cannot find a K{} embedding for given Chimera lattice"'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '164', 'type': 'argument_list', 'children': ['165']}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'k'}; {'id': '166', 'type': 'return_statement', 'children': ['167']}; {'id': '167', 'type': 'call', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'dict'}; {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'call', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'zip'}; {'id': '172', 'type': 'argument_list', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'nodes'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'embedding'}
def find_clique_embedding(k, m, n=None, t=None, target_edges=None): import random _, nodes = k m, n, t, target_edges = _chimera_input(m, n, t, target_edges) if len(nodes) == 1: qubits = set().union(*target_edges) qubit = random.choice(tuple(qubits)) embedding = [[qubit]] elif len(nodes) == 2: if not isinstance(target_edges, list): edges = list(target_edges) edge = edges[random.randrange(len(edges))] embedding = [[edge[0]], [edge[1]]] else: embedding = processor(target_edges, M=m, N=n, L=t).tightestNativeClique(len(nodes)) if not embedding: raise ValueError("cannot find a K{} embedding for given Chimera lattice".format(k)) return dict(zip(nodes, embedding))
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'find_grid_embedding'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'dim'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '11', 'type': 'integer', 'children': [], 'value': '4'}; {'id': '12', 'type': 'block', 'children': ['13', '27', '42', '49', '56', '126', '133', '171']}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '20']}; {'id': '15', 'type': 'pattern_list', 'children': ['16', '17', '18', '19']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'target_edges'}; {'id': '20', 'type': 'call', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': '_chimera_input'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '24', '25', '26']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '26', 'type': 'None', 'children': []}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'indexer'}; {'id': '30', 'type': 'call', 'children': ['31', '38']}; {'id': '31', 'type': 'attribute', 'children': ['32', '37']}; {'id': '32', 'type': 'attribute', 'children': ['33', '36']}; {'id': '33', 'type': 'attribute', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'dnx'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'generators'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'chimera'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'chimera_coordinates'}; {'id': '38', 'type': 'argument_list', 'children': ['39', '40', '41']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'dim'}; {'id': '45', 'type': 'call', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'dim'}; {'id': '49', 'type': 'expression_statement', 'children': ['50']}; {'id': '50', 'type': 'assignment', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'num_dim'}; {'id': '52', 'type': 'call', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '54', 'type': 'argument_list', 'children': ['55']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'dim'}; {'id': '56', 'type': 'if_statement', 'children': ['57', '60', '79', '102', '119']}; {'id': '57', 'type': 'comparison_operator', 'children': ['58', '59'], 'value': '=='}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'num_dim'}; {'id': '59', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '60', 'type': 'block', 'children': ['61', '70']}; {'id': '61', 'type': 'function_definition', 'children': ['62', '63', '67']}; {'id': '62', 'type': 'function_name', 'children': [], 'value': '_key'}; {'id': '63', 'type': 'parameters', 'children': ['64', '65', '66']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'aisle'}; {'id': '67', 'type': 'block', 'children': ['68']}; {'id': '68', 'type': 'return_statement', 'children': ['69']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '70', 'type': 'expression_statement', 'children': ['71']}; {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'dim'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'extend'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'list', 'children': ['77', '78'], 'value': '[1, 1]'}; {'id': '77', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '78', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '79', 'type': 'elif_clause', 'children': ['80', '83']}; {'id': '80', 'type': 'comparison_operator', 'children': ['81', '82'], 'value': '=='}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'num_dim'}; {'id': '82', 'type': 'integer', 'children': [], 'value': '2'}; {'id': '83', 'type': 'block', 'children': ['84', '95']}; {'id': '84', 'type': 'function_definition', 'children': ['85', '86', '90']}; {'id': '85', 'type': 'function_name', 'children': [], 'value': '_key'}; {'id': '86', 'type': 'parameters', 'children': ['87', '88', '89']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'aisle'}; {'id': '90', 'type': 'block', 'children': ['91']}; {'id': '91', 'type': 'return_statement', 'children': ['92']}; {'id': '92', 'type': 'expression_list', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '95', 'type': 'expression_statement', 'children': ['96']}; {'id': '96', 'type': 'call', 'children': ['97', '100']}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'dim'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}; {'id': '101', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '102', 'type': 'elif_clause', 'children': ['103', '106']}; {'id': '103', 'type': 'comparison_operator', 'children': ['104', '105'], 'value': '=='}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'num_dim'}; {'id': '105', 'type': 'integer', 'children': [], 'value': '3'}; {'id': '106', 'type': 'block', 'children': ['107']}; {'id': '107', 'type': 'function_definition', 'children': ['108', '109', '113']}; {'id': '108', 'type': 'function_name', 'children': [], 'value': '_key'}; {'id': '109', 'type': 'parameters', 'children': ['110', '111', '112']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'aisle'}; {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'return_statement', 'children': ['115']}; {'id': '115', 'type': 'expression_list', 'children': ['116', '117', '118']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'aisle'}; {'id': '119', 'type': 'else_clause', 'children': ['120']}; {'id': '120', 'type': 'block', 'children': ['121']}; {'id': '121', 'type': 'raise_statement', 'children': ['122']}; {'id': '122', 'type': 'call', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '124', 'type': 'argument_list', 'children': ['125']}; {'id': '125', 'type': 'string', 'children': [], 'value': '"find_grid_embedding supports between one and three dimensions"'}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}; {'id': '127', 'type': 'assignment', 'children': ['128', '132']}; {'id': '128', 'type': 'pattern_list', 'children': ['129', '130', '131']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'aisles'}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'dim'}; {'id': '133', 'type': 'if_statement', 'children': ['134', '145']}; {'id': '134', 'type': 'boolean_operator', 'children': ['135', '142'], 'value': 'or'}; {'id': '135', 'type': 'boolean_operator', 'children': ['136', '139'], 'value': 'or'}; {'id': '136', 'type': 'comparison_operator', 'children': ['137', '138'], 'value': '>'}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '139', 'type': 'comparison_operator', 'children': ['140', '141'], 'value': '>'}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '142', 'type': 'comparison_operator', 'children': ['143', '144'], 'value': '>'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'aisles'}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '145', 'type': 'block', 'children': ['146', '166']}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}; {'id': '147', 'type': 'assignment', 'children': ['148', '149']}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '149', 'type': 'call', 'children': ['150', '156']}; {'id': '150', 'type': 'attribute', 'children': ['151', '155']}; {'id': '151', 'type': '()', 'children': ['152']}; {'id': '152', 'type': 'concatenated_string', 'children': ['153', '154']}; {'id': '153', 'type': 'string', 'children': [], 'value': '"the largest grid that find_grid_embedding can fit in a ({}, {}, {}) Chimera-lattice "'}; {'id': '154', 'type': 'string', 'children': [], 'value': '"is {}x{}x{}; given grid is {}x{}x{}"'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'format'}; {'id': '156', 'type': 'argument_list', 'children': ['157', '158', '159', '160', '161', '162', '163', '164', '165']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'm'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'n'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 't'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'rows'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'cols'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'aisles'}; {'id': '166', 'type': 'raise_statement', 'children': ['167']}; {'id': '167', 'type': 'call', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '169', 'type': 'argument_list', 'children': ['170']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'msg'}; {'id': '171', 'type': 'return_statement', 'children': ['172']}; {'id': '172', 'type': 'dictionary_comprehension', 'children': ['173', '201', '209', '217']}; {'id': '173', 'type': 'pair', 'children': ['174', '180']}; {'id': '174', 'type': 'call', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': '_key'}; {'id': '176', 'type': 'argument_list', 'children': ['177', '178', '179']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'aisle'}; {'id': '180', 'type': 'list', 'children': ['181', '191'], 'value': '[indexer.int((row, col, 0, aisle)), indexer.int((row, col, 1, aisle))]'}; {'id': '181', 'type': 'call', 'children': ['182', '185']}; {'id': '182', 'type': 'attribute', 'children': ['183', '184']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'indexer'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '185', 'type': 'argument_list', 'children': ['186']}; {'id': '186', 'type': 'tuple', 'children': ['187', '188', '189', '190']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '189', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'aisle'}; {'id': '191', 'type': 'call', 'children': ['192', '195']}; {'id': '192', 'type': 'attribute', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'indexer'}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'int'}; {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'tuple', 'children': ['197', '198', '199', '200']}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '199', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'aisle'}; {'id': '201', 'type': 'for_in_clause', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'row'}; {'id': '203', 'type': 'call', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '205', 'type': 'argument_list', 'children': ['206']}; {'id': '206', 'type': 'subscript', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'dim'}; {'id': '208', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '209', 'type': 'for_in_clause', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'col'}; {'id': '211', 'type': 'call', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '213', 'type': 'argument_list', 'children': ['214']}; {'id': '214', 'type': 'subscript', 'children': ['215', '216']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'dim'}; {'id': '216', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '217', 'type': 'for_in_clause', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'aisle'}; {'id': '219', 'type': 'call', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'range'}; {'id': '221', 'type': 'argument_list', 'children': ['222']}; {'id': '222', 'type': 'subscript', 'children': ['223', '224']}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'dim'}; {'id': '224', 'type': 'integer', 'children': [], 'value': '2'}
def find_grid_embedding(dim, m, n=None, t=4): m, n, t, target_edges = _chimera_input(m, n, t, None) indexer = dnx.generators.chimera.chimera_coordinates(m, n, t) dim = list(dim) num_dim = len(dim) if num_dim == 1: def _key(row, col, aisle): return row dim.extend([1, 1]) elif num_dim == 2: def _key(row, col, aisle): return row, col dim.append(1) elif num_dim == 3: def _key(row, col, aisle): return row, col, aisle else: raise ValueError("find_grid_embedding supports between one and three dimensions") rows, cols, aisles = dim if rows > m or cols > n or aisles > t: msg = ("the largest grid that find_grid_embedding can fit in a ({}, {}, {}) Chimera-lattice " "is {}x{}x{}; given grid is {}x{}x{}").format(m, n, t, m, n, t, rows, cols, aisles) raise ValueError(msg) return {_key(row, col, aisle): [indexer.int((row, col, 0, aisle)), indexer.int((row, col, 1, aisle))] for row in range(dim[0]) for col in range(dim[1]) for aisle in range(dim[2])}
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sample'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'bqm'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '8', 'type': 'block', 'children': ['9', '15', '21', '27', '33', '54', '100', '115', '122', '152', '173', '203', '209', '216']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'cutoff'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '_cutoff'}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'cutoff_vartype'}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '_cutoff_vartype'}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'comp'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '_comparison'}; {'id': '33', 'type': 'if_statement', 'children': ['34', '39', '46']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'is'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'cutoff_vartype'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'dimod'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'SPIN'}; {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'original'}; {'id': '43', 'type': 'attribute', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'bqm'}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'spin'}; {'id': '46', 'type': 'else_clause', 'children': ['47']}; {'id': '47', 'type': 'block', 'children': ['48']}; {'id': '48', 'type': 'expression_statement', 'children': ['49']}; {'id': '49', 'type': 'assignment', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'original'}; {'id': '51', 'type': 'attribute', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'bqm'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'binary'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}; {'id': '55', 'type': 'assignment', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '57', 'type': 'call', 'children': ['58', '62']}; {'id': '58', 'type': 'call', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'bqm'}; {'id': '62', 'type': 'argument_list', 'children': ['63', '66', '94', '97']}; {'id': '63', 'type': 'attribute', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'original'}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'linear'}; {'id': '66', 'type': 'generator_expression', 'children': ['67', '71', '84']}; {'id': '67', 'type': 'tuple', 'children': ['68', '69', '70']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'bias'}; {'id': '71', 'type': 'for_in_clause', 'children': ['72', '77']}; {'id': '72', 'type': 'pattern_list', 'children': ['73', '76']}; {'id': '73', 'type': 'tuple_pattern', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'u'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'bias'}; {'id': '77', 'type': 'call', 'children': ['78', '83']}; {'id': '78', 'type': 'attribute', 'children': ['79', '82']}; {'id': '79', 'type': 'attribute', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'original'}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'quadratic'}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '83', 'type': 'argument_list', 'children': []}; {'id': '84', 'type': 'if_clause', 'children': ['85']}; {'id': '85', 'type': 'not_operator', 'children': ['86']}; {'id': '86', 'type': 'call', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'comp'}; {'id': '88', 'type': 'argument_list', 'children': ['89', '93']}; {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'bias'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'cutoff'}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'original'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'original'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'vartype'}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}; {'id': '101', 'type': 'assignment', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'isolated'}; {'id': '103', 'type': 'list_comprehension', 'children': ['104', '105', '108']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '105', 'type': 'for_in_clause', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '108', 'type': 'if_clause', 'children': ['109']}; {'id': '109', 'type': 'not_operator', 'children': ['110']}; {'id': '110', 'type': 'subscript', 'children': ['111', '114']}; {'id': '111', 'type': 'attribute', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'adj'}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'call', 'children': ['117', '120']}; {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'remove_variables_from'}; {'id': '120', 'type': 'argument_list', 'children': ['121']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'isolated'}; {'id': '122', 'type': 'if_statement', 'children': ['123', '131']}; {'id': '123', 'type': 'boolean_operator', 'children': ['124', '125'], 'value': 'and'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'isolated'}; {'id': '125', 'type': 'comparison_operator', 'children': ['126', '130'], 'value': '=='}; {'id': '126', 'type': 'call', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '128', 'type': 'argument_list', 'children': ['129']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '130', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '131', 'type': 'block', 'children': ['132', '140']}; {'id': '132', 'type': 'expression_statement', 'children': ['133']}; {'id': '133', 'type': 'assignment', 'children': ['134', '135']}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '135', 'type': 'call', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'isolated'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '139', 'type': 'argument_list', 'children': []}; {'id': '140', 'type': 'expression_statement', 'children': ['141']}; {'id': '141', 'type': 'assignment', 'children': ['142', '147']}; {'id': '142', 'type': 'subscript', 'children': ['143', '146']}; {'id': '143', 'type': 'attribute', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'linear'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '147', 'type': 'subscript', 'children': ['148', '151']}; {'id': '148', 'type': 'attribute', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'original'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'linear'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '152', 'type': 'expression_statement', 'children': ['153']}; {'id': '153', 'type': 'assignment', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'sampleset'}; {'id': '155', 'type': 'call', 'children': ['156', '166']}; {'id': '156', 'type': 'attribute', 'children': ['157', '165']}; {'id': '157', 'type': 'call', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '161', 'type': 'argument_list', 'children': ['162', '163']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '163', 'type': 'dictionary_splat', 'children': ['164']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'change_vartype'}; {'id': '166', 'type': 'argument_list', 'children': ['167', '170']}; {'id': '167', 'type': 'attribute', 'children': ['168', '169']}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'bqm'}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'vartype'}; {'id': '170', 'type': 'keyword_argument', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'inplace'}; {'id': '172', 'type': 'True', 'children': []}; {'id': '173', 'type': 'if_statement', 'children': ['174', '175', '187']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'isolated'}; {'id': '175', 'type': 'block', 'children': ['176']}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}; {'id': '177', 'type': 'assignment', 'children': ['178', '181']}; {'id': '178', 'type': 'pattern_list', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '181', 'type': 'call', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': '_restore_isolated'}; {'id': '183', 'type': 'argument_list', 'children': ['184', '185', '186']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'sampleset'}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'bqm'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'isolated'}; {'id': '187', 'type': 'else_clause', 'children': ['188']}; {'id': '188', 'type': 'block', 'children': ['189', '197']}; {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '192']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '192', 'type': 'attribute', 'children': ['193', '196']}; {'id': '193', 'type': 'attribute', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'sampleset'}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '197', 'type': 'expression_statement', 'children': ['198']}; {'id': '198', 'type': 'assignment', 'children': ['199', '200']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '200', 'type': 'attribute', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'sampleset'}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '203', 'type': 'expression_statement', 'children': ['204']}; {'id': '204', 'type': 'assignment', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'vectors'}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'sampleset'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'data_vectors'}; {'id': '209', 'type': 'expression_statement', 'children': ['210']}; {'id': '210', 'type': 'call', 'children': ['211', '214']}; {'id': '211', 'type': 'attribute', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'vectors'}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '214', 'type': 'argument_list', 'children': ['215']}; {'id': '215', 'type': 'string', 'children': [], 'value': "'energy'"}; {'id': '216', 'type': 'return_statement', 'children': ['217']}; {'id': '217', 'type': 'call', 'children': ['218', '223']}; {'id': '218', 'type': 'attribute', 'children': ['219', '222']}; {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'dimod'}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'SampleSet'}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'from_samples_bqm'}; {'id': '223', 'type': 'argument_list', 'children': ['224', '227', '228']}; {'id': '224', 'type': 'tuple', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'bqm'}; {'id': '228', 'type': 'dictionary_splat', 'children': ['229']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'vectors'}
def sample(self, bqm, **parameters): child = self.child cutoff = self._cutoff cutoff_vartype = self._cutoff_vartype comp = self._comparison if cutoff_vartype is dimod.SPIN: original = bqm.spin else: original = bqm.binary new = type(bqm)(original.linear, ((u, v, bias) for (u, v), bias in original.quadratic.items() if not comp(abs(bias), cutoff)), original.offset, original.vartype) isolated = [v for v in new if not new.adj[v]] new.remove_variables_from(isolated) if isolated and len(new) == 0: v = isolated.pop() new.linear[v] = original.linear[v] sampleset = child.sample(new, **parameters).change_vartype(bqm.vartype, inplace=True) if isolated: samples, variables = _restore_isolated(sampleset, bqm, isolated) else: samples = sampleset.record.sample variables = sampleset.variables vectors = sampleset.data_vectors vectors.pop('energy') return dimod.SampleSet.from_samples_bqm((samples, variables), bqm, **vectors)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'sample_poly'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'poly'}; {'id': '6', 'type': 'dictionary_splat_pattern', 'children': ['7']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '8', 'type': 'block', 'children': ['9', '15', '21', '27', '33', '64', '104', '128', '144', '171', '192', '222', '228', '235']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'cutoff'}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': '_cutoff'}; {'id': '21', 'type': 'expression_statement', 'children': ['22']}; {'id': '22', 'type': 'assignment', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'cutoff_vartype'}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': '_cutoff_vartype'}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'comp'}; {'id': '30', 'type': 'attribute', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '32', 'type': 'identifier', 'children': [], 'value': '_comparison'}; {'id': '33', 'type': 'if_statement', 'children': ['34', '39', '51']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'is'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'cutoff_vartype'}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'dimod'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'SPIN'}; {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'original'}; {'id': '43', 'type': 'call', 'children': ['44', '47']}; {'id': '44', 'type': 'attribute', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'poly'}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'to_spin'}; {'id': '47', 'type': 'argument_list', 'children': ['48']}; {'id': '48', 'type': 'keyword_argument', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '50', 'type': 'False', 'children': []}; {'id': '51', 'type': 'else_clause', 'children': ['52']}; {'id': '52', 'type': 'block', 'children': ['53']}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'original'}; {'id': '56', 'type': 'call', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'poly'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'to_binary'}; {'id': '60', 'type': 'argument_list', 'children': ['61']}; {'id': '61', 'type': 'keyword_argument', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'copy'}; {'id': '63', 'type': 'False', 'children': []}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '67', 'type': 'call', 'children': ['68', '72']}; {'id': '68', 'type': 'call', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'poly'}; {'id': '72', 'type': 'argument_list', 'children': ['73', '103']}; {'id': '73', 'type': 'generator_expression', 'children': ['74', '77', '86']}; {'id': '74', 'type': 'tuple', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'term'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'bias'}; {'id': '77', 'type': 'for_in_clause', 'children': ['78', '81']}; {'id': '78', 'type': 'pattern_list', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'term'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'bias'}; {'id': '81', 'type': 'call', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'original'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '85', 'type': 'argument_list', 'children': []}; {'id': '86', 'type': 'if_clause', 'children': ['87']}; {'id': '87', 'type': 'boolean_operator', 'children': ['88', '94'], 'value': 'and'}; {'id': '88', 'type': 'comparison_operator', 'children': ['89', '93'], 'value': '>'}; {'id': '89', 'type': 'call', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '91', 'type': 'argument_list', 'children': ['92']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'term'}; {'id': '93', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '94', 'type': 'not_operator', 'children': ['95']}; {'id': '95', 'type': 'call', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'comp'}; {'id': '97', 'type': 'argument_list', 'children': ['98', '102']}; {'id': '98', 'type': 'call', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'abs'}; {'id': '100', 'type': 'argument_list', 'children': ['101']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'bias'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'cutoff'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'cutoff_vartype'}; {'id': '104', 'type': 'for_statement', 'children': ['105', '106', '109']}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '106', 'type': 'attribute', 'children': ['107', '108']}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '109', 'type': 'block', 'children': ['110', '115']}; {'id': '110', 'type': 'expression_statement', 'children': ['111']}; {'id': '111', 'type': 'assignment', 'children': ['112', '113']}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'term'}; {'id': '113', 'type': 'expression_list', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'v'}; {'id': '115', 'type': 'if_statement', 'children': ['116', '119']}; {'id': '116', 'type': 'comparison_operator', 'children': ['117', '118'], 'value': 'in'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'term'}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'original'}; {'id': '119', 'type': 'block', 'children': ['120']}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}; {'id': '121', 'type': 'assignment', 'children': ['122', '125']}; {'id': '122', 'type': 'subscript', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'term'}; {'id': '125', 'type': 'subscript', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'original'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'term'}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}; {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'isolated'}; {'id': '131', 'type': 'call', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'list'}; {'id': '133', 'type': 'argument_list', 'children': ['134']}; {'id': '134', 'type': 'call', 'children': ['135', '140']}; {'id': '135', 'type': 'attribute', 'children': ['136', '139']}; {'id': '136', 'type': 'attribute', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'original'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'difference'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}; {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '144', 'type': 'if_statement', 'children': ['145', '153']}; {'id': '145', 'type': 'boolean_operator', 'children': ['146', '147'], 'value': 'and'}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'isolated'}; {'id': '147', 'type': 'comparison_operator', 'children': ['148', '152'], 'value': '=='}; {'id': '148', 'type': 'call', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '150', 'type': 'argument_list', 'children': ['151']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '152', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '153', 'type': 'block', 'children': ['154', '163']}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}; {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'term'}; {'id': '157', 'type': 'expression_list', 'children': ['158']}; {'id': '158', 'type': 'call', 'children': ['159', '162']}; {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'isolated'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '162', 'type': 'argument_list', 'children': []}; {'id': '163', 'type': 'expression_statement', 'children': ['164']}; {'id': '164', 'type': 'assignment', 'children': ['165', '168']}; {'id': '165', 'type': 'subscript', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'term'}; {'id': '168', 'type': 'subscript', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'original'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'term'}; {'id': '171', 'type': 'expression_statement', 'children': ['172']}; {'id': '172', 'type': 'assignment', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'sampleset'}; {'id': '174', 'type': 'call', 'children': ['175', '185']}; {'id': '175', 'type': 'attribute', 'children': ['176', '184']}; {'id': '176', 'type': 'call', 'children': ['177', '180']}; {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'child'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'sample_poly'}; {'id': '180', 'type': 'argument_list', 'children': ['181', '182']}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'new'}; {'id': '182', 'type': 'dictionary_splat', 'children': ['183']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'change_vartype'}; {'id': '185', 'type': 'argument_list', 'children': ['186', '189']}; {'id': '186', 'type': 'attribute', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'poly'}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'vartype'}; {'id': '189', 'type': 'keyword_argument', 'children': ['190', '191']}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'inplace'}; {'id': '191', 'type': 'True', 'children': []}; {'id': '192', 'type': 'if_statement', 'children': ['193', '194', '206']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'isolated'}; {'id': '194', 'type': 'block', 'children': ['195']}; {'id': '195', 'type': 'expression_statement', 'children': ['196']}; {'id': '196', 'type': 'assignment', 'children': ['197', '200']}; {'id': '197', 'type': 'pattern_list', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '200', 'type': 'call', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': '_restore_isolated_higherorder'}; {'id': '202', 'type': 'argument_list', 'children': ['203', '204', '205']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'sampleset'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'poly'}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'isolated'}; {'id': '206', 'type': 'else_clause', 'children': ['207']}; {'id': '207', 'type': 'block', 'children': ['208', '216']}; {'id': '208', 'type': 'expression_statement', 'children': ['209']}; {'id': '209', 'type': 'assignment', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '211', 'type': 'attribute', 'children': ['212', '215']}; {'id': '212', 'type': 'attribute', 'children': ['213', '214']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'sampleset'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'record'}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'sample'}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}; {'id': '217', 'type': 'assignment', 'children': ['218', '219']}; {'id': '218', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'sampleset'}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}; {'id': '223', 'type': 'assignment', 'children': ['224', '225']}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'vectors'}; {'id': '225', 'type': 'attribute', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'sampleset'}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'data_vectors'}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}; {'id': '229', 'type': 'call', 'children': ['230', '233']}; {'id': '230', 'type': 'attribute', 'children': ['231', '232']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'vectors'}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'pop'}; {'id': '233', 'type': 'argument_list', 'children': ['234']}; {'id': '234', 'type': 'string', 'children': [], 'value': "'energy'"}; {'id': '235', 'type': 'return_statement', 'children': ['236']}; {'id': '236', 'type': 'call', 'children': ['237', '242']}; {'id': '237', 'type': 'attribute', 'children': ['238', '241']}; {'id': '238', 'type': 'attribute', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'dimod'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'SampleSet'}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'from_samples_bqm'}; {'id': '242', 'type': 'argument_list', 'children': ['243', '246', '247']}; {'id': '243', 'type': 'tuple', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'samples'}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'variables'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': 'poly'}; {'id': '247', 'type': 'dictionary_splat', 'children': ['248']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'vectors'}
def sample_poly(self, poly, **kwargs): child = self.child cutoff = self._cutoff cutoff_vartype = self._cutoff_vartype comp = self._comparison if cutoff_vartype is dimod.SPIN: original = poly.to_spin(copy=False) else: original = poly.to_binary(copy=False) new = type(poly)(((term, bias) for term, bias in original.items() if len(term) > 1 and not comp(abs(bias), cutoff)), cutoff_vartype) for v in new.variables: term = v, if term in original: new[term] = original[term] isolated = list(original.variables.difference(new.variables)) if isolated and len(new) == 0: term = isolated.pop(), new[term] = original[term] sampleset = child.sample_poly(new, **kwargs).change_vartype(poly.vartype, inplace=True) if isolated: samples, variables = _restore_isolated_higherorder(sampleset, poly, isolated) else: samples = sampleset.record.sample variables = sampleset.variables vectors = sampleset.data_vectors vectors.pop('energy') return dimod.SampleSet.from_samples_bqm((samples, variables), poly, **vectors)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'diagnose_embedding'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'emb'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '7', 'type': 'block', 'children': ['8', '25', '42', '46', '52', '169', '177', '204']}; {'id': '8', 'type': 'if_statement', 'children': ['9', '15']}; {'id': '9', 'type': 'not_operator', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '12', 'type': 'argument_list', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '14', 'type': 'string', 'children': [], 'value': "'edges'"}; {'id': '15', 'type': 'block', 'children': ['16']}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'nx'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'Graph'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '25', 'type': 'if_statement', 'children': ['26', '32']}; {'id': '26', 'type': 'not_operator', 'children': ['27']}; {'id': '27', 'type': 'call', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'hasattr'}; {'id': '29', 'type': 'argument_list', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '31', 'type': 'string', 'children': [], 'value': "'edges'"}; {'id': '32', 'type': 'block', 'children': ['33']}; {'id': '33', 'type': 'expression_statement', 'children': ['34']}; {'id': '34', 'type': 'assignment', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '36', 'type': 'call', 'children': ['37', '40']}; {'id': '37', 'type': 'attribute', 'children': ['38', '39']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'nx'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'Graph'}; {'id': '40', 'type': 'argument_list', 'children': ['41']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '45', 'type': 'dictionary', 'children': []}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'embedded'}; {'id': '49', 'type': 'call', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '51', 'type': 'argument_list', 'children': []}; {'id': '52', 'type': 'for_statement', 'children': ['53', '54', '55']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '54', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '55', 'type': 'block', 'children': ['56', '80', '89', '93', '140']}; {'id': '56', 'type': 'try_statement', 'children': ['57', '73']}; {'id': '57', 'type': 'block', 'children': ['58', '64']}; {'id': '58', 'type': 'expression_statement', 'children': ['59']}; {'id': '59', 'type': 'assignment', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'embx'}; {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'emb'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '64', 'type': 'expression_statement', 'children': ['65']}; {'id': '65', 'type': 'assignment', 'children': ['66', '67']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'missing_chain'}; {'id': '67', 'type': 'comparison_operator', 'children': ['68', '72'], 'value': '=='}; {'id': '68', 'type': 'call', 'children': ['69', '70']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '70', 'type': 'argument_list', 'children': ['71']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'embx'}; {'id': '72', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '73', 'type': 'except_clause', 'children': ['74', '75']}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'KeyError'}; {'id': '75', 'type': 'block', 'children': ['76']}; {'id': '76', 'type': 'expression_statement', 'children': ['77']}; {'id': '77', 'type': 'assignment', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'missing_chain'}; {'id': '79', 'type': 'True', 'children': []}; {'id': '80', 'type': 'if_statement', 'children': ['81', '82']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'missing_chain'}; {'id': '82', 'type': 'block', 'children': ['83', '88']}; {'id': '83', 'type': 'expression_statement', 'children': ['84']}; {'id': '84', 'type': 'yield', 'children': ['85']}; {'id': '85', 'type': 'expression_list', 'children': ['86', '87']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'MissingChainError'}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '88', 'type': 'continue_statement', 'children': []}; {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'all_present'}; {'id': '92', 'type': 'True', 'children': []}; {'id': '93', 'type': 'for_statement', 'children': ['94', '95', '96']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'embx'}; {'id': '96', 'type': 'block', 'children': ['97']}; {'id': '97', 'type': 'if_statement', 'children': ['98', '107', '117', '132']}; {'id': '98', 'type': 'comparison_operator', 'children': ['99', '106'], 'value': '!='}; {'id': '99', 'type': 'call', 'children': ['100', '103']}; {'id': '100', 'type': 'attribute', 'children': ['101', '102']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'get'}; {'id': '103', 'type': 'argument_list', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '107', 'type': 'block', 'children': ['108']}; {'id': '108', 'type': 'expression_statement', 'children': ['109']}; {'id': '109', 'type': 'yield', 'children': ['110']}; {'id': '110', 'type': 'expression_list', 'children': ['111', '112', '113', '114']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'ChainOverlapError'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '114', 'type': 'subscript', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '117', 'type': 'elif_clause', 'children': ['118', '121']}; {'id': '118', 'type': 'comparison_operator', 'children': ['119', '120'], 'value': 'not'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '121', 'type': 'block', 'children': ['122', '126']}; {'id': '122', 'type': 'expression_statement', 'children': ['123']}; {'id': '123', 'type': 'assignment', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'all_present'}; {'id': '125', 'type': 'False', 'children': []}; {'id': '126', 'type': 'expression_statement', 'children': ['127']}; {'id': '127', 'type': 'yield', 'children': ['128']}; {'id': '128', 'type': 'expression_list', 'children': ['129', '130', '131']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'InvalidNodeError'}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '132', 'type': 'else_clause', 'children': ['133']}; {'id': '133', 'type': 'block', 'children': ['134']}; {'id': '134', 'type': 'expression_statement', 'children': ['135']}; {'id': '135', 'type': 'assignment', 'children': ['136', '139']}; {'id': '136', 'type': 'subscript', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '140', 'type': 'if_statement', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'all_present'}; {'id': '142', 'type': 'block', 'children': ['143', '150']}; {'id': '143', 'type': 'expression_statement', 'children': ['144']}; {'id': '144', 'type': 'call', 'children': ['145', '148']}; {'id': '145', 'type': 'attribute', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'embedded'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'add'}; {'id': '148', 'type': 'argument_list', 'children': ['149']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '150', 'type': 'if_statement', 'children': ['151', '163']}; {'id': '151', 'type': 'not_operator', 'children': ['152']}; {'id': '152', 'type': 'call', 'children': ['153', '156']}; {'id': '153', 'type': 'attribute', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'nx'}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'is_connected'}; {'id': '156', 'type': 'argument_list', 'children': ['157']}; {'id': '157', 'type': 'call', 'children': ['158', '161']}; {'id': '158', 'type': 'attribute', 'children': ['159', '160']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'subgraph'}; {'id': '161', 'type': 'argument_list', 'children': ['162']}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'embx'}; {'id': '163', 'type': 'block', 'children': ['164']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}; {'id': '165', 'type': 'yield', 'children': ['166']}; {'id': '166', 'type': 'expression_list', 'children': ['167', '168']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'DisconnectedChainError'}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '169', 'type': 'expression_statement', 'children': ['170']}; {'id': '170', 'type': 'assignment', 'children': ['171', '172']}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'yielded'}; {'id': '172', 'type': 'call', 'children': ['173', '176']}; {'id': '173', 'type': 'attribute', 'children': ['174', '175']}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'nx'}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'Graph'}; {'id': '176', 'type': 'argument_list', 'children': []}; {'id': '177', 'type': 'for_statement', 'children': ['178', '181', '191']}; {'id': '178', 'type': 'pattern_list', 'children': ['179', '180']}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '181', 'type': 'call', 'children': ['182', '190']}; {'id': '182', 'type': 'attribute', 'children': ['183', '189']}; {'id': '183', 'type': 'call', 'children': ['184', '187']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'target'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'subgraph'}; {'id': '187', 'type': 'argument_list', 'children': ['188']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'edges'}; {'id': '190', 'type': 'argument_list', 'children': []}; {'id': '191', 'type': 'block', 'children': ['192']}; {'id': '192', 'type': 'expression_statement', 'children': ['193']}; {'id': '193', 'type': 'call', 'children': ['194', '197']}; {'id': '194', 'type': 'attribute', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'yielded'}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'add_edge'}; {'id': '197', 'type': 'argument_list', 'children': ['198', '201']}; {'id': '198', 'type': 'subscript', 'children': ['199', '200']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'p'}; {'id': '201', 'type': 'subscript', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'label'}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'q'}; {'id': '204', 'type': 'for_statement', 'children': ['205', '208', '213']}; {'id': '205', 'type': 'pattern_list', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '208', 'type': 'call', 'children': ['209', '212']}; {'id': '209', 'type': 'attribute', 'children': ['210', '211']}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'edges'}; {'id': '212', 'type': 'argument_list', 'children': []}; {'id': '213', 'type': 'block', 'children': ['214', '220']}; {'id': '214', 'type': 'if_statement', 'children': ['215', '218']}; {'id': '215', 'type': 'comparison_operator', 'children': ['216', '217'], 'value': '=='}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '218', 'type': 'block', 'children': ['219']}; {'id': '219', 'type': 'continue_statement', 'children': []}; {'id': '220', 'type': 'if_statement', 'children': ['221', '237']}; {'id': '221', 'type': 'boolean_operator', 'children': ['222', '229'], 'value': 'and'}; {'id': '222', 'type': 'boolean_operator', 'children': ['223', '226'], 'value': 'and'}; {'id': '223', 'type': 'comparison_operator', 'children': ['224', '225'], 'value': 'in'}; {'id': '224', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'embedded'}; {'id': '226', 'type': 'comparison_operator', 'children': ['227', '228'], 'value': 'in'}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'embedded'}; {'id': '229', 'type': 'not_operator', 'children': ['230']}; {'id': '230', 'type': 'call', 'children': ['231', '234']}; {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'yielded'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'has_edge'}; {'id': '234', 'type': 'argument_list', 'children': ['235', '236']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'y'}; {'id': '237', 'type': 'block', 'children': ['238']}; {'id': '238', 'type': 'expression_statement', 'children': ['239']}; {'id': '239', 'type': 'yield', 'children': ['240']}; {'id': '240', 'type': 'expression_list', 'children': ['241', '242', '243']}; {'id': '241', 'type': 'identifier', 'children': [], 'value': 'MissingEdgeError'}; {'id': '242', 'type': 'identifier', 'children': [], 'value': 'x'}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'y'}
def diagnose_embedding(emb, source, target): if not hasattr(source, 'edges'): source = nx.Graph(source) if not hasattr(target, 'edges'): target = nx.Graph(target) label = {} embedded = set() for x in source: try: embx = emb[x] missing_chain = len(embx) == 0 except KeyError: missing_chain = True if missing_chain: yield MissingChainError, x continue all_present = True for q in embx: if label.get(q, x) != x: yield ChainOverlapError, q, x, label[q] elif q not in target: all_present = False yield InvalidNodeError, x, q else: label[q] = x if all_present: embedded.add(x) if not nx.is_connected(target.subgraph(embx)): yield DisconnectedChainError, x yielded = nx.Graph() for p, q in target.subgraph(label).edges(): yielded.add_edge(label[p], label[q]) for x, y in source.edges(): if x == y: continue if x in embedded and y in embedded and not yielded.has_edge(x, y): yield MissingEdgeError, x, y
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '18']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'response'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8', '13', '16']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '10', 'type': 'attribute', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'HTTPStatus'}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'OK'}; {'id': '13', 'type': 'default_parameter', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'description'}; {'id': '15', 'type': 'None', 'children': []}; {'id': '16', 'type': 'dictionary_splat_pattern', 'children': ['17']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '18', 'type': 'block', 'children': ['19', '26', '37', '89', '100', '217', '339']}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '22', 'type': 'call', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'HTTPStatus'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '26', 'type': 'if_statement', 'children': ['27', '32']}; {'id': '27', 'type': 'comparison_operator', 'children': ['28', '29'], 'value': 'is'}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'HTTPStatus'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'NO_CONTENT'}; {'id': '32', 'type': 'block', 'children': ['33']}; {'id': '33', 'type': 'assert_statement', 'children': ['34']}; {'id': '34', 'type': 'comparison_operator', 'children': ['35', '36'], 'value': 'is'}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '36', 'type': 'None', 'children': []}; {'id': '37', 'type': 'if_statement', 'children': ['38', '51']}; {'id': '38', 'type': 'boolean_operator', 'children': ['39', '42'], 'value': 'and'}; {'id': '39', 'type': 'comparison_operator', 'children': ['40', '41'], 'value': 'is'}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '41', 'type': 'None', 'children': []}; {'id': '42', 'type': 'comparison_operator', 'children': ['43', '44'], 'value': 'not'}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '44', 'type': 'set', 'children': ['45', '48']}; {'id': '45', 'type': 'attribute', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'HTTPStatus'}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'ACCEPTED'}; {'id': '48', 'type': 'attribute', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'HTTPStatus'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'NO_CONTENT'}; {'id': '51', 'type': 'block', 'children': ['52', '68']}; {'id': '52', 'type': 'if_statement', 'children': ['53', '60']}; {'id': '53', 'type': 'comparison_operator', 'children': ['54', '57'], 'value': 'not'}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'http_exceptions'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'default_exceptions'}; {'id': '60', 'type': 'block', 'children': ['61']}; {'id': '61', 'type': 'raise_statement', 'children': ['62']}; {'id': '62', 'type': 'call', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '64', 'type': 'argument_list', 'children': ['65']}; {'id': '65', 'type': 'binary_operator', 'children': ['66', '67'], 'value': '%'}; {'id': '66', 'type': 'string', 'children': [], 'value': '"`model` parameter is required for code %d"'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '71', 'type': 'call', 'children': ['72', '75']}; {'id': '72', 'type': 'attribute', 'children': ['73', '74']}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '75', 'type': 'argument_list', 'children': ['76', '81']}; {'id': '76', 'type': 'keyword_argument', 'children': ['77', '78']}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'name'}; {'id': '78', 'type': 'binary_operator', 'children': ['79', '80'], 'value': '%'}; {'id': '79', 'type': 'string', 'children': [], 'value': "'HTTPError%d'"}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '81', 'type': 'keyword_argument', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '83', 'type': 'call', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'DefaultHTTPErrorSchema'}; {'id': '85', 'type': 'argument_list', 'children': ['86']}; {'id': '86', 'type': 'keyword_argument', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'http_code'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '89', 'type': 'if_statement', 'children': ['90', '93']}; {'id': '90', 'type': 'comparison_operator', 'children': ['91', '92'], 'value': 'is'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'description'}; {'id': '92', 'type': 'None', 'children': []}; {'id': '93', 'type': 'block', 'children': ['94']}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}; {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'description'}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'description'}; {'id': '100', 'type': 'function_definition', 'children': ['101', '102', '104']}; {'id': '101', 'type': 'function_name', 'children': [], 'value': 'response_serializer_decorator'}; {'id': '102', 'type': 'parameters', 'children': ['103']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '104', 'type': 'block', 'children': ['105', '215']}; {'id': '105', 'type': 'function_definition', 'children': ['106', '107', '112']}; {'id': '106', 'type': 'function_name', 'children': [], 'value': 'dump_wrapper'}; {'id': '107', 'type': 'parameters', 'children': ['108', '110']}; {'id': '108', 'type': 'list_splat_pattern', 'children': ['109']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '110', 'type': 'dictionary_splat_pattern', 'children': ['111']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '112', 'type': 'block', 'children': ['113', '123', '127', '191', '210']}; {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '116', 'type': 'call', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'func'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '121']}; {'id': '119', 'type': 'list_splat', 'children': ['120']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'args'}; {'id': '121', 'type': 'dictionary_splat', 'children': ['122']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'kwargs'}; {'id': '123', 'type': 'expression_statement', 'children': ['124']}; {'id': '124', 'type': 'assignment', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'extra_headers'}; {'id': '126', 'type': 'None', 'children': []}; {'id': '127', 'type': 'if_statement', 'children': ['128', '131', '153', '168', '185']}; {'id': '128', 'type': 'comparison_operator', 'children': ['129', '130'], 'value': 'is'}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '130', 'type': 'None', 'children': []}; {'id': '131', 'type': 'block', 'children': ['132', '144']}; {'id': '132', 'type': 'if_statement', 'children': ['133', '136']}; {'id': '133', 'type': 'comparison_operator', 'children': ['134', '135'], 'value': 'is'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '135', 'type': 'None', 'children': []}; {'id': '136', 'type': 'block', 'children': ['137']}; {'id': '137', 'type': 'raise_statement', 'children': ['138']}; {'id': '138', 'type': 'call', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}; {'id': '141', 'type': 'binary_operator', 'children': ['142', '143'], 'value': '%'}; {'id': '142', 'type': 'string', 'children': [], 'value': '"Response cannot not be None with HTTP status %d"'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '144', 'type': 'return_statement', 'children': ['145']}; {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'flask'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'Response'}; {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'keyword_argument', 'children': ['151', '152']}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'status'}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '153', 'type': 'elif_clause', 'children': ['154', '165']}; {'id': '154', 'type': 'boolean_operator', 'children': ['155', '162'], 'value': 'or'}; {'id': '155', 'type': 'call', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '157', 'type': 'argument_list', 'children': ['158', '159']}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '159', 'type': 'attribute', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'flask'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'Response'}; {'id': '162', 'type': 'comparison_operator', 'children': ['163', '164'], 'value': 'is'}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '164', 'type': 'None', 'children': []}; {'id': '165', 'type': 'block', 'children': ['166']}; {'id': '166', 'type': 'return_statement', 'children': ['167']}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '168', 'type': 'elif_clause', 'children': ['169', '174']}; {'id': '169', 'type': 'call', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '171', 'type': 'argument_list', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'tuple'}; {'id': '174', 'type': 'block', 'children': ['175']}; {'id': '175', 'type': 'expression_statement', 'children': ['176']}; {'id': '176', 'type': 'assignment', 'children': ['177', '181']}; {'id': '177', 'type': 'pattern_list', 'children': ['178', '179', '180']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': '_code'}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'extra_headers'}; {'id': '181', 'type': 'call', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'unpack'}; {'id': '183', 'type': 'argument_list', 'children': ['184']}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '185', 'type': 'else_clause', 'children': ['186']}; {'id': '186', 'type': 'block', 'children': ['187']}; {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'assignment', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': '_code'}; {'id': '190', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '191', 'type': 'if_statement', 'children': ['192', '198']}; {'id': '192', 'type': 'comparison_operator', 'children': ['193', '197'], 'value': 'is'}; {'id': '193', 'type': 'call', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'HTTPStatus'}; {'id': '195', 'type': 'argument_list', 'children': ['196']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': '_code'}; {'id': '197', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '198', 'type': 'block', 'children': ['199']}; {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '202', 'type': 'attribute', 'children': ['203', '209']}; {'id': '203', 'type': 'call', 'children': ['204', '207']}; {'id': '204', 'type': 'attribute', 'children': ['205', '206']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'dump'}; {'id': '207', 'type': 'argument_list', 'children': ['208']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '210', 'type': 'return_statement', 'children': ['211']}; {'id': '211', 'type': 'expression_list', 'children': ['212', '213', '214']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'response'}; {'id': '213', 'type': 'identifier', 'children': [], 'value': '_code'}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'extra_headers'}; {'id': '215', 'type': 'return_statement', 'children': ['216']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'dump_wrapper'}; {'id': '217', 'type': 'function_definition', 'children': ['218', '219', '221']}; {'id': '218', 'type': 'function_name', 'children': [], 'value': 'decorator'}; {'id': '219', 'type': 'parameters', 'children': ['220']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'func_or_class'}; {'id': '221', 'type': 'block', 'children': ['222', '268', '316', '334']}; {'id': '222', 'type': 'if_statement', 'children': ['223', '230', '235', '253']}; {'id': '223', 'type': 'comparison_operator', 'children': ['224', '227'], 'value': 'in'}; {'id': '224', 'type': 'attribute', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '227', 'type': 'attribute', 'children': ['228', '229']}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'http_exceptions'}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'default_exceptions'}; {'id': '230', 'type': 'block', 'children': ['231']}; {'id': '231', 'type': 'expression_statement', 'children': ['232']}; {'id': '232', 'type': 'assignment', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'decorated_func_or_class'}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'func_or_class'}; {'id': '235', 'type': 'elif_clause', 'children': ['236', '241']}; {'id': '236', 'type': 'call', 'children': ['237', '238']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '238', 'type': 'argument_list', 'children': ['239', '240']}; {'id': '239', 'type': 'identifier', 'children': [], 'value': 'func_or_class'}; {'id': '240', 'type': 'identifier', 'children': [], 'value': 'type'}; {'id': '241', 'type': 'block', 'children': ['242', '249']}; {'id': '242', 'type': 'expression_statement', 'children': ['243']}; {'id': '243', 'type': 'call', 'children': ['244', '247']}; {'id': '244', 'type': 'attribute', 'children': ['245', '246']}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'func_or_class'}; {'id': '246', 'type': 'identifier', 'children': [], 'value': '_apply_decorator_to_methods'}; {'id': '247', 'type': 'argument_list', 'children': ['248']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'response_serializer_decorator'}; {'id': '249', 'type': 'expression_statement', 'children': ['250']}; {'id': '250', 'type': 'assignment', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'decorated_func_or_class'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'func_or_class'}; {'id': '253', 'type': 'else_clause', 'children': ['254']}; {'id': '254', 'type': 'block', 'children': ['255']}; {'id': '255', 'type': 'expression_statement', 'children': ['256']}; {'id': '256', 'type': 'assignment', 'children': ['257', '258']}; {'id': '257', 'type': 'identifier', 'children': [], 'value': 'decorated_func_or_class'}; {'id': '258', 'type': 'call', 'children': ['259', '263']}; {'id': '259', 'type': 'call', 'children': ['260', '261']}; {'id': '260', 'type': 'identifier', 'children': [], 'value': 'wraps'}; {'id': '261', 'type': 'argument_list', 'children': ['262']}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'func_or_class'}; {'id': '263', 'type': 'argument_list', 'children': ['264']}; {'id': '264', 'type': 'call', 'children': ['265', '266']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'response_serializer_decorator'}; {'id': '266', 'type': 'argument_list', 'children': ['267']}; {'id': '267', 'type': 'identifier', 'children': [], 'value': 'func_or_class'}; {'id': '268', 'type': 'if_statement', 'children': ['269', '272', '277']}; {'id': '269', 'type': 'comparison_operator', 'children': ['270', '271'], 'value': 'is'}; {'id': '270', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '271', 'type': 'None', 'children': []}; {'id': '272', 'type': 'block', 'children': ['273']}; {'id': '273', 'type': 'expression_statement', 'children': ['274']}; {'id': '274', 'type': 'assignment', 'children': ['275', '276']}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'api_model'}; {'id': '276', 'type': 'None', 'children': []}; {'id': '277', 'type': 'else_clause', 'children': ['278']}; {'id': '278', 'type': 'block', 'children': ['279', '303']}; {'id': '279', 'type': 'if_statement', 'children': ['280', '285', '290']}; {'id': '280', 'type': 'call', 'children': ['281', '282']}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'isinstance'}; {'id': '282', 'type': 'argument_list', 'children': ['283', '284']}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '284', 'type': 'identifier', 'children': [], 'value': 'Model'}; {'id': '285', 'type': 'block', 'children': ['286']}; {'id': '286', 'type': 'expression_statement', 'children': ['287']}; {'id': '287', 'type': 'assignment', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'api_model'}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '290', 'type': 'else_clause', 'children': ['291']}; {'id': '291', 'type': 'block', 'children': ['292']}; {'id': '292', 'type': 'expression_statement', 'children': ['293']}; {'id': '293', 'type': 'assignment', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'api_model'}; {'id': '295', 'type': 'call', 'children': ['296', '299']}; {'id': '296', 'type': 'attribute', 'children': ['297', '298']}; {'id': '297', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '298', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '299', 'type': 'argument_list', 'children': ['300']}; {'id': '300', 'type': 'keyword_argument', 'children': ['301', '302']}; {'id': '301', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '303', 'type': 'if_statement', 'children': ['304', '310']}; {'id': '304', 'type': 'call', 'children': ['305', '306']}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'getattr'}; {'id': '306', 'type': 'argument_list', 'children': ['307', '308', '309']}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'model'}; {'id': '308', 'type': 'string', 'children': [], 'value': "'many'"}; {'id': '309', 'type': 'False', 'children': []}; {'id': '310', 'type': 'block', 'children': ['311']}; {'id': '311', 'type': 'expression_statement', 'children': ['312']}; {'id': '312', 'type': 'assignment', 'children': ['313', '314']}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'api_model'}; {'id': '314', 'type': 'list', 'children': ['315'], 'value': '[api_model]'}; {'id': '315', 'type': 'identifier', 'children': [], 'value': 'api_model'}; {'id': '316', 'type': 'expression_statement', 'children': ['317']}; {'id': '317', 'type': 'assignment', 'children': ['318', '319']}; {'id': '318', 'type': 'identifier', 'children': [], 'value': 'doc_decorator'}; {'id': '319', 'type': 'call', 'children': ['320', '323']}; {'id': '320', 'type': 'attribute', 'children': ['321', '322']}; {'id': '321', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'doc'}; {'id': '323', 'type': 'argument_list', 'children': ['324']}; {'id': '324', 'type': 'keyword_argument', 'children': ['325', '326']}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'responses'}; {'id': '326', 'type': 'dictionary', 'children': ['327']}; {'id': '327', 'type': 'pair', 'children': ['328', '331']}; {'id': '328', 'type': 'attribute', 'children': ['329', '330']}; {'id': '329', 'type': 'identifier', 'children': [], 'value': 'code'}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'value'}; {'id': '331', 'type': 'tuple', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'description'}; {'id': '333', 'type': 'identifier', 'children': [], 'value': 'api_model'}; {'id': '334', 'type': 'return_statement', 'children': ['335']}; {'id': '335', 'type': 'call', 'children': ['336', '337']}; {'id': '336', 'type': 'identifier', 'children': [], 'value': 'doc_decorator'}; {'id': '337', 'type': 'argument_list', 'children': ['338']}; {'id': '338', 'type': 'identifier', 'children': [], 'value': 'decorated_func_or_class'}; {'id': '339', 'type': 'return_statement', 'children': ['340']}; {'id': '340', 'type': 'identifier', 'children': [], 'value': 'decorator'}
def response(self, model=None, code=HTTPStatus.OK, description=None, **kwargs): code = HTTPStatus(code) if code is HTTPStatus.NO_CONTENT: assert model is None if model is None and code not in {HTTPStatus.ACCEPTED, HTTPStatus.NO_CONTENT}: if code.value not in http_exceptions.default_exceptions: raise ValueError("`model` parameter is required for code %d" % code) model = self.model( name='HTTPError%d' % code, model=DefaultHTTPErrorSchema(http_code=code) ) if description is None: description = code.description def response_serializer_decorator(func): def dump_wrapper(*args, **kwargs): response = func(*args, **kwargs) extra_headers = None if response is None: if model is not None: raise ValueError("Response cannot not be None with HTTP status %d" % code) return flask.Response(status=code) elif isinstance(response, flask.Response) or model is None: return response elif isinstance(response, tuple): response, _code, extra_headers = unpack(response) else: _code = code if HTTPStatus(_code) is code: response = model.dump(response).data return response, _code, extra_headers return dump_wrapper def decorator(func_or_class): if code.value in http_exceptions.default_exceptions: decorated_func_or_class = func_or_class elif isinstance(func_or_class, type): func_or_class._apply_decorator_to_methods(response_serializer_decorator) decorated_func_or_class = func_or_class else: decorated_func_or_class = wraps(func_or_class)( response_serializer_decorator(func_or_class) ) if model is None: api_model = None else: if isinstance(model, Model): api_model = model else: api_model = self.model(model=model) if getattr(model, 'many', False): api_model = [api_model] doc_decorator = self.doc( responses={ code.value: (description, api_model) } ) return doc_decorator(decorated_func_or_class) return decorator
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'enrich_items'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'ocean_backend'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'events'}; {'id': '8', 'type': 'False', 'children': []}; {'id': '9', 'type': 'block', 'children': ['10', '18', '22', '26', '30', '38', '42', '52', '68', '236', '253', '260', '297', '309']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'max_items'}; {'id': '13', 'type': 'attribute', 'children': ['14', '17']}; {'id': '14', 'type': 'attribute', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'elastic'}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'max_items_bulk'}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'assignment', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'current'}; {'id': '21', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'assignment', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '25', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'bulk_json'}; {'id': '29', 'type': 'string', 'children': [], 'value': '""'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '33', 'type': 'call', 'children': ['34', '37']}; {'id': '34', 'type': 'attribute', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'ocean_backend'}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'fetch'}; {'id': '37', 'type': 'argument_list', 'children': []}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'images_items'}; {'id': '41', 'type': 'dictionary', 'children': []}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '45', 'type': 'binary_operator', 'children': ['46', '51'], 'value': '+'}; {'id': '46', 'type': 'attribute', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'elastic'}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'index_url'}; {'id': '51', 'type': 'string', 'children': [], 'value': "'/items/_bulk'"}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '57', 'type': 'argument_list', 'children': ['58', '59', '67']}; {'id': '58', 'type': 'string', 'children': [], 'value': '"Adding items to %s (in %i packs)"'}; {'id': '59', 'type': 'call', 'children': ['60', '65']}; {'id': '60', 'type': 'attribute', 'children': ['61', '64']}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'elastic'}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'anonymize_url'}; {'id': '65', 'type': 'argument_list', 'children': ['66']}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'max_items'}; {'id': '68', 'type': 'for_statement', 'children': ['69', '70', '71']}; {'id': '69', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'items'}; {'id': '71', 'type': 'block', 'children': ['72', '128', '137', '146', '160', '166', '170']}; {'id': '72', 'type': 'if_statement', 'children': ['73', '76']}; {'id': '73', 'type': 'comparison_operator', 'children': ['74', '75'], 'value': '>='}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'current'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'max_items'}; {'id': '76', 'type': 'block', 'children': ['77', '89', '103', '120', '124']}; {'id': '77', 'type': 'expression_statement', 'children': ['78']}; {'id': '78', 'type': 'augmented_assignment', 'children': ['79', '80'], 'value': '+='}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '80', 'type': 'call', 'children': ['81', '86']}; {'id': '81', 'type': 'attribute', 'children': ['82', '85']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'elastic'}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'safe_put_bulk'}; {'id': '86', 'type': 'argument_list', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'bulk_json'}; {'id': '89', 'type': 'expression_statement', 'children': ['90']}; {'id': '90', 'type': 'assignment', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'json_size'}; {'id': '92', 'type': 'binary_operator', 'children': ['93', '99'], 'value': '/'}; {'id': '93', 'type': 'call', 'children': ['94', '97']}; {'id': '94', 'type': 'attribute', 'children': ['95', '96']}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'sys'}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'getsizeof'}; {'id': '97', 'type': 'argument_list', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'bulk_json'}; {'id': '99', 'type': '()', 'children': ['100']}; {'id': '100', 'type': 'binary_operator', 'children': ['101', '102'], 'value': '*'}; {'id': '101', 'type': 'integer', 'children': [], 'value': '1024'}; {'id': '102', 'type': 'integer', 'children': [], 'value': '1024'}; {'id': '103', 'type': 'expression_statement', 'children': ['104']}; {'id': '104', 'type': 'call', 'children': ['105', '108']}; {'id': '105', 'type': 'attribute', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '107', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '108', 'type': 'argument_list', 'children': ['109', '110', '111', '119']}; {'id': '109', 'type': 'string', 'children': [], 'value': '"Added %i items to %s (%0.2f MB)"'}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '111', 'type': 'call', 'children': ['112', '117']}; {'id': '112', 'type': 'attribute', 'children': ['113', '116']}; {'id': '113', 'type': 'attribute', 'children': ['114', '115']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'elastic'}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'anonymize_url'}; {'id': '117', 'type': 'argument_list', 'children': ['118']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'json_size'}; {'id': '120', 'type': 'expression_statement', 'children': ['121']}; {'id': '121', 'type': 'assignment', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'bulk_json'}; {'id': '123', 'type': 'string', 'children': [], 'value': '""'}; {'id': '124', 'type': 'expression_statement', 'children': ['125']}; {'id': '125', 'type': 'assignment', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'current'}; {'id': '127', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}; {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'rich_item'}; {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'attribute', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '134', 'type': 'identifier', 'children': [], 'value': 'get_rich_item'}; {'id': '135', 'type': 'argument_list', 'children': ['136']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '137', 'type': 'expression_statement', 'children': ['138']}; {'id': '138', 'type': 'assignment', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'data_json'}; {'id': '140', 'type': 'call', 'children': ['141', '144']}; {'id': '141', 'type': 'attribute', 'children': ['142', '143']}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'dumps'}; {'id': '144', 'type': 'argument_list', 'children': ['145']}; {'id': '145', 'type': 'identifier', 'children': [], 'value': 'rich_item'}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}; {'id': '147', 'type': 'augmented_assignment', 'children': ['148', '149'], 'value': '+='}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'bulk_json'}; {'id': '149', 'type': 'binary_operator', 'children': ['150', '151', '152'], 'value': '%'}; {'id': '150', 'type': 'string', 'children': [], 'value': '\'{"index" : {"_id" : "%s" } }\\n\''}; {'id': '151', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '152', 'type': '()', 'children': ['153']}; {'id': '153', 'type': 'subscript', 'children': ['154', '155']}; {'id': '154', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '155', 'type': 'call', 'children': ['156', '159']}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'get_field_unique_id'}; {'id': '159', 'type': 'argument_list', 'children': []}; {'id': '160', 'type': 'expression_statement', 'children': ['161']}; {'id': '161', 'type': 'augmented_assignment', 'children': ['162', '163'], 'value': '+='}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'bulk_json'}; {'id': '163', 'type': 'binary_operator', 'children': ['164', '165'], 'value': '+'}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'data_json'}; {'id': '165', 'type': 'string', 'children': [], 'value': '"\\n"'}; {'id': '166', 'type': 'expression_statement', 'children': ['167']}; {'id': '167', 'type': 'augmented_assignment', 'children': ['168', '169'], 'value': '+='}; {'id': '168', 'type': 'identifier', 'children': [], 'value': 'current'}; {'id': '169', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '170', 'type': 'if_statement', 'children': ['171', '176', '197']}; {'id': '171', 'type': 'comparison_operator', 'children': ['172', '175'], 'value': 'not'}; {'id': '172', 'type': 'subscript', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'rich_item'}; {'id': '174', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'images_items'}; {'id': '176', 'type': 'block', 'children': ['177', '183', '189']}; {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'assignment', 'children': ['179', '182']}; {'id': '179', 'type': 'subscript', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'rich_item'}; {'id': '181', 'type': 'string', 'children': [], 'value': "'is_docker_image'"}; {'id': '182', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '188']}; {'id': '185', 'type': 'subscript', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'rich_item'}; {'id': '187', 'type': 'string', 'children': [], 'value': "'is_event'"}; {'id': '188', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '189', 'type': 'expression_statement', 'children': ['190']}; {'id': '190', 'type': 'assignment', 'children': ['191', '196']}; {'id': '191', 'type': 'subscript', 'children': ['192', '193']}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'images_items'}; {'id': '193', 'type': 'subscript', 'children': ['194', '195']}; {'id': '194', 'type': 'identifier', 'children': [], 'value': 'rich_item'}; {'id': '195', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'rich_item'}; {'id': '197', 'type': 'else_clause', 'children': ['198']}; {'id': '198', 'type': 'block', 'children': ['199', '209']}; {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'image_date'}; {'id': '202', 'type': 'subscript', 'children': ['203', '208']}; {'id': '203', 'type': 'subscript', 'children': ['204', '205']}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'images_items'}; {'id': '205', 'type': 'subscript', 'children': ['206', '207']}; {'id': '206', 'type': 'identifier', 'children': [], 'value': 'rich_item'}; {'id': '207', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '208', 'type': 'string', 'children': [], 'value': "'last_updated'"}; {'id': '209', 'type': 'if_statement', 'children': ['210', '215']}; {'id': '210', 'type': 'comparison_operator', 'children': ['211', '212'], 'value': '<='}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'image_date'}; {'id': '212', 'type': 'subscript', 'children': ['213', '214']}; {'id': '213', 'type': 'identifier', 'children': [], 'value': 'rich_item'}; {'id': '214', 'type': 'string', 'children': [], 'value': "'last_updated'"}; {'id': '215', 'type': 'block', 'children': ['216', '222', '228']}; {'id': '216', 'type': 'expression_statement', 'children': ['217']}; {'id': '217', 'type': 'assignment', 'children': ['218', '221']}; {'id': '218', 'type': 'subscript', 'children': ['219', '220']}; {'id': '219', 'type': 'identifier', 'children': [], 'value': 'rich_item'}; {'id': '220', 'type': 'string', 'children': [], 'value': "'is_docker_image'"}; {'id': '221', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '222', 'type': 'expression_statement', 'children': ['223']}; {'id': '223', 'type': 'assignment', 'children': ['224', '227']}; {'id': '224', 'type': 'subscript', 'children': ['225', '226']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'rich_item'}; {'id': '226', 'type': 'string', 'children': [], 'value': "'is_event'"}; {'id': '227', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '228', 'type': 'expression_statement', 'children': ['229']}; {'id': '229', 'type': 'assignment', 'children': ['230', '235']}; {'id': '230', 'type': 'subscript', 'children': ['231', '232']}; {'id': '231', 'type': 'identifier', 'children': [], 'value': 'images_items'}; {'id': '232', 'type': 'subscript', 'children': ['233', '234']}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'rich_item'}; {'id': '234', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'rich_item'}; {'id': '236', 'type': 'if_statement', 'children': ['237', '240']}; {'id': '237', 'type': 'comparison_operator', 'children': ['238', '239'], 'value': '>'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'current'}; {'id': '239', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '240', 'type': 'block', 'children': ['241']}; {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'augmented_assignment', 'children': ['243', '244'], 'value': '+='}; {'id': '243', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '244', 'type': 'call', 'children': ['245', '250']}; {'id': '245', 'type': 'attribute', 'children': ['246', '249']}; {'id': '246', 'type': 'attribute', 'children': ['247', '248']}; {'id': '247', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'elastic'}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'safe_put_bulk'}; {'id': '250', 'type': 'argument_list', 'children': ['251', '252']}; {'id': '251', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '252', 'type': 'identifier', 'children': [], 'value': 'bulk_json'}; {'id': '253', 'type': 'if_statement', 'children': ['254', '257']}; {'id': '254', 'type': 'comparison_operator', 'children': ['255', '256'], 'value': '=='}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '256', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '257', 'type': 'block', 'children': ['258']}; {'id': '258', 'type': 'return_statement', 'children': ['259']}; {'id': '259', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '260', 'type': 'for_statement', 'children': ['261', '262', '263']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'image'}; {'id': '262', 'type': 'identifier', 'children': [], 'value': 'images_items'}; {'id': '263', 'type': 'block', 'children': ['264', '270', '279', '291']}; {'id': '264', 'type': 'expression_statement', 'children': ['265']}; {'id': '265', 'type': 'assignment', 'children': ['266', '267']}; {'id': '266', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '267', 'type': 'subscript', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'images_items'}; {'id': '269', 'type': 'identifier', 'children': [], 'value': 'image'}; {'id': '270', 'type': 'expression_statement', 'children': ['271']}; {'id': '271', 'type': 'assignment', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'data_json'}; {'id': '273', 'type': 'call', 'children': ['274', '277']}; {'id': '274', 'type': 'attribute', 'children': ['275', '276']}; {'id': '275', 'type': 'identifier', 'children': [], 'value': 'json'}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'dumps'}; {'id': '277', 'type': 'argument_list', 'children': ['278']}; {'id': '278', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '279', 'type': 'expression_statement', 'children': ['280']}; {'id': '280', 'type': 'augmented_assignment', 'children': ['281', '282'], 'value': '+='}; {'id': '281', 'type': 'identifier', 'children': [], 'value': 'bulk_json'}; {'id': '282', 'type': 'binary_operator', 'children': ['283', '284', '285'], 'value': '%'}; {'id': '283', 'type': 'string', 'children': [], 'value': '\'{"index" : {"_id" : "%s" } }\\n\''}; {'id': '284', 'type': 'line_continuation', 'children': [], 'value': '\\'}; {'id': '285', 'type': '()', 'children': ['286']}; {'id': '286', 'type': 'binary_operator', 'children': ['287', '290'], 'value': '+'}; {'id': '287', 'type': 'subscript', 'children': ['288', '289']}; {'id': '288', 'type': 'identifier', 'children': [], 'value': 'data'}; {'id': '289', 'type': 'string', 'children': [], 'value': "'id'"}; {'id': '290', 'type': 'string', 'children': [], 'value': '"_image"'}; {'id': '291', 'type': 'expression_statement', 'children': ['292']}; {'id': '292', 'type': 'augmented_assignment', 'children': ['293', '294'], 'value': '+='}; {'id': '293', 'type': 'identifier', 'children': [], 'value': 'bulk_json'}; {'id': '294', 'type': 'binary_operator', 'children': ['295', '296'], 'value': '+'}; {'id': '295', 'type': 'identifier', 'children': [], 'value': 'data_json'}; {'id': '296', 'type': 'string', 'children': [], 'value': '"\\n"'}; {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'augmented_assignment', 'children': ['299', '300'], 'value': '+='}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '300', 'type': 'call', 'children': ['301', '306']}; {'id': '301', 'type': 'attribute', 'children': ['302', '305']}; {'id': '302', 'type': 'attribute', 'children': ['303', '304']}; {'id': '303', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '304', 'type': 'identifier', 'children': [], 'value': 'elastic'}; {'id': '305', 'type': 'identifier', 'children': [], 'value': 'safe_put_bulk'}; {'id': '306', 'type': 'argument_list', 'children': ['307', '308']}; {'id': '307', 'type': 'identifier', 'children': [], 'value': 'url'}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'bulk_json'}; {'id': '309', 'type': 'return_statement', 'children': ['310']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'total'}
def enrich_items(self, ocean_backend, events=False): max_items = self.elastic.max_items_bulk current = 0 total = 0 bulk_json = "" items = ocean_backend.fetch() images_items = {} url = self.elastic.index_url + '/items/_bulk' logger.debug("Adding items to %s (in %i packs)", self.elastic.anonymize_url(url), max_items) for item in items: if current >= max_items: total += self.elastic.safe_put_bulk(url, bulk_json) json_size = sys.getsizeof(bulk_json) / (1024 * 1024) logger.debug("Added %i items to %s (%0.2f MB)", total, self.elastic.anonymize_url(url), json_size) bulk_json = "" current = 0 rich_item = self.get_rich_item(item) data_json = json.dumps(rich_item) bulk_json += '{"index" : {"_id" : "%s" } }\n' % \ (item[self.get_field_unique_id()]) bulk_json += data_json + "\n" current += 1 if rich_item['id'] not in images_items: rich_item['is_docker_image'] = 1 rich_item['is_event'] = 0 images_items[rich_item['id']] = rich_item else: image_date = images_items[rich_item['id']]['last_updated'] if image_date <= rich_item['last_updated']: rich_item['is_docker_image'] = 1 rich_item['is_event'] = 0 images_items[rich_item['id']] = rich_item if current > 0: total += self.elastic.safe_put_bulk(url, bulk_json) if total == 0: return total for image in images_items: data = images_items[image] data_json = json.dumps(data) bulk_json += '{"index" : {"_id" : "%s" } }\n' % \ (data['id'] + "_image") bulk_json += data_json + "\n" total += self.elastic.safe_put_bulk(url, bulk_json) return total
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_identity'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'backend'}; {'id': '8', 'type': 'block', 'children': ['9', '13', '154', '204']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'assignment', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '12', 'type': 'None', 'children': []}; {'id': '13', 'type': 'try_statement', 'children': ['14', '82', '94', '107', '129']}; {'id': '14', 'type': 'block', 'children': ['15', '34', '51', '72']}; {'id': '15', 'type': 'expression_statement', 'children': ['16']}; {'id': '16', 'type': 'assignment', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '18', 'type': 'call', 'children': ['19', '22']}; {'id': '19', 'type': 'attribute', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'api'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'add_identity'}; {'id': '22', 'type': 'argument_list', 'children': ['23', '24', '25', '28', '31']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'backend'}; {'id': '25', 'type': 'subscript', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '27', 'type': 'string', 'children': [], 'value': "'email'"}; {'id': '28', 'type': 'subscript', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '30', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '31', 'type': 'subscript', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '33', 'type': 'string', 'children': [], 'value': "'username'"}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '39', 'type': 'argument_list', 'children': ['40', '41', '42', '45', '48']}; {'id': '40', 'type': 'string', 'children': [], 'value': '"New sortinghat identity %s %s,%s,%s "'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '42', 'type': 'subscript', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '44', 'type': 'string', 'children': [], 'value': "'username'"}; {'id': '45', 'type': 'subscript', 'children': ['46', '47']}; {'id': '46', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '47', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '48', 'type': 'subscript', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '50', 'type': 'string', 'children': [], 'value': "'email'"}; {'id': '51', 'type': 'expression_statement', 'children': ['52']}; {'id': '52', 'type': 'assignment', 'children': ['53', '54']}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'profile'}; {'id': '54', 'type': 'dictionary', 'children': ['55', '67']}; {'id': '55', 'type': 'pair', 'children': ['56', '57']}; {'id': '56', 'type': 'string', 'children': [], 'value': '"name"'}; {'id': '57', 'type': 'conditional_expression', 'children': ['58', '61', '64'], 'value': 'if'}; {'id': '58', 'type': 'subscript', 'children': ['59', '60']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '60', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '61', 'type': 'subscript', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '63', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '64', 'type': 'subscript', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '66', 'type': 'string', 'children': [], 'value': "'username'"}; {'id': '67', 'type': 'pair', 'children': ['68', '69']}; {'id': '68', 'type': 'string', 'children': [], 'value': '"email"'}; {'id': '69', 'type': 'subscript', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '71', 'type': 'string', 'children': [], 'value': "'email'"}; {'id': '72', 'type': 'expression_statement', 'children': ['73']}; {'id': '73', 'type': 'call', 'children': ['74', '77']}; {'id': '74', 'type': 'attribute', 'children': ['75', '76']}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'api'}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'edit_profile'}; {'id': '77', 'type': 'argument_list', 'children': ['78', '79', '80']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '80', 'type': 'dictionary_splat', 'children': ['81']}; {'id': '81', 'type': 'identifier', 'children': [], 'value': 'profile'}; {'id': '82', 'type': 'except_clause', 'children': ['83', '87']}; {'id': '83', 'type': 'as_pattern', 'children': ['84', '85']}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'AlreadyExistsError'}; {'id': '85', 'type': 'as_pattern_target', 'children': ['86']}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '87', 'type': 'block', 'children': ['88']}; {'id': '88', 'type': 'expression_statement', 'children': ['89']}; {'id': '89', 'type': 'assignment', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '91', 'type': 'attribute', 'children': ['92', '93']}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'eid'}; {'id': '94', 'type': 'except_clause', 'children': ['95', '99']}; {'id': '95', 'type': 'as_pattern', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'InvalidValueError'}; {'id': '97', 'type': 'as_pattern_target', 'children': ['98']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '99', 'type': 'block', 'children': ['100']}; {'id': '100', 'type': 'expression_statement', 'children': ['101']}; {'id': '101', 'type': 'call', 'children': ['102', '105']}; {'id': '102', 'type': 'attribute', 'children': ['103', '104']}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '105', 'type': 'argument_list', 'children': ['106']}; {'id': '106', 'type': 'string', 'children': [], 'value': '"Trying to add a None identity. Ignoring it."'}; {'id': '107', 'type': 'except_clause', 'children': ['108', '112']}; {'id': '108', 'type': 'as_pattern', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'UnicodeEncodeError'}; {'id': '110', 'type': 'as_pattern_target', 'children': ['111']}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '112', 'type': 'block', 'children': ['113']}; {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'call', 'children': ['115', '118']}; {'id': '115', 'type': 'attribute', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120', '123', '126']}; {'id': '119', 'type': 'string', 'children': [], 'value': '"UnicodeEncodeError. Ignoring it. %s %s %s"'}; {'id': '120', 'type': 'subscript', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '122', 'type': 'string', 'children': [], 'value': "'email'"}; {'id': '123', 'type': 'subscript', 'children': ['124', '125']}; {'id': '124', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '125', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '126', 'type': 'subscript', 'children': ['127', '128']}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '128', 'type': 'string', 'children': [], 'value': "'username'"}; {'id': '129', 'type': 'except_clause', 'children': ['130', '134']}; {'id': '130', 'type': 'as_pattern', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '132', 'type': 'as_pattern_target', 'children': ['133']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'ex'}; {'id': '134', 'type': 'block', 'children': ['135']}; {'id': '135', 'type': 'expression_statement', 'children': ['136']}; {'id': '136', 'type': 'call', 'children': ['137', '140']}; {'id': '137', 'type': 'attribute', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '140', 'type': 'argument_list', 'children': ['141', '142', '145', '148', '151']}; {'id': '141', 'type': 'string', 'children': [], 'value': '"Unknown exception adding identity. Ignoring it. %s %s %s"'}; {'id': '142', 'type': 'subscript', 'children': ['143', '144']}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '144', 'type': 'string', 'children': [], 'value': "'email'"}; {'id': '145', 'type': 'subscript', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '147', 'type': 'string', 'children': [], 'value': "'name'"}; {'id': '148', 'type': 'subscript', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '150', 'type': 'string', 'children': [], 'value': "'username'"}; {'id': '151', 'type': 'keyword_argument', 'children': ['152', '153']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'exc_info'}; {'id': '153', 'type': 'True', 'children': []}; {'id': '154', 'type': 'if_statement', 'children': ['155', '164']}; {'id': '155', 'type': 'boolean_operator', 'children': ['156', '159'], 'value': 'and'}; {'id': '156', 'type': 'comparison_operator', 'children': ['157', '158'], 'value': 'in'}; {'id': '157', 'type': 'string', 'children': [], 'value': "'company'"}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '159', 'type': 'comparison_operator', 'children': ['160', '163'], 'value': 'is'}; {'id': '160', 'type': 'subscript', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '162', 'type': 'string', 'children': [], 'value': "'company'"}; {'id': '163', 'type': 'None', 'children': []}; {'id': '164', 'type': 'block', 'children': ['165']}; {'id': '165', 'type': 'try_statement', 'children': ['166', '200']}; {'id': '166', 'type': 'block', 'children': ['167', '177']}; {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'call', 'children': ['169', '172']}; {'id': '169', 'type': 'attribute', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'api'}; {'id': '171', 'type': 'identifier', 'children': [], 'value': 'add_organization'}; {'id': '172', 'type': 'argument_list', 'children': ['173', '174']}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '174', 'type': 'subscript', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '176', 'type': 'string', 'children': [], 'value': "'company'"}; {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'call', 'children': ['179', '182']}; {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'api'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'add_enrollment'}; {'id': '182', 'type': 'argument_list', 'children': ['183', '184', '185', '188', '194']}; {'id': '183', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '185', 'type': 'subscript', 'children': ['186', '187']}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '187', 'type': 'string', 'children': [], 'value': "'company'"}; {'id': '188', 'type': 'call', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '190', 'type': 'argument_list', 'children': ['191', '192', '193']}; {'id': '191', 'type': 'integer', 'children': [], 'value': '1900'}; {'id': '192', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '193', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '194', 'type': 'call', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'datetime'}; {'id': '196', 'type': 'argument_list', 'children': ['197', '198', '199']}; {'id': '197', 'type': 'integer', 'children': [], 'value': '2100'}; {'id': '198', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '199', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '200', 'type': 'except_clause', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'AlreadyExistsError'}; {'id': '202', 'type': 'block', 'children': ['203']}; {'id': '203', 'type': 'pass_statement', 'children': []}; {'id': '204', 'type': 'return_statement', 'children': ['205']}; {'id': '205', 'type': 'identifier', 'children': [], 'value': 'uuid'}
def add_identity(cls, db, identity, backend): uuid = None try: uuid = api.add_identity(db, backend, identity['email'], identity['name'], identity['username']) logger.debug("New sortinghat identity %s %s,%s,%s ", uuid, identity['username'], identity['name'], identity['email']) profile = {"name": identity['name'] if identity['name'] else identity['username'], "email": identity['email']} api.edit_profile(db, uuid, **profile) except AlreadyExistsError as ex: uuid = ex.eid except InvalidValueError as ex: logger.warning("Trying to add a None identity. Ignoring it.") except UnicodeEncodeError as ex: logger.warning("UnicodeEncodeError. Ignoring it. %s %s %s", identity['email'], identity['name'], identity['username']) except Exception as ex: logger.warning("Unknown exception adding identity. Ignoring it. %s %s %s", identity['email'], identity['name'], identity['username'], exc_info=True) if 'company' in identity and identity['company'] is not None: try: api.add_organization(db, identity['company']) api.add_enrollment(db, uuid, identity['company'], datetime(1900, 1, 1), datetime(2100, 1, 1)) except AlreadyExistsError: pass return uuid
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'add_identities'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'identities'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'backend'}; {'id': '8', 'type': 'block', 'children': ['9', '16', '20', '55']}; {'id': '9', 'type': 'expression_statement', 'children': ['10']}; {'id': '10', 'type': 'call', 'children': ['11', '14']}; {'id': '11', 'type': 'attribute', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '14', 'type': 'argument_list', 'children': ['15']}; {'id': '15', 'type': 'string', 'children': [], 'value': '"Adding the identities to SortingHat"'}; {'id': '16', 'type': 'expression_statement', 'children': ['17']}; {'id': '17', 'type': 'assignment', 'children': ['18', '19']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '19', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '20', 'type': 'for_statement', 'children': ['21', '22', '23']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'identities'}; {'id': '23', 'type': 'block', 'children': ['24']}; {'id': '24', 'type': 'try_statement', 'children': ['25', '39']}; {'id': '25', 'type': 'block', 'children': ['26', '35']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'add_identity'}; {'id': '31', 'type': 'argument_list', 'children': ['32', '33', '34']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'db'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'backend'}; {'id': '35', 'type': 'expression_statement', 'children': ['36']}; {'id': '36', 'type': 'augmented_assignment', 'children': ['37', '38'], 'value': '+='}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '38', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '39', 'type': 'except_clause', 'children': ['40', '44']}; {'id': '40', 'type': 'as_pattern', 'children': ['41', '42']}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '42', 'type': 'as_pattern_target', 'children': ['43']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '44', 'type': 'block', 'children': ['45', '54']}; {'id': '45', 'type': 'expression_statement', 'children': ['46']}; {'id': '46', 'type': 'call', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'error'}; {'id': '50', 'type': 'argument_list', 'children': ['51']}; {'id': '51', 'type': 'binary_operator', 'children': ['52', '53'], 'value': '%'}; {'id': '52', 'type': 'string', 'children': [], 'value': '"Unexcepted error when adding identities: %s"'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '54', 'type': 'continue_statement', 'children': []}; {'id': '55', 'type': 'expression_statement', 'children': ['56']}; {'id': '56', 'type': 'call', 'children': ['57', '60']}; {'id': '57', 'type': 'attribute', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '60', 'type': 'argument_list', 'children': ['61', '62']}; {'id': '61', 'type': 'string', 'children': [], 'value': '"Total identities added to SH: %i"'}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'total'}
def add_identities(cls, db, identities, backend): logger.info("Adding the identities to SortingHat") total = 0 for identity in identities: try: cls.add_identity(db, identity, backend) total += 1 except Exception as e: logger.error("Unexcepted error when adding identities: %s" % e) continue logger.info("Total identities added to SH: %i", total)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'remove_identity'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sh_db'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'ident_id'}; {'id': '7', 'type': 'block', 'children': ['8', '12', '51']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'success'}; {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'try_statement', 'children': ['13', '34']}; {'id': '13', 'type': 'block', 'children': ['14', '22', '30']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'api'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'delete_identity'}; {'id': '19', 'type': 'argument_list', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'sh_db'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'ident_id'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'string', 'children': [], 'value': '"Identity %s deleted"'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'ident_id'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'success'}; {'id': '33', 'type': 'True', 'children': []}; {'id': '34', 'type': 'except_clause', 'children': ['35', '39']}; {'id': '35', 'type': 'as_pattern', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '37', 'type': 'as_pattern_target', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '45', 'type': 'argument_list', 'children': ['46', '47']}; {'id': '46', 'type': 'string', 'children': [], 'value': '"Identity not deleted due to %s"'}; {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '51', 'type': 'return_statement', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'success'}
def remove_identity(cls, sh_db, ident_id): success = False try: api.delete_identity(sh_db, ident_id) logger.debug("Identity %s deleted", ident_id) success = True except Exception as e: logger.debug("Identity not deleted due to %s", str(e)) return success
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'remove_unique_identity'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sh_db'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '7', 'type': 'block', 'children': ['8', '12', '51']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'success'}; {'id': '11', 'type': 'False', 'children': []}; {'id': '12', 'type': 'try_statement', 'children': ['13', '34']}; {'id': '13', 'type': 'block', 'children': ['14', '22', '30']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'call', 'children': ['16', '19']}; {'id': '16', 'type': 'attribute', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'api'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'delete_unique_identity'}; {'id': '19', 'type': 'argument_list', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'sh_db'}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '22', 'type': 'expression_statement', 'children': ['23']}; {'id': '23', 'type': 'call', 'children': ['24', '27']}; {'id': '24', 'type': 'attribute', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '27', 'type': 'argument_list', 'children': ['28', '29']}; {'id': '28', 'type': 'string', 'children': [], 'value': '"Unique identity %s deleted"'}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '30', 'type': 'expression_statement', 'children': ['31']}; {'id': '31', 'type': 'assignment', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'success'}; {'id': '33', 'type': 'True', 'children': []}; {'id': '34', 'type': 'except_clause', 'children': ['35', '39']}; {'id': '35', 'type': 'as_pattern', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '37', 'type': 'as_pattern_target', 'children': ['38']}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '39', 'type': 'block', 'children': ['40']}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'call', 'children': ['42', '45']}; {'id': '42', 'type': 'attribute', 'children': ['43', '44']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '45', 'type': 'argument_list', 'children': ['46', '47']}; {'id': '46', 'type': 'string', 'children': [], 'value': '"Unique identity not deleted due to %s"'}; {'id': '47', 'type': 'call', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '49', 'type': 'argument_list', 'children': ['50']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '51', 'type': 'return_statement', 'children': ['52']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'success'}
def remove_unique_identity(cls, sh_db, uuid): success = False try: api.delete_unique_identity(sh_db, uuid) logger.debug("Unique identity %s deleted", uuid) success = True except Exception as e: logger.debug("Unique identity not deleted due to %s", str(e)) return success
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '6']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'unique_identities'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'cls'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sh_db'}; {'id': '6', 'type': 'block', 'children': ['7']}; {'id': '7', 'type': 'try_statement', 'children': ['8', '21']}; {'id': '8', 'type': 'block', 'children': ['9']}; {'id': '9', 'type': 'for_statement', 'children': ['10', '11', '17']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'unique_identity'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'api'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'unique_identities'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'sh_db'}; {'id': '17', 'type': 'block', 'children': ['18']}; {'id': '18', 'type': 'expression_statement', 'children': ['19']}; {'id': '19', 'type': 'yield', 'children': ['20']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'unique_identity'}; {'id': '21', 'type': 'except_clause', 'children': ['22', '26']}; {'id': '22', 'type': 'as_pattern', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'Exception'}; {'id': '24', 'type': 'as_pattern_target', 'children': ['25']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'e'}; {'id': '26', 'type': 'block', 'children': ['27']}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'call', 'children': ['29', '32']}; {'id': '29', 'type': 'attribute', 'children': ['30', '31']}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '34']}; {'id': '33', 'type': 'string', 'children': [], 'value': '"Unique identities not returned from SortingHat due to %s"'}; {'id': '34', 'type': 'call', 'children': ['35', '36']}; {'id': '35', 'type': 'identifier', 'children': [], 'value': 'str'}; {'id': '36', 'type': 'argument_list', 'children': ['37']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'e'}
def unique_identities(cls, sh_db): try: for unique_identity in api.unique_identities(sh_db): yield unique_identity except Exception as e: logger.debug("Unique identities not returned from SortingHat due to %s", str(e))
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '11']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'refresh_identities'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'enrich_backend'}; {'id': '5', 'type': 'default_parameter', 'children': ['6', '7']}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'author_field'}; {'id': '7', 'type': 'None', 'children': []}; {'id': '8', 'type': 'default_parameter', 'children': ['9', '10']}; {'id': '9', 'type': 'identifier', 'children': [], 'value': 'author_values'}; {'id': '10', 'type': 'None', 'children': []}; {'id': '11', 'type': 'block', 'children': ['12', '62', '81', '85', '93', '100', '204']}; {'id': '12', 'type': 'function_definition', 'children': ['13', '14', '16']}; {'id': '13', 'type': 'function_name', 'children': [], 'value': 'update_items'}; {'id': '14', 'type': 'parameters', 'children': ['15']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'new_filter_author'}; {'id': '16', 'type': 'block', 'children': ['17']}; {'id': '17', 'type': 'for_statement', 'children': ['18', '19', '25']}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'eitem'}; {'id': '19', 'type': 'call', 'children': ['20', '23']}; {'id': '20', 'type': 'attribute', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'enrich_backend'}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'fetch'}; {'id': '23', 'type': 'argument_list', 'children': ['24']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'new_filter_author'}; {'id': '25', 'type': 'block', 'children': ['26', '30', '42', '52', '59']}; {'id': '26', 'type': 'expression_statement', 'children': ['27']}; {'id': '27', 'type': 'assignment', 'children': ['28', '29']}; {'id': '28', 'type': 'identifier', 'children': [], 'value': 'roles'}; {'id': '29', 'type': 'None', 'children': []}; {'id': '30', 'type': 'try_statement', 'children': ['31', '38']}; {'id': '31', 'type': 'block', 'children': ['32']}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'roles'}; {'id': '35', 'type': 'attribute', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'enrich_backend'}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'roles'}; {'id': '38', 'type': 'except_clause', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'AttributeError'}; {'id': '40', 'type': 'block', 'children': ['41']}; {'id': '41', 'type': 'pass_statement', 'children': []}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'new_identities'}; {'id': '45', 'type': 'call', 'children': ['46', '49']}; {'id': '46', 'type': 'attribute', 'children': ['47', '48']}; {'id': '47', 'type': 'identifier', 'children': [], 'value': 'enrich_backend'}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'get_item_sh_from_id'}; {'id': '49', 'type': 'argument_list', 'children': ['50', '51']}; {'id': '50', 'type': 'identifier', 'children': [], 'value': 'eitem'}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'roles'}; {'id': '52', 'type': 'expression_statement', 'children': ['53']}; {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'eitem'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '57', 'type': 'argument_list', 'children': ['58']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'new_identities'}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'yield', 'children': ['61']}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'eitem'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}; {'id': '63', 'type': 'call', 'children': ['64', '67']}; {'id': '64', 'type': 'attribute', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '67', 'type': 'argument_list', 'children': ['68', '69']}; {'id': '68', 'type': 'string', 'children': [], 'value': '"Refreshing identities fields from %s"'}; {'id': '69', 'type': 'call', 'children': ['70', '75']}; {'id': '70', 'type': 'attribute', 'children': ['71', '74']}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'enrich_backend'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'elastic'}; {'id': '74', 'type': 'identifier', 'children': [], 'value': 'anonymize_url'}; {'id': '75', 'type': 'argument_list', 'children': ['76']}; {'id': '76', 'type': 'attribute', 'children': ['77', '80']}; {'id': '77', 'type': 'attribute', 'children': ['78', '79']}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'enrich_backend'}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'elastic'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'index_url'}; {'id': '81', 'type': 'expression_statement', 'children': ['82']}; {'id': '82', 'type': 'assignment', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '84', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '85', 'type': 'expression_statement', 'children': ['86']}; {'id': '86', 'type': 'assignment', 'children': ['87', '88']}; {'id': '87', 'type': 'identifier', 'children': [], 'value': 'max_ids'}; {'id': '88', 'type': 'attribute', 'children': ['89', '92']}; {'id': '89', 'type': 'attribute', 'children': ['90', '91']}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'enrich_backend'}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'elastic'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'max_items_clause'}; {'id': '93', 'type': 'expression_statement', 'children': ['94']}; {'id': '94', 'type': 'call', 'children': ['95', '98']}; {'id': '95', 'type': 'attribute', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '98', 'type': 'argument_list', 'children': ['99']}; {'id': '99', 'type': 'string', 'children': [], 'value': "'Refreshing identities'"}; {'id': '100', 'type': 'if_statement', 'children': ['101', '104', '119']}; {'id': '101', 'type': 'comparison_operator', 'children': ['102', '103'], 'value': 'is'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'author_field'}; {'id': '103', 'type': 'None', 'children': []}; {'id': '104', 'type': 'block', 'children': ['105']}; {'id': '105', 'type': 'for_statement', 'children': ['106', '107', '111']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '107', 'type': 'call', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'update_items'}; {'id': '109', 'type': 'argument_list', 'children': ['110']}; {'id': '110', 'type': 'None', 'children': []}; {'id': '111', 'type': 'block', 'children': ['112', '115']}; {'id': '112', 'type': 'expression_statement', 'children': ['113']}; {'id': '113', 'type': 'yield', 'children': ['114']}; {'id': '114', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '115', 'type': 'expression_statement', 'children': ['116']}; {'id': '116', 'type': 'augmented_assignment', 'children': ['117', '118'], 'value': '+='}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '118', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '119', 'type': 'else_clause', 'children': ['120']}; {'id': '120', 'type': 'block', 'children': ['121', '125', '172']}; {'id': '121', 'type': 'expression_statement', 'children': ['122']}; {'id': '122', 'type': 'assignment', 'children': ['123', '124']}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'to_refresh'}; {'id': '124', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '125', 'type': 'for_statement', 'children': ['126', '127', '128']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'author_value'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'author_values'}; {'id': '128', 'type': 'block', 'children': ['129', '136']}; {'id': '129', 'type': 'expression_statement', 'children': ['130']}; {'id': '130', 'type': 'call', 'children': ['131', '134']}; {'id': '131', 'type': 'attribute', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'to_refresh'}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '134', 'type': 'argument_list', 'children': ['135']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'author_value'}; {'id': '136', 'type': 'if_statement', 'children': ['137', '143']}; {'id': '137', 'type': 'comparison_operator', 'children': ['138', '142'], 'value': '>'}; {'id': '138', 'type': 'call', 'children': ['139', '140']}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '140', 'type': 'argument_list', 'children': ['141']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'to_refresh'}; {'id': '142', 'type': 'identifier', 'children': [], 'value': 'max_ids'}; {'id': '143', 'type': 'block', 'children': ['144', '154', '168']}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}; {'id': '145', 'type': 'assignment', 'children': ['146', '147']}; {'id': '146', 'type': 'identifier', 'children': [], 'value': 'filter_author'}; {'id': '147', 'type': 'dictionary', 'children': ['148', '151']}; {'id': '148', 'type': 'pair', 'children': ['149', '150']}; {'id': '149', 'type': 'string', 'children': [], 'value': '"name"'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'author_field'}; {'id': '151', 'type': 'pair', 'children': ['152', '153']}; {'id': '152', 'type': 'string', 'children': [], 'value': '"value"'}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'to_refresh'}; {'id': '154', 'type': 'for_statement', 'children': ['155', '156', '160']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '156', 'type': 'call', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'update_items'}; {'id': '158', 'type': 'argument_list', 'children': ['159']}; {'id': '159', 'type': 'identifier', 'children': [], 'value': 'filter_author'}; {'id': '160', 'type': 'block', 'children': ['161', '164']}; {'id': '161', 'type': 'expression_statement', 'children': ['162']}; {'id': '162', 'type': 'yield', 'children': ['163']}; {'id': '163', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}; {'id': '165', 'type': 'augmented_assignment', 'children': ['166', '167'], 'value': '+='}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '167', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '168', 'type': 'expression_statement', 'children': ['169']}; {'id': '169', 'type': 'assignment', 'children': ['170', '171']}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'to_refresh'}; {'id': '171', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '172', 'type': 'if_statement', 'children': ['173', '179']}; {'id': '173', 'type': 'comparison_operator', 'children': ['174', '178'], 'value': '>'}; {'id': '174', 'type': 'call', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '176', 'type': 'argument_list', 'children': ['177']}; {'id': '177', 'type': 'identifier', 'children': [], 'value': 'to_refresh'}; {'id': '178', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '179', 'type': 'block', 'children': ['180', '190']}; {'id': '180', 'type': 'expression_statement', 'children': ['181']}; {'id': '181', 'type': 'assignment', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'filter_author'}; {'id': '183', 'type': 'dictionary', 'children': ['184', '187']}; {'id': '184', 'type': 'pair', 'children': ['185', '186']}; {'id': '185', 'type': 'string', 'children': [], 'value': '"name"'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'author_field'}; {'id': '187', 'type': 'pair', 'children': ['188', '189']}; {'id': '188', 'type': 'string', 'children': [], 'value': '"value"'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'to_refresh'}; {'id': '190', 'type': 'for_statement', 'children': ['191', '192', '196']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '192', 'type': 'call', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'update_items'}; {'id': '194', 'type': 'argument_list', 'children': ['195']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'filter_author'}; {'id': '196', 'type': 'block', 'children': ['197', '200']}; {'id': '197', 'type': 'expression_statement', 'children': ['198']}; {'id': '198', 'type': 'yield', 'children': ['199']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '200', 'type': 'expression_statement', 'children': ['201']}; {'id': '201', 'type': 'augmented_assignment', 'children': ['202', '203'], 'value': '+='}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'total'}; {'id': '203', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '204', 'type': 'expression_statement', 'children': ['205']}; {'id': '205', 'type': 'call', 'children': ['206', '209']}; {'id': '206', 'type': 'attribute', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'info'}; {'id': '209', 'type': 'argument_list', 'children': ['210', '211']}; {'id': '210', 'type': 'string', 'children': [], 'value': '"Total eitems refreshed for identities fields %i"'}; {'id': '211', 'type': 'identifier', 'children': [], 'value': 'total'}
def refresh_identities(enrich_backend, author_field=None, author_values=None): def update_items(new_filter_author): for eitem in enrich_backend.fetch(new_filter_author): roles = None try: roles = enrich_backend.roles except AttributeError: pass new_identities = enrich_backend.get_item_sh_from_id(eitem, roles) eitem.update(new_identities) yield eitem logger.debug("Refreshing identities fields from %s", enrich_backend.elastic.anonymize_url(enrich_backend.elastic.index_url)) total = 0 max_ids = enrich_backend.elastic.max_items_clause logger.debug('Refreshing identities') if author_field is None: for item in update_items(None): yield item total += 1 else: to_refresh = [] for author_value in author_values: to_refresh.append(author_value) if len(to_refresh) > max_ids: filter_author = {"name": author_field, "value": to_refresh} for item in update_items(filter_author): yield item total += 1 to_refresh = [] if len(to_refresh) > 0: filter_author = {"name": author_field, "value": to_refresh} for item in update_items(filter_author): yield item total += 1 logger.info("Total eitems refreshed for identities fields %i", total)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '13']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_ocean_backend'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '10']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'backend_cmd'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'enrich_backend'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'no_incremental'}; {'id': '7', 'type': 'default_parameter', 'children': ['8', '9']}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'filter_raw'}; {'id': '9', 'type': 'None', 'children': []}; {'id': '10', 'type': 'default_parameter', 'children': ['11', '12']}; {'id': '11', 'type': 'identifier', 'children': [], 'value': 'filter_raw_should'}; {'id': '12', 'type': 'None', 'children': []}; {'id': '13', 'type': 'block', 'children': ['14', '34', '42', '46', '58', '216', '226', '236']}; {'id': '14', 'type': 'if_statement', 'children': ['15', '16', '21']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'no_incremental'}; {'id': '16', 'type': 'block', 'children': ['17']}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'last_enrich'}; {'id': '20', 'type': 'None', 'children': []}; {'id': '21', 'type': 'else_clause', 'children': ['22']}; {'id': '22', 'type': 'block', 'children': ['23']}; {'id': '23', 'type': 'expression_statement', 'children': ['24']}; {'id': '24', 'type': 'assignment', 'children': ['25', '26']}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'last_enrich'}; {'id': '26', 'type': 'call', 'children': ['27', '28']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'get_last_enrich'}; {'id': '28', 'type': 'argument_list', 'children': ['29', '30', '31']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'backend_cmd'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'enrich_backend'}; {'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'filter_raw'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'filter_raw'}; {'id': '34', 'type': 'expression_statement', 'children': ['35']}; {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '39', 'type': 'argument_list', 'children': ['40', '41']}; {'id': '40', 'type': 'string', 'children': [], 'value': '"Last enrichment: %s"'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'last_enrich'}; {'id': '42', 'type': 'expression_statement', 'children': ['43']}; {'id': '43', 'type': 'assignment', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'backend'}; {'id': '45', 'type': 'None', 'children': []}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'connector'}; {'id': '49', 'type': 'subscript', 'children': ['50', '53']}; {'id': '50', 'type': 'call', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'get_connectors'}; {'id': '52', 'type': 'argument_list', 'children': []}; {'id': '53', 'type': 'call', 'children': ['54', '57']}; {'id': '54', 'type': 'attribute', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'enrich_backend'}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'get_connector_name'}; {'id': '57', 'type': 'argument_list', 'children': []}; {'id': '58', 'type': 'if_statement', 'children': ['59', '60', '151']}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'backend_cmd'}; {'id': '60', 'type': 'block', 'children': ['61', '68', '74', '85']}; {'id': '61', 'type': 'expression_statement', 'children': ['62']}; {'id': '62', 'type': 'assignment', 'children': ['63', '64']}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'backend_cmd'}; {'id': '64', 'type': 'call', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'init_backend'}; {'id': '66', 'type': 'argument_list', 'children': ['67']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'backend_cmd'}; {'id': '68', 'type': 'expression_statement', 'children': ['69']}; {'id': '69', 'type': 'assignment', 'children': ['70', '71']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'backend'}; {'id': '71', 'type': 'attribute', 'children': ['72', '73']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'backend_cmd'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'backend'}; {'id': '74', 'type': 'expression_statement', 'children': ['75']}; {'id': '75', 'type': 'assignment', 'children': ['76', '77']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'signature'}; {'id': '77', 'type': 'call', 'children': ['78', '81']}; {'id': '78', 'type': 'attribute', 'children': ['79', '80']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'inspect'}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'signature'}; {'id': '81', 'type': 'argument_list', 'children': ['82']}; {'id': '82', 'type': 'attribute', 'children': ['83', '84']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'backend'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'fetch'}; {'id': '85', 'type': 'if_statement', 'children': ['86', '91', '104', '123']}; {'id': '86', 'type': 'comparison_operator', 'children': ['87', '88'], 'value': 'in'}; {'id': '87', 'type': 'string', 'children': [], 'value': "'from_date'"}; {'id': '88', 'type': 'attribute', 'children': ['89', '90']}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'signature'}; {'id': '90', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '91', 'type': 'block', 'children': ['92']}; {'id': '92', 'type': 'expression_statement', 'children': ['93']}; {'id': '93', 'type': 'assignment', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'ocean_backend'}; {'id': '95', 'type': 'call', 'children': ['96', '99']}; {'id': '96', 'type': 'subscript', 'children': ['97', '98']}; {'id': '97', 'type': 'identifier', 'children': [], 'value': 'connector'}; {'id': '98', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '99', 'type': 'argument_list', 'children': ['100', '101']}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'backend'}; {'id': '101', 'type': 'keyword_argument', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'from_date'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'last_enrich'}; {'id': '104', 'type': 'elif_clause', 'children': ['105', '110']}; {'id': '105', 'type': 'comparison_operator', 'children': ['106', '107'], 'value': 'in'}; {'id': '106', 'type': 'string', 'children': [], 'value': "'offset'"}; {'id': '107', 'type': 'attribute', 'children': ['108', '109']}; {'id': '108', 'type': 'identifier', 'children': [], 'value': 'signature'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'parameters'}; {'id': '110', 'type': 'block', 'children': ['111']}; {'id': '111', 'type': 'expression_statement', 'children': ['112']}; {'id': '112', 'type': 'assignment', 'children': ['113', '114']}; {'id': '113', 'type': 'identifier', 'children': [], 'value': 'ocean_backend'}; {'id': '114', 'type': 'call', 'children': ['115', '118']}; {'id': '115', 'type': 'subscript', 'children': ['116', '117']}; {'id': '116', 'type': 'identifier', 'children': [], 'value': 'connector'}; {'id': '117', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '118', 'type': 'argument_list', 'children': ['119', '120']}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'backend'}; {'id': '120', 'type': 'keyword_argument', 'children': ['121', '122']}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'offset'}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'last_enrich'}; {'id': '123', 'type': 'else_clause', 'children': ['124']}; {'id': '124', 'type': 'block', 'children': ['125']}; {'id': '125', 'type': 'if_statement', 'children': ['126', '127', '140']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'last_enrich'}; {'id': '127', 'type': 'block', 'children': ['128']}; {'id': '128', 'type': 'expression_statement', 'children': ['129']}; {'id': '129', 'type': 'assignment', 'children': ['130', '131']}; {'id': '130', 'type': 'identifier', 'children': [], 'value': 'ocean_backend'}; {'id': '131', 'type': 'call', 'children': ['132', '135']}; {'id': '132', 'type': 'subscript', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'connector'}; {'id': '134', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '135', 'type': 'argument_list', 'children': ['136', '137']}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'backend'}; {'id': '137', 'type': 'keyword_argument', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'from_date'}; {'id': '139', 'type': 'identifier', 'children': [], 'value': 'last_enrich'}; {'id': '140', 'type': 'else_clause', 'children': ['141']}; {'id': '141', 'type': 'block', 'children': ['142']}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}; {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'ocean_backend'}; {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'subscript', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'connector'}; {'id': '148', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '149', 'type': 'argument_list', 'children': ['150']}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'backend'}; {'id': '151', 'type': 'else_clause', 'children': ['152']}; {'id': '152', 'type': 'block', 'children': ['153', '159', '190']}; {'id': '153', 'type': 'expression_statement', 'children': ['154']}; {'id': '154', 'type': 'assignment', 'children': ['155', '156']}; {'id': '155', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '156', 'type': 'attribute', 'children': ['157', '158']}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'enrich_backend'}; {'id': '158', 'type': 'identifier', 'children': [], 'value': 'backend_params'}; {'id': '159', 'type': 'if_statement', 'children': ['160', '161']}; {'id': '160', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '161', 'type': 'block', 'children': ['162']}; {'id': '162', 'type': 'try_statement', 'children': ['163', '186']}; {'id': '163', 'type': 'block', 'children': ['164', '173']}; {'id': '164', 'type': 'expression_statement', 'children': ['165']}; {'id': '165', 'type': 'assignment', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'date_pos'}; {'id': '167', 'type': 'call', 'children': ['168', '171']}; {'id': '168', 'type': 'attribute', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '170', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '171', 'type': 'argument_list', 'children': ['172']}; {'id': '172', 'type': 'string', 'children': [], 'value': "'--from-date'"}; {'id': '173', 'type': 'expression_statement', 'children': ['174']}; {'id': '174', 'type': 'assignment', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'last_enrich'}; {'id': '176', 'type': 'call', 'children': ['177', '180']}; {'id': '177', 'type': 'attribute', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '179', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '180', 'type': 'argument_list', 'children': ['181']}; {'id': '181', 'type': 'subscript', 'children': ['182', '183']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'params'}; {'id': '183', 'type': 'binary_operator', 'children': ['184', '185'], 'value': '+'}; {'id': '184', 'type': 'identifier', 'children': [], 'value': 'date_pos'}; {'id': '185', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '186', 'type': 'except_clause', 'children': ['187', '188']}; {'id': '187', 'type': 'identifier', 'children': [], 'value': 'ValueError'}; {'id': '188', 'type': 'block', 'children': ['189']}; {'id': '189', 'type': 'pass_statement', 'children': []}; {'id': '190', 'type': 'if_statement', 'children': ['191', '192', '205']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'last_enrich'}; {'id': '192', 'type': 'block', 'children': ['193']}; {'id': '193', 'type': 'expression_statement', 'children': ['194']}; {'id': '194', 'type': 'assignment', 'children': ['195', '196']}; {'id': '195', 'type': 'identifier', 'children': [], 'value': 'ocean_backend'}; {'id': '196', 'type': 'call', 'children': ['197', '200']}; {'id': '197', 'type': 'subscript', 'children': ['198', '199']}; {'id': '198', 'type': 'identifier', 'children': [], 'value': 'connector'}; {'id': '199', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '200', 'type': 'argument_list', 'children': ['201', '202']}; {'id': '201', 'type': 'identifier', 'children': [], 'value': 'backend'}; {'id': '202', 'type': 'keyword_argument', 'children': ['203', '204']}; {'id': '203', 'type': 'identifier', 'children': [], 'value': 'from_date'}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'last_enrich'}; {'id': '205', 'type': 'else_clause', 'children': ['206']}; {'id': '206', 'type': 'block', 'children': ['207']}; {'id': '207', 'type': 'expression_statement', 'children': ['208']}; {'id': '208', 'type': 'assignment', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'ocean_backend'}; {'id': '210', 'type': 'call', 'children': ['211', '214']}; {'id': '211', 'type': 'subscript', 'children': ['212', '213']}; {'id': '212', 'type': 'identifier', 'children': [], 'value': 'connector'}; {'id': '213', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '214', 'type': 'argument_list', 'children': ['215']}; {'id': '215', 'type': 'identifier', 'children': [], 'value': 'backend'}; {'id': '216', 'type': 'if_statement', 'children': ['217', '218']}; {'id': '217', 'type': 'identifier', 'children': [], 'value': 'filter_raw'}; {'id': '218', 'type': 'block', 'children': ['219']}; {'id': '219', 'type': 'expression_statement', 'children': ['220']}; {'id': '220', 'type': 'call', 'children': ['221', '224']}; {'id': '221', 'type': 'attribute', 'children': ['222', '223']}; {'id': '222', 'type': 'identifier', 'children': [], 'value': 'ocean_backend'}; {'id': '223', 'type': 'identifier', 'children': [], 'value': 'set_filter_raw'}; {'id': '224', 'type': 'argument_list', 'children': ['225']}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'filter_raw'}; {'id': '226', 'type': 'if_statement', 'children': ['227', '228']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'filter_raw_should'}; {'id': '228', 'type': 'block', 'children': ['229']}; {'id': '229', 'type': 'expression_statement', 'children': ['230']}; {'id': '230', 'type': 'call', 'children': ['231', '234']}; {'id': '231', 'type': 'attribute', 'children': ['232', '233']}; {'id': '232', 'type': 'identifier', 'children': [], 'value': 'ocean_backend'}; {'id': '233', 'type': 'identifier', 'children': [], 'value': 'set_filter_raw_should'}; {'id': '234', 'type': 'argument_list', 'children': ['235']}; {'id': '235', 'type': 'identifier', 'children': [], 'value': 'filter_raw_should'}; {'id': '236', 'type': 'return_statement', 'children': ['237']}; {'id': '237', 'type': 'identifier', 'children': [], 'value': 'ocean_backend'}
def get_ocean_backend(backend_cmd, enrich_backend, no_incremental, filter_raw=None, filter_raw_should=None): if no_incremental: last_enrich = None else: last_enrich = get_last_enrich(backend_cmd, enrich_backend, filter_raw=filter_raw) logger.debug("Last enrichment: %s", last_enrich) backend = None connector = get_connectors()[enrich_backend.get_connector_name()] if backend_cmd: backend_cmd = init_backend(backend_cmd) backend = backend_cmd.backend signature = inspect.signature(backend.fetch) if 'from_date' in signature.parameters: ocean_backend = connector[1](backend, from_date=last_enrich) elif 'offset' in signature.parameters: ocean_backend = connector[1](backend, offset=last_enrich) else: if last_enrich: ocean_backend = connector[1](backend, from_date=last_enrich) else: ocean_backend = connector[1](backend) else: params = enrich_backend.backend_params if params: try: date_pos = params.index('--from-date') last_enrich = parser.parse(params[date_pos + 1]) except ValueError: pass if last_enrich: ocean_backend = connector[1](backend, from_date=last_enrich) else: ocean_backend = connector[1](backend) if filter_raw: ocean_backend.set_filter_raw(filter_raw) if filter_raw_should: ocean_backend.set_filter_raw_should(filter_raw_should) return ocean_backend
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '8']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'delete_orphan_unique_identities'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'es'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sortinghat_db'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'current_data_source'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'active_data_sources'}; {'id': '8', 'type': 'block', 'children': ['9', '73', '107', '153', '183', '187', '191', '195', '301', '342', '350']}; {'id': '9', 'type': 'function_definition', 'children': ['10', '11', '13']}; {'id': '10', 'type': 'function_name', 'children': [], 'value': 'get_uuids_in_index'}; {'id': '11', 'type': 'parameters', 'children': ['12']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'target_uuids'}; {'id': '13', 'type': 'block', 'children': ['14', '50', '54', '71']}; {'id': '14', 'type': 'expression_statement', 'children': ['15']}; {'id': '15', 'type': 'assignment', 'children': ['16', '17']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '17', 'type': 'call', 'children': ['18', '21']}; {'id': '18', 'type': 'attribute', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'es'}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'search'}; {'id': '21', 'type': 'argument_list', 'children': ['22', '25', '28', '31']}; {'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'IDENTITIES_INDEX'}; {'id': '25', 'type': 'keyword_argument', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'scroll'}; {'id': '27', 'type': 'string', 'children': [], 'value': '"360m"'}; {'id': '28', 'type': 'keyword_argument', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'SIZE_SCROLL_IDENTITIES_INDEX'}; {'id': '31', 'type': 'keyword_argument', 'children': ['32', '33']}; {'id': '32', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '33', 'type': 'dictionary', 'children': ['34']}; {'id': '34', 'type': 'pair', 'children': ['35', '36']}; {'id': '35', 'type': 'string', 'children': [], 'value': '"query"'}; {'id': '36', 'type': 'dictionary', 'children': ['37']}; {'id': '37', 'type': 'pair', 'children': ['38', '39']}; {'id': '38', 'type': 'string', 'children': [], 'value': '"bool"'}; {'id': '39', 'type': 'dictionary', 'children': ['40']}; {'id': '40', 'type': 'pair', 'children': ['41', '42']}; {'id': '41', 'type': 'string', 'children': [], 'value': '"filter"'}; {'id': '42', 'type': 'list', 'children': ['43'], 'value': '[\n {\n "terms": {\n "sh_uuid": target_uuids\n }\n }\n ]'}; {'id': '43', 'type': 'dictionary', 'children': ['44']}; {'id': '44', 'type': 'pair', 'children': ['45', '46']}; {'id': '45', 'type': 'string', 'children': [], 'value': '"terms"'}; {'id': '46', 'type': 'dictionary', 'children': ['47']}; {'id': '47', 'type': 'pair', 'children': ['48', '49']}; {'id': '48', 'type': 'string', 'children': [], 'value': '"sh_uuid"'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'target_uuids'}; {'id': '50', 'type': 'expression_statement', 'children': ['51']}; {'id': '51', 'type': 'assignment', 'children': ['52', '53']}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'hits'}; {'id': '53', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '54', 'type': 'if_statement', 'children': ['55', '62']}; {'id': '55', 'type': 'comparison_operator', 'children': ['56', '61'], 'value': '!='}; {'id': '56', 'type': 'subscript', 'children': ['57', '60']}; {'id': '57', 'type': 'subscript', 'children': ['58', '59']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '59', 'type': 'string', 'children': [], 'value': "'hits'"}; {'id': '60', 'type': 'string', 'children': [], 'value': "'total'"}; {'id': '61', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '62', 'type': 'block', 'children': ['63']}; {'id': '63', 'type': 'expression_statement', 'children': ['64']}; {'id': '64', 'type': 'assignment', 'children': ['65', '66']}; {'id': '65', 'type': 'identifier', 'children': [], 'value': 'hits'}; {'id': '66', 'type': 'subscript', 'children': ['67', '70']}; {'id': '67', 'type': 'subscript', 'children': ['68', '69']}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '69', 'type': 'string', 'children': [], 'value': "'hits'"}; {'id': '70', 'type': 'string', 'children': [], 'value': "'hits'"}; {'id': '71', 'type': 'return_statement', 'children': ['72']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'hits'}; {'id': '73', 'type': 'function_definition', 'children': ['74', '75', '77']}; {'id': '74', 'type': 'function_name', 'children': [], 'value': 'delete_unique_identities'}; {'id': '75', 'type': 'parameters', 'children': ['76']}; {'id': '76', 'type': 'identifier', 'children': [], 'value': 'target_uuids'}; {'id': '77', 'type': 'block', 'children': ['78', '82', '105']}; {'id': '78', 'type': 'expression_statement', 'children': ['79']}; {'id': '79', 'type': 'assignment', 'children': ['80', '81']}; {'id': '80', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '81', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '82', 'type': 'for_statement', 'children': ['83', '84', '85']}; {'id': '83', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '84', 'type': 'identifier', 'children': [], 'value': 'target_uuids'}; {'id': '85', 'type': 'block', 'children': ['86', '96']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}; {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'success'}; {'id': '89', 'type': 'call', 'children': ['90', '93']}; {'id': '90', 'type': 'attribute', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'SortingHat'}; {'id': '92', 'type': 'identifier', 'children': [], 'value': 'remove_unique_identity'}; {'id': '93', 'type': 'argument_list', 'children': ['94', '95']}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'sortinghat_db'}; {'id': '95', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '96', 'type': 'expression_statement', 'children': ['97']}; {'id': '97', 'type': 'assignment', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '99', 'type': 'conditional_expression', 'children': ['100', '103', '104'], 'value': 'if'}; {'id': '100', 'type': 'binary_operator', 'children': ['101', '102'], 'value': '+'}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '102', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'success'}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '105', 'type': 'return_statement', 'children': ['106']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '107', 'type': 'function_definition', 'children': ['108', '109', '112']}; {'id': '108', 'type': 'function_name', 'children': [], 'value': 'delete_identities'}; {'id': '109', 'type': 'parameters', 'children': ['110', '111']}; {'id': '110', 'type': 'identifier', 'children': [], 'value': 'unique_ident'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'data_sources'}; {'id': '112', 'type': 'block', 'children': ['113', '117', '151']}; {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '116', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '117', 'type': 'for_statement', 'children': ['118', '119', '122']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'ident'}; {'id': '119', 'type': 'attribute', 'children': ['120', '121']}; {'id': '120', 'type': 'identifier', 'children': [], 'value': 'unique_ident'}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'identities'}; {'id': '122', 'type': 'block', 'children': ['123']}; {'id': '123', 'type': 'if_statement', 'children': ['124', '129']}; {'id': '124', 'type': 'comparison_operator', 'children': ['125', '128'], 'value': 'not'}; {'id': '125', 'type': 'attribute', 'children': ['126', '127']}; {'id': '126', 'type': 'identifier', 'children': [], 'value': 'ident'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '128', 'type': 'identifier', 'children': [], 'value': 'data_sources'}; {'id': '129', 'type': 'block', 'children': ['130', '142']}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}; {'id': '131', 'type': 'assignment', 'children': ['132', '133']}; {'id': '132', 'type': 'identifier', 'children': [], 'value': 'success'}; {'id': '133', 'type': 'call', 'children': ['134', '137']}; {'id': '134', 'type': 'attribute', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'SortingHat'}; {'id': '136', 'type': 'identifier', 'children': [], 'value': 'remove_identity'}; {'id': '137', 'type': 'argument_list', 'children': ['138', '139']}; {'id': '138', 'type': 'identifier', 'children': [], 'value': 'sortinghat_db'}; {'id': '139', 'type': 'attribute', 'children': ['140', '141']}; {'id': '140', 'type': 'identifier', 'children': [], 'value': 'ident'}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'id'}; {'id': '142', 'type': 'expression_statement', 'children': ['143']}; {'id': '143', 'type': 'assignment', 'children': ['144', '145']}; {'id': '144', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '145', 'type': 'conditional_expression', 'children': ['146', '149', '150'], 'value': 'if'}; {'id': '146', 'type': 'binary_operator', 'children': ['147', '148'], 'value': '+'}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '148', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'success'}; {'id': '150', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '151', 'type': 'return_statement', 'children': ['152']}; {'id': '152', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '153', 'type': 'function_definition', 'children': ['154', '155', '158']}; {'id': '154', 'type': 'function_name', 'children': [], 'value': 'has_identities_in_data_sources'}; {'id': '155', 'type': 'parameters', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'unique_ident'}; {'id': '157', 'type': 'identifier', 'children': [], 'value': 'data_sources'}; {'id': '158', 'type': 'block', 'children': ['159', '163', '181']}; {'id': '159', 'type': 'expression_statement', 'children': ['160']}; {'id': '160', 'type': 'assignment', 'children': ['161', '162']}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'in_active'}; {'id': '162', 'type': 'False', 'children': []}; {'id': '163', 'type': 'for_statement', 'children': ['164', '165', '168']}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'ident'}; {'id': '165', 'type': 'attribute', 'children': ['166', '167']}; {'id': '166', 'type': 'identifier', 'children': [], 'value': 'unique_ident'}; {'id': '167', 'type': 'identifier', 'children': [], 'value': 'identities'}; {'id': '168', 'type': 'block', 'children': ['169']}; {'id': '169', 'type': 'if_statement', 'children': ['170', '175']}; {'id': '170', 'type': 'comparison_operator', 'children': ['171', '174'], 'value': 'in'}; {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'ident'}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'source'}; {'id': '174', 'type': 'identifier', 'children': [], 'value': 'data_sources'}; {'id': '175', 'type': 'block', 'children': ['176', '180']}; {'id': '176', 'type': 'expression_statement', 'children': ['177']}; {'id': '177', 'type': 'assignment', 'children': ['178', '179']}; {'id': '178', 'type': 'identifier', 'children': [], 'value': 'in_active'}; {'id': '179', 'type': 'True', 'children': []}; {'id': '180', 'type': 'break_statement', 'children': []}; {'id': '181', 'type': 'return_statement', 'children': ['182']}; {'id': '182', 'type': 'identifier', 'children': [], 'value': 'in_active'}; {'id': '183', 'type': 'expression_statement', 'children': ['184']}; {'id': '184', 'type': 'assignment', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'deleted_unique_identities'}; {'id': '186', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '187', 'type': 'expression_statement', 'children': ['188']}; {'id': '188', 'type': 'assignment', 'children': ['189', '190']}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'deleted_identities'}; {'id': '190', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '191', 'type': 'expression_statement', 'children': ['192']}; {'id': '192', 'type': 'assignment', 'children': ['193', '194']}; {'id': '193', 'type': 'identifier', 'children': [], 'value': 'uuids_to_process'}; {'id': '194', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '195', 'type': 'for_statement', 'children': ['196', '197', '203']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'unique_identity'}; {'id': '197', 'type': 'call', 'children': ['198', '201']}; {'id': '198', 'type': 'attribute', 'children': ['199', '200']}; {'id': '199', 'type': 'identifier', 'children': [], 'value': 'SortingHat'}; {'id': '200', 'type': 'identifier', 'children': [], 'value': 'unique_identities'}; {'id': '201', 'type': 'argument_list', 'children': ['202']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'sortinghat_db'}; {'id': '203', 'type': 'block', 'children': ['204', '223', '231', '241', '250', '259', '266', '278', '290', '297']}; {'id': '204', 'type': 'if_statement', 'children': ['205', '211']}; {'id': '205', 'type': 'not_operator', 'children': ['206']}; {'id': '206', 'type': 'call', 'children': ['207', '208']}; {'id': '207', 'type': 'identifier', 'children': [], 'value': 'has_identities_in_data_sources'}; {'id': '208', 'type': 'argument_list', 'children': ['209', '210']}; {'id': '209', 'type': 'identifier', 'children': [], 'value': 'unique_identity'}; {'id': '210', 'type': 'identifier', 'children': [], 'value': 'active_data_sources'}; {'id': '211', 'type': 'block', 'children': ['212', '222']}; {'id': '212', 'type': 'expression_statement', 'children': ['213']}; {'id': '213', 'type': 'augmented_assignment', 'children': ['214', '215'], 'value': '+='}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'deleted_unique_identities'}; {'id': '215', 'type': 'call', 'children': ['216', '217']}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'delete_unique_identities'}; {'id': '217', 'type': 'argument_list', 'children': ['218']}; {'id': '218', 'type': 'list', 'children': ['219'], 'value': '[unique_identity.uuid]'}; {'id': '219', 'type': 'attribute', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'unique_identity'}; {'id': '221', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '222', 'type': 'continue_statement', 'children': []}; {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'augmented_assignment', 'children': ['225', '226'], 'value': '+='}; {'id': '225', 'type': 'identifier', 'children': [], 'value': 'deleted_identities'}; {'id': '226', 'type': 'call', 'children': ['227', '228']}; {'id': '227', 'type': 'identifier', 'children': [], 'value': 'delete_identities'}; {'id': '228', 'type': 'argument_list', 'children': ['229', '230']}; {'id': '229', 'type': 'identifier', 'children': [], 'value': 'unique_identity'}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'active_data_sources'}; {'id': '231', 'type': 'if_statement', 'children': ['232', '239']}; {'id': '232', 'type': 'not_operator', 'children': ['233']}; {'id': '233', 'type': 'call', 'children': ['234', '235']}; {'id': '234', 'type': 'identifier', 'children': [], 'value': 'has_identities_in_data_sources'}; {'id': '235', 'type': 'argument_list', 'children': ['236', '237']}; {'id': '236', 'type': 'identifier', 'children': [], 'value': 'unique_identity'}; {'id': '237', 'type': 'list', 'children': ['238'], 'value': '[current_data_source]'}; {'id': '238', 'type': 'identifier', 'children': [], 'value': 'current_data_source'}; {'id': '239', 'type': 'block', 'children': ['240']}; {'id': '240', 'type': 'continue_statement', 'children': []}; {'id': '241', 'type': 'expression_statement', 'children': ['242']}; {'id': '242', 'type': 'call', 'children': ['243', '246']}; {'id': '243', 'type': 'attribute', 'children': ['244', '245']}; {'id': '244', 'type': 'identifier', 'children': [], 'value': 'uuids_to_process'}; {'id': '245', 'type': 'identifier', 'children': [], 'value': 'append'}; {'id': '246', 'type': 'argument_list', 'children': ['247']}; {'id': '247', 'type': 'attribute', 'children': ['248', '249']}; {'id': '248', 'type': 'identifier', 'children': [], 'value': 'unique_identity'}; {'id': '249', 'type': 'identifier', 'children': [], 'value': 'uuid'}; {'id': '250', 'type': 'if_statement', 'children': ['251', '257']}; {'id': '251', 'type': 'comparison_operator', 'children': ['252', '256'], 'value': '!='}; {'id': '252', 'type': 'call', 'children': ['253', '254']}; {'id': '253', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '254', 'type': 'argument_list', 'children': ['255']}; {'id': '255', 'type': 'identifier', 'children': [], 'value': 'uuids_to_process'}; {'id': '256', 'type': 'identifier', 'children': [], 'value': 'SIZE_SCROLL_IDENTITIES_INDEX'}; {'id': '257', 'type': 'block', 'children': ['258']}; {'id': '258', 'type': 'continue_statement', 'children': []}; {'id': '259', 'type': 'expression_statement', 'children': ['260']}; {'id': '260', 'type': 'assignment', 'children': ['261', '262']}; {'id': '261', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '262', 'type': 'call', 'children': ['263', '264']}; {'id': '263', 'type': 'identifier', 'children': [], 'value': 'get_uuids_in_index'}; {'id': '264', 'type': 'argument_list', 'children': ['265']}; {'id': '265', 'type': 'identifier', 'children': [], 'value': 'uuids_to_process'}; {'id': '266', 'type': 'expression_statement', 'children': ['267']}; {'id': '267', 'type': 'assignment', 'children': ['268', '269']}; {'id': '268', 'type': 'identifier', 'children': [], 'value': 'uuids_found'}; {'id': '269', 'type': 'list_comprehension', 'children': ['270', '275']}; {'id': '270', 'type': 'subscript', 'children': ['271', '274']}; {'id': '271', 'type': 'subscript', 'children': ['272', '273']}; {'id': '272', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '273', 'type': 'string', 'children': [], 'value': "'_source'"}; {'id': '274', 'type': 'string', 'children': [], 'value': "'sh_uuid'"}; {'id': '275', 'type': 'for_in_clause', 'children': ['276', '277']}; {'id': '276', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '277', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '278', 'type': 'expression_statement', 'children': ['279']}; {'id': '279', 'type': 'assignment', 'children': ['280', '281']}; {'id': '280', 'type': 'identifier', 'children': [], 'value': 'orphan_uuids'}; {'id': '281', 'type': 'binary_operator', 'children': ['282', '286'], 'value': '-'}; {'id': '282', 'type': 'call', 'children': ['283', '284']}; {'id': '283', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '284', 'type': 'argument_list', 'children': ['285']}; {'id': '285', 'type': 'identifier', 'children': [], 'value': 'uuids_to_process'}; {'id': '286', 'type': 'call', 'children': ['287', '288']}; {'id': '287', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '288', 'type': 'argument_list', 'children': ['289']}; {'id': '289', 'type': 'identifier', 'children': [], 'value': 'uuids_found'}; {'id': '290', 'type': 'expression_statement', 'children': ['291']}; {'id': '291', 'type': 'augmented_assignment', 'children': ['292', '293'], 'value': '+='}; {'id': '292', 'type': 'identifier', 'children': [], 'value': 'deleted_unique_identities'}; {'id': '293', 'type': 'call', 'children': ['294', '295']}; {'id': '294', 'type': 'identifier', 'children': [], 'value': 'delete_unique_identities'}; {'id': '295', 'type': 'argument_list', 'children': ['296']}; {'id': '296', 'type': 'identifier', 'children': [], 'value': 'orphan_uuids'}; {'id': '297', 'type': 'expression_statement', 'children': ['298']}; {'id': '298', 'type': 'assignment', 'children': ['299', '300']}; {'id': '299', 'type': 'identifier', 'children': [], 'value': 'uuids_to_process'}; {'id': '300', 'type': 'list', 'children': [], 'value': '[]'}; {'id': '301', 'type': 'if_statement', 'children': ['302', '303']}; {'id': '302', 'type': 'identifier', 'children': [], 'value': 'uuids_to_process'}; {'id': '303', 'type': 'block', 'children': ['304', '311', '323', '335']}; {'id': '304', 'type': 'expression_statement', 'children': ['305']}; {'id': '305', 'type': 'assignment', 'children': ['306', '307']}; {'id': '306', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '307', 'type': 'call', 'children': ['308', '309']}; {'id': '308', 'type': 'identifier', 'children': [], 'value': 'get_uuids_in_index'}; {'id': '309', 'type': 'argument_list', 'children': ['310']}; {'id': '310', 'type': 'identifier', 'children': [], 'value': 'uuids_to_process'}; {'id': '311', 'type': 'expression_statement', 'children': ['312']}; {'id': '312', 'type': 'assignment', 'children': ['313', '314']}; {'id': '313', 'type': 'identifier', 'children': [], 'value': 'uuids_found'}; {'id': '314', 'type': 'list_comprehension', 'children': ['315', '320']}; {'id': '315', 'type': 'subscript', 'children': ['316', '319']}; {'id': '316', 'type': 'subscript', 'children': ['317', '318']}; {'id': '317', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '318', 'type': 'string', 'children': [], 'value': "'_source'"}; {'id': '319', 'type': 'string', 'children': [], 'value': "'sh_uuid'"}; {'id': '320', 'type': 'for_in_clause', 'children': ['321', '322']}; {'id': '321', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '322', 'type': 'identifier', 'children': [], 'value': 'results'}; {'id': '323', 'type': 'expression_statement', 'children': ['324']}; {'id': '324', 'type': 'assignment', 'children': ['325', '326']}; {'id': '325', 'type': 'identifier', 'children': [], 'value': 'orphan_uuids'}; {'id': '326', 'type': 'binary_operator', 'children': ['327', '331'], 'value': '-'}; {'id': '327', 'type': 'call', 'children': ['328', '329']}; {'id': '328', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '329', 'type': 'argument_list', 'children': ['330']}; {'id': '330', 'type': 'identifier', 'children': [], 'value': 'uuids_to_process'}; {'id': '331', 'type': 'call', 'children': ['332', '333']}; {'id': '332', 'type': 'identifier', 'children': [], 'value': 'set'}; {'id': '333', 'type': 'argument_list', 'children': ['334']}; {'id': '334', 'type': 'identifier', 'children': [], 'value': 'uuids_found'}; {'id': '335', 'type': 'expression_statement', 'children': ['336']}; {'id': '336', 'type': 'augmented_assignment', 'children': ['337', '338'], 'value': '+='}; {'id': '337', 'type': 'identifier', 'children': [], 'value': 'deleted_unique_identities'}; {'id': '338', 'type': 'call', 'children': ['339', '340']}; {'id': '339', 'type': 'identifier', 'children': [], 'value': 'delete_unique_identities'}; {'id': '340', 'type': 'argument_list', 'children': ['341']}; {'id': '341', 'type': 'identifier', 'children': [], 'value': 'orphan_uuids'}; {'id': '342', 'type': 'expression_statement', 'children': ['343']}; {'id': '343', 'type': 'call', 'children': ['344', '347']}; {'id': '344', 'type': 'attribute', 'children': ['345', '346']}; {'id': '345', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '346', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '347', 'type': 'argument_list', 'children': ['348', '349']}; {'id': '348', 'type': 'string', 'children': [], 'value': '"[identities retention] Total orphan unique identities deleted from SH: %i"'}; {'id': '349', 'type': 'identifier', 'children': [], 'value': 'deleted_unique_identities'}; {'id': '350', 'type': 'expression_statement', 'children': ['351']}; {'id': '351', 'type': 'call', 'children': ['352', '355']}; {'id': '352', 'type': 'attribute', 'children': ['353', '354']}; {'id': '353', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '354', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '355', 'type': 'argument_list', 'children': ['356', '357']}; {'id': '356', 'type': 'string', 'children': [], 'value': '"[identities retention] Total identities in non-active data sources deleted from SH: %i"'}; {'id': '357', 'type': 'identifier', 'children': [], 'value': 'deleted_identities'}
def delete_orphan_unique_identities(es, sortinghat_db, current_data_source, active_data_sources): def get_uuids_in_index(target_uuids): page = es.search( index=IDENTITIES_INDEX, scroll="360m", size=SIZE_SCROLL_IDENTITIES_INDEX, body={ "query": { "bool": { "filter": [ { "terms": { "sh_uuid": target_uuids } } ] } } } ) hits = [] if page['hits']['total'] != 0: hits = page['hits']['hits'] return hits def delete_unique_identities(target_uuids): count = 0 for uuid in target_uuids: success = SortingHat.remove_unique_identity(sortinghat_db, uuid) count = count + 1 if success else count return count def delete_identities(unique_ident, data_sources): count = 0 for ident in unique_ident.identities: if ident.source not in data_sources: success = SortingHat.remove_identity(sortinghat_db, ident.id) count = count + 1 if success else count return count def has_identities_in_data_sources(unique_ident, data_sources): in_active = False for ident in unique_ident.identities: if ident.source in data_sources: in_active = True break return in_active deleted_unique_identities = 0 deleted_identities = 0 uuids_to_process = [] for unique_identity in SortingHat.unique_identities(sortinghat_db): if not has_identities_in_data_sources(unique_identity, active_data_sources): deleted_unique_identities += delete_unique_identities([unique_identity.uuid]) continue deleted_identities += delete_identities(unique_identity, active_data_sources) if not has_identities_in_data_sources(unique_identity, [current_data_source]): continue uuids_to_process.append(unique_identity.uuid) if len(uuids_to_process) != SIZE_SCROLL_IDENTITIES_INDEX: continue results = get_uuids_in_index(uuids_to_process) uuids_found = [item['_source']['sh_uuid'] for item in results] orphan_uuids = set(uuids_to_process) - set(uuids_found) deleted_unique_identities += delete_unique_identities(orphan_uuids) uuids_to_process = [] if uuids_to_process: results = get_uuids_in_index(uuids_to_process) uuids_found = [item['_source']['sh_uuid'] for item in results] orphan_uuids = set(uuids_to_process) - set(uuids_found) deleted_unique_identities += delete_unique_identities(orphan_uuids) logger.debug("[identities retention] Total orphan unique identities deleted from SH: %i", deleted_unique_identities) logger.debug("[identities retention] Total identities in non-active data sources deleted from SH: %i", deleted_identities)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'delete_inactive_unique_identities'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'es'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'sortinghat_db'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'before_date'}; {'id': '7', 'type': 'block', 'children': ['8', '40', '46', '54', '69', '73', '144']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'es'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'search'}; {'id': '15', 'type': 'argument_list', 'children': ['16', '19', '22', '25']}; {'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'index'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'IDENTITIES_INDEX'}; {'id': '19', 'type': 'keyword_argument', 'children': ['20', '21']}; {'id': '20', 'type': 'identifier', 'children': [], 'value': 'scroll'}; {'id': '21', 'type': 'string', 'children': [], 'value': '"360m"'}; {'id': '22', 'type': 'keyword_argument', 'children': ['23', '24']}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'size'}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'SIZE_SCROLL_IDENTITIES_INDEX'}; {'id': '25', 'type': 'keyword_argument', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'body'}; {'id': '27', 'type': 'dictionary', 'children': ['28']}; {'id': '28', 'type': 'pair', 'children': ['29', '30']}; {'id': '29', 'type': 'string', 'children': [], 'value': '"query"'}; {'id': '30', 'type': 'dictionary', 'children': ['31']}; {'id': '31', 'type': 'pair', 'children': ['32', '33']}; {'id': '32', 'type': 'string', 'children': [], 'value': '"range"'}; {'id': '33', 'type': 'dictionary', 'children': ['34']}; {'id': '34', 'type': 'pair', 'children': ['35', '36']}; {'id': '35', 'type': 'string', 'children': [], 'value': '"last_seen"'}; {'id': '36', 'type': 'dictionary', 'children': ['37']}; {'id': '37', 'type': 'pair', 'children': ['38', '39']}; {'id': '38', 'type': 'string', 'children': [], 'value': '"lte"'}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'before_date'}; {'id': '40', 'type': 'expression_statement', 'children': ['41']}; {'id': '41', 'type': 'assignment', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'sid'}; {'id': '43', 'type': 'subscript', 'children': ['44', '45']}; {'id': '44', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '45', 'type': 'string', 'children': [], 'value': "'_scroll_id'"}; {'id': '46', 'type': 'expression_statement', 'children': ['47']}; {'id': '47', 'type': 'assignment', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'scroll_size'}; {'id': '49', 'type': 'subscript', 'children': ['50', '53']}; {'id': '50', 'type': 'subscript', 'children': ['51', '52']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '52', 'type': 'string', 'children': [], 'value': "'hits'"}; {'id': '53', 'type': 'string', 'children': [], 'value': "'total'"}; {'id': '54', 'type': 'if_statement', 'children': ['55', '58']}; {'id': '55', 'type': 'comparison_operator', 'children': ['56', '57'], 'value': '=='}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'scroll_size'}; {'id': '57', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '58', 'type': 'block', 'children': ['59', '68']}; {'id': '59', 'type': 'expression_statement', 'children': ['60']}; {'id': '60', 'type': 'call', 'children': ['61', '64']}; {'id': '61', 'type': 'attribute', 'children': ['62', '63']}; {'id': '62', 'type': 'identifier', 'children': [], 'value': 'logging'}; {'id': '63', 'type': 'identifier', 'children': [], 'value': 'warning'}; {'id': '64', 'type': 'argument_list', 'children': ['65', '66', '67']}; {'id': '65', 'type': 'string', 'children': [], 'value': '"[identities retention] No inactive identities found in %s after %s!"'}; {'id': '66', 'type': 'identifier', 'children': [], 'value': 'IDENTITIES_INDEX'}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'before_date'}; {'id': '68', 'type': 'return_statement', 'children': []}; {'id': '69', 'type': 'expression_statement', 'children': ['70']}; {'id': '70', 'type': 'assignment', 'children': ['71', '72']}; {'id': '71', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '72', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '73', 'type': 'while_statement', 'children': ['74', '77']}; {'id': '74', 'type': 'comparison_operator', 'children': ['75', '76'], 'value': '>'}; {'id': '75', 'type': 'identifier', 'children': [], 'value': 'scroll_size'}; {'id': '76', 'type': 'integer', 'children': [], 'value': '0'}; {'id': '77', 'type': 'block', 'children': ['78', '113', '127', '133']}; {'id': '78', 'type': 'for_statement', 'children': ['79', '80', '85']}; {'id': '79', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '80', 'type': 'subscript', 'children': ['81', '84']}; {'id': '81', 'type': 'subscript', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '83', 'type': 'string', 'children': [], 'value': "'hits'"}; {'id': '84', 'type': 'string', 'children': [], 'value': "'hits'"}; {'id': '85', 'type': 'block', 'children': ['86', '94', '104']}; {'id': '86', 'type': 'expression_statement', 'children': ['87']}; {'id': '87', 'type': 'assignment', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'to_delete'}; {'id': '89', 'type': 'subscript', 'children': ['90', '93']}; {'id': '90', 'type': 'subscript', 'children': ['91', '92']}; {'id': '91', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '92', 'type': 'string', 'children': [], 'value': "'_source'"}; {'id': '93', 'type': 'string', 'children': [], 'value': "'sh_uuid'"}; {'id': '94', 'type': 'expression_statement', 'children': ['95']}; {'id': '95', 'type': 'assignment', 'children': ['96', '97']}; {'id': '96', 'type': 'identifier', 'children': [], 'value': 'success'}; {'id': '97', 'type': 'call', 'children': ['98', '101']}; {'id': '98', 'type': 'attribute', 'children': ['99', '100']}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'SortingHat'}; {'id': '100', 'type': 'identifier', 'children': [], 'value': 'remove_unique_identity'}; {'id': '101', 'type': 'argument_list', 'children': ['102', '103']}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'sortinghat_db'}; {'id': '103', 'type': 'identifier', 'children': [], 'value': 'to_delete'}; {'id': '104', 'type': 'expression_statement', 'children': ['105']}; {'id': '105', 'type': 'assignment', 'children': ['106', '107']}; {'id': '106', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '107', 'type': 'conditional_expression', 'children': ['108', '111', '112'], 'value': 'if'}; {'id': '108', 'type': 'binary_operator', 'children': ['109', '110'], 'value': '+'}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '110', 'type': 'integer', 'children': [], 'value': '1'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'success'}; {'id': '112', 'type': 'identifier', 'children': [], 'value': 'count'}; {'id': '113', 'type': 'expression_statement', 'children': ['114']}; {'id': '114', 'type': 'assignment', 'children': ['115', '116']}; {'id': '115', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '116', 'type': 'call', 'children': ['117', '120']}; {'id': '117', 'type': 'attribute', 'children': ['118', '119']}; {'id': '118', 'type': 'identifier', 'children': [], 'value': 'es'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'scroll'}; {'id': '120', 'type': 'argument_list', 'children': ['121', '124']}; {'id': '121', 'type': 'keyword_argument', 'children': ['122', '123']}; {'id': '122', 'type': 'identifier', 'children': [], 'value': 'scroll_id'}; {'id': '123', 'type': 'identifier', 'children': [], 'value': 'sid'}; {'id': '124', 'type': 'keyword_argument', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'scroll'}; {'id': '126', 'type': 'string', 'children': [], 'value': "'60m'"}; {'id': '127', 'type': 'expression_statement', 'children': ['128']}; {'id': '128', 'type': 'assignment', 'children': ['129', '130']}; {'id': '129', 'type': 'identifier', 'children': [], 'value': 'sid'}; {'id': '130', 'type': 'subscript', 'children': ['131', '132']}; {'id': '131', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '132', 'type': 'string', 'children': [], 'value': "'_scroll_id'"}; {'id': '133', 'type': 'expression_statement', 'children': ['134']}; {'id': '134', 'type': 'assignment', 'children': ['135', '136']}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'scroll_size'}; {'id': '136', 'type': 'call', 'children': ['137', '138']}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'len'}; {'id': '138', 'type': 'argument_list', 'children': ['139']}; {'id': '139', 'type': 'subscript', 'children': ['140', '143']}; {'id': '140', 'type': 'subscript', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'page'}; {'id': '142', 'type': 'string', 'children': [], 'value': "'hits'"}; {'id': '143', 'type': 'string', 'children': [], 'value': "'hits'"}; {'id': '144', 'type': 'expression_statement', 'children': ['145']}; {'id': '145', 'type': 'call', 'children': ['146', '149']}; {'id': '146', 'type': 'attribute', 'children': ['147', '148']}; {'id': '147', 'type': 'identifier', 'children': [], 'value': 'logger'}; {'id': '148', 'type': 'identifier', 'children': [], 'value': 'debug'}; {'id': '149', 'type': 'argument_list', 'children': ['150', '151']}; {'id': '150', 'type': 'string', 'children': [], 'value': '"[identities retention] Total inactive identities deleted from SH: %i"'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'count'}
def delete_inactive_unique_identities(es, sortinghat_db, before_date): page = es.search( index=IDENTITIES_INDEX, scroll="360m", size=SIZE_SCROLL_IDENTITIES_INDEX, body={ "query": { "range": { "last_seen": { "lte": before_date } } } } ) sid = page['_scroll_id'] scroll_size = page['hits']['total'] if scroll_size == 0: logging.warning("[identities retention] No inactive identities found in %s after %s!", IDENTITIES_INDEX, before_date) return count = 0 while scroll_size > 0: for item in page['hits']['hits']: to_delete = item['_source']['sh_uuid'] success = SortingHat.remove_unique_identity(sortinghat_db, to_delete) count = count + 1 if success else count page = es.scroll(scroll_id=sid, scroll='60m') sid = page['_scroll_id'] scroll_size = len(page['hits']['hits']) logger.debug("[identities retention] Total inactive identities deleted from SH: %i", count)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '9']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'retain_identities'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '7', '8']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'retention_time'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'es_enrichment_url'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'sortinghat_db'}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'data_source'}; {'id': '8', 'type': 'identifier', 'children': [], 'value': 'active_data_sources'}; {'id': '9', 'type': 'block', 'children': ['10', '19', '27', '47', '54']}; {'id': '10', 'type': 'expression_statement', 'children': ['11']}; {'id': '11', 'type': 'assignment', 'children': ['12', '13']}; {'id': '12', 'type': 'identifier', 'children': [], 'value': 'before_date'}; {'id': '13', 'type': 'call', 'children': ['14', '15']}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'get_diff_current_date'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'keyword_argument', 'children': ['17', '18']}; {'id': '17', 'type': 'identifier', 'children': [], 'value': 'minutes'}; {'id': '18', 'type': 'identifier', 'children': [], 'value': 'retention_time'}; {'id': '19', 'type': 'expression_statement', 'children': ['20']}; {'id': '20', 'type': 'assignment', 'children': ['21', '22']}; {'id': '21', 'type': 'identifier', 'children': [], 'value': 'before_date_str'}; {'id': '22', 'type': 'call', 'children': ['23', '26']}; {'id': '23', 'type': 'attribute', 'children': ['24', '25']}; {'id': '24', 'type': 'identifier', 'children': [], 'value': 'before_date'}; {'id': '25', 'type': 'identifier', 'children': [], 'value': 'isoformat'}; {'id': '26', 'type': 'argument_list', 'children': []}; {'id': '27', 'type': 'expression_statement', 'children': ['28']}; {'id': '28', 'type': 'assignment', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'es'}; {'id': '30', 'type': 'call', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'Elasticsearch'}; {'id': '32', 'type': 'argument_list', 'children': ['33', '35', '38', '41', '44']}; {'id': '33', 'type': 'list', 'children': ['34'], 'value': '[es_enrichment_url]'}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'es_enrichment_url'}; {'id': '35', 'type': 'keyword_argument', 'children': ['36', '37']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'timeout'}; {'id': '37', 'type': 'integer', 'children': [], 'value': '120'}; {'id': '38', 'type': 'keyword_argument', 'children': ['39', '40']}; {'id': '39', 'type': 'identifier', 'children': [], 'value': 'max_retries'}; {'id': '40', 'type': 'integer', 'children': [], 'value': '20'}; {'id': '41', 'type': 'keyword_argument', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'retry_on_timeout'}; {'id': '43', 'type': 'True', 'children': []}; {'id': '44', 'type': 'keyword_argument', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'verify_certs'}; {'id': '46', 'type': 'False', 'children': []}; {'id': '47', 'type': 'expression_statement', 'children': ['48']}; {'id': '48', 'type': 'call', 'children': ['49', '50']}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'delete_inactive_unique_identities'}; {'id': '50', 'type': 'argument_list', 'children': ['51', '52', '53']}; {'id': '51', 'type': 'identifier', 'children': [], 'value': 'es'}; {'id': '52', 'type': 'identifier', 'children': [], 'value': 'sortinghat_db'}; {'id': '53', 'type': 'identifier', 'children': [], 'value': 'before_date_str'}; {'id': '54', 'type': 'expression_statement', 'children': ['55']}; {'id': '55', 'type': 'call', 'children': ['56', '57']}; {'id': '56', 'type': 'identifier', 'children': [], 'value': 'delete_orphan_unique_identities'}; {'id': '57', 'type': 'argument_list', 'children': ['58', '59', '60', '61']}; {'id': '58', 'type': 'identifier', 'children': [], 'value': 'es'}; {'id': '59', 'type': 'identifier', 'children': [], 'value': 'sortinghat_db'}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'data_source'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'active_data_sources'}
def retain_identities(retention_time, es_enrichment_url, sortinghat_db, data_source, active_data_sources): before_date = get_diff_current_date(minutes=retention_time) before_date_str = before_date.isoformat() es = Elasticsearch([es_enrichment_url], timeout=120, max_retries=20, retry_on_timeout=True, verify_certs=False) delete_inactive_unique_identities(es, sortinghat_db, before_date_str) delete_orphan_unique_identities(es, sortinghat_db, data_source, active_data_sources)
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '7']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_review_sh'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'revision'}; {'id': '6', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '7', 'type': 'block', 'children': ['8', '17', '32', '42']}; {'id': '8', 'type': 'expression_statement', 'children': ['9']}; {'id': '9', 'type': 'assignment', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '11', 'type': 'call', 'children': ['12', '15']}; {'id': '12', 'type': 'attribute', 'children': ['13', '14']}; {'id': '13', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '14', 'type': 'identifier', 'children': [], 'value': 'get_sh_identity'}; {'id': '15', 'type': 'argument_list', 'children': ['16']}; {'id': '16', 'type': 'identifier', 'children': [], 'value': 'revision'}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'parser'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'parse'}; {'id': '24', 'type': 'argument_list', 'children': ['25']}; {'id': '25', 'type': 'subscript', 'children': ['26', '27']}; {'id': '26', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '27', 'type': 'call', 'children': ['28', '31']}; {'id': '28', 'type': 'attribute', 'children': ['29', '30']}; {'id': '29', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '30', 'type': 'identifier', 'children': [], 'value': 'get_field_date'}; {'id': '31', 'type': 'argument_list', 'children': []}; {'id': '32', 'type': 'expression_statement', 'children': ['33']}; {'id': '33', 'type': 'assignment', 'children': ['34', '35']}; {'id': '34', 'type': 'identifier', 'children': [], 'value': 'erevision'}; {'id': '35', 'type': 'call', 'children': ['36', '39']}; {'id': '36', 'type': 'attribute', 'children': ['37', '38']}; {'id': '37', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '38', 'type': 'identifier', 'children': [], 'value': 'get_item_sh_fields'}; {'id': '39', 'type': 'argument_list', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '41', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '42', 'type': 'return_statement', 'children': ['43']}; {'id': '43', 'type': 'identifier', 'children': [], 'value': 'erevision'}
def get_review_sh(self, revision, item): identity = self.get_sh_identity(revision) update = parser.parse(item[self.get_field_date()]) erevision = self.get_item_sh_fields(identity, update) return erevision
{'id': '0', 'type': 'module', 'children': ['1']}; {'id': '1', 'type': 'function_definition', 'children': ['2', '3', '12']}; {'id': '2', 'type': 'function_name', 'children': [], 'value': 'get_item_sh'}; {'id': '3', 'type': 'parameters', 'children': ['4', '5', '6', '9']}; {'id': '4', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '5', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '6', 'type': 'default_parameter', 'children': ['7', '8']}; {'id': '7', 'type': 'identifier', 'children': [], 'value': 'roles'}; {'id': '8', 'type': 'None', 'children': []}; {'id': '9', 'type': 'default_parameter', 'children': ['10', '11']}; {'id': '10', 'type': 'identifier', 'children': [], 'value': 'date_field'}; {'id': '11', 'type': 'None', 'children': []}; {'id': '12', 'type': 'block', 'children': ['13', '17', '25', '34', '62', '71', '154', '158', '229']}; {'id': '13', 'type': 'expression_statement', 'children': ['14']}; {'id': '14', 'type': 'assignment', 'children': ['15', '16']}; {'id': '15', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'}; {'id': '16', 'type': 'dictionary', 'children': []}; {'id': '17', 'type': 'expression_statement', 'children': ['18']}; {'id': '18', 'type': 'assignment', 'children': ['19', '20']}; {'id': '19', 'type': 'identifier', 'children': [], 'value': 'author_field'}; {'id': '20', 'type': 'call', 'children': ['21', '24']}; {'id': '21', 'type': 'attribute', 'children': ['22', '23']}; {'id': '22', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '23', 'type': 'identifier', 'children': [], 'value': 'get_field_author'}; {'id': '24', 'type': 'argument_list', 'children': []}; {'id': '25', 'type': 'if_statement', 'children': ['26', '28']}; {'id': '26', 'type': 'not_operator', 'children': ['27']}; {'id': '27', 'type': 'identifier', 'children': [], 'value': 'roles'}; {'id': '28', 'type': 'block', 'children': ['29']}; {'id': '29', 'type': 'expression_statement', 'children': ['30']}; {'id': '30', 'type': 'assignment', 'children': ['31', '32']}; {'id': '31', 'type': 'identifier', 'children': [], 'value': 'roles'}; {'id': '32', 'type': 'list', 'children': ['33'], 'value': '[author_field]'}; {'id': '33', 'type': 'identifier', 'children': [], 'value': 'author_field'}; {'id': '34', 'type': 'if_statement', 'children': ['35', '37', '51']}; {'id': '35', 'type': 'not_operator', 'children': ['36']}; {'id': '36', 'type': 'identifier', 'children': [], 'value': 'date_field'}; {'id': '37', 'type': 'block', 'children': ['38']}; {'id': '38', 'type': 'expression_statement', 'children': ['39']}; {'id': '39', 'type': 'assignment', 'children': ['40', '41']}; {'id': '40', 'type': 'identifier', 'children': [], 'value': 'item_date'}; {'id': '41', 'type': 'call', 'children': ['42', '43']}; {'id': '42', 'type': 'identifier', 'children': [], 'value': 'str_to_datetime'}; {'id': '43', 'type': 'argument_list', 'children': ['44']}; {'id': '44', 'type': 'subscript', 'children': ['45', '46']}; {'id': '45', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '46', 'type': 'call', 'children': ['47', '50']}; {'id': '47', 'type': 'attribute', 'children': ['48', '49']}; {'id': '48', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '49', 'type': 'identifier', 'children': [], 'value': 'get_field_date'}; {'id': '50', 'type': 'argument_list', 'children': []}; {'id': '51', 'type': 'else_clause', 'children': ['52']}; {'id': '52', 'type': 'block', 'children': ['53']}; {'id': '53', 'type': 'expression_statement', 'children': ['54']}; {'id': '54', 'type': 'assignment', 'children': ['55', '56']}; {'id': '55', 'type': 'identifier', 'children': [], 'value': 'item_date'}; {'id': '56', 'type': 'call', 'children': ['57', '58']}; {'id': '57', 'type': 'identifier', 'children': [], 'value': 'str_to_datetime'}; {'id': '58', 'type': 'argument_list', 'children': ['59']}; {'id': '59', 'type': 'subscript', 'children': ['60', '61']}; {'id': '60', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '61', 'type': 'identifier', 'children': [], 'value': 'date_field'}; {'id': '62', 'type': 'expression_statement', 'children': ['63']}; {'id': '63', 'type': 'assignment', 'children': ['64', '65']}; {'id': '64', 'type': 'identifier', 'children': [], 'value': 'users_data'}; {'id': '65', 'type': 'call', 'children': ['66', '69']}; {'id': '66', 'type': 'attribute', 'children': ['67', '68']}; {'id': '67', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '68', 'type': 'identifier', 'children': [], 'value': 'get_users_data'}; {'id': '69', 'type': 'argument_list', 'children': ['70']}; {'id': '70', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '71', 'type': 'for_statement', 'children': ['72', '73', '74']}; {'id': '72', 'type': 'identifier', 'children': [], 'value': 'rol'}; {'id': '73', 'type': 'identifier', 'children': [], 'value': 'roles'}; {'id': '74', 'type': 'block', 'children': ['75']}; {'id': '75', 'type': 'if_statement', 'children': ['76', '79']}; {'id': '76', 'type': 'comparison_operator', 'children': ['77', '78'], 'value': 'in'}; {'id': '77', 'type': 'identifier', 'children': [], 'value': 'rol'}; {'id': '78', 'type': 'identifier', 'children': [], 'value': 'users_data'}; {'id': '79', 'type': 'block', 'children': ['80', '90', '106', '122', '138']}; {'id': '80', 'type': 'expression_statement', 'children': ['81']}; {'id': '81', 'type': 'assignment', 'children': ['82', '83']}; {'id': '82', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '83', 'type': 'call', 'children': ['84', '87']}; {'id': '84', 'type': 'attribute', 'children': ['85', '86']}; {'id': '85', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '86', 'type': 'identifier', 'children': [], 'value': 'get_sh_identity'}; {'id': '87', 'type': 'argument_list', 'children': ['88', '89']}; {'id': '88', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '89', 'type': 'identifier', 'children': [], 'value': 'rol'}; {'id': '90', 'type': 'expression_statement', 'children': ['91']}; {'id': '91', 'type': 'call', 'children': ['92', '95']}; {'id': '92', 'type': 'attribute', 'children': ['93', '94']}; {'id': '93', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'}; {'id': '94', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '95', 'type': 'argument_list', 'children': ['96']}; {'id': '96', 'type': 'call', 'children': ['97', '100']}; {'id': '97', 'type': 'attribute', 'children': ['98', '99']}; {'id': '98', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '99', 'type': 'identifier', 'children': [], 'value': 'get_item_sh_fields'}; {'id': '100', 'type': 'argument_list', 'children': ['101', '102', '103']}; {'id': '101', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '102', 'type': 'identifier', 'children': [], 'value': 'item_date'}; {'id': '103', 'type': 'keyword_argument', 'children': ['104', '105']}; {'id': '104', 'type': 'identifier', 'children': [], 'value': 'rol'}; {'id': '105', 'type': 'identifier', 'children': [], 'value': 'rol'}; {'id': '106', 'type': 'if_statement', 'children': ['107', '113']}; {'id': '107', 'type': 'not_operator', 'children': ['108']}; {'id': '108', 'type': 'subscript', 'children': ['109', '110']}; {'id': '109', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'}; {'id': '110', 'type': 'binary_operator', 'children': ['111', '112'], 'value': '+'}; {'id': '111', 'type': 'identifier', 'children': [], 'value': 'rol'}; {'id': '112', 'type': 'string', 'children': [], 'value': "'_org_name'"}; {'id': '113', 'type': 'block', 'children': ['114']}; {'id': '114', 'type': 'expression_statement', 'children': ['115']}; {'id': '115', 'type': 'assignment', 'children': ['116', '121']}; {'id': '116', 'type': 'subscript', 'children': ['117', '118']}; {'id': '117', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'}; {'id': '118', 'type': 'binary_operator', 'children': ['119', '120'], 'value': '+'}; {'id': '119', 'type': 'identifier', 'children': [], 'value': 'rol'}; {'id': '120', 'type': 'string', 'children': [], 'value': "'_org_name'"}; {'id': '121', 'type': 'identifier', 'children': [], 'value': 'SH_UNKNOWN_VALUE'}; {'id': '122', 'type': 'if_statement', 'children': ['123', '129']}; {'id': '123', 'type': 'not_operator', 'children': ['124']}; {'id': '124', 'type': 'subscript', 'children': ['125', '126']}; {'id': '125', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'}; {'id': '126', 'type': 'binary_operator', 'children': ['127', '128'], 'value': '+'}; {'id': '127', 'type': 'identifier', 'children': [], 'value': 'rol'}; {'id': '128', 'type': 'string', 'children': [], 'value': "'_name'"}; {'id': '129', 'type': 'block', 'children': ['130']}; {'id': '130', 'type': 'expression_statement', 'children': ['131']}; {'id': '131', 'type': 'assignment', 'children': ['132', '137']}; {'id': '132', 'type': 'subscript', 'children': ['133', '134']}; {'id': '133', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'}; {'id': '134', 'type': 'binary_operator', 'children': ['135', '136'], 'value': '+'}; {'id': '135', 'type': 'identifier', 'children': [], 'value': 'rol'}; {'id': '136', 'type': 'string', 'children': [], 'value': "'_name'"}; {'id': '137', 'type': 'identifier', 'children': [], 'value': 'SH_UNKNOWN_VALUE'}; {'id': '138', 'type': 'if_statement', 'children': ['139', '145']}; {'id': '139', 'type': 'not_operator', 'children': ['140']}; {'id': '140', 'type': 'subscript', 'children': ['141', '142']}; {'id': '141', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'}; {'id': '142', 'type': 'binary_operator', 'children': ['143', '144'], 'value': '+'}; {'id': '143', 'type': 'identifier', 'children': [], 'value': 'rol'}; {'id': '144', 'type': 'string', 'children': [], 'value': "'_user_name'"}; {'id': '145', 'type': 'block', 'children': ['146']}; {'id': '146', 'type': 'expression_statement', 'children': ['147']}; {'id': '147', 'type': 'assignment', 'children': ['148', '153']}; {'id': '148', 'type': 'subscript', 'children': ['149', '150']}; {'id': '149', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'}; {'id': '150', 'type': 'binary_operator', 'children': ['151', '152'], 'value': '+'}; {'id': '151', 'type': 'identifier', 'children': [], 'value': 'rol'}; {'id': '152', 'type': 'string', 'children': [], 'value': "'_user_name'"}; {'id': '153', 'type': 'identifier', 'children': [], 'value': 'SH_UNKNOWN_VALUE'}; {'id': '154', 'type': 'expression_statement', 'children': ['155']}; {'id': '155', 'type': 'assignment', 'children': ['156', '157']}; {'id': '156', 'type': 'identifier', 'children': [], 'value': 'rol_author'}; {'id': '157', 'type': 'string', 'children': [], 'value': "'author'"}; {'id': '158', 'type': 'if_statement', 'children': ['159', '166']}; {'id': '159', 'type': 'boolean_operator', 'children': ['160', '163'], 'value': 'and'}; {'id': '160', 'type': 'comparison_operator', 'children': ['161', '162'], 'value': 'in'}; {'id': '161', 'type': 'identifier', 'children': [], 'value': 'author_field'}; {'id': '162', 'type': 'identifier', 'children': [], 'value': 'users_data'}; {'id': '163', 'type': 'comparison_operator', 'children': ['164', '165'], 'value': '!='}; {'id': '164', 'type': 'identifier', 'children': [], 'value': 'author_field'}; {'id': '165', 'type': 'identifier', 'children': [], 'value': 'rol_author'}; {'id': '166', 'type': 'block', 'children': ['167', '177', '193', '205', '217']}; {'id': '167', 'type': 'expression_statement', 'children': ['168']}; {'id': '168', 'type': 'assignment', 'children': ['169', '170']}; {'id': '169', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '170', 'type': 'call', 'children': ['171', '174']}; {'id': '171', 'type': 'attribute', 'children': ['172', '173']}; {'id': '172', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '173', 'type': 'identifier', 'children': [], 'value': 'get_sh_identity'}; {'id': '174', 'type': 'argument_list', 'children': ['175', '176']}; {'id': '175', 'type': 'identifier', 'children': [], 'value': 'item'}; {'id': '176', 'type': 'identifier', 'children': [], 'value': 'author_field'}; {'id': '177', 'type': 'expression_statement', 'children': ['178']}; {'id': '178', 'type': 'call', 'children': ['179', '182']}; {'id': '179', 'type': 'attribute', 'children': ['180', '181']}; {'id': '180', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'}; {'id': '181', 'type': 'identifier', 'children': [], 'value': 'update'}; {'id': '182', 'type': 'argument_list', 'children': ['183']}; {'id': '183', 'type': 'call', 'children': ['184', '187']}; {'id': '184', 'type': 'attribute', 'children': ['185', '186']}; {'id': '185', 'type': 'identifier', 'children': [], 'value': 'self'}; {'id': '186', 'type': 'identifier', 'children': [], 'value': 'get_item_sh_fields'}; {'id': '187', 'type': 'argument_list', 'children': ['188', '189', '190']}; {'id': '188', 'type': 'identifier', 'children': [], 'value': 'identity'}; {'id': '189', 'type': 'identifier', 'children': [], 'value': 'item_date'}; {'id': '190', 'type': 'keyword_argument', 'children': ['191', '192']}; {'id': '191', 'type': 'identifier', 'children': [], 'value': 'rol'}; {'id': '192', 'type': 'identifier', 'children': [], 'value': 'rol_author'}; {'id': '193', 'type': 'if_statement', 'children': ['194', '198']}; {'id': '194', 'type': 'not_operator', 'children': ['195']}; {'id': '195', 'type': 'subscript', 'children': ['196', '197']}; {'id': '196', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'}; {'id': '197', 'type': 'string', 'children': [], 'value': "'author_org_name'"}; {'id': '198', 'type': 'block', 'children': ['199']}; {'id': '199', 'type': 'expression_statement', 'children': ['200']}; {'id': '200', 'type': 'assignment', 'children': ['201', '204']}; {'id': '201', 'type': 'subscript', 'children': ['202', '203']}; {'id': '202', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'}; {'id': '203', 'type': 'string', 'children': [], 'value': "'author_org_name'"}; {'id': '204', 'type': 'identifier', 'children': [], 'value': 'SH_UNKNOWN_VALUE'}; {'id': '205', 'type': 'if_statement', 'children': ['206', '210']}; {'id': '206', 'type': 'not_operator', 'children': ['207']}; {'id': '207', 'type': 'subscript', 'children': ['208', '209']}; {'id': '208', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'}; {'id': '209', 'type': 'string', 'children': [], 'value': "'author_name'"}; {'id': '210', 'type': 'block', 'children': ['211']}; {'id': '211', 'type': 'expression_statement', 'children': ['212']}; {'id': '212', 'type': 'assignment', 'children': ['213', '216']}; {'id': '213', 'type': 'subscript', 'children': ['214', '215']}; {'id': '214', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'}; {'id': '215', 'type': 'string', 'children': [], 'value': "'author_name'"}; {'id': '216', 'type': 'identifier', 'children': [], 'value': 'SH_UNKNOWN_VALUE'}; {'id': '217', 'type': 'if_statement', 'children': ['218', '222']}; {'id': '218', 'type': 'not_operator', 'children': ['219']}; {'id': '219', 'type': 'subscript', 'children': ['220', '221']}; {'id': '220', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'}; {'id': '221', 'type': 'string', 'children': [], 'value': "'author_user_name'"}; {'id': '222', 'type': 'block', 'children': ['223']}; {'id': '223', 'type': 'expression_statement', 'children': ['224']}; {'id': '224', 'type': 'assignment', 'children': ['225', '228']}; {'id': '225', 'type': 'subscript', 'children': ['226', '227']}; {'id': '226', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'}; {'id': '227', 'type': 'string', 'children': [], 'value': "'author_user_name'"}; {'id': '228', 'type': 'identifier', 'children': [], 'value': 'SH_UNKNOWN_VALUE'}; {'id': '229', 'type': 'return_statement', 'children': ['230']}; {'id': '230', 'type': 'identifier', 'children': [], 'value': 'eitem_sh'}
def get_item_sh(self, item, roles=None, date_field=None): eitem_sh = {} 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 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