automatic key generation, medline pasting

Nils Becker <[email protected]> Fri, 7 Oct 2005 11:42:27 +0200
Newsgroups gmane.comp.gnome.apps.pybliographer
Message-ID <[email protected]>
Hi all, 

after having looked through the examples on the mailing list archive, I have 
now a working version of an automatic key generation in the format 
"nameYYsuff" where name is the first author's last name in lowercase and suff 
starts with b in case there exists an entry with the same key in the data 
base, and then counts up. It can be added to ~/.pybrc.py. I attached it since 
I found no completely working version on the mailing archive.

Since I am not a python programmer, it took me quite a while to figure this 
out. To make life easier for people who just want to USE pybliographic, I 
think it would be a good idea to post a selection of popular key generators 
in the FAQ section  on the web site. (repeating a suggestion on the 
archive..)

Another wish:
When doing a medline search, I open a new database, do the search, and then 
paste the entries that I want into my "standard database" with drag and drop. 
It would be helpful if in this process the keys of the dropped entries were 
re-generated. This would avoid duplicate keys that now arise if in the 
standard database there already exist entries with the same author and year.

By the way, has anyone set up a browser to allow automatic import of entries 
by clicking on "export to reference software" in ISI Web of Knowledge ? I 
would be interested!



Cheers, Nils


# DAE new type of key format AuthorBCDEYY
# NB modified to give authorYYbc.. 
 
from string import *

from Pyblio import Key, Autoload, recode

_flat = recode.recode ('latin1..flat')

def generate_key_new (entry, table):

    if   entry.has_key ('author'): aut = entry ['author']
    elif entry.has_key ('editor'): aut = entry ['editor']
    else:                          aut = ()

    if len (aut) == 0:
        __entry = 1
	global __entry
        key = 'entry-%d' % __entry
        __entry = __entry + 1
    else:
        honorific, first, last, lineage = aut [0].format ()
        key = join (split (last, ' '), '')
	key = lower (key)
        nextkey = ''
#         if len (aut) > 1:
#             for a in aut:
#                 honorific, first, last, lineage = a.format ()
#                 nextkey = nextkey + join (map (lambda x:
#                                        x [0], split (last, ' ')), '')
# 	nextkey = str (nextkey) [1:]
#         key = key + join (nextkey, '')
        
        if entry.has_key ('date'):
            year = entry ['date'].year
            
            if year: key = key + str (year) [2:]


    base = _flat (key)
    key  = Key.Key (table, base)
    
    if table.has_key (key):
	suff = ord ('a')
	
        while table.has_key (key):
            suff = suff + 1
            
            if suff > ord ('z'):
                suff = ord ('a')
                base = base + 'a'

            key  = Key.Key (table, base + chr (suff))
            
    return Key.Key (table, key)

Autoload.register ('key', 'AuthorYYbcd', generate_key_new)


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl