Changeset 857

Show
Ignore:
Timestamp:
06/19/07 13:50:38 (2 years ago)
Author:
thomase
Message:

Fix an xpath construction error in the mods mixing cascade.

Files:

Legend:

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

    r845 r857  
    7676                    logging.warning("found multiple matches in on short title library for '%s = %s" % (s_short_title.encode('latin', 'xmlcharrefreplace'), s_title.encode('latin', 'xmlcharrefreplace'))) 
    7777            if len(lnodes) == 0: 
    78                 squery = u"*[local-name()='abstract']/descendant::*[local-name()='i' and contains(normalize-space(.),'%s')]/ancestor::mods:mods" % s_title 
    79                 if len(snode.xpath(squery)) == 0: 
    80                     logging.warning("unmatched article '%s'" % s_short_title.encode('latin', 'xmlcharrefreplace')) 
    81                 else: 
    82                     logging.warning("unmatched book '%s = %s" % (s_short_title.encode('latin', 'xmlcharrefreplace'), s_title.encode('latin', 'xmlcharrefreplace'))) 
     78                squery = u"*[local-name()='abstract']/descendant::*[local-name()='i' and contains(normalize-space(),'%s')]/ancestor::*[local-name() = 'mods']" % s_title.encode('ascii', 'xmlcharrefreplace') 
     79                try: 
     80                    if len(snode.xpath(squery)) == 0: 
     81                        logging.warning("unmatched article '%s'" % s_short_title.encode('ascii', 'xmlcharrefreplace')) 
     82                    else: 
     83                        logging.warning("unmatched book '%s = %s" % (s_short_title.encode('ascii', 'xmlcharrefreplace'), s_title.encode('latin', 'xmlcharrefreplace'))) 
     84                except: 
     85                    logging.warning("something went horribly wrong") 
     86                    logging.warning("squery = %s" % squery.encode('ascii', 'backslashreplace'))  
    8387            if len(lnodes)==1: 
    8488                # one match, so gather up all the data we will need 
     
    183187        richecked = 0 
    184188        orphtot = 0 
     189        libfails = [] 
    185190        while orphans: 
    186191            for relatedItem in relatedItems: 
     
    190195                    if len(lnodes) != 1: 
    191196                        logging.warning("failure seeking %s in library file; match count = %s" % (ri_id, len(lnodes))) 
    192                         break 
     197                        libfails.append(ri_id) 
    193198                    else: 
    194199                        orphtot += 1 
     
    197202            relatedItems = self.student.xpath("//mods:relatedItem", NSD) 
    198203            ricount = len(relatedItems) 
    199             if ricount <= richecked: 
     204            if ricount - len(libfails) <= richecked: 
    200205                orphans = False  
    201206            richecked = 0