Files
MoFin/venv/lib/python3.12/site-packages/nltk/help.py
T
知微 fa45d8aa5f fix: 小果地址统一node122(兼容LAN+EasyTier)
- health_checklist.json: 192.168.1.122→node122
- ocr_client.py: docstring IP→node122
- docs/market-data-requirements.md: IP→node122
- 所有API调用通过ProxyHandler({})绕过系统代理
  Privoxy对node122:18003返回500,直连正常
2026-06-30 02:56:35 +08:00

69 lines
1.7 KiB
Python

# Natural Language Toolkit (NLTK) Help
#
# Copyright (C) 2001-2026 NLTK Project
# Authors: Steven Bird <stevenbird1@gmail.com>
# URL: <https://www.nltk.org/>
# For license information, see LICENSE.TXT
"""
Provide structured access to documentation.
"""
import json
import re
from textwrap import wrap
from nltk.data import find, open_datafile
def brown_tagset(tagpattern=None):
_format_tagset("brown_tagset", tagpattern)
def claws5_tagset(tagpattern=None):
_format_tagset("claws5_tagset", tagpattern)
def upenn_tagset(tagpattern=None):
_format_tagset("upenn_tagset", tagpattern)
#####################################################################
# UTILITIES
#####################################################################
def _print_entries(tags, tagdict):
for tag in tags:
entry = tagdict[tag]
defn = [tag + ": " + entry[0]]
examples = wrap(
entry[1], width=75, initial_indent=" ", subsequent_indent=" "
)
print("\n".join(defn + examples))
def _format_tagset(tagset, tagpattern=None):
# Load tagset from json file.
with open_datafile(find("help/tagsets_json/PY3_json/"), f"{tagset}.json") as fin:
tagdict = json.load(fin)
if not tagpattern:
_print_entries(sorted(tagdict), tagdict)
elif tagpattern in tagdict:
_print_entries([tagpattern], tagdict)
else:
tagpattern = re.compile(tagpattern)
tags = [tag for tag in sorted(tagdict) if tagpattern.match(tag)]
if tags:
_print_entries(tags, tagdict)
else:
print("No matching tags found.")
if __name__ == "__main__":
brown_tagset(r"NN.*")
upenn_tagset(r".*\$")
claws5_tagset("UNDEFINED")
brown_tagset(r"NN")