Annotation of documentViewer/MpdlXmlTextServer.py, revision 1.242
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.242 ! abukhman 201: xpointer = pageinfo['xpointer']
1.20 abukhman 202: characterNormalization=pageinfo['characterNormalization']
1.2 casties 203: tocPN = pageinfo['tocPN']
204: selfurl = self.absolute_url()
205: if mode == "text_dict":
206: textmode = "textPollux"
207: else:
208: textmode = mode
1.222 abukhman 209:
1.242 ! abukhman 210: textParam = "document=%s&mode=%s&pn=%s&characterNormalization=%s&options=withXmlNodeId&xpointer=%s"%(docpath,textmode,pn,characterNormalization, xpointer)
1.190 abukhman 211: if highlightQuery is not None:
1.241 abukhman 212: #textParam +="&highlightQuery=%s&sn=%s"%(urllib.quote(highlightQuery),sn)
213: textParam +="&highlightQuery=%s&s=%s&highlightElement=%s&highlightElementPos=%s"%(urllib.quote(highlightQuery),s, highlightElement, highlightElementPos)
1.222 abukhman 214:
1.38 abukhman 215: pagexml = self.getServerData("page-fragment.xql",textParam)
1.222 abukhman 216: dom = Parse(pagexml)
1.238 abukhman 217: #dom = NonvalidatingReader.parseStream(pagexml)
1.236 abukhman 218:
1.222 abukhman 219: #original Pages
1.233 abukhman 220: pagedivs = dom.xpath("//div[@class='pageNumberOrig']")
1.236 abukhman 221:
1.230 abukhman 222: """if pagedivs == dom.xpath("//div[@class='pageNumberOrig']"):
1.222 abukhman 223: if len(pagedivs)>0:
224: docinfo['pageNumberOrig']= getTextFromNode(pagedivs[0])
1.230 abukhman 225: logging.debug("ORIGINAL PAGE: %s"%(docinfo['pageNumberOrig']))
1.226 abukhman 226:
227: #original Pages Norm
228: pagedivs = dom.xpath("//div[@class='pageNumberOrigNorm']")
229: if pagedivs == dom.xpath("//div[@class='pageNumberOrigNorm']"):
230: if len(pagedivs)>0:
231: docinfo['pageNumberOrigNorm']= getTextFromNode(pagedivs[0])
1.230 abukhman 232: logging.debug("ORIGINAL PAGE NORM: %s"%(docinfo['pageNumberOrigNorm']))
233: """
1.222 abukhman 234: #figureEntries
235: pagedivs = dom.xpath("//div[@class='countFigureEntries']")
236: if pagedivs == dom.xpath("//div[@class='countFigureEntries']"):
237: if len(pagedivs)>0:
238: docinfo['countFigureEntries'] = getTextFromNode(pagedivs[0])
239: s = getTextFromNode(pagedivs[0])
240: if s=='0':
241: try:
242: docinfo['countFigureEntries'] = int(s)
243: except:
244: docinfo['countFigureEntries'] = 0
245: else:
246: s1 = int(s)/30+1
247: try:
248: docinfo['countFigureEntries'] = int(s1)
249: except:
250: docinfo['countFigureEntries'] = 0
251:
252: #allPlaces
253: pagedivs = dom.xpath("//div[@class='countPlaces']")
254: if pagedivs == dom.xpath("//div[@class='countPlaces']"):
255: if len(pagedivs)>0:
256: docinfo['countPlaces']= getTextFromNode(pagedivs[0])
257: s = getTextFromNode(pagedivs[0])
258: try:
259: docinfo['countPlaces'] = int(s)
260: except:
261: docinfo['countPlaces'] = 0
262:
263: #tocEntries
264: pagedivs = dom.xpath("//div[@class='countTocEntries']")
265: if pagedivs == dom.xpath("//div[@class='countTocEntries']"):
266: if len(pagedivs)>0:
267: docinfo['countTocEntries'] = int(getTextFromNode(pagedivs[0]))
268: s = getTextFromNode(pagedivs[0])
269: if s=='0':
270: try:
271: docinfo['countTocEntries'] = int(s)
272: except:
273: docinfo['countTocEntries'] = 0
274: else:
275: s1 = int(s)/30+1
276: try:
277: docinfo['countTocEntries'] = int(s1)
278: except:
279: docinfo['countTocEntries'] = 0
280:
281: #numTextPages
282: pagedivs = dom.xpath("//div[@class='countPages']")
283: if pagedivs == dom.xpath("//div[@class='countPages']"):
284: if len(pagedivs)>0:
285: docinfo['numPages'] = getTextFromNode(pagedivs[0])
286: s = getTextFromNode(pagedivs[0])
287:
288: try:
289: docinfo['numPages'] = int(s)
1.228 abukhman 290: #logging.debug("PAGE NUMBER: %s"%(s))
1.222 abukhman 291:
292: np = docinfo['numPages']
293: pageinfo['end'] = min(pageinfo['end'], np)
294: pageinfo['numgroups'] = int(np / pageinfo['groupsize'])
295: if np % pageinfo['groupsize'] > 0:
296: pageinfo['numgroups'] += 1
297: except:
298: docinfo['numPages'] = 0
299:
300: else:
301: #no full text -- init to 0
302: docinfo['pageNumberOrig'] = 0
303: docinfo['countFigureEntries'] = 0
304: docinfo['countPlaces'] = 0
305: docinfo['countTocEntries'] = 0
306: docinfo['numPages'] = 0
1.226 abukhman 307: docinfo['pageNumberOrigNorm'] = 0
1.222 abukhman 308: #return docinfo
1.2 casties 309:
310: # plain text mode
311: if mode == "text":
312: # first div contains text
1.222 abukhman 313: pagedivs = dom.xpath("/div")
1.2 casties 314: if len(pagedivs) > 0:
315: pagenode = pagedivs[0]
316: links = pagenode.xpath("//a")
317: for l in links:
318: hrefNode = l.getAttributeNodeNS(None, u"href")
319: if hrefNode:
320: href= hrefNode.nodeValue
321: if href.startswith('#note-'):
1.227 abukhman 322: hrefNode.nodeValue = href.replace('#note-',"?url=%s&viewMode=text&tocMode=%s&tocPN=%s&pn=%s#note-"%(url,tocMode,tocPN,pn))
1.242 ! abukhman 323: #if href.startswith():
1.2 casties 324: return serializeNode(pagenode)
325: if mode == "xml":
326: # first div contains text
1.222 abukhman 327: pagedivs = dom.xpath("/div")
1.2 casties 328: if len(pagedivs) > 0:
329: pagenode = pagedivs[0]
330: return serializeNode(pagenode)
1.7 abukhman 331: if mode == "gis":
332: # first div contains text
1.222 abukhman 333: pagedivs = dom.xpath("/div")
1.7 abukhman 334: if len(pagedivs) > 0:
335: pagenode = pagedivs[0]
1.28 abukhman 336: links =pagenode.xpath("//a")
337: for l in links:
338: hrefNode =l.getAttributeNodeNS(None, u"href")
339: if hrefNode:
340: href=hrefNode.nodeValue
341: if href.startswith('http://chinagis.mpiwg-berlin.mpg.de'):
1.75 abukhman 342: hrefNode.nodeValue =href.replace('chinagis_REST/REST/db/chgis/mpdl','chinagis/REST/db/mpdl/%s'%name)
1.62 abukhman 343: l.setAttributeNS(None, 'target', '_blank')
1.61 abukhman 344: return serializeNode(pagenode)
1.7 abukhman 345:
1.2 casties 346: if mode == "pureXml":
347: # first div contains text
1.222 abukhman 348: pagedivs = dom.xpath("/div")
1.2 casties 349: if len(pagedivs) > 0:
350: pagenode = pagedivs[0]
351: return serializeNode(pagenode)
352: # text-with-links mode
353: if mode == "text_dict":
354: # first div contains text
1.227 abukhman 355: #mode = pageinfo ['viewMode']
1.222 abukhman 356: pagedivs = dom.xpath("/div")
1.2 casties 357: if len(pagedivs) > 0:
358: pagenode = pagedivs[0]
359: # check all a-tags
360: links = pagenode.xpath("//a")
1.236 abukhman 361:
1.2 casties 362: for l in links:
363: hrefNode = l.getAttributeNodeNS(None, u"href")
1.236 abukhman 364:
1.2 casties 365: if hrefNode:
366: # is link with href
367: href = hrefNode.nodeValue
1.241 abukhman 368: if href.startswith('http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/interface/lt/wordInfo.xql'):
1.2 casties 369: # is pollux link
370: selfurl = self.absolute_url()
371: # change href
1.241 abukhman 372: hrefNode.nodeValue = href.replace('http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/interface/lt/wordInfo.xql','%s/head_main_voc'%selfurl)
1.2 casties 373: # add target
374: l.setAttributeNS(None, 'target', '_blank')
1.238 abukhman 375: #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;")
376: #l.setAttributeNS(None, "ondblclick", "popupWin.focus();")
377: #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 378:
1.241 abukhman 379: if href.startswith('http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/lt/lemma.xql'):
1.2 casties 380: selfurl = self.absolute_url()
1.241 abukhman 381: hrefNode.nodeValue = href.replace('http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/lt/lemma.xql','%s/head_main_lemma'%selfurl)
1.2 casties 382: l.setAttributeNS(None, 'target', '_blank')
1.239 abukhman 383: 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 384: l.setAttributeNS(None, 'ondblclick', 'popupWin.focus();')
385:
1.2 casties 386: if href.startswith('#note-'):
1.236 abukhman 387: hrefNode.nodeValue = href.replace('#note-',"?url=%s&viewMode=text_dict&tocMode=%s&tocPN=%s&pn=%s#note-"%(url,tocMode,tocPN,pn))
388:
1.2 casties 389: return serializeNode(pagenode)
390: return "no text here"
1.225 abukhman 391:
1.230 abukhman 392: def getOrigPages(self, docinfo=None, pageinfo=None):
393: docpath = docinfo['textURLPath']
394: pn =pageinfo['current']
395: selfurl = self.absolute_url()
396: pagexml = self.getServerData("page-fragment.xql","document=%s&pn=%s"%(docpath, pn))
397: dom = Parse(pagexml)
398: pagedivs = dom.xpath("//div[@class='pageNumberOrig']")
399: if pagedivs == dom.xpath("//div[@class='pageNumberOrig']"):
400: if len(pagedivs)>0:
401: docinfo['pageNumberOrig']= getTextFromNode(pagedivs[0])
402: return docinfo['pageNumberOrig']
403:
404: def getOrigPagesNorm(self, docinfo=None, pageinfo=None):
405: docpath = docinfo['textURLPath']
406: pn =pageinfo['current']
407: selfurl = self.absolute_url()
408: pagexml = self.getServerData("page-fragment.xql","document=%s&pn=%s"%(docpath, pn))
409: dom = Parse(pagexml)
410: pagedivs = dom.xpath("//div[@class='pageNumberOrigNorm']")
411: if pagedivs == dom.xpath("//div[@class='pageNumberOrigNorm']"):
412: if len(pagedivs)>0:
413: docinfo['pageNumberOrigNorm']= getTextFromNode(pagedivs[0])
414: return docinfo['pageNumberOrigNorm']
415:
416:
1.240 abukhman 417: def getTranslate(self, word=None, language=None, display=None):
1.2 casties 418: """translate into another languages"""
1.239 abukhman 419: data = self.getServerData("lt/wordInfo.xql","language="+str(language)+"&word="+urllib.quote(word)+"&display="+urllib.quote(display)+"&output=html")
1.2 casties 420: #pagexml=self.template.fulltextclient.eval("/mpdl/interface/lt/lex.xql","document=&language="+str(language)+"&query="+url_quote(str(query)))
421: return data
422:
423: def getLemma(self, lemma=None, language=None):
424: """simular words lemma """
1.235 abukhman 425: data = self.getServerData("lt/lemma.xql","language="+str(language)+"&lemma="+urllib.quote(lemma)+"&output=html")
1.2 casties 426: return data
427:
1.235 abukhman 428: def getLemmaQuery(self, query=None, language=None):
1.2 casties 429: """simular words lemma """
1.235 abukhman 430: data = self.getServerData("lt/lemma.xql","language="+str(language)+"&query="+urllib.quote(query)+"&output=html")
431: return data
432:
433: def getLex(self, query=None, language=None):
434: #simular words lemma
435: data = self.getServerData("lt/lex.xql","document=&language="+str(language)+"&query="+urllib.quote(query))
1.2 casties 436: return data
1.28 abukhman 437:
1.237 abukhman 438: def getQuery (self, docinfo=None, pageinfo=None, query=None, queryType=None, pn=1):
1.222 abukhman 439: #number of
1.2 casties 440: docpath = docinfo['textURLPath']
441: pagesize = pageinfo['queryPageSize']
442: pn = pageinfo['searchPN']
1.34 abukhman 443: query =pageinfo['query']
1.2 casties 444: queryType =pageinfo['queryType']
445: tocSearch = 0
446: tocDiv = None
447:
1.32 abukhman 448: 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 449: pagedom = Parse(pagexml)
450: numdivs = pagedom.xpath("//div[@class='queryResultHits']")
451: tocSearch = int(getTextFromNode(numdivs[0]))
452: tc=int((tocSearch/10)+1)
453: return tc
1.222 abukhman 454:
1.2 casties 455: def getToc(self, mode="text", docinfo=None):
456: """loads table of contents and stores in docinfo"""
457: if mode == "none":
458: return docinfo
459: if 'tocSize_%s'%mode in docinfo:
460: # cached toc
461: return docinfo
462:
463: docpath = docinfo['textURLPath']
464: # we need to set a result set size
465: pagesize = 1000
466: pn = 1
467: if mode == "text":
468: queryType = "toc"
469: else:
470: queryType = mode
471: # number of entries in toc
472: tocSize = 0
473: tocDiv = None
474:
475: pagexml = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s"%(docpath,queryType, pagesize, pn))
1.222 abukhman 476:
1.2 casties 477: # post-processing downloaded xml
478: pagedom = Parse(pagexml)
479: # get number of entries
480: numdivs = pagedom.xpath("//div[@class='queryResultHits']")
481: if len(numdivs) > 0:
482: tocSize = int(getTextFromNode(numdivs[0]))
483: docinfo['tocSize_%s'%mode] = tocSize
484: return docinfo
485:
486: def getTocPage(self, mode="text", pn=1, pageinfo=None, docinfo=None):
487: """returns single page from the table of contents"""
488: # TODO: this should use the cached TOC
489: if mode == "text":
490: queryType = "toc"
491: else:
492: queryType = mode
493: docpath = docinfo['textURLPath']
494: path = docinfo['textURLPath']
495: pagesize = pageinfo['tocPageSize']
496: pn = pageinfo['tocPN']
497: url = docinfo['url']
498: selfurl = self.absolute_url()
499: viewMode= pageinfo['viewMode']
1.26 abukhman 500: characterNormalization = pageinfo ['characterNormalization']
1.237 abukhman 501: #optionToggle =pageinfo ['optionToggle']
1.2 casties 502: tocMode = pageinfo['tocMode']
503: tocPN = pageinfo['tocPN']
504:
1.237 abukhman 505: data = self.getServerData("doc-query.xql","document=%s&queryType=%s&queryResultPageSize=%s&queryResultPN=%s&characterNormalization=regPlusNorm"%(docpath,queryType, pagesize, pn))
506: 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 507: text = page.replace('mode=image','mode=texttool')
508: return text
509:
1.234 abukhman 510: def manage_changeMpdlXmlTextServer(self,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None):
511: #def manage_changeMpdlXmlTextServer(self,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de:30030/mpdl/interface/",timeout=40,RESPONSE=None):
1.2 casties 512: """change settings"""
513: self.title=title
514: self.timeout = timeout
515: self.serverUrl = serverUrl
516: if RESPONSE is not None:
517: RESPONSE.redirect('manage_main')
518:
519: # management methods
520: def manage_addMpdlXmlTextServerForm(self):
521: """Form for adding"""
522: pt = PageTemplateFile("zpt/manage_addMpdlXmlTextServer", globals()).__of__(self)
523: return pt()
524:
1.234 abukhman 525: def manage_addMpdlXmlTextServer(self,id,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de/mpdl/interface/",timeout=40,RESPONSE=None):
526: #def manage_addMpdlXmlTextServer(self,id,title="",serverUrl="http://mpdl-text.mpiwg-berlin.mpg.de:30030/mpdl/interface/",timeout=40,RESPONSE=None):
1.2 casties 527: """add zogiimage"""
528: newObj = MpdlXmlTextServer(id,title,serverUrl,timeout)
529: self.Destination()._setObject(id, newObj)
530: if RESPONSE is not None:
1.224 abukhman 531: RESPONSE.redirect('manage_main')
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>