示例#1
0
def scopus_abs(scopus_id=None):
    ## Scopus (Abtract) document example
    # Initialize document with ID as integer
    scp_doc = AbsDoc(scp_id=scopus_id)
    if scp_doc.read(client):
        print("scp_doc.title: ", scp_doc.title)
        scp_doc.write()
 def readAbsDocWithScopusID(self, scpID='84872135457'):
     ## Scopus (Abtract) document example
     # Initialize document with Scopus ID.
     scp_doc = AbsDoc(scp_id=scpID)
     if scp_doc.read(self.client):
         print("scp_doc.title: ", scp_doc.title)
         scp_doc.write()
     else:
         print("Read document failed.")
示例#3
0
def autorships(dataset_name, aut_dump_name):
    data = pd.read_csv(dataset_name)
    ids = data['scopusID'].values

    with open(aut_dump_name, 'w') as aut:
        num = 0
        for id in tqdm(ids):
            scp_doc = AbsDoc(scp_id=id.split(':')[1])
            if scp_doc.read(client):
                scp_doc.write()
            else:
                print("Read document failed.")
                aut.write('None' + u'\r\n')
                continue
            num += 1
            try:
                aut.write(';'.join([':'.join([i['ce:indexed-name'], i['@auid']])
                                    for i in scp_doc.data['authors']['author']]) + u'\r\n')
            except:
                aut.write('None' + u'\r\n')
示例#4
0
class TestAbsDoc:
    """Test Scopus document functionality"""
    
    ## Test data
    abs_uri = "https://api.elsevier.com/content/abstract/scopus_id/84872135457"
    scp_id_int = 84872135457
    scp_id_str = "84872135457"
    
    ## Test initialization
    def test_init_uri(self):
        """ Test case: uri is set correctly during initialization with uri"""
        myAbsDoc = AbsDoc(uri = self.abs_uri)
        assert myAbsDoc.uri == self.abs_uri
        
    def test_init_scp_id_int(self):
        """ Test case: uri is set correctly during initialization with Scopus id as integer"""
        myAbsDoc = AbsDoc(scp_id = self.scp_id_int)
        assert myAbsDoc.uri == self.abs_uri
        
    def test_init_scp_id_str(self):
        """ Test case: uri is set correctly during initialization with Scopus id as string"""
        myAbsDoc = AbsDoc(scp_id = self.scp_id_str)
        assert myAbsDoc.uri == self.abs_uri
        
    ## Test reading/writing author profile data
    bad_client = ElsClient("dummy")
    good_client = ElsClient(config['apikey'], inst_token = config['insttoken'])
    good_client.local_dir = str(test_path)

    myAbsDoc = AbsDoc(uri = abs_uri)
    
    def test_read_good_bad_client(self):
        """Test case: using a well-configured client leads to successful read
            and using a badly-configured client does not."""
        assert self.myAbsDoc.read(self.bad_client) == False
        assert self.myAbsDoc.read(self.good_client) == True

    def test_json_to_dict(self):
        """Test case: the JSON read by the abstract document object from the 
            API is parsed into a Python dictionary"""
        assert type(self.myAbsDoc.data) == dict
        
    def test_title_getter(self):
        """Test case: the title attribute is returned as a non-empty string"""
        assert (type(self.myAbsDoc.title) == str and self.myAbsDoc.title != '')
        
    def test_write(self):
        """Test case: the abstract document object's data is written to a file with the Scopus
            ID in the filename"""
        self.myAbsDoc.write()
        assert util.file_exist_with_id(self.myAbsDoc.data['coredata']['dc:identifier'].split(':')[1])
示例#5
0
 def get_bib(self,EID=None):
     
     EID = int(EID)
     scp_doc = AbsDoc(scp_id = EID)
     scp_doc.read(self.client)
     scp_doc.write()
     bib=[]
     for x in scp_doc.data.get('item').get('bibrecord').get('tail').get('bibliography').get('reference'):
         EID_x = x.get('ref-info').get('refd-itemidlist').get('itemid')[1].get('$')
         bib.append(EID_x)
     return bib
示例#6
0
 def test_init_scp_id_str(self):
     """ Test case: uri is set correctly during initialization with Scopus id as string"""
     myAbsDoc = AbsDoc(scp_id = self.scp_id_str)
     assert myAbsDoc.uri == self.abs_uri
