def testFindLiterals(self): textTags = hrefliterals.extractTextInfo( self.document, self.exclude_re, '') literals = {'word':None, 'W.O.R.D.2.':None} literalTags = hrefliterals.findLiterals( textTags['f'], literals, {}, self.words, self.stemmer, 0) self.assertEqual(len(literalTags), 3) self.assertEqual(literalTags[0], hrefliterals.TextTag( hrefliterals.TextTag.Type.LITERAL, 29, 34, 'word')) self.assertEqual(literalTags[1], hrefliterals.TextTag( hrefliterals.TextTag.Type.LITERAL, 37, 42, 'W.O.R.D.2.')) self.assertEqual(literalTags[2], hrefliterals.TextTag( hrefliterals.TextTag.Type.LITERAL, 43, 72, 'word'))
def testReplaceTags(self): textTags = hrefliterals.extractTextInfo( self.document, self.exclude_re, '') literals = {'word':None, 'W.O.R.D.2.':None} literalTags = hrefliterals.findLiterals( textTags['f'], literals, {}, self.words, self.stemmer, 0) literalTags[0].value = '*' literalTags[1].value = '**' literalTags[2].value = '***' replaced = hrefliterals.replaceLiterals(self.source, literalTags) rsource = r""" \begin{document}* 1 ** *** \begin{equation}word\end{equation} \end{document} """ self.assertEqual(replaced, rsource)
def testReplaceTags(self): textTags = hrefliterals.extractTextInfo(self.document, self.exclude_re, '') literals = {'word': None, 'W.O.R.D.2.': None} literalTags = hrefliterals.findLiterals(textTags['f'], literals, {}, self.words, self.stemmer, 0) literalTags[0].value = '*' literalTags[1].value = '**' literalTags[2].value = '***' replaced = hrefliterals.replaceLiterals(self.source, literalTags) rsource = r""" \begin{document}* 1 ** *** \begin{equation}word\end{equation} \end{document} """ self.assertEqual(replaced, rsource)
def testFindLiterals(self): textTags = hrefliterals.extractTextInfo(self.document, self.exclude_re, '') literals = {'word': None, 'W.O.R.D.2.': None} literalTags = hrefliterals.findLiterals(textTags['f'], literals, {}, self.words, self.stemmer, 0) self.assertEqual(len(literalTags), 3) self.assertEqual( literalTags[0], hrefliterals.TextTag(hrefliterals.TextTag.Type.LITERAL, 29, 34, 'word')) self.assertEqual( literalTags[1], hrefliterals.TextTag(hrefliterals.TextTag.Type.LITERAL, 37, 42, 'W.O.R.D.2.')) self.assertEqual( literalTags[2], hrefliterals.TextTag(hrefliterals.TextTag.Type.LITERAL, 43, 72, 'word'))
def findLiterals(self, source, literals, notLiterals): document = hrefliterals.parseDocument('f', StringIO.StringIO(source), os.getcwd()) textTags = hrefliterals.extractTextInfo(document, self.exclude_re, '') return hrefliterals.findLiterals(textTags['f'], literals, notLiterals, self.words, self.stemmer, 0)