| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- .. Copyright (C) 2001-2020 NLTK Project
- .. For license information, see LICENSE.TXT
- ========================================================
- Unit tests for nltk.treeprettyprinter.TreePrettyPrinter
- ========================================================
- >>> from nltk.tree import Tree
- >>> from nltk.treeprettyprinter import TreePrettyPrinter
- Tree nr 2170 from nltk.corpus.treebank:
- >>> tree = Tree.fromstring(
- ... '(S (NP-SBJ (PRP I)) (VP (VBP feel) (ADJP-PRD (RB pretty) '
- ... '(JJ good)) (PP-CLR (IN about) (NP (PRP it)))) (. .))')
- >>> tpp = TreePrettyPrinter(tree)
- >>> print(tpp.text())
- S
- __________________________|_____________________
- | VP |
- | ____________________|___________ |
- | | | PP-CLR |
- | | | _____|_____ |
- NP-SBJ | ADJP-PRD | NP |
- | | _______|______ | | |
- PRP VBP RB JJ IN PRP .
- | | | | | | |
- I feel pretty good about it .
- >>> print(tpp.text(unicodelines=True))
- S
- ┌──────────────────────────┼─────────────────────┐
- │ VP │
- │ ┌─────────────┬──────┴───────────┐ │
- │ │ │ PP-CLR │
- │ │ │ ┌─────┴─────┐ │
- NP-SBJ │ ADJP-PRD │ NP │
- │ │ ┌───────┴──────┐ │ │ │
- PRP VBP RB JJ IN PRP .
- │ │ │ │ │ │ │
- I feel pretty good about it .
- A tree with long labels:
- >>> tree = Tree.fromstring(
- ... '(sentence (plural-noun-phrase (plural-noun Superconductors)) '
- ... '(verb-phrase (plural-verb conduct) '
- ... '(noun-phrase (singular-noun electricity))))')
- >>> tpp = TreePrettyPrinter(tree)
- >>> print(tpp.text(abbreviate=8, nodedist=2))
- sentence
- __________|__________
- | verb-phr.
- | __________|__________
- plural-n. | noun-phr.
- | | |
- plural-n. plural-v. singular.
- | | |
- Supercon. conduct electric.
- >>> print(tpp.text(maxwidth=8, nodedist=2))
- sentence
- _________|________
- | verb-
- | phrase
- | ________|_________
- plural- | noun-
- noun- | phrase
- phrase | |
- | | |
- plural- plural- singular-
- noun verb noun
- | | |
- Supercon conduct electric
- ductors ity
- A discontinuous tree:
- >>> tree = Tree.fromstring(
- ... '(top (punct 8) (smain (noun 0) (verb 1) (inf (verb 5) (inf (verb 6) '
- ... '(conj (inf (pp (prep 2) (np (det 3) (noun 4))) (verb 7)) (inf (verb 9)) '
- ... '(vg 10) (inf (verb 11)))))) (punct 12))', read_leaf=int)
- >>> sentence = ('Ze had met haar moeder kunnen gaan winkelen ,'
- ... ' zwemmen of terrassen .'.split())
- >>> tpp = TreePrettyPrinter(tree, sentence)
- >>> print(tpp.text())
- top
- _____|______________________________________________
- smain | |
- _______________________________|_____ | |
- | | inf | |
- | | _____|____ | |
- | | | inf | |
- | | | ____|_____ | |
- | | | | conj | |
- | | _____ | ___ | _________|______ | __________________ |
- | | inf | | | | | | |
- | | _________|_____ | ___ | _________ | | | | |
- | | pp | | | | | | | |
- | | ____|____ | | | | | | | |
- | | | np | | | | inf | inf |
- | | | ____|____ | | | | | | | |
- noun verb prep det noun verb verb verb punct verb vg verb punct
- | | | | | | | | | | | | |
- Ze had met haar moeder kunnen gaan winkelen , zwemmen of terrassen .
- >>> print(tpp.text(unicodelines=True))
- top
- ┌─────┴──────────────────┬───────────────────────────┐
- smain │ │
- ┌────┬──────────────────────────┴─────┐ │ │
- │ │ inf │ │
- │ │ ┌─────┴────┐ │ │
- │ │ │ inf │ │
- │ │ │ ┌────┴─────┐ │ │
- │ │ │ │ conj │ │
- │ │ ┌───── │ ─── │ ─────────┴────── │ ─────┬─────┬──────┐ │
- │ │ inf │ │ │ │ │ │ │
- │ │ ┌─────────┴───── │ ─── │ ─────────┐ │ │ │ │ │
- │ │ pp │ │ │ │ │ │ │ │
- │ │ ┌────┴────┐ │ │ │ │ │ │ │ │
- │ │ │ np │ │ │ │ inf │ inf │
- │ │ │ ┌────┴────┐ │ │ │ │ │ │ │ │
- noun verb prep det noun verb verb verb punct verb vg verb punct
- │ │ │ │ │ │ │ │ │ │ │ │ │
- Ze had met haar moeder kunnen gaan winkelen , zwemmen of terrassen .
|