Files
task-3-2-1-Text-Processing-…/yzz.py
2026-04-23 16:04:42 +08:00

45 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import subprocess
subprocess.run(['pip', 'install', 'jieba', '-q'])
print("jieba安装完成")
import jieba
print("=" * 50)
print("jieba分词演示")
print("=" * 50)
text = "我喜欢深度学习和人工智能"
print(f"原文: {text}")
print()
# 精确模式(默认)
words精确 = list(jieba.cut(text, cut_all=False))
print(f"精确模式: {' / '.join(words精确)}")
# 全模式
words全 = list(jieba.cut(text, cut_all=True))
print(f"全模式: {' / '.join(words全)}")
# 搜索引擎模式
words搜索 = list(jieba.cut_for_search(text))
print(f"搜索模式: {' / '.join(words搜索)}")
import jieba
print("=" * 50)
print("更多分词示例")
print("=" * 50)
examples = [
"今天天气真不错",
"人工智能是未来的发展方向",
"Python是一门非常流行的编程语言",
"小明毕业于清华大学计算机系",
"我今天在京东买了一部iPhone手机"
]
for i, text in enumerate(examples):
words = list(jieba.cut(text))
print(f"{i+1}. {text}")
print(f"{' / '.join(words)}")
print()