Changeset 843
- Timestamp:
- 06/15/07 16:26:34 (2 years ago)
- Files:
-
- BADataMunger/trunk/placesaver.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
BADataMunger/trunk/placesaver.py
r842 r843 1 import re 1 2 from os.path import join 2 3 from StringIO import StringIO … … 11 12 TEI = "http://www.tei-c.org/ns/1.0" 12 13 XHTML = "http://www.w3.org/1999/xhtml" 14 13 15 14 16 periods = { … … 88 90 tag_refs.append(tag_bibl) 89 91 # now, any other references 92 magicrefs = {} 93 if len(place.placenames) == 1: 94 for ref in place.references: 95 magicrefs[ref] = refmagic(ref, place.placenames[0]) 96 elif len(place.placenames) > 1: 97 for pn in place.placenames: 98 for ref in pn.references: 99 magicrefs[ref] = refmagic(ref, pn) 100 #print "bing: %s == %s" % (ref.encode('ascii', 'backslashreplace'), refmagic(ref, pn).encode('ascii', 'backslashreplace')) 101 102 if len(magicrefs) == 0 and len(place.references) > 0: 103 for ref in place.references: 104 magicrefs[ref] = ref 105 90 106 for ref in place.references: 91 107 tag_bibl = etree.Element("{%s}bibl" % TEI) 92 tag_bibl.text = ref 108 try: 109 tag_bibl.text = magicrefs[ref] 110 except KeyError: 111 print 'KeyError %s' % ref.encode('ascii', 'backslashreplace') 112 print magicrefs 93 113 tag_refs.append(tag_bibl) 94 114 ge.append(tag_refs) … … 174 194 for ref in pn.references: 175 195 tag_bibl = etree.Element("{%s}bibl" % TEI) 176 tag_bibl.text = ref 196 tag_bibl.text = refmagic(ref, pn) 177 197 tag_refs.append(tag_bibl) 178 198 … … 360 380 return result 361 381 362 382 def refmagic(ref, pn): 383 if ref == "RE": 384 result = "RE %s" % pn.name 385 elif ref == "NPauly": 386 result = "NPauly %s" % pn.name 387 elif ref == "KlPauly": 388 result = "KlPauly %s" % pn.name 389 elif ref == "PECS": 390 result = "PECS %s" % pn.name 391 else: 392 result = "" 393 ptrns = ["(RE) (\d+)", "(NPauly) (\d+)"] 394 for ptrn in ptrns: 395 m = re.match(ptrn, ref) 396 if m: 397 result = "%s %s %s" % (m.group(1), pn.name, m.group(2)) 398 break 399 if len(result) == 0: 400 result = ref 401 return result
