comparison documentViewer.py @ 59:996b61d71351

added all fields from bib tag to docinfo
author casties
date Fri, 08 Jun 2007 20:10:22 +0200
parents 7cdb0fc34a92
children f3d2f240692c
comparison
equal deleted inserted replaced
58:cc1d3d22ca72 59:996b61d71351
307 return docinfo 307 return docinfo
308 308
309 309
310 def getBibinfoFromIndexMeta(self,path,docinfo=None,dom=None): 310 def getBibinfoFromIndexMeta(self,path,docinfo=None,dom=None):
311 """gets bibliographical info from the index.meta file at path or given by dom""" 311 """gets bibliographical info from the index.meta file at path or given by dom"""
312 logger("documentViewer (getbibinfofromindexmeta)", logging.INFO,"path: %s"%(path)) 312 logging.debug("documentViewer (getbibinfofromindexmeta) path: %s"%(path))
313 313
314 if docinfo is None: 314 if docinfo is None:
315 docinfo = {} 315 docinfo = {}
316 316
317 if dom is None: 317 if dom is None:
318 dom = self.getIndexMeta(getParentDir(path)) 318 dom = self.getIndexMeta(getParentDir(path))
319 319
320 # put in all raw bib fields as dict "bib"
321 bib = dom.xpath("//bib/*")
322 if bib and len(bib)>0:
323 bibinfo = {}
324 for e in bib:
325 bibinfo[e.localName] = getTextFromNode(e)
326 docinfo['bib'] = bibinfo
327
328 # extract some fields (author, title, year) according to their mapping
320 metaData=self.metadata.main.meta.bib 329 metaData=self.metadata.main.meta.bib
321 bibtype=dom.xpath("//bib/@type") 330 bibtype=dom.xpath("//bib/@type")
322 if bibtype and (len(bibtype)>0): 331 if bibtype and (len(bibtype)>0):
323 bibtype=bibtype[0].value 332 bibtype=bibtype[0].value
324 else: 333 else:
325 bibtype="generic" 334 bibtype="generic"
335
326 bibtype=bibtype.replace("-"," ") # wrong typesiin index meta "-" instead of " " (not wrong! ROC) 336 bibtype=bibtype.replace("-"," ") # wrong typesiin index meta "-" instead of " " (not wrong! ROC)
337 docinfo['bib_type'] = bibtype
327 bibmap=metaData.generateMappingForType(bibtype) 338 bibmap=metaData.generateMappingForType(bibtype)
328 #print "bibmap: ", bibmap, " for: ", bibtype
329 # if there is no mapping bibmap is empty (mapping sometimes has empty fields) 339 # if there is no mapping bibmap is empty (mapping sometimes has empty fields)
330 if len(bibmap) > 0 and len(bibmap['author'][0]) > 0: 340 if len(bibmap) > 0 and len(bibmap['author'][0]) > 0:
331 docinfo['author']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['author'][0])[0]) 341 docinfo['author']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['author'][0])[0])
332 docinfo['title']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['title'][0])[0]) 342 docinfo['title']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['title'][0])[0])
333 docinfo['year']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['year'][0])[0]) 343 docinfo['year']=getTextFromNode(dom.xpath("//bib/%s"%bibmap['year'][0])[0])
334 344 logging.debug("documentViewer (getbibinfofromindexmeta) using mapping for %s"%bibtype)
335 logging.info("bla")
336 try: 345 try:
337 docinfo['lang']=getTextFromNode(dom.xpath("//bib/lang")[0]) 346 docinfo['lang']=getTextFromNode(dom.xpath("//bib/lang")[0])
338 except: 347 except:
339 docinfo['lang']='' 348 docinfo['lang']=''
349
340 return docinfo 350 return docinfo
341 351
342 352
343 def getDocinfoFromTextTool(self,url,dom=None,docinfo=None): 353 def getDocinfoFromTextTool(self,url,dom=None,docinfo=None):
344 """parse texttool tag in index meta""" 354 """parse texttool tag in index meta"""