示例#7
0
 def test_init_uri(self):
     """ Test case: uri is set correctly during initialization with uri"""
     myAbsDoc = AbsDoc(uri = self.abs_uri)
     assert myAbsDoc.uri == self.abs_uri
示例#8
0
    my_auth.write()
else:
    print ("Read author failed.")

## Affiliation example
# Initialize affiliation with ID as string
my_aff = ElsAffil(affil_id = '60101411')
if my_aff.read(client):
    print ("my_aff.name: ", my_aff.name)
    my_aff.write()
else:
    print ("Read affiliation failed.")

## Scopus (Abtract) document example
# Initialize document with ID as integer
scp_doc = AbsDoc(scp_id = 84872135457)
if scp_doc.read(client):
    print ("scp_doc.title: ", scp_doc.title)
    scp_doc.write()   
else:
    print ("Read document failed.")

## ScienceDirect (full-text) document example using PII
pii_doc = FullDoc(sd_pii = 'S1674927814000082')
if pii_doc.read(client):
    print ("pii_doc.title: ", pii_doc.title)
    pii_doc.write()   
else:
    print ("Read document failed.")

## ScienceDirect (full-text) document example using DOI
示例#9
0
        authDF.loc[authDF.isin(thisComm['lastname'].values)['lastname'],
                   'comm'] = 'me'
        print('community ' + str(commer) + ' is ME!')
    if meCount < cbCount:
        authDF.loc[authDF.isin(thisComm['lastname'].values)['lastname'],
                   'comm'] = 'cb'
        print('community ' + str(commer) + ' is CB!')
authDF.to_csv('author_mecb.csv')
sys.exit("bye!")

#u_id(24588214300)
## Initialize doc search object and execute search, retrieving all results
#doc_srch = ElsSearch('collective+movement+ecology+AU-ID(24588214300)+AU-ID(23479355600)','scopus')
doc_srch = ElsSearch(
    'movement+ecology+AU-ID(24588214300)+OR+AU-ID(23479355600)', 'scopus')
doc_srch.execute(client, get_all=True)
print("doc_srch has", len(doc_srch.results), "results.")
for i in range(len(doc_srch.results)):
    print(doc_srch.results[i]['dc:title'])

## Scopus (Abtract) document example
# Initialize document with ID as integer
title = scp_doc.data['coredata']['prism:publicationName']
scp_doc = AbsDoc(uri=doc_srch.results[i]['prism:url'])
if scp_doc.read(client):
    print("scp_doc.title: ", scp_doc.title)
    abstract = scp_doc.data['coredata']['dc:description']
    print(abstract)
