Annotation of documentViewer/MpdlXmlTextServer.py, revision 1.241
1.2 casties 1:
2: from OFS.SimpleItem import SimpleItem
3: from Products.PageTemplates.PageTemplateFile import PageTemplateFile
4: from Ft.Xml import EMPTY_NAMESPACE, Parse
1.238 abukhman 5: from Ft.Xml.Domlette import NonvalidatingReader
1.2 casties 6:
1.224 abukhman 7: import md5
1.2 casties 8: import sys
9: import logging
1.5 casties 10: import urllib
1.2 casties 11: import documentViewer
12: from documentViewer import getTextFromNode, serializeNode
13:
14: class MpdlXmlTextServer(SimpleItem):
15: """TextServer implementation for MPDL-XML eXist server"""
16: meta_type="MPDL-XML TextServer"
17:
18: manage_options=(
19: {'label':'Config','action':'manage_changeMpdlXmlTextServerForm'},
20: )+SimpleItem.manage_options
21:
22: manage_changeMpdlXmlTextServerForm = PageTemplateFile("zpt/manage_changeMpdlXmlTextServer", globals())
23:
1.241 ! abukhman 24: def __init__(self,id,title="",serverUrl="http://mpdl-test.mpiwg-berlin.mpg.de/mpdl/interface/", serverName=None, timeout=40):
1.234 abukhman 25: #def __init__(self,id,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de:30030/mpdl/interface/", serverName=None, timeout=40):
1.231 abukhman 26:
1.2 casties 27: """constructor"""
28: self.id=id
29: self.title=title
30: self.timeout = timeout
1.3 casties 31: if serverName is None:
32: self.serverUrl = serverUrl
33: else:
34: self.serverUrl = "http://%s/mpdl/interface/"%serverName
1.2 casties 35:
36: def getHttpData(self, url, data=None):
37: """returns result from url+data HTTP request"""
38: return documentViewer.getHttpData(url,data,timeout=self.timeout)
39:
40: def getServerData(self, method, data=None):
41: """returns result from text server for method+data"""
42: url = self.serverUrl+method
43: return documentViewer.getHttpData(url,data,timeout=self.timeout)
44:
1.235 abukhman 45: def getSearch(self, pageinfo=None, docinfo=None):
1.2 casties 46: """get search list"""
47: docpath = docinfo['textURLPath']
48: url = docinfo['url']
49: pagesize = pageinfo['queryPageSize']
1.222 abukhman 50: pn = pageinfo.get('searchPN',1)
1.241 ! abukhman 51: #sn = pageinfo['sn']
! 52: s = pageinfo['s']
! 53: highlightElementPos =pageinfo ['highlightElementPos']
! 54: highlightElement = pageinfo ['highlightElement']
! 55:
1.2 casties 56: highlightQuery = pageinfo['highlightQuery']
1.34 abukhman 57: query =pageinfo['query']
1.2 casties 58: queryType =pageinfo['queryType']
59: viewMode= pageinfo['viewMode']
60: tocMode = pageinfo['tocMode']
1.24 abukhman 61: characterNormalization = pageinfo['characterNormalization']
1.237 abukhman 62: #optionToggle = pageinfo['optionToggle']
1.2 casties 63: tocPN = pageinfo['tocPN']
64: selfurl = self.absolute_url()
1.241 ! abukhman 65: data = self.getServerData("doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&s=%s&viewMode=%s&characterNormalization=%s&highlightElementPos=%s&highlightElement=%s&highlightQuery=%s"%(docpath, 'text', queryType, urllib.quote(query), pagesize, pn, s, viewMode,characterNormalization, highlightElementPos, highlightElement, urllib.quote(highlightQuery)))
! 66: #data = self.getServerData("doc-query.xql","document=%s&mode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&sn=%s&viewMode=%s&characterNormalization=%s&highlightQuery=%s"%(docpath, 'text', queryType, urllib.quote(query), pagesize, pn, sn, viewMode,characterNormalization, urllib.quote(highlightQuery)))
1.2 casties 67: pagexml = data.replace('?document=%s'%str(docpath),'?url=%s'%url)
68: pagedom = Parse(pagexml)
1.222 abukhman 69:
70: """
71: pagedivs = pagedom.xpath("//div[@class='queryResultHits']")
72: if (pagedivs == pagedom.xpath("//div[@class='queryResultHits']")):
73: if len(pagedivs)>0:
74: docinfo['queryResultHits'] = int(getTextFromNode(pagedivs[0]))
75: s = getTextFromNode(pagedivs[0])
76: s1 = int(s)/10+1
77: try:
78: docinfo['queryResultHits'] = int(s1)
79: logging.debug("SEARCH ENTRIES: %s"%(s1))
80: except:
81: docinfo['queryResultHits'] = 0
82: """
1.2 casties 83: if (queryType=="fulltext")or(queryType=="xpath")or(queryType=="xquery")or(queryType=="fulltextMorphLemma"):
84: pagedivs = pagedom.xpath("//div[@class='queryResultPage']")
85: if len(pagedivs)>0:
86: pagenode=pagedivs[0]
87: links=pagenode.xpath("//a")
88: for l in links:
89: hrefNode = l.getAttributeNodeNS(None, u"href")
90: if hrefNode:
91: href = hrefNode.nodeValue
92: if href.startswith('page-fragment.xql'):
93: selfurl = self.absolute_url()
1.237 abukhman 94: pagexml=href.replace('mode=text','mode=texttool&viewMode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&tocMode=%s&searchPN=%s&tocPN=%s&characterNormalization=%s'%(viewMode,queryType,urllib.quote(query),pagesize,pn,tocMode,pn,tocPN, characterNormalization))
1.2 casties 95: hrefNode.nodeValue = pagexml.replace('page-fragment.xql','%s'%selfurl)
1.230 abukhman 96: #logging.debug("PUREXML :%s"%(serializeNode(pagenode)))
1.2 casties 97: return serializeNode(pagenode)
98: if (queryType=="fulltextMorph"):
99: pagedivs = pagedom.xpath("//div[@class='queryResult']")
100: if len(pagedivs)>0:
101: pagenode=pagedivs[0]
102: links=pagenode.xpath("//a")
103: for l in links:
104: hrefNode = l.getAttributeNodeNS(None, u"href")
105: if hrefNode:
106: href = hrefNode.nodeValue
107: if href.startswith('page-fragment.xql'):
108: selfurl = self.absolute_url()
1.237 abukhman 109: pagexml=href.replace('mode=text','mode=texttool&viewMode=%s&queryType=%s&query=%s&queryResultPageSize=%s&queryResultPN=%s&tocMode=%s&searchPN=%s&tocPN=%s&characterNormalization=%s'%(viewMode,queryType,urllib.quote(query),pagesize,pn,tocMode,pn,tocPN,characterNormalization))
1.2 casties 110: hrefNode.nodeValue = pagexml.replace('page-fragment.xql','%s'%selfurl)
111: if href.startswith('../lt/lemma.xql'):
1.235 abukhman 112: hrefNode.nodeValue = href.replace('../lt/lemma.xql','%s/template/head_main_query'%(selfurl))
1.2 casties 113: l.setAttributeNS(None, 'target', '_blank')
1.239 abukhman 114: l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=300,height=400,top=180, left=400, scrollbars=1'); return false;")
1.235 abukhman 115: l.setAttributeNS(None, 'onDblclick', 'popupWin.focus();')
1.2 casties 116: pagedivs = pagedom.xpath("//div[@class='queryResultMorphExpansion']")
117: return serializeNode(pagenode)
118: if (queryType=="ftIndex")or(queryType=="ftIndexMorph"):
119: pagedivs= pagedom.xpath("//div[@class='queryResultPage']")
120: if len(pagedivs)>0:
121: pagenode=pagedivs[0]
122: links=pagenode.xpath("//a")
123: for l in links:
124: hrefNode = l.getAttributeNodeNS(None, u"href")
125: if hrefNode:
126: href = hrefNode.nodeValue
1.237 abukhman 127: hrefNode.nodeValue=href.replace('mode=text','mode=texttool&viewMode=%s&tocMode=%s&tocPN=%s&pn=%s&characterNormalization=%s'%(viewMode,tocMode,tocPN,pn,characterNormalization))
1.2 casties 128: if href.startswith('../lt/lex.xql'):
1.235 abukhman 129: hrefNode.nodeValue = href.replace('../lt/lex.xql','%s/template/head_main_lex'%selfurl)
1.2 casties 130: l.setAttributeNS(None, 'target', '_blank')
131: l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=500,height=600,top=180, left=400, scrollbars=1'); return false;")
1.235 abukhman 132: l.setAttributeNS(None, 'onDblclick', 'popupWin.focus();')
1.2 casties 133: if href.startswith('../lt/lemma.xql'):
1.235 abukhman 134: hrefNode.nodeValue = href.replace('../lt/lemma.xql','%s/template/head_main_lemma'%(selfurl))
1.2 casties 135: l.setAttributeNS(None, 'target', '_blank')
1.239 abukhman 136: l.setAttributeNS(None, 'onClick',"popupWin = window.open(this.href, 'contacts', 'location,width=300,height=400,top=180, left=400, scrollbars=1'); return false;")
1.235 abukhman 137: l.setAttributeNS(None, 'onDblclick', 'popupWin.focus();')
1.2 casties 138: return serializeNode(pagenode)
139: return "no text here"
1.222 abukhman 140:
1.89 abukhman 141: def getGisPlaces(self, docinfo=None, pageinfo=None):
1.58 abukhman 142: """ Show all Gis Places of whole Page"""
1.100 abukhman 143: xpath='//place'
1.214 casties 144: docpath = docinfo.get('textURLPath',None)
145: if not docpath:
146: return None
147:
1.89 abukhman 148: url = docinfo['url']
149: selfurl = self.absolute_url()
1.93 abukhman 150: pn = pageinfo['current']
1.127 abukhman 151: hrefList=[]
1.142 abukhman 152: myList= ""
1.100 abukhman 153: text=self.getServerData("xpath.xql", "document=%s&xpath=%s&pn=%s"%(docinfo['textURLPath'],xpath,pn))
154: dom = Parse(text)
1.101 abukhman 155: result = dom.xpath("//result/resultPage/place")
1.72 abukhman 156: for l in result:
1.86 abukhman 157: hrefNode= l.getAttributeNodeNS(None, u"id")
1.108 abukhman 158: href= hrefNode.nodeValue
1.128 abukhman 159: hrefList.append(href)
1.145 abukhman 160: myList = ",".join(hrefList)
1.230 abukhman 161: #logging.debug("getGisPlaces :%s"%(myList))
1.143 abukhman 162: return myList
163:
164: def getAllGisPlaces (self, docinfo=None, pageinfo=None):
165: """Show all Gis Places of whole Book """
166: xpath ='//echo:place'
167: docpath =docinfo['textURLPath']
168: url = docinfo['url']
169: selfurl =self.absolute_url()
170: pn =pageinfo['current']
171: hrefList=[]
172: myList=""
173: text=self.getServerData("xpath.xql", "document=%s&xpath=%s"%(docinfo['textURLPath'],xpath))
174: dom =Parse(text)
175: result = dom.xpath("//result/resultPage/place")
1.205 abukhman 176:
1.143 abukhman 177: for l in result:
178: hrefNode = l.getAttributeNodeNS(None, u"id")
179: href= hrefNode.nodeValue
180: hrefList.append(href)
1.136 abukhman 181: myList = ",".join(hrefList)
1.230 abukhman 182: #logging.debug("getALLGisPlaces :%s"%(myList))
1.145 abukhman 183: return myList
1.222 abukhman 184:
1.215 abukhman 185:
1.227 abukhman 186: def getTextPage(self, mode="text_dict", pn=1, docinfo=None, pageinfo=None):
1.2 casties 187: """returns single page from fulltext"""
188: docpath = docinfo['textURLPath']
189: path = docinfo['textURLPath']
1.222 abukhman 190: url = docinfo.get('url',None)
191: name = docinfo.get('name',None)
192: pn =pageinfo['current']
1.241 ! abukhman 193: #sn = pageinfo['sn']
! 194: s = pageinfo['s']
! 195: highlightElementPos =pageinfo ['highlightElementPos']
! 196: highlightElement = pageinfo ['highlightElement']
1.237 abukhman 197: #optionToggle =pageinfo ['optionToggle']
1.187 abukhman 198: highlightQuery = pageinfo['highlightQuery']
1.225 abukhman 199: #mode = pageinfo ['viewMode']
1.2 casties 200: tocMode = pageinfo['tocMode']
1.20 abukhman 201: characterNormalization=pageinfo['characterNormalization']
1.2 casties 202: tocPN = pageinfo['tocPN']
203: selfurl = self.absolute_url()
204: if mode == "text_dict":
205: textmode = "textPollux"
206: else:
207: textmode = mode
1.222 abukhman 208:
1.237 abukhman 209: textParam = "document=%s&mode=%s&pn=%s&characterNormalization=%s"%(docpath,textmode,pn,characterNormalization)
1.190 abukhman 210: if highlightQuery is not None:
1.241 ! abukhman 211: #textParam +="&highlightQuery=%s&sn=%s"%(urllib.quote(highlightQuery),sn)
! 212: textParam +="&highlightQuery=%s&s=%s&highlightElement=%s&highlightElementPos=%s"%(urllib.quote(highlightQuery),s, highlightElement, highlightElementPos)
1.222 abukhman 213:
1.38 abukhman 214: pagexml = self.getServerData("page-fragment.xql",textParam)
1.222 abukhman 215: dom = Parse(pagexml)
1.238 abukhman 216: #dom = NonvalidatingReader.parseStream(pagexml)
1.236 abukhman 217:
1.222 abukhman 218: #original Pages
1.233 abukhman 219: pagedivs = dom.xpath("//div[@class='pageNumberOrig']")
1.236 abukhman 220:
1.230 abukhman 221: """if pagedivs == dom.xpath("//div[@class='pageNumberOrig']"):
1.222 abukhman 222: if len(pagedivs)>0:
223: docinfo['pageNumberOrig']= getTextFromNode(pagedivs[0])
1.230 abukhman 224: logging.debug("ORIGINAL PAGE: %s"%(docinfo['pageNumberOrig']))
1.226 abukhman 225:
226: #original Pages Norm
227: pagedivs = dom.xpath("//div[@class='pageNumberOrigNorm']")
228: if pagedivs == dom.xpath("//div[@class='pageNumberOrigNorm']"):
229: if len(pagedivs)>0:
230: docinfo['pageNumberOrigNorm']= getTextFromNode(pagedivs[0])
1.230 abukhman 231: logging.debug("ORIGINAL PAGE NORM: %s"%(docinfo['pageNumberOrigNorm']))
232: """
1.222 abukhman 233: #figureEntries
234: pagedivs = dom.xpath("//div[@class='countFigureEntries']")
235: if pagedivs == dom.xpath("//div[@class='countFigureEntries']"):
236: if len(pagedivs)>0:
237: docinfo['countFigureEntries'] = getTextFromNode(pagedivs[0])
238: s = getTextFromNode(pagedivs[0])
239: if s=='0':
240: try:
241: docinfo['countFigureEntries'] = int(s)
242: except:
243: docinfo['countFigureEntries'] = 0
244: else:
245: s1 = int(s)/30+1
246: try:
247: docinfo['countFigureEntries'] = int(s1)
248: except:
249: docinfo['countFigureEntries'] = 0
250:
251: #allPlaces
252: pagedivs = dom.xpath("//div[@class='countPlaces']")
253: if pagedivs == dom.xpath("//div[@class='countPlaces']"):
254: if len(pagedivs)>0:
255: docinfo['countPlaces']= getTextFromNode(pagedivs[0])
256: s = getTextFromNode(pagedivs[0])
257: try:
258: docinfo['countPlaces'] = int(s)
259: except:
260: docinfo['countPlaces'] = 0
261:
262: #tocEntries
263: pagedivs = dom.xpath("//div[@class='countTocEntries']")
264: if pagedivs == dom.xpath("//div[@class='countTocEntries']"):
265: if len(pagedivs)>0:
266: docinfo['countTocEntries'] = int(getTextFromNode(pagedivs[0]))
267: s = getTextFromNode(pagedivs[0])
268: if s=='0':
269: try:
270: docinfo['countTocEntries'] = int(s)
271: except:
272: docinfo['countTocEntries'] = 0
273: else:
274: s1 = int(s)/30+1
275: try:
276: docinfo['countTocEntries'] = int(s1)
277: except:
278: docinfo['countTocEntries'] = 0
279:
280: #numTextPages
281: pagedivs = dom.xpath("//div[@class='countPages']")
282: if pagedivs == dom.xpath("//div[@class='countPages']"):
283: if len(pagedivs)>0:
284: docinfo['numPages'] = getTextFromNode(pagedivs[0])
285: s = getTextFromNode(pagedivs[0])
286:
287: try:
288: docinfo['numPages'] = int(s)
1.228 abukhman 289: #logging.debug("PAGE NUMBER: %s"%(s))
1.222 abukhman 290:
291: np = docinfo['numPages']
292: pageinfo['end'] = min(pageinfo['end'], np)
293: pageinfo['numgroups'] = int(np / pageinfo['groupsize'])
294: if np % pageinfo['groupsize'] > 0:
295: pageinfo['numgroups'] += 1
296: except:
297: docinfo['numPages'] = 0
298:
299: else:
300: #no full text -- init to 0
301: docinfo['pageNumberOrig'] = 0
302: docinfo['countFigureEntries'] = 0
303: docinfo['countPlaces'] = 0
304: docinfo['countTocEntries'] = 0
305: docinfo['numPages'] = 0
1.226 abukhman 306: docinfo['pageNumberOrigNorm'] = 0
1.222 abukhman 307: #return docinfo
1.2 casties 308:
309: # plain text mode
310: if mode == "text":
311: # first div contains text
1.222 abukhman 312: pagedivs = dom.xpath("/div")
1.2 casties 313: if len(pagedivs) > 0:
314: pagenode = pagedivs[0]
315: links = pagenode.xpath("//a")
316: for l in links:
317: hrefNode = l.getAttributeNodeNS(None, u"href")
318: if hrefNode:
319: href= hrefNode.nodeValue
320: if href.startswith('#note-'):
1.227 abukhman 321: hrefNode.nodeValue = href.replace('#note-',"?url=%s&viewMode=text&tocMode=%s&tocPN=%s&pn=%s#note-"%(url,tocMode,tocPN,pn))
1.2 casties 322: return serializeNode(pagenode)
323: if mode == "xml":
324: # first div contains text
1.222 abukhman 325: pagedivs = dom.xpath("/div")
1.2 casties 326: if len(pagedivs) > 0:
327: pagenode = pagedivs[0]
328: return serializeNode(pagenode)
1.7 abukhman 329: if mode == "gis":
330: # first div contains text
1.222 abukhman 331: pagedivs = dom.xpath("/div")
1.7 abukhman 332: if len(pagedivs) > 0:
333: pagenode = pagedivs[0]
1.28 abukhman 334: links =pagenode.xpath("//a")
335: for l in links:
336: hrefNode =l.getAttributeNodeNS(None, u"href")
337: if hrefNode:
338: href=hrefNode.nodeValue
339: if href.startswith('http://chinagis.mpiwg-berlin.mpg.de'):
1.75 abukhman 340: hrefNode.nodeValue =href.replace('chinagis_REST/REST/db/chgis/mpdl','chinagis/REST/db/mpdl/%s'%name)
1.62 abukhman 341: l.setAttributeNS(None, 'target', '_blank')
1.61 abukhman 342: return serializeNode(pagenode)
1.7 abukhman 343:
1.2 casties 344: if mode == "pureXml":
345: # first div contains text
1.222 abukhman 346: pagedivs = dom.xpath("/div")
1.2 casties 347: if len(pagedivs) > 0:
348: pagenode = pagedivs[0]
349: return serializeNode(pagenode)
350: # text-with-links mode
351: if mode == "text_dict":
352: # first div contains text
1.227 abukhman 353: #mode = pageinfo ['viewMode']
1.222 abukhman 354: pagedivs = dom.xpath("/div")
1.2 casties 355: if len(pagedivs) > 0:
356: pagenode = pagedivs[0]
357: # check all a-tags
358: links = pagenode.xpath("//a")
1.236 abukhman 359:
1.2 casties 360: for l in links:
361: hrefNode = l.getAttributeNodeNS(None, u"href")
1.236 abukhman 362:
1.2 casties 363: if hrefNode:
364: # is link with href
365: href = hrefNode.nodeValue
1.241 ! abukhman 366: if href.startswith('http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/interface/lt/wordInfo.xql'):
1.2 casties 367: # is pollux link
368: selfurl = self.absolute_url()
369: # change href
1.241 ! abukhman 370: hrefNode.nodeValue = href.replace('http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/interface/lt/wordInfo.xql','%s/head_main_voc'%selfurl)
1.2 casties 371: # add target
372: l.setAttributeNS(None, 'target', '_blank')
1.238 abukhman 373: #l.setAttributeNS(None, 'onclick',"popupWin = window.open(this.href, 'InfoWindow', 'menubar=no, location,width=500,height=600,top=180, left=700, toolbar=no, scrollbars=1'); return false;")
374: #l.setAttributeNS(None, "ondblclick", "popupWin.focus();")
375: #window.open("this.href, 'InfoWindow', 'menubar=no, location,width=500,height=600,top=180, left=700, toolbar=yes, scrollbars=1'"); return false;")
1.235 abukhman 376:
1.241 ! abukhman 377: if href.startswith('http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/lt/lemma.xql'):
1.2 casties 378: selfurl = self.absolute_url()
1.241 ! abukhman 379: hrefNode.nodeValue = href.replace('http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/lt/lemma.xql','%s/head_main_lemma'%selfurl)
1.2 casties 380: l.setAttributeNS(None, 'target', '_blank')
1.239 abukhman 381: l.setAttributeNS(None, 'onclick',"popupWin = window.open(this.href, 'InfoWindow', 'menubar=no, location,width=300,height=400,top=180, left=700, toolbar=no, scrollbars=1'); return false;")
1.236 abukhman 382: l.setAttributeNS(None, 'ondblclick', 'popupWin.focus();')
383:
1.2 casties 384: if href.startswith('#note-'):
1.236 abukhman 385: hrefNode.nodeValue = href.replace('#note-',"?url=%s&viewMode=text_dict&tocMode=%s&tocPN=%s&pn=%s#note-"%(url,tocMode,tocPN,pn))
386:
1.2 casties 387: return serializeNode(pagenode)
388: return "no text here"
1.225 abukhman 389:
1.230 abukhman 390: def getOrigPages(self, docinfo=None, pageinfo=None):
391: docpath = docinfo['textURLPath']
392: pn =pageinfo['current']
393: selfurl = self.absolute_url()
394: pagexml = self.getServerData("page-fragment.xql","document=%s&pn=%s"%(docpath, pn))
395: dom = Parse(pagexml)
396: pagedivs = dom.xpath("//div[@class='pageNumberOrig']")
397: if pagedivs == dom.xpath("//div[@class='pageNumberOrig']"):
398: if len(pagedivs)>0:
399: docinfo['pageNumberOrig']= getTextFromNode(pagedivs[0])
400: return docinfo['pageNumberOrig']
401:
402: def getOrigPagesNorm(self, docinfo=None, pageinfo=None):
403: docpath = docinfo['textURLPath']
404: pn =pageinfo['current']
405: selfurl = self.absolute_url()
406: pagexml = self.getServerData("page-fragment.xql","document=%s&pn=%s"%(docpath, pn))
407: dom = Parse(pagexml)
408: pagedivs = dom.xpath("//div[@class='pageNumberOrigNorm']")
409: if pagedivs == dom.xpath("//div[@class='pageNumberOrigNorm']"):
410: if len(pagedivs)>0:
411: docinfo['pageNumberOrigNorm']= getTextFromNode(pagedivs[0])
412: return docinfo['pageNumberOrigNorm']
413:
414:
1.240 abukhman 415: def getTranslate(self, word=None, language=None, display=None):
1.2 casties 416: """translate into another languages"""
1.239 abukhman 417: data = self.getServerData("lt/wordInfo.xql","language="+str(language)+"&word="+urllib.quote(word)+"&display="+urllib.quote(display)+"&output=html")
1.2 casties 418: #pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lex.xql","document=&language="+str(language)+"&query="+url_quote(str(query)))
419: return data
420:
421: def getLemma(self, lemma=None, language=None):
422: """simular words lemma """
1.235 abukhman 423: data = self.getServerData("lt/lemma.xql","language="+str(language)+"&lemma="+urllib.quote(lemma)+"&output=html")
1.2 casties 424: return data
425:
1.235 abukhman 426: def getLemmaQuery(self, query=None, language=None):
1.2 casties 427: """simular words lemma """
1.235 abukhman 428: data = self.getServerData("lt/lemma.xql","language="+str(language)+"&query="+urllib.quote(query)+"&output=html")
429: return data
430:
431: def getLex(self, query=None, language=None):
432: #simular words lemma
433: data = self.getServerData("lt/lex.xql","document=&language="+str(language)+"&query="+urllib.quote(query))
1.2 casties 434: return data
1.28 abukhman 435:
1.237 abukhman 436: def getQuery (self, docinfo=None, pageinfo=None, query=None, queryType=None, pn=1):
1.222 abukhman 437: #number of
1.2 casties 438: docpath = docinfo['textURLPath']
439: pagesize = pageinfo['queryPageSize']
440: pn = pageinfo['searchPN']
1.34 abukhman 441: query =pageinfo['query']
1.2 casties 442: queryType =pageinfo['queryType']
443: tocSearch = 0
444: tocDiv = None
445:
1.32 abukhman 446: 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))
1.2 casties 447: pagedom = Parse(pagexml)
448: numdivs = pagedom.xpath("//div[@class='queryResultHits']")
449: tocSearch = int(getTextFromNode(numdivs[0]))
450: tc=int((tocSearch/10)+1)
451: return tc
1.222 abukhman 452:
1.2 casties 453: def getToc(self, mode="text", docinfo=None):
454: """loads table of contents and stores in docinfo"""
455: if mode == "none":
456: return docinfo
457: if 'tocSize_%s'%mode in docinfo:
458: # cached toc
459: return docinfo
460:
461: docpath = docinfo['textURLPath']
462: # we need to set a result set size
463: pagesize = 1000
464: pn = 1
465: if mode == "text":
466: queryType = "toc"
467: else:
468: queryType = mode
469: # number of entries in toc
470: tocSize = 0
471: tocDiv = None
472:
473: pagexml = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType, pagesize, pn))
1.222 abukhman 474:
1.2 casties 475: # post-processing downloaded xml
476: pagedom = Parse(pagexml)
477: # get number of entries
478: numdivs = pagedom.xpath("//div[@class='queryResultHits']")
479: if len(numdivs) > 0:
480: tocSize = int(getTextFromNode(numdivs[0]))
481: docinfo['tocSize_%s'%mode] = tocSize
482: return docinfo
483:
484: def getTocPage(self, mode="text", pn=1, pageinfo=None, docinfo=None):
485: """returns single page from the table of contents"""
486: # TODO: this should use the cached TOC
487: if mode == "text":
488: queryType = "toc"
489: else:
490: queryType = mode
491: docpath = docinfo['textURLPath']
492: path = docinfo['textURLPath']
493: pagesize = pageinfo['tocPageSize']
494: pn = pageinfo['tocPN']
495: url = docinfo['url']
496: selfurl = self.absolute_url()
497: viewMode= pageinfo['viewMode']
1.26 abukhman 498: characterNormalization = pageinfo ['characterNormalization']
1.237 abukhman 499: #optionToggle =pageinfo ['optionToggle']
1.2 casties 500: tocMode = pageinfo['tocMode']
501: tocPN = pageinfo['tocPN']
502:
1.237 abukhman 503: data = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s&characterNormalization=regPlusNorm"%(docpath,queryType, pagesize, pn))
504: page = data.replace('page-fragment.xql?document=%s'%str(path),'%s?url=%s&viewMode=%s&tocMode=%s&tocPN=%s'%(selfurl,url, viewMode, tocMode, tocPN))
1.2 casties 505: text = page.replace('mode=image','mode=texttool')
506: return text
507:
1.234 abukhman 508: def manage_changeMpdlXmlTextServer(self,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None):
509: #def manage_changeMpdlXmlTextServer(self,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de:30030/mpdl/interface/",timeout=40,RESPONSE=None):
1.2 casties 510: """change settings"""
511: self.title=title
512: self.timeout = timeout
513: self.serverUrl = serverUrl
514: if RESPONSE is not None:
515: RESPONSE.redirect('manage_main')
516:
517: # management methods
518: def manage_addMpdlXmlTextServerForm(self):
519: """Form for adding"""
520: pt = PageTemplateFile("zpt/manage_addMpdlXmlTextServer", globals()).__of__(self)
521: return pt()
522:
1.234 abukhman 523: def manage_addMpdlXmlTextServer(self,id,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None):
524: #def manage_addMpdlXmlTextServer(self,id,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de:30030/mpdl/interface/",timeout=40,RESPONSE=None):
1.2 casties 525: """add zogiimage"""
526: newObj = MpdlXmlTextServer(id,title,serverUrl,timeout)
527: self.Destination()._setObject(id, newObj)
528: if RESPONSE is not None:
1.224 abukhman 529: RESPONSE.redirect('manage_main')
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>