Diff for /documentViewer/MpdlXmlTextServer.py between versions 1.221 and 1.222

version 1.221, 2010/12/23 17:13:01 version 1.222, 2011/01/06 15:44:18
Line 38  class MpdlXmlTextServer(SimpleItem): Line 38  class MpdlXmlTextServer(SimpleItem):
         url = self.serverUrl+method          url = self.serverUrl+method
         return documentViewer.getHttpData(url,data,timeout=self.timeout)          return documentViewer.getHttpData(url,data,timeout=self.timeout)
   
     def getSearch(self, pn=1, pageinfo=None,  docinfo=None, query=None, queryType=None, lemma=None, characterNormalization=None, optionToggle=None):      def getSearch(self, pageinfo=None,  docinfo=None,   lemma=None):
         """get search list"""          """get search list"""
         docpath = docinfo['textURLPath']           docpath = docinfo['textURLPath'] 
         url = docinfo['url']          url = docinfo['url']
         pagesize = pageinfo['queryPageSize']          pagesize = pageinfo['queryPageSize']
         pn = pageinfo['searchPN']          pn = pageinfo.get('searchPN',1)
         sn = pageinfo['sn']          sn = pageinfo['sn']
         highlightQuery = pageinfo['highlightQuery']          highlightQuery = pageinfo['highlightQuery']
         query =pageinfo['query']          query =pageinfo['query']
Line 56  class MpdlXmlTextServer(SimpleItem): Line 56  class MpdlXmlTextServer(SimpleItem):
         selfurl = self.absolute_url()          selfurl = self.absolute_url()
                   
         data = self.getServerData("doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&sn=%s&viewMode=%s&characterNormalization=%s&optionToggle=%s&highlightQuery=%s"%(docpath, 'text', queryType, urllib.quote(query), pagesize, pn, sn, viewMode,characterNormalization,optionToggle ,urllib.quote(highlightQuery)))          data = self.getServerData("doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&sn=%s&viewMode=%s&characterNormalization=%s&optionToggle=%s&highlightQuery=%s"%(docpath, 'text', queryType, urllib.quote(query), pagesize, pn, sn, viewMode,characterNormalization,optionToggle ,urllib.quote(highlightQuery)))
         #page=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&sn=%s&viewMode=%s&highlightQuery=%s"%(docpath, 'text', queryType, query, pagesize, pn, sn, viewMode,highlightQuery) ,outputUnicode=False)                  
                   
         pagexml = data.replace('?document=%s'%str(docpath),'?url=%s'%url)          pagexml = data.replace('?document=%s'%str(docpath),'?url=%s'%url)
         pagedom = Parse(pagexml)          pagedom = Parse(pagexml)
           
           """
           pagedivs = pagedom.xpath("//div[@class='queryResultHits']") 
           if (pagedivs == pagedom.xpath("//div[@class='queryResultHits']")):
               if len(pagedivs)>0:
                   docinfo['queryResultHits'] = int(getTextFromNode(pagedivs[0]))
                   s = getTextFromNode(pagedivs[0])
                   s1 = int(s)/10+1
                   try:
                       docinfo['queryResultHits'] = int(s1)
                       logging.debug("SEARCH ENTRIES: %s"%(s1))
                   except:
                       docinfo['queryResultHits'] = 0
           """
         if (queryType=="fulltext")or(queryType=="xpath")or(queryType=="xquery")or(queryType=="fulltextMorphLemma"):             if (queryType=="fulltext")or(queryType=="xpath")or(queryType=="xquery")or(queryType=="fulltextMorphLemma"):   
             pagedivs = pagedom.xpath("//div[@class='queryResultPage']")              pagedivs = pagedom.xpath("//div[@class='queryResultPage']")
             if len(pagedivs)>0:              if len(pagedivs)>0:
