Changeset 575:f0e5e9c6737f in documentViewer for MpiwgXmlTextServer.py


Ignore:
Timestamp:
Oct 16, 2012, 5:46:53 PM (12 years ago)
Author:
casties
Branch:
default
Message:

new w-tag solution with css.
(processWTags doesn't work)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • MpiwgXmlTextServer.py

    r574 r575  
    205205                      'page': pn}
    206206       
    207         if 'characterNormalization' in pageinfo:
    208             cn = pageinfo['characterNormalization']
    209             # TODO: change values in form
    210             if cn == 'regPlusNorm':
    211                 cn = 'norm'
    212                
    213             textParams['normalization'] = cn
    214        
     207        normMode = pageinfo.get('characterNormalization', 'reg')
     208        # TODO: change values in form
     209        if normMode == 'regPlusNorm':
     210            normMode = 'norm'
     211                       
    215212        if not mode:
    216213            # default is dict
     
    250247            textParams['mode'] = 'untokenized'
    251248            textParams['outputFormat'] = 'xmlDisplay'
    252             textParams['normalization'] = 'orig'
     249            textParams['normMode'] = 'orig'
    253250        elif 'gis' in modes:
    254251            #FIXME!
     
    256253        else:
    257254            # text is default mode
    258             textmode = 'text'
     255            textmode = 'plain'
    259256            textParams['mode'] = 'untokenized'
    260257            textParams['outputFormat'] = 'html'
     
    269266       
    270267        # plain text or text-with-links mode
    271         if textmode == "text" or textmode == "dict":
     268        if textmode == "plain" or textmode == "dict":
    272269            # the text is in div@class=text
    273270            pagediv = dom.find(".//div[@class='text']")
    274271            logging.debug("pagediv: %s"%repr(pagediv))
    275272            if pagediv is not None:
     273                # add textmode and normMode classes
     274                pagediv.set('class', 'text %s %s'%(textmode, normMode))
     275                #self._processWTags(textmode, normMode, pagediv)
    276276                #self._processPbTag(pagediv, pageinfo)
    277277                self._processFigures(pagediv, docinfo)
     
    343343        return None
    344344
     345    def _processWTags(self, textMode, normMode, pagediv):
     346        """selects the necessary information from w-spans and removes the rest from pagediv"""
     347        logging.debug("processWTags(textMode=%s,norm=%s,pagediv"%(repr(textMode),repr(normMode)))
     348        wtags = pagediv.findall(".//span[@class='w']")
     349        for wtag in wtags:
     350            text = None
     351            attr = None
     352            if textMode == 'dict':
     353                # take a-tag and matching child
     354                attr = wtag.find('a').items()
     355                text = wtag.find("a/span[@class='%s']"%normMode).text
     356            else:
     357                # take matching child
     358                text = wtag.find("span[@class='nodictionary %s']"%normMode).text
     359               
     360            if text:
     361                # replace wtag by new content
     362                logging.debug("new w-tag attr=%s text=%s"%(attr,text))
     363                wtag.clear()
     364                   
     365                if attr:
     366                    # make dictionary link
     367                    wtag.tag = 'a'
     368                    wtag.attrib.update(dict(attr))
     369                   
     370                # text content
     371                wtag.text = text
     372               
     373        return pagediv
     374       
    345375    def _processPbTag(self, pagediv, pageinfo):
    346376        """extracts information from pb-tag and removes it from pagediv"""
Note: See TracChangeset for help on using the changeset viewer.