def test_citnet_add_node(): """ Check if a node is added correctly """ citnet = CitationNetwork() citnet.add_node(TEST_NODE['bibcode']) assert citnet.has_node(TEST_NODE['bibcode'])
def citnet(): """ Check if nodes added by judgement sampling are correct """ citnet = CitationNetwork() citnet.sample_judgement(bibcodes=[TEST_NODE['bibcode']]) return citnet
def test_citnet_add_edge(): """ Check if an edge is added correctly """ citnet = CitationNetwork() edge = ('1975NW.....62..309F', '1963RvMP...35..947B', 0) citnet.add_edge(edge) assert citnet.has_edge(edge)
def test_citnet_add_node_two_times(): """ Make sure that no duplicates can be added """ citnet = CitationNetwork() citnet.add_node(TEST_NODE['bibcode']) citnet.add_node(TEST_NODE['bibcode']) assert len(citnet.nodes) == 1
def test_citnet_author_identity_same(): """ Check functionality of of author identity checker """ citnet = CitationNetwork() assert citnet.author_is_same('Burbidge, X. Y.', 'Burbidge, Xenya Yakupova') assert citnet.author_is_same('Ambartsumyan, V.', 'Ambartsumian, V. A.') assert citnet.author_is_same('Ambarcuman, Viktor', 'Ambartsumian, V. A.')
def test_citnet_author_identity_different(): """ Check functionality of of author identity checker """ citnet = CitationNetwork() assert not citnet.author_is_same('Burbidge, X. Y.', 'Burbidge, A. B.') assert not citnet.author_is_same('Arp, A.', 'Arp, Hans') assert not citnet.author_is_same('Bergmann, Hans Albert', 'Berg, H.')
def test_citnet_add_edge_two_times(): """ Make sure that no duplicates can be added """ citnet = CitationNetwork() edge = ('1975NW.....62..309F', '1963RvMP...35..947B', 0) citnet.add_edge(edge) citnet.add_edge(edge) assert len(citnet.edges) == 1
def test_database_readwrite_citnet(): """ Check if Database loads and writes CitationNetwork """ db_path = 'tests/ads2gephi_test.db' citnet = CitationNetwork() db = Database(db_path) db.write_citnet_to_db() db.read_citnet_from_db() assert len(db.citnet) == len(citnet) os.remove(db_path)
def main(): args = parse_args() home_dir = os.path.expanduser('~') conf_file = os.path.join(home_dir, '.ads2gephi/ads2gephi.cfg') # Check if config file available and if not, prompt for API Key and create config file if os.path.isfile(conf_file) == False: print("Please enter your API Key for the Astrophysical Data System (ADS). The key will be stored in a " "configuration file for future use. Please refer to the help text (-h) if you want to assign a new key.") key_input = input("API Key: ") conf_dir = os.path.join(home_dir, '.ads2gephi') os.makedirs(conf_dir) with open(conf_file, 'w+') as file: file.write("[ads_api]\n" "apikey = {}\n\n" "[snowball_default_interval]\n" "startyear = 1900\n" "endyear=2000".format(key_input)) print("API Key has been set.") print("Default year interval for snowball sampling has been set to 1900-2000.") if args.version: print('0.1') if args.snowball_interval is not None: # Get year parameters from string start_year = args.snowball_interval[:4] end_year = args.snowball_interval[-4:] # Update config file config = ConfigParser() config.read_file(open(conf_file)) config.set('snowball_default_interval', 'StartYear', start_year) config.set('snowball_default_interval', 'EndYear', end_year) with open(conf_file, 'w') as cp: config.write(cp) print("Default year interval for snowball sampling set to {}.".format(args.snowball_interval)) if args.api_key is not None: # Update config file config = ConfigParser() config.read_file(conf_file) config['ads_api']['APIKey'] = args.api_key config.set('ads_api', 'APIKey', args.api_key) with open(conf_file, 'w') as cp: config.write(cp) citnet = CitationNetwork(args.database) citnet.parse_config(conf_file) if args.coreset_sampler: print('Starting core set (judgement) sampling...') with open(args.coreset_sampler) as file: for line in file: citnet.bibcode_list.append(line[:19]) citnet.sample('judgement') if args.snowball_sampler == 'cit': print('Starting snowball sampling based on citation metadata...') citnet.snowball['scope'] = 'cit' citnet.sample('snowball') elif args.snowball_sampler == 'ref': print('Starting snowball sampling based on reference metadata...') citnet.snowball['scope'] = 'ref' citnet.sample('snowball') elif args.snowball_sampler == 'cit+ref': print('Starting snowball sampling based on citation and reference metadata...') citnet.snowball['scope'] = 'citref' citnet.sample('snowball') if args.edge_generator == 'citnet': print('Starting edge generator with regular citation network values...') citnet.make_regular_edges('bwd') elif args.edge_generator == 'cocit': print('Starting edge generator with co-citation values...') citnet.make_semsim_edges('cocit') elif args.edge_generator == 'bibcp': print('Starting edge generator with bibliographic coupling values...') citnet.make_semsim_edges('bibcp')