Line 118  class MpdlXmlTextServer(SimpleItem): Line 131  class MpdlXmlTextServer(SimpleItem):
         return "no text here"             return "no text here"   
                                                 
           
     def getNumTextPages (self, docinfo=None):  
         """get list of pages from fulltext (texts without images) and put in docinfo"""  
         logging.debug("getNumTextPages")  
         docpath = docinfo['textURLPath']   
         selfurl = self.absolute_url()     
         #viewMode=  pageinfo['viewMode']  
         if 'numPages' in docinfo:  
             # allredy there  
             return docinfo  
           
         text = self.getServerData("page-fragment.xql","document=%s"%(docinfo['textURLPath']))  
         dom =Parse(text)  
         pagedivs = dom.xpath("//div[@class='countPages']")  
         logging.debug ("pagedivs=%s"%(pagedivs))  
         if len(pagedivs)>0:  
             docinfo['numPages']= int(getTextFromNode(pagedivs[0]))  
             return docinfo  
        
     def getTocEntries (self, docinfo=None):  
         """ number of text entries"""  
         docinfo = self.getInfoFromPage(docinfo)  
         logging.debug("gettocentries: docinfo=%s"%docinfo)  
         return docinfo['tocEntries']  
               
     def getFigureEntries (self, docinfo=None):  
         """ number of figure entries"""  
         docinfo = self.getInfoFromPage(docinfo)  
         return docinfo['figureEntries']  
                          
     def getGisPlaces(self, docinfo=None, pageinfo=None):      def getGisPlaces(self, docinfo=None, pageinfo=None):
         """ Show all Gis Places of whole Page"""          """ Show all Gis Places of whole Page"""
         xpath='//place'          xpath='//place'
