예제 #1
0
 def test_node_encoding(self):
     '''
     Test that tgrep search strings handles bytes and strs the same
     way.
     '''
     tree = ParentedTree.fromstring('(S (NP (DT the) (JJ big) (NN dog)) '
                                    '(VP bit) (NP (DT a) (NN cat)))')
     self.assertEqual(list(tgrep.tgrep_positions(b('NN'), [tree])),
                      list(tgrep.tgrep_positions('NN', [tree])))
     self.assertEqual(list(tgrep.tgrep_nodes(b('NN'), [tree])),
                      list(tgrep.tgrep_nodes('NN', [tree])))
     self.assertEqual(list(tgrep.tgrep_positions(b('NN|JJ'), [tree])),
                      list(tgrep.tgrep_positions('NN|JJ', [tree])))
예제 #2
0
파일: test_tgrep.py 프로젝트: DrDub/nltk
 def test_node_encoding(self):
     '''
     Test that tgrep search strings handles bytes and strs the same
     way.
     '''
     tree = ParentedTree.fromstring(
         '(S (NP (DT the) (JJ big) (NN dog)) '
         '(VP bit) (NP (DT a) (NN cat)))')
     self.assertEqual(list(tgrep.tgrep_positions(b('NN'), [tree])),
                      list(tgrep.tgrep_positions('NN', [tree])))
     self.assertEqual(list(tgrep.tgrep_nodes(b('NN'), [tree])),
                      list(tgrep.tgrep_nodes('NN', [tree])))
     self.assertEqual(list(tgrep.tgrep_positions(b('NN|JJ'), [tree])),
                      list(tgrep.tgrep_positions('NN|JJ', [tree])))
예제 #3
0
 def test_tokenize_encoding(self):
     '''
     Test that tokenization handles bytes and strs the same way.
     '''
     self.assertEqual(
         tgrep.tgrep_tokenize(b('A .. (B !< C . D) | ![<< (E , F) $ G]')),
         tgrep.tgrep_tokenize('A .. (B !< C . D) | ![<< (E , F) $ G]'))
예제 #4
0
파일: test_tgrep.py 프로젝트: DrDub/nltk
 def test_tokenize_encoding(self):
     '''
     Test that tokenization handles bytes and strs the same way.
     '''
     self.assertEqual(
         tgrep.tgrep_tokenize(b('A .. (B !< C . D) | ![<< (E , F) $ G]')),
         tgrep.tgrep_tokenize('A .. (B !< C . D) | ![<< (E , F) $ G]'))
예제 #5
0
    def __init__(self, term_stream=sys.stdout):
        # If the stream isn't a tty, then assume it has no capabilities.
        if not term_stream.isatty(): return
        if self.FORCE_SIMPLE_TERM: return

        # Curses isn't available on all platforms
        try:
            import curses
        except:
            # If it's not available, then try faking enough to get a
            # simple progress bar.
            self.BOL = '\r'
            self.CLEAR_LINE = '\r' + ' ' * self.COLS + '\r'

        # Check the terminal type.  If we fail, then assume that the
        # terminal has no capabilities.
        try:
            curses.setupterm()
        except:
            return

        # Look up numeric capabilities.
        self.COLS = curses.tigetnum('cols')

        # Look up string capabilities.
        for capability in self._STRING_CAPABILITIES:
            (attrib, cap_name) = capability.split('=')
            s = self._tigetstr(cap_name) or ''
            if isinstance(s, bytes): s = s.decode('utf-8')
            setattr(self, attrib, s)
        if self.BOL and self.CLEAR_EOL:
            self.CLEAR_LINE = self.BOL + self.CLEAR_EOL

        # Colors
        set_fg = self._tigetstr('setf')
        if set_fg:
            for i, color in enumerate(self._COLORS):
                s = curses.tparm(b(set_fg), i) or ''
                if isinstance(s, bytes): s = s.decode('utf-8')
                setattr(self, color, s)
        set_fg_ansi = self._tigetstr('setaf')
        if set_fg_ansi:
            for i, color in enumerate(self._ANSICOLORS):
                s = curses.tparm(b(set_fg_ansi), i) or ''
                if isinstance(s, bytes): s = s.decode('utf-8')
                setattr(self, color, s)
예제 #6
0
    def __init__(self, term_stream=sys.stdout):
        # If the stream isn't a tty, then assume it has no capabilities.
        if not term_stream.isatty(): return
        if self.FORCE_SIMPLE_TERM: return

        # Curses isn't available on all platforms
        try: import curses
        except:
            # If it's not available, then try faking enough to get a
            # simple progress bar.
            self.BOL = '\r'
            self.CLEAR_LINE = '\r' + ' '*self.COLS + '\r'

        # Check the terminal type.  If we fail, then assume that the
        # terminal has no capabilities.
        try: curses.setupterm()
        except: return

        # Look up numeric capabilities.
        self.COLS = curses.tigetnum('cols')

        # Look up string capabilities.
        for capability in self._STRING_CAPABILITIES:
            (attrib, cap_name) = capability.split('=')
            s = self._tigetstr(cap_name) or ''
            if isinstance(s, bytes): s = s.decode('utf-8')
            setattr(self, attrib, s)
        if self.BOL and self.CLEAR_EOL:
            self.CLEAR_LINE = self.BOL+self.CLEAR_EOL

        # Colors
        set_fg = self._tigetstr('setf')
        if set_fg:
            for i,color in enumerate(self._COLORS):
                s = curses.tparm(b(set_fg), i) or ''
                if isinstance(s, bytes): s = s.decode('utf-8')
                setattr(self, color, s)
        set_fg_ansi = self._tigetstr('setaf')
        if set_fg_ansi:
            for i,color in enumerate(self._ANSICOLORS):
                s = curses.tparm(b(set_fg_ansi), i) or ''
                if isinstance(s, bytes): s = s.decode('utf-8')
                setattr(self, color, s)