Exemple #1
0
	def findCitations(self):
		"""Returns a list of tuples ``(citation, range)`` where ``citation`` is a :class:`bBase.citation`
		object, and ``range`` is a range returned by a :mod:`bTextProcessor` implementation.
		
		Unlike natbib, the two commands ``\\citealt`` and ``\\citealt`` both produce the same result and
		are mapped on the 'i' citation type (see :attr:`citation.type` in :mod:`bBase`).
		
		The use of ``\\citetalias`` and ``\\citepalias`` is not supported.
		"""
		
		ls = self.textProcessor.findRegexp(self.cite)
		citations = list()
		for c in ls:
			txt, span, grps = c
			
			cite = bBase.citation()
			
			cite.cite_ref = [x.strip() for x in grps[4].split(',')]
			
			if grps[1]=='':
				if grps[2]=='t' or grps[2]=='p':
					cite.type = grps[2]
			else:
				cite.type = 'i'
			
			if grps[0].isupper():
				cite.type = cite.type.capitalize()
			
			if grps[3]=='*':
				cite.type += '*'
			
			cite.search = {'search_type': 'ref'}
			
			citations.append((cite, span))
		
		ls = self.textProcessor.findRegexp(self.citeauthor)
		for c in ls:
			txt, span, grps = c
			
			cite = bBase.citation()
			
			cite.cite_ref = [x.strip() for x in grps[4].split(',')]
			cite.type = 'a'
			
			if grps[0].isupper():
				cite.type = cite.type.capitalize()
			
			if grps[3]=='*':
				cite.type += '*'
			
			cite.search = {'search_type': 'ref'}
			
			citations.append((cite, span))
		
		ls = self.textProcessor.findRegexp(self.citeyear)
		for c in ls:
			txt, span, grps = c
			
			cite = bBase.citation()
			
			cite.cite_ref = [x.strip() for x in grps[4].split(',')]
			cite.type = 'y'
			
			cite.search = {'search_type': 'ref'}
			
			citations.append((cite, span))
		
		return citations
Exemple #2
0
	def findCitations(self):
		"""Search for citations in plain text. For each candidate, defines a search string and
		tries to guess the type of citation.
		
		Returns a list of ``(citation, range)`` where ``citation`` is a :class:`bBase.citation` object and
		``range`` is tuple of cursor indices.
		"""
		
		ls = self.textProcessor.findRegexp(self.reCitation)
		
		# For each citation candidate, determine the type, authors and year
		citations = list()
		for c in ls:
			txt, span, grps = c
			
			cite = bBase.citation()
			
			cite.text = bBase.text(txt)
			
			# Type
			if txt.startswith('(') and txt.endswith(')'):
				type = 'p'
				if len(txt.split(','))-1>1:
					type += '*'
			else:
				if txt.find('(')!=-1 and txt.find(')')!=-1:
					type = 't'
					if len(txt.split(','))-1>0:
						type += '*'
				else:
					type = 'i'
					if len(txt.split(','))-1>1:
						type += '*'
			txt = txt.strip('()')
			
			for x in ['Van', 'De', 'Von', 'Del', 'Della']:
				if txt.startswith(x+' '):
					type = type.capitalize()
			
			# Search string
			cite.search = dict()
			cite.search['search_type'] = 'string'
			
			m = reDateI.search(txt)
			year = m.group(0)
			m = reDate.search(txt)
			txt = txt.replace(m.group(0), '')
			
			for x in '()':
				txt = txt.replace(x, '')
			txt = txt.strip(',. ')
			
			if txt.endswith('et al'):
				txt = txt.replace('et al', '')
				cite.etal = True
			txt = txt.strip(',. ')
			
			txt = txt.replace(' and ', ', ')
			txt = txt.replace(' & ', ', ')
			txt = txt.replace(', , ', ', ')
			
			cite.search['search_string'] = txt+", "+year
			
			citations.append((cite, span))
		
		return citations