Line 191  class MpdlXmlTextServer(SimpleItem): Line 175  class MpdlXmlTextServer(SimpleItem):
             logging.debug("getALLGisPlaces :%s"%(myList))              logging.debug("getALLGisPlaces :%s"%(myList))
         return myList          return myList
                                 
     def getOrigPages (self, docinfo=None, pageinfo=None):             
         """Show original page """      def getTextPage(self, docinfo=None, pageinfo=None):
         docpath = docinfo.get('textURLPath',None)          """returns single page from fulltext"""
         if not docpath:          docpath = docinfo['textURLPath']
             return None          path = docinfo['textURLPath']
         selfurl = self.absolute_url()          url = docinfo.get('url',None)
           name = docinfo.get('name',None)
         pn =pageinfo['current']          pn =pageinfo['current']
           #viewMode= pageinfo['viewMode']
           sn = pageinfo['sn']
           highlightQuery = pageinfo['highlightQuery']
           mode = pageinfo ['viewMode']
           tocMode = pageinfo['tocMode']
           characterNormalization=pageinfo['characterNormalization']
           tocPN = pageinfo['tocPN']
           selfurl = self.absolute_url()   
           if mode == "text_dict":
               textmode = "textPollux"
           else:
               textmode = mode
                 
         viewMode=  pageinfo['viewMode']          textParam = "document=%s&mode=%s&pn=%s&characterNormalization=%s"%(docpath,textmode,pn,characterNormalization)
         text = self.getServerData("page-fragment.xql","document=%s&mode=%s&pn=%s"%(docinfo['textURLPath'], 'text',  pn))          if highlightQuery is not None:
         dom =Parse(text)              textParam +="&highlightQuery=%s&sn=%s"%(urllib.quote(highlightQuery),sn)           
           
           pagexml = self.getServerData("page-fragment.xql",textParam)
           dom = Parse(pagexml)
           
           #original Pages
         pagedivs = dom.xpath("//div[@class='pageNumberOrig']")          pagedivs = dom.xpath("//div[@class='pageNumberOrig']")
           if pagedivs == dom.xpath("//div[@class='pageNumberOrig']"):
         if len(pagedivs)>0:          if len(pagedivs)>0:
             originalPage= getTextFromNode(pagedivs[0])                  docinfo['pageNumberOrig']= getTextFromNode(pagedivs[0])
             #return docinfo['originalPage']                  logging.debug("ORIGINAL PAGES: %s"%(docinfo['pageNumberOrig']))
             return originalPage  
       
     def getAllPlaces (self, docinfo=None):  
         """Show all Places if no places than 0"""  
         docinfo = self.getInfoFromPage(docinfo)  
         return docinfo['allPlaces']  
   
     def getInfoFromPage(self, docinfo=None):  
         """ extract diverse info from page-fragment"""  
         docpath = docinfo['textURLPath']  
         if 'allPlaces' in docinfo:  
             # allredy there  
             return docinfo  
                   
         if (docpath is not None):     
             text = self.getServerData("page-fragment.xql","document=%s"%(docinfo['textURLPath']))  
             dom = Parse(text)  
             # figureEntries              # figureEntries
             pagedivs = dom.xpath("//div[@class='countFigureEntries']")              pagedivs = dom.xpath("//div[@class='countFigureEntries']")
           if pagedivs == dom.xpath("//div[@class='countFigureEntries']"):
               if len(pagedivs)>0:
                   docinfo['countFigureEntries'] = getTextFromNode(pagedivs[0])
             s = getTextFromNode(pagedivs[0])              s = getTextFromNode(pagedivs[0])
                   if s=='0':
             try:              try:
                 docinfo['figureEntries'] = int(s)                          docinfo['countFigureEntries'] = int(s)
                           logging.debug("FIGURE ENTRIES: %s"%(s))
             except:              except:
                 docinfo['figureEntries'] = 0                          docinfo['countFigureEntries'] = 0
             # tocEntries                  else:
             pagedivs = dom.xpath("//div[@class='countTocEntries']")                      s1 = int(s)/30+1
             s = getTextFromNode(pagedivs[0])  
             try:              try:
                 docinfo['tocEntries'] = int(s)                          docinfo['countFigureEntries'] = int(s1)
                           logging.debug("FIGURE ENTRIES: %s"%(s1))
             except:              except:
                 docinfo['tocEntries'] = 0                          docinfo['countFigureEntries'] = 0      
           
             # allPlaces              # allPlaces
             pagedivs = dom.xpath("//div[@class='countPlaces']")              pagedivs = dom.xpath("//div[@class='countPlaces']")
           if pagedivs == dom.xpath("//div[@class='countPlaces']"):
               if len(pagedivs)>0:
                   docinfo['countPlaces']= getTextFromNode(pagedivs[0])
             s = getTextFromNode(pagedivs[0])              s = getTextFromNode(pagedivs[0])
             try:              try:
                 docinfo['allPlaces'] = int(s)                      docinfo['countPlaces'] = int(s)
                       logging.debug("PLACES HERE: %s"%(s))
             except:              except:
                 docinfo['allPlaces'] = 0                      docinfo['countPlaces'] = 0
                                   
           #tocEntries
           pagedivs = dom.xpath("//div[@class='countTocEntries']")
           if pagedivs == dom.xpath("//div[@class='countTocEntries']"):
               if len(pagedivs)>0:
                   docinfo['countTocEntries'] = int(getTextFromNode(pagedivs[0]))
                   s = getTextFromNode(pagedivs[0])
                   if s=='0':
                       try:
                           docinfo['countTocEntries'] = int(s)
                           logging.debug("TEXT ENTRIES: %s"%(s))
                       except:
                           docinfo['countTocEntries'] = 0
         else:          else:
             # no full text -- init to 0                      s1 = int(s)/30+1
             docinfo['figureEntries'] = 0                      try:
             docinfo['tocEntries'] = 0                          docinfo['countTocEntries'] = int(s1)
             docinfo['allPlaces'] = 0                          logging.debug("TEXT ENTRIES: %s"%(s1))
                       except:
                           docinfo['countTocEntries'] = 0
   
         return docinfo          #numTextPages
           pagedivs = dom.xpath("//div[@class='countPages']")
           if pagedivs == dom.xpath("//div[@class='countPages']"):
               if len(pagedivs)>0:
                   docinfo['numPages'] = getTextFromNode(pagedivs[0])
                   s = getTextFromNode(pagedivs[0])
                                                 
                   try:
                       docinfo['numPages'] = int(s)
                       logging.debug("PAGE NUMBER: %s"%(s))
                         
     def getTextPage(self, mode="text", pn=1, docinfo=None, pageinfo=None, viewMode=None, tocMode=None, tocPN=None, characterNormalization="reg", highlightQuery=None, sn=None, optionToggle=None):                      np = docinfo['numPages']
         """returns single page from fulltext"""                      pageinfo['end'] = min(pageinfo['end'], np)
         docpath = docinfo['textURLPath']                      pageinfo['numgroups'] = int(np / pageinfo['groupsize'])
         path = docinfo['textURLPath']                      if np % pageinfo['groupsize'] > 0:
         url = docinfo['url']                          pageinfo['numgroups'] += 1                
         name = docinfo['name']                  except:
         viewMode= pageinfo['viewMode']                      docinfo['numPages'] = 0
         sn = pageinfo['sn']  
         highlightQuery = pageinfo['highlightQuery']  
                   
         tocMode = pageinfo['tocMode']  
         characterNormalization=pageinfo['characterNormalization']  
         tocPN = pageinfo['tocPN']  
         selfurl = self.absolute_url()     
         if mode == "text_dict":  
             textmode = "textPollux"  
         else:          else:
             textmode = mode           #no full text -- init to 0
         #logging.debug("documentViewer highlightQuery: %s"%(highlightQuery))              docinfo['pageNumberOrig'] = 0
         textParam = "document=%s&mode=%s&pn=%s&characterNormalization=%s"%(docpath,textmode,pn,characterNormalization)              docinfo['countFigureEntries'] = 0
         if highlightQuery is not None:              docinfo['countPlaces'] = 0
             textParam +="&highlightQuery=%s&sn=%s"%(urllib.quote(highlightQuery),sn)                         docinfo['countTocEntries'] = 0
             #logging.debug("documentViewer highlightQuery: %s"%(highlightQuery))              docinfo['numPages'] = 0
         pagexml = self.getServerData("page-fragment.xql",textParam)          #return docinfo
         logging.debug("documentViewer highlightQuery: %s"%(highlightQuery))  
         #pagexml=self.template.fulltextclient.eval("/mpdl/interface/page-fragment.xql", textParam, outputUnicode=False)  
                   
         pagedom = Parse(pagexml)  
         # plain text mode          # plain text mode
         if mode == "text":          if mode == "text":
             # first div contains text              # first div contains text
             pagedivs = pagedom.xpath("/div")              pagedivs = dom.xpath("/div")
             if len(pagedivs) > 0:                    if len(pagedivs) > 0:      
                 pagenode = pagedivs[0]                  pagenode = pagedivs[0]
                 links = pagenode.xpath("//a")                  links = pagenode.xpath("//a")
