def string_key(entry, fmt, table): """ Generates an alphabetical key for an entry. fmt is the output coding """ rc = recode.recode("latin1.." + fmt) if entry.has_key("author"): aut = entry["author"] elif entry.has_key("editor"): aut = entry["editor"] else: aut = () if len(aut) > 0: if len(aut) > 1: key = "" for a in aut: honorific, first, last, lineage = a.format(fmt) key = key + string.join(map(lambda x: x[0], string.split(last, " ")), "") if len(key) >= 3: if len(aut) > 3: key = key + "+" break else: honorific, first, last, lineage = aut[0].format(fmt) parts = string.split(last, " ") if len(parts) == 1: key = parts[0][0:3] else: key = string.join(map(lambda x: x[0], parts), "") else: key = rc(entry.key.key[0:3]) if entry.has_key("date"): year = entry["date"].format(fmt)[0] if year: key = key + year[2:] if table.has_key(key) or table.has_key(key + "a"): if table.has_key(key): # rename the old entry new = key + "a" table[new] = table[key] del table[key] base = key suff = ord("b") key = base + chr(suff) while table.has_key(key): suff = suff + 1 key = base + chr(suff) return key
def authoryear_key(entry, fmt, table, oldnew): """ Generates an author-year type key for an entry. fmt is the output coding """ rc = recode.recode("latin1.." + fmt) if entry.has_key("author"): aut = entry["author"] elif entry.has_key("editor"): aut = entry["editor"] else: aut = () key = "" if len(aut) > 0: if len(aut) > 1: if len(aut) == 2: for a in aut: honorific, first, last, lineage = a.format(fmt) parts = string.split(last, " ") if key: key = key + " and " key = key + parts[0] else: a = aut[0] honorific, first, last, lineage = a.format(fmt) parts = string.split(last, " ") key = parts[0] + " et al." else: honorific, first, last, lineage = aut[0].format(fmt) parts = string.split(last, " ") key = parts[0] else: key = rc(entry.key.key) if entry.has_key("date"): year = entry["date"].format(fmt)[0] if year: key = key + ", " + year if table.has_key(key) or table.has_key(key + "a"): if table.has_key(key): # rename the old entry new = key + "a" oldnew[table[key].key] = new table[new] = table[key] del table[key] base = key suff = ord("b") key = base + chr(suff) while table.has_key(key): suff = suff + 1 key = base + chr(suff) return key
# This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # import re from string import * from Legacy import Key, Autoload, recode _flat = recode.recode ('latin1..flat') def compress_page_range (pages, separator='-'): """Returns a page range with common prefix elided from the second number. Resulte is string firstpage(separator)(lastpage), except if separator is None, then a sequence is returned.""" p = re.sub (' *--? *', '-', pages) s = p.split('-') if len(s) > 1: l, r = s if len(l) == len(r): i = 0 while r [i] == l[i]: i += 1