Changeset 842

Show
Ignore:
Timestamp:
06/15/07 15:41:33 (2 years ago)
Author:
thomase
Message:

All certainty measures, plus name-wise references.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • BADataMunger/trunk/placesaver.py

    r840 r842  
    8383        tag_bibl = etree.Element("{%s}bibl" % TEI) 
    8484        try: 
    85             tag_bibl.text = u"BAtlas %s %s %s" % (self.map_number, place.grid, place.namestring
     85            tag_bibl.text = u"BAtlas %s %s %s" % (self.map_number, place.grid, place.namestring.replace("/ ", "/")
    8686        except: 
    8787            tag_bibl.text = u"BAtlas %s %s" % (self.map_number, place.grid) 
     
    141141            tag_css.append(tag_csn) 
    142142            tag_cs.append(tag_css) 
    143             #if pn.certainty != "certain": 
     143            if pn.inferred: 
     144                tag_naspect = etree.Element("{%s}nameAspect" % AWMC) 
     145                tag_naspect.attrib['ref'] = 'na-inferred' 
     146                tag_cs.append(tag_naspect) 
     147            if pn.completeness != 'complete': 
     148                tag_naspect = etree.Element("{%s}nameAspect" % AWMC) 
     149                tag_naspect.attrib['ref'] = 'na-reconstructed' 
     150                tag_cs.append(tag_naspect) 
     151            if pn.accuracy != 'accurate': 
     152                tag_naspect = etree.Element("{%s}nameAspect" % AWMC) 
     153                tag_naspect.attrib['ref'] = 'na-inaccurate' 
     154                tag_cs.append(tag_naspect) 
    144155            tag_nassoc = etree.Element("{%s}nameAssociation" % AWMC) 
    145156            tag_nassoc.attrib['ref'] = pn.certainty 
     
    157168                tag_tp.append(tag_tpn) 
    158169                tag_fn.append(tag_tp) 
     170                 
     171            # secondary references for the name 
     172            if len(pn.references) > 0: 
     173                tag_refs = etree.Element("{%s}secondaryReferences" % AWMC) 
     174                for ref in pn.references: 
     175                    tag_bibl = etree.Element("{%s}bibl" % TEI) 
     176                    tag_bibl.text = ref 
     177                    tag_refs.append(tag_bibl) 
     178                     
     179                tag_fn.append(tag_refs) 
     180 
    159181                 
    160182            ge.append(tag_fn) 
  • BADataMunger/trunk/tableparser.py

    r840 r842  
    211211        elif d.tag == 'placenames': 
    212212             
    213             # placenames should be coordinated with periods, if possible 
     213            # placenames should be coordinated with periods and references, if possible 
    214214            try: 
    215215                context = d.xpath("ancestor::when | ancestor::otherwise")[0] 
     
    221221                except: 
    222222                    pass 
     223                try: 
     224                    rcelli = context.xpath("./descendant::references")[0].attrib['cell'] 
     225                except: 
     226                    pass 
    223227            else: 
    224228                try: 
     
    226230                except: 
    227231                    pass 
    228             if pcelli: 
    229                 #print "processing placenames from celli = %s (%s) with periods from pcelli = %s (%s)" 
     232                try: 
     233                    rcelli = context.xpath("./descendant::periods[not(ancestor::when) and not(ancestor::otherwise)]")[0].attrib['cell'] 
     234                except: 
     235                    pass 
     236            if pcelli and rcelli: 
     237                self.placenames = self.parse_placenames(cells[celli], cells[pcelli], cells[rcelli]) 
     238            elif pcelli: 
    230239                self.placenames = self.parse_placenames(cells[celli], cells[pcelli]) 
     240            elif rcelli: 
     241                self.placenames = self.parse_placenames(cells[celli], None, cells[rcelli]) 
    231242            else: 
    232243                self.placenames = self.parse_placenames(cells[celli]) 
     
    263274        self.periods = self.parse_periods(cells[2]) 
    264275        self.locdesc = normalizetext(getalltext(cells[3])) 
    265         self.placenames = self.parse_placenames(cells[1], cells[2]
     276        self.placenames = self.parse_placenames(cells[1], cells[2], cells[4]
    266277        self.namestring = normalizetext(getalltext(cells[1])) 
    267278        self.references = self.parse_references(cells[4]) 
     
    271282        # name | references | comment 
    272283        self.type = 'false' 
    273         self.placenames = self.parse_placenames(cells[0]
     284        self.placenames = self.parse_placenames(cells[0], None, cells[1]
    274285        self.namestring = normalizetext(getalltext(cells[0])) 
    275286        self.references = self.parse_references(cells[1]) 
     
    301312        self.periods = self.parse_periods(cells[1]) 
    302313        self.locdesc = normalizetext(getalltext(cells[2])) 
    303         self.placenames = self.parse_placenames(cells[0], cells[1]
     314        self.placenames = self.parse_placenames(cells[0], cells[1], cells[3]
    304315        self.namestring = normalizetext(getalltext(cells[0])) 
    305316        self.references = self.parse_references(cells[3]) 
     
    343354        return [normalizetext(place) for place in places] 
    344355         
    345     def parse_placenames(self, namecell, periodcell=None): 
     356    def parse_placenames(self, namecell, periodcell=None, refcell=None): 
    346357        """We can have multiple placenames in a single cell, and there are two types of delimiters. 
    347358        Parse this mess to get the individual names, and then deal with variants too.""" 
     
    388399                pname.periods = self.periods 
    389400                 
     401        # associate references, if necessary, with the placenames 
     402        # if separate references are provided for each work  
     403        if refcell: 
     404            refparas = refcell.xpath("*[local-name()='p']") 
     405            if len(refparas) > 1: 
     406                for pname in placenames: 
     407                    try: 
     408                        pname.references = self.parse_references(refparas[pname.originalPosition]) 
     409                    except: 
     410                        pass 
     411            elif len(self.references) > 0: 
     412                for pname in placenames: 
     413                    pname.references = self.references 
     414 
    390415        return placenames 
    391416         
     
    429454        m = re.match(pattern, ntext) 
    430455        if m: 
    431             interred = True 
     456            inferred = True 
    432457            pattern = u'[\[\]]' 
    433458            newntext = re.sub(pattern, u'', ntext) 
     
    447472        references=[] 
    448473         
    449         paragraphs = referencecell.xpath("*[local-name()='p']") 
     474        paragraphs = referencecell.xpath("descendant-or-self::*[local-name()='p']") 
    450475        for paragraph in paragraphs: 
    451476            ptext = normalizetext(getalltext(paragraph)) 
     
    475500         
    476501         
    477     def parse_periodcell(self, periodcell): 
    478         print "parse_periodcell" 
    479         periods=[] 
    480         pctext = normalizetext(getalltext(periodcell)) 
    481         if len(pctext) > 0: 
    482             periodishes = periodcell.xpath("descendant::*[local-name()='p']") 
    483             try: 
    484                 periodish = periodishes[self.originalPosition] 
    485             except: 
    486                 pass 
    487             if periodish: 
    488                 lpstring = normalizetext(getalltext(periodish)) 
    489                 if len(lpstring) > 0: 
    490                     for pcode in periodcodes: 
    491                         qpcode = '%s?' % pcode 
    492                         if lpstring.find(qpcode) != -1: 
    493                             lpstring = lpstring.replace(qpcode, '') 
    494                             if lpstring.find(pcode) != -1: 
    495                                 lpstring = lpstring.replace(pcode, '') 
    496                                 periods.append((pcode, 'confident')) 
    497                             else: 
    498                                 periods.append((pcode, 'less-confident')) 
    499                         else: 
    500                             if lpstring.find(pcode) != -1: 
    501                                 lpstring = lpstring.replace(pcode, '') 
    502                                 periods.append((pcode, 'confident')) 
    503                      
    504         return periods 
    505502         
    506503    def __str__(self):