Line 298  class MpdlXmlTextServer(SimpleItem): Line 306  class MpdlXmlTextServer(SimpleItem):
                 return serializeNode(pagenode)                  return serializeNode(pagenode)
         if mode == "xml":          if mode == "xml":
               # first div contains text                # first div contains text
               pagedivs = pagedom.xpath("/div")                pagedivs = dom.xpath("/div")
               if len(pagedivs) > 0:                if len(pagedivs) > 0:
                   pagenode = pagedivs[0]                    pagenode = pagedivs[0]
                   return serializeNode(pagenode)                    return serializeNode(pagenode)
         if mode == "gis":          if mode == "gis":
               # first div contains text                # first div contains text
               pagedivs = pagedom.xpath("/div")                pagedivs = dom.xpath("/div")
               if len(pagedivs) > 0:                if len(pagedivs) > 0:
                   pagenode = pagedivs[0]                    pagenode = pagedivs[0]
                   links =pagenode.xpath("//a")                    links =pagenode.xpath("//a")
Line 319  class MpdlXmlTextServer(SimpleItem): Line 327  class MpdlXmlTextServer(SimpleItem):
                                           
         if mode == "pureXml":          if mode == "pureXml":
               # first div contains text                # first div contains text
               pagedivs = pagedom.xpath("/div")                pagedivs = dom.xpath("/div")
               if len(pagedivs) > 0:                if len(pagedivs) > 0:
                   pagenode = pagedivs[0]                    pagenode = pagedivs[0]
                   return serializeNode(pagenode)                          return serializeNode(pagenode)      
         # text-with-links mode          # text-with-links mode
         if mode == "text_dict":          if mode == "text_dict":
             # first div contains text              # first div contains text
             pagedivs = pagedom.xpath("/div")              pagedivs = dom.xpath("/div")
             if len(pagedivs) > 0:              if len(pagedivs) > 0:
                 pagenode = pagedivs[0]                  pagenode = pagedivs[0]
                 # check all a-tags                  # check all a-tags
