| Server IP : 54.37.205.81 / Your IP : 216.73.216.76 Web Server : nginx/1.22.1 System : Linux vps-249481fa 6.1.0-50-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.176-1 (2026-07-02) x86_64 User : debian ( 1000) PHP Version : 8.2.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /usr/lib/python3/dist-packages/nltk/test/ |
Upload File : |
.. Copyright (C) 2001-2022 NLTK Project
.. For license information, see LICENSE.TXT
=================
Utility functions
=================
>>> from nltk.util import *
>>> from nltk.tree import Tree
>>> print_string("This is a long string, therefore it should break", 25)
This is a long string,
therefore it should break
>>> re_show("[a-z]+", "sdf123")
{sdf}123
>>> tree = Tree(5,
... [Tree(4, [Tree(2, [1, 3])]),
... Tree(8, [Tree(6, [7]), 9])])
>>> for x in breadth_first(tree):
... if isinstance(x, int): print(x)
... else: print(x.label())
5
4
8
2
6
9
1
3
7
>>> for x in breadth_first(tree, maxdepth=2):
... if isinstance(x, int): print(x)
... else: print(x.label())
5
4
8
2
6
9
>>> invert_dict({1: 2})
defaultdict(<... 'list'>, {2: 1})
>>> invert_dict({1: [3, 4, 5]})
defaultdict(<... 'list'>, {3: [1], 4: [1], 5: [1]})