1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """
23 Generate citation keys.
24 """
25
26 from sets import Set
27
29 a = ord('a')
30 while a <= ord('z'):
31 yield chr(a)
32 a += 1
33 return
34
36 """ Base class to handle caching of generated keys. Ensures that
37 the same uid will always get the same key."""
38
40 self.map = {}
41 self.db = db
42 return
43
45 if self.map.has_key(uid):
46 return self.map[uid]
47 return None
48
50 self.map[uid] = k
51 return k
52
60
61
63 """ Base class to add a disambiguation letter after generated keys
64 that clash with already generated ones."""
65
70
82
83
85 """ Return a numeric key for documents, in the order in which they
86 are requested."""
87
92
94 k = str(self.current)
95 self.current += 1
96 return k
97
98
100 """ Return citations in their order of appearance in the
101 document. This is the order in which they are presented in input,
102 except that we don't want duplicates. """
103 seen = Set()
104 for uid, key, extra in uids:
105 if uid in seen:
106 continue
107 seen.add(uid)
108 yield (uid, key)
109 return
110