Exemplo n.º 1
0
	def _do_patching(self, t_app, tau, tau1, covered_pos, grounded_only):
		(a,b) = tau
		t_app = t_app.split()

		if(any(a<=c<=b for c in covered_pos)):
			return None, None

		seg = ' '.join(t_app[a:b+1])
		seg_left = ' '.join(t_app[:a])
		seg_right = ' '.join(t_app[b+1:])

		if grounded_only:
			pe = PhraseExtractor(seg.lower(), tau1.lower())
			aligns = pe.find_alignments()
			if aligns == []:
				return None, None
			p = min(a[0] for a in aligns)
			q = max(a[0] for a in aligns)
			r = min(a[1] for a in aligns)
			s = max(a[1] for a in aligns)
			if p == q or r ==s or p != 0 or q != (b-a) or r != 0 or s != len(tau1.split())-1 :
				return None, None
		
		seg = tau1.split()
		
		pe = PhraseExtractor(' '.join(t_app[a:b+1]).lower(), tau1.lower())
		aligns = pe.find_alignments()
		
		tg_aligns = [x for (_, x) in aligns]
		cp = [a+i for i in range(len(seg)) if i not in tg_aligns]
		cp += covered_pos
		# print(cp)

		if seg_left != '':
			tau1 = tau1.lower()
		return (seg_left + ' ' + tau1 + ' ' + seg_right).strip(), cp