Line 375  class MpdlXmlTextServer(SimpleItem): Line 383  class MpdlXmlTextServer(SimpleItem):
         return data          return data
           
     def getQuery (self,  docinfo=None, pageinfo=None, query=None, queryType=None, pn=1, optionToggle=None):      def getQuery (self,  docinfo=None, pageinfo=None, query=None, queryType=None, pn=1, optionToggle=None):
          """number of"""           #number of
          docpath = docinfo['textURLPath']            docpath = docinfo['textURLPath'] 
          pagesize = pageinfo['queryPageSize']           pagesize = pageinfo['queryPageSize']
          pn = pageinfo['searchPN']           pn = pageinfo['searchPN']
Line 385  class MpdlXmlTextServer(SimpleItem): Line 393  class MpdlXmlTextServer(SimpleItem):
          tocDiv = None           tocDiv = None
                     
          pagexml = self.getServerData("doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath, 'text', queryType, urllib.quote(query), pagesize, pn))           pagexml = self.getServerData("doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath, 'text', queryType, urllib.quote(query), pagesize, pn))
          #pagexml=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath, 'text', queryType, query, pagesize, pn) ,outputUnicode=False)  
          pagedom = Parse(pagexml)           pagedom = Parse(pagexml)
          numdivs = pagedom.xpath("//div[@class='queryResultHits']")           numdivs = pagedom.xpath("//div[@class='queryResultHits']")
          tocSearch = int(getTextFromNode(numdivs[0]))           tocSearch = int(getTextFromNode(numdivs[0]))