else:
    print("Read document failed.")
    def genData(self):

        raw_df = self.raw_df
        scopus_list = raw_df['scopus']
        # Load configuration
        con_file = open("config.json")
        config = json.load(con_file)
        con_file.close()
        # Initialize client
        client = ElsClient(config['apikey'])

        author_id_list = []
        given_name_list = []
        sur_name_list = []
        affiliation_id_list = []
        affiliation_city_list = []
        affilname_list = []
        affiliation_country_list = []
        citedby_count_list = []

        for scopus_id in scopus_list:
            print(len(author_id_list))
            # Initialize document with Scopus ID.
            print(scopus_id)
            if type(scopus_id) is str:
                scopus_id = self.scopusID(scopus_id)
                # ['client', 'data', 'id', 'int_id', 'read', 'title', 'uri', 'write']
                scp_doc = AbsDoc(scp_id=scopus_id)
                if scp_doc.read(client):

                    # dict_keys(['coredata'])
                    # dict_keys(['srctype', 'prism:issueIdentifier', 'eid', 'prism:coverDate', 'prism:aggregationType', 'prism:url', 'subtypeDescription', 'dc:creator', 'link', 'prism:publicationName', 'source-id', 'citedby-count', 'prism:volume', 'subtype', 'prism:pageRange', 'dc:title', 'prism:endingPage', 'openaccess', 'openaccessFlag', 'prism:doi', 'prism:issn', 'prism:startingPage', 'dc:identifier'])
                    # dict_keys(['ce:given-name', 'preferred-name', '@seq', 'ce:initials', '@_fa', 'affiliation', 'ce:surname', '@auid', 'author-url', 'ce:indexed-name'])
                    if 'dc:creator' in scp_doc.data['coredata'].keys():
                        if 'ce:given-name' in scp_doc.data['coredata'][
                                'dc:creator']['author'][0].keys():
                            given_name_list.append(
                                scp_doc.data['coredata']['dc:creator']
                                ['author'][0]['ce:given-name'])
                        else:
                            given_name_list.append(
                                scp_doc.data['coredata']['dc:creator']
                                ['author'][0]['preferred-name']
                                ['ce:given-name'])

                        if 'affiliation' in scp_doc.data['coredata'][
                                'dc:creator']['author'][0].keys():
                            # print(type(scp_doc.data['coredata']['dc:creator']['author'][0]['affiliation']))
                            if type(scp_doc.data['coredata']['dc:creator']
                                    ['author'][0]['affiliation']) is list:
                                affiliation_id_list.append(
                                    scp_doc.data['coredata']['dc:creator']
                                    ['author'][0]['affiliation'][0]['@id'])
                            else:
                                affiliation_id_list.append(
                                    scp_doc.data['coredata']['dc:creator']
                                    ['author'][0]['affiliation']['@id'])
                        else:
                            affiliation_id_list.append('NA')
                        author_id_list.append(
                            scp_doc.data['coredata']['dc:creator']['author'][0]
                            ['@auid'])
                        sur_name_list.append(
                            scp_doc.data['coredata']['dc:creator']['author'][0]
                            ['ce:surname'])
                    else:
                        given_name_list.append('NA')
                        sur_name_list.append('NA')
                        author_id_list.append('NA')
                        affiliation_id_list.append('NA')
                    citedby_count_list.append(
                        scp_doc.data['coredata']['citedby-count'])
                else:
                    given_name_list.append('NA')
                    sur_name_list.append('NA')
                    author_id_list.append('NA')
                    affiliation_id_list.append('NA')
                    citedby_count_list.append('NA')
            else:
                given_name_list.append('NA')
                sur_name_list.append('NA')
                author_id_list.append('NA')
                affiliation_id_list.append('NA')
                citedby_count_list.append('NA')

        raw_df['given-name'] = given_name_list
        raw_df['sur_name'] = sur_name_list
        raw_df['author_id'] = author_id_list
        raw_df['affiliation_id'] = affiliation_id_list
        raw_df['citedby_count'] = citedby_count_list

        return raw_df
示例#11
0
## Author example
# Initialize author with uri
my_auth = ElsAuthor(
        uri = 'https://api.elsevier.com/content/author/author_id/7004367821')
# Read author data, then write to disk
if my_auth.read(client):
    print ("my_auth.full_name: ", my_auth.full_name)
    my_auth.write()
else:
    print ("Read author failed.")

## Affiliation example
# Initialize affiliation with ID as string
my_aff = ElsAffil(affil_id = '60101411')
if my_aff.read(client):
    print ("my_aff.name: ", my_aff.name)
    my_aff.write()
else:
    print ("Read affiliation failed.")

## Scopus (Abtract) document example
# Initialize document with Scopus ID.
scp_doc = AbsDoc('gene')
if scp_doc.read(client):
    print ("scp_doc.title: ", scp_doc.title)
    scp_doc.write()   
else:
    print ("Read document failed.")

示例#12
0
    my_auth.write()
else:
    print("Read author failed.")

## Affiliation example
# Initialize affiliation with ID as string
my_aff = ElsAffil(affil_id='60101411')
if my_aff.read(client):
    print("my_aff.name: ", my_aff.name)
    my_aff.write()
else:
    print("Read affiliation failed.")

## Scopus (Abtract) document example
# Initialize document with ID as integer
scp_doc = AbsDoc(scp_id=36706629400)
if scp_doc.read(client):
    print("scp_doc.title: ", scp_doc.title)
    scp_doc.write()
else:
    print("Read document failed.")

## ScienceDirect (full-text) document example using PII
pii_doc = FullDoc(sd_pii='S1674927814000082')
if pii_doc.read(client):
    print("pii_doc.title: ", pii_doc.title)
    pii_doc.write()
else:
    print("Read document failed.")

## ScienceDirect (full-text) document example using DOI