--- documentViewer/MpdlXmlTextServer.py 2010/10/05 10:38:17 1.47 +++ documentViewer/MpdlXmlTextServer.py 2010/11/23 17:05:20 1.212 @@ -38,12 +38,10 @@ class MpdlXmlTextServer(SimpleItem): url = self.serverUrl+method return documentViewer.getHttpData(url,data,timeout=self.timeout) - def getSearch(self, pn=1, pageinfo=None, docinfo=None, query=None, queryType=None, lemma=None): + def getSearch(self, pn=1, pageinfo=None, docinfo=None, query=None, queryType=None, lemma=None, characterNormalization=None, optionToggle=None): """get search list""" docpath = docinfo['textURLPath'] url = docinfo['url'] - logging.debug("documentViewer (gettoc) docpath: %s"%(docpath)) - logging.debug("documentViewer (gettoc) url: %s"%(url)) pagesize = pageinfo['queryPageSize'] pn = pageinfo['searchPN'] sn = pageinfo['sn'] @@ -53,10 +51,11 @@ class MpdlXmlTextServer(SimpleItem): viewMode= pageinfo['viewMode'] tocMode = pageinfo['tocMode'] characterNormalization = pageinfo['characterNormalization'] + optionToggle = pageinfo['optionToggle'] tocPN = pageinfo['tocPN'] 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&highlightQuery=%s"%(docpath, 'text', queryType, urllib.quote(query), pagesize, pn, sn, viewMode,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) @@ -72,7 +71,7 @@ class MpdlXmlTextServer(SimpleItem): href = hrefNode.nodeValue if href.startswith('page-fragment.xql'): selfurl = self.absolute_url() - pagexml=href.replace('mode=text','mode=texttool&viewMode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&tocMode=%s&searchPN=%s&tocPN=%s'%(viewMode,queryType,urllib.quote(query),pagesize,pn,tocMode,pn,tocPN)) + pagexml=href.replace('mode=text','mode=texttool&viewMode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&tocMode=%s&searchPN=%s&tocPN=%s&optionToggle=%s'%(viewMode,queryType,urllib.quote(query),pagesize,pn,tocMode,pn,tocPN,optionToggle)) hrefNode.nodeValue = pagexml.replace('page-fragment.xql','%s'%selfurl) return serializeNode(pagenode) if (queryType=="fulltextMorph"): @@ -86,7 +85,7 @@ class MpdlXmlTextServer(SimpleItem): href = hrefNode.nodeValue if href.startswith('page-fragment.xql'): selfurl = self.absolute_url() - pagexml=href.replace('mode=text','mode=texttool&viewMode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&tocMode=%s&searchPN=%s&tocPN=%s'%(viewMode,queryType,urllib.quote(query),pagesize,pn,tocMode,pn,tocPN)) + pagexml=href.replace('mode=text','mode=texttool&viewMode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&tocMode=%s&searchPN=%s&tocPN=%s&optionToggle=%s'%(viewMode,queryType,urllib.quote(query),pagesize,pn,tocMode,pn,tocPN,optionToggle)) hrefNode.nodeValue = pagexml.replace('page-fragment.xql','%s'%selfurl) if href.startswith('../lt/lemma.xql'): hrefNode.nodeValue = href.replace('../lt/lemma.xql','%s/template/head_main_lemma_New'%(selfurl)) @@ -104,7 +103,7 @@ class MpdlXmlTextServer(SimpleItem): hrefNode = l.getAttributeNodeNS(None, u"href") if hrefNode: href = hrefNode.nodeValue - hrefNode.nodeValue=href.replace('mode=text','mode=texttool&viewMode=%s&tocMode=%s&tocPN=%s&pn=%s'%(viewMode,tocMode,tocPN,pn)) + hrefNode.nodeValue=href.replace('mode=text','mode=texttool&viewMode=%s&tocMode=%s&tocPN=%s&pn=%s&optionToggle=%s'%(viewMode,tocMode,tocPN,pn,optionToggle)) if href.startswith('../lt/lex.xql'): hrefNode.nodeValue = href.replace('../lt/lex.xql','%s/template/head_main_voc'%selfurl) l.setAttributeNS(None, 'target', '_blank') @@ -118,8 +117,8 @@ class MpdlXmlTextServer(SimpleItem): return serializeNode(pagenode) return "no text here" - def getNumPages(self, docinfo): - """get list of pages from fulltext and put in docinfo""" + """def getNumPages(self, docinfo): + ""get list of pages from fulltext and put in docinfo"" if 'numPages' in docinfo: # already there return docinfo @@ -127,7 +126,7 @@ class MpdlXmlTextServer(SimpleItem): text = self.getServerData("xquery.xql","document=%s&xquery=%s"%(docinfo['textURLPath'],xquery)) docinfo['numPages'] = text.count("0: + originalPage= getTextFromNode(pagedivs[0]) + #return docinfo['originalPage'] + return originalPage + + + def getTextPage(self, mode="text", pn=1, docinfo=None, pageinfo=None, viewMode=None, tocMode=None, tocPN=None, characterNormalization="regPlusNorm", highlightQuery=None, sn=None, optionToggle=None): """returns single page from fulltext""" docpath = docinfo['textURLPath'] path = docinfo['textURLPath'] url = docinfo['url'] + name = docinfo['name'] viewMode= pageinfo['viewMode'] + sn = pageinfo['sn'] + highlightQuery = pageinfo['highlightQuery'] + tocMode = pageinfo['tocMode'] characterNormalization=pageinfo['characterNormalization'] tocPN = pageinfo['tocPN'] @@ -154,12 +233,13 @@ class MpdlXmlTextServer(SimpleItem): textmode = "textPollux" else: textmode = mode - #logging.debug("documentViewer (characterNormalization) characterNormalization: %s"%(characterNormalization)) + #logging.debug("documentViewer highlightQuery: %s"%(highlightQuery)) textParam = "document=%s&mode=%s&pn=%s&characterNormalization=%s"%(docpath,textmode,pn,characterNormalization) if highlightQuery is not None: textParam +="&highlightQuery=%s&sn=%s"%(urllib.quote(highlightQuery),sn) - + #logging.debug("documentViewer highlightQuery: %s"%(highlightQuery)) pagexml = self.getServerData("page-fragment.xql",textParam) + logging.debug("documentViewer highlightQuery: %s"%(highlightQuery)) #pagexml=self.template.fulltextclient.eval("/mpdl/interface/page-fragment.xql", textParam, outputUnicode=False) pagedom = Parse(pagexml) @@ -194,8 +274,8 @@ class MpdlXmlTextServer(SimpleItem): if hrefNode: href=hrefNode.nodeValue if href.startswith('http://chinagis.mpiwg-berlin.mpg.de'): - hrefNode.nodeValue =href.replace('chinagis_REST','chinagis') - l.setAttributeNS(None, 'target', '_blank') + hrefNode.nodeValue =href.replace('chinagis_REST/REST/db/chgis/mpdl','chinagis/REST/db/mpdl/%s'%name) + l.setAttributeNS(None, 'target', '_blank') return serializeNode(pagenode) if mode == "pureXml": @@ -255,7 +335,7 @@ class MpdlXmlTextServer(SimpleItem): #pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lemma.xql","document=&language="+str(language)+"&lemma="+url_quote(str(query))) return data - def getQuery (self, docinfo=None, pageinfo=None, query=None, queryType=None, pn=1): + def getQuery (self, docinfo=None, pageinfo=None, query=None, queryType=None, pn=1, optionToggle=None): """number of""" docpath = docinfo['textURLPath'] pagesize = pageinfo['queryPageSize'] @@ -270,10 +350,71 @@ class MpdlXmlTextServer(SimpleItem): pagedom = Parse(pagexml) numdivs = pagedom.xpath("//div[@class='queryResultHits']") tocSearch = int(getTextFromNode(numdivs[0])) + logging.debug("documentViewer (gettoc) tocSearch: %s"%(tocSearch)) tc=int((tocSearch/10)+1) logging.debug("documentViewer (gettoc) tc: %s"%(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""" + + docpath = docinfo['textURLPath'] + pagesize = pageinfo['queryPageSize'] + pn = pageinfo['searchPN'] + query =pageinfo['query'] + queryType =pageinfo['queryType'] + tocSearch = 0 + tocDiv = None + tocMode = pageinfo['tocMode'] + tocPN = pageinfo['tocPN'] + pagexml=self.getServerData("doc-query.xql", "document=%s&queryType=%s"%(docpath,'toc')) + pagedom = Parse(pagexml) + logging.debug("documentViewer (pagedom) pagedom: %s"%(pagedom)) + numdivs = pagedom.xpath("//div[@class='queryResultHits']") + tocSearch = int(getTextFromNode(numdivs[0])) + tc=int((tocSearch/30)+1) + return tc + + def getQueryResultHitsFigures(self, docinfo=None, pageinfo=None): + """number of hits in Text of Figures mode""" + + docpath = docinfo['textURLPath'] + pagesize = pageinfo['queryPageSize'] + pn = pageinfo['searchPN'] + query =pageinfo['query'] + queryType =pageinfo['queryType'] + tocSearch = 0 + tocDiv = None + tocMode = pageinfo['tocMode'] + tocPN = pageinfo['tocPN'] + pagexml=self.getServerData("doc-query.xql", "document=%s&queryType=%s"%(docpath,'figures')) + pagedom = Parse(pagexml) + logging.debug("documentViewer (pagedom) pagedom: %s"%(pagedom)) + numdivs = pagedom.xpath("//div[@class='queryResultHits']") + tocSearch = int(getTextFromNode(numdivs[0])) + tc=int((tocSearch/30)+1) + return tc + + def getToc(self, mode="text", docinfo=None): """loads table of contents and stores in docinfo""" logging.debug("documentViewer (gettoc) mode: %s"%(mode)) @@ -321,11 +462,12 @@ class MpdlXmlTextServer(SimpleItem): selfurl = self.absolute_url() viewMode= pageinfo['viewMode'] characterNormalization = pageinfo ['characterNormalization'] + optionToggle =pageinfo ['optionToggle'] tocMode = pageinfo['tocMode'] tocPN = pageinfo['tocPN'] - data = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s&characterNormalization=%s"%(docpath,queryType, pagesize, pn,characterNormalization)) - page = data.replace('page-fragment.xql?document=%s'%str(path),'%s?url=%s&viewMode=%s&tocMode=%s&tocPN=%s'%(selfurl,url, viewMode, tocMode, tocPN)) + data = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s&characterNormalization=regPlusNorm&optionToggle=%s"%(docpath,queryType, pagesize, pn,optionToggle)) + page = data.replace('page-fragment.xql?document=%s'%str(path),'%s?url=%s&viewMode=%s&tocMode=%s&tocPN=%s&optionToggle=%s'%(selfurl,url, viewMode, tocMode, tocPN,optionToggle)) text = page.replace('mode=image','mode=texttool') logging.debug("documentViewer (characterNormalization) characterNormalization: %s"%(characterNormalization)) #logging.debug("documentViewer (characterNormalization) text: %s"%(text))