Line 394  class MpdlXmlTextServer(SimpleItem): Line 401  class MpdlXmlTextServer(SimpleItem):
          logging.debug("documentViewer (gettoc) tc: %s"%(tc))           logging.debug("documentViewer (gettoc) tc: %s"%(tc))
          return tc           return tc
   
     def getQueryResultHits(self,  docinfo=None, pageinfo=None, query=None, queryType=None, pn=1, optionsClose=None):  
           
          """number of hits in Search mode"""  
          docpath = docinfo['textURLPath']   
          pagesize = pageinfo['queryPageSize']  
          pn = pageinfo['searchPN']  
          query =pageinfo['query']  
          queryType =pageinfo['queryType']  
          tocSearch = 0  
          tocDiv = None  
            
          pagexml = self.getServerData("doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath, 'text', queryType, urllib.quote(query), pagesize, pn))  
          #pagexml=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath, 'text', queryType, query, pagesize, pn) ,outputUnicode=False)  
          pagedom = Parse(pagexml)  
          numdivs = pagedom.xpath("//div[@class='queryResultHits']")  
          tocSearch = int(getTextFromNode(numdivs[0]))   
          tc=int((tocSearch/10)+1)     
          return tc  
        
     def getQueryResultHitsText(self,  docinfo=None, pageinfo=None):        
          """number of hits in Text of Contents mode"""  
          selfurl = self.absolute_url()  
          docpath = docinfo['textURLPath']  
          viewMode=  pageinfo['viewMode']  
          text = self.getServerData("page-fragment.xql","document=%s&mode=%s"%(docinfo['textURLPath'], 'text'))  
          dom =Parse(text)  
          pagedivs = dom.xpath("//div[@class='countTocEntries']")  
          logging.debug ("pagedivs=%s"%(pagedivs))  
          if len(pagedivs)>0:  
             originalPage= (getTextFromNode(pagedivs[0]))  
             tc = int (originalPage)  
             tc1 =tc/30+1  
             return tc1  
            
     def getQueryResultHitsFigures(self,  docinfo=None, pageinfo=None):        
          """number of hits in Text of Figures mode"""  
            
          selfurl = self.absolute_url()  
          docpath = docinfo['textURLPath']  
          viewMode=  pageinfo['viewMode']  
          text = self.getServerData("page-fragment.xql","document=%s&mode=%s"%(docinfo['textURLPath'], 'text'))  
          dom =Parse(text)  
          pagedivs = dom.xpath("//div[@class='countFigureEntries']")  
          logging.debug ("pagedivs=%s"%(pagedivs))  
          if len(pagedivs)>0:  
             originalPage= (getTextFromNode(pagedivs[0]))  
             tc = int (originalPage)  
             tc1 =tc/30+1  
             return tc1   
   
   
     def getToc(self, mode="text", docinfo=None):      def getToc(self, mode="text", docinfo=None):
         """loads table of contents and stores in docinfo"""          """loads table of contents and stores in docinfo"""
         logging.debug("documentViewer (gettoc) mode: %s"%(mode))          logging.debug("documentViewer (gettoc) mode: %s"%(mode))
Line 467  class MpdlXmlTextServer(SimpleItem): Line 423  class MpdlXmlTextServer(SimpleItem):
         tocDiv = None          tocDiv = None
                   
         pagexml = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType, pagesize, pn))          pagexml = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType, pagesize, pn))
         #pagexml=self.template.fulltextclient.eval("/mpdl/interface/doc-query.xql", "document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType,pagesize,pn), outputUnicode=False)          
         # post-processing downloaded xml          # post-processing downloaded xml
         pagedom = Parse(pagexml)          pagedom = Parse(pagexml)
         # get number of entries          # get number of entries
Line 499  class MpdlXmlTextServer(SimpleItem): Line 455  class MpdlXmlTextServer(SimpleItem):
         data = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s&characterNormalization=regPlusNorm&optionToggle=1"%(docpath,queryType, pagesize, pn))            data = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s&characterNormalization=regPlusNorm&optionToggle=1"%(docpath,queryType, pagesize, pn))  
         page = data.replace('page-fragment.xql?document=%s'%str(path),'%s?url=%s&viewMode=%s&tocMode=%s&tocPN=%s&optionToggle=1'%(selfurl,url, viewMode, tocMode, tocPN))          page = data.replace('page-fragment.xql?document=%s'%str(path),'%s?url=%s&viewMode=%s&tocMode=%s&tocPN=%s&optionToggle=1'%(selfurl,url, viewMode, tocMode, tocPN))
         text = page.replace('mode=image','mode=texttool')          text = page.replace('mode=image','mode=texttool')
         logging.debug("documentViewer (characterNormalization) characterNormalization: %s"%(characterNormalization))          #logging.debug("documentViewer (characterNormalization) characterNormalization: %s"%(characterNormalization))
         #logging.debug("documentViewer (characterNormalization) text: %s"%(text))          
         return text          return text
           
     def manage_changeMpdlXmlTextServer(self,title="",serverUrl="http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None):      def manage_changeMpdlXmlTextServer(self,title="",serverUrl="http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None):

Removed from v.1.221  
changed lines
  Added in v.1.222


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>