textstats-demo-student 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- textstats_demo_student-1.0.0/LICENSE +21 -0
- textstats_demo_student-1.0.0/PKG-INFO +51 -0
- textstats_demo_student-1.0.0/README.md +36 -0
- textstats_demo_student-1.0.0/pyproject.toml +23 -0
- textstats_demo_student-1.0.0/setup.cfg +4 -0
- textstats_demo_student-1.0.0/src/textstats/__init__.py +31 -0
- textstats_demo_student-1.0.0/src/textstats/core.py +84 -0
- textstats_demo_student-1.0.0/src/textstats_demo_student.egg-info/PKG-INFO +51 -0
- textstats_demo_student-1.0.0/src/textstats_demo_student.egg-info/SOURCES.txt +9 -0
- textstats_demo_student-1.0.0/src/textstats_demo_student.egg-info/dependency_links.txt +1 -0
- textstats_demo_student-1.0.0/src/textstats_demo_student.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Student
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: textstats-demo-student
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A lightweight English text statistics analysis package
|
|
5
|
+
Author: Student
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: text,statistics,nlp,demo
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# textstats-demo-student
|
|
17
|
+
|
|
18
|
+
A lightweight English text statistics analysis package.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install textstats-demo-student
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from textstats import text_summary, word_count, is_palindrome
|
|
30
|
+
|
|
31
|
+
print(word_count("Hello world, hello Python!")) # 4
|
|
32
|
+
print(is_palindrome("A man, a plan, a canal: Panama")) # True
|
|
33
|
+
print(text_summary("Python is fun. Python is easy!"))
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Functions
|
|
37
|
+
|
|
38
|
+
- `word_count(text)` - count English words
|
|
39
|
+
- `char_count(text)` - count characters
|
|
40
|
+
- `char_frequency(text)` - character frequency dict
|
|
41
|
+
- `sentence_count(text)` - count sentences
|
|
42
|
+
- `top_words(text, n)` - top-n frequent words
|
|
43
|
+
- `is_palindrome(text)` - palindrome check
|
|
44
|
+
- `reverse_text(text)` - reverse a string
|
|
45
|
+
- `avg_word_length(text)` - average word length
|
|
46
|
+
- `longest_word(text)` - the longest word
|
|
47
|
+
- `text_summary(text)` - full statistics summary
|
|
48
|
+
|
|
49
|
+
## License
|
|
50
|
+
|
|
51
|
+
MIT
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# textstats-demo-student
|
|
2
|
+
|
|
3
|
+
A lightweight English text statistics analysis package.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install textstats-demo-student
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from textstats import text_summary, word_count, is_palindrome
|
|
15
|
+
|
|
16
|
+
print(word_count("Hello world, hello Python!")) # 4
|
|
17
|
+
print(is_palindrome("A man, a plan, a canal: Panama")) # True
|
|
18
|
+
print(text_summary("Python is fun. Python is easy!"))
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Functions
|
|
22
|
+
|
|
23
|
+
- `word_count(text)` - count English words
|
|
24
|
+
- `char_count(text)` - count characters
|
|
25
|
+
- `char_frequency(text)` - character frequency dict
|
|
26
|
+
- `sentence_count(text)` - count sentences
|
|
27
|
+
- `top_words(text, n)` - top-n frequent words
|
|
28
|
+
- `is_palindrome(text)` - palindrome check
|
|
29
|
+
- `reverse_text(text)` - reverse a string
|
|
30
|
+
- `avg_word_length(text)` - average word length
|
|
31
|
+
- `longest_word(text)` - the longest word
|
|
32
|
+
- `text_summary(text)` - full statistics summary
|
|
33
|
+
|
|
34
|
+
## License
|
|
35
|
+
|
|
36
|
+
MIT
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "textstats-demo-student"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "A lightweight English text statistics analysis package"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Student" },
|
|
14
|
+
]
|
|
15
|
+
keywords = ["text", "statistics", "nlp", "demo"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
[tool.setuptools.packages.find]
|
|
23
|
+
where = ["src"]
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""textstats - 一个轻量级的英文文本统计分析包"""
|
|
3
|
+
|
|
4
|
+
__version__ = "1.0.0"
|
|
5
|
+
__author__ = "Student"
|
|
6
|
+
|
|
7
|
+
from .core import (
|
|
8
|
+
word_count,
|
|
9
|
+
char_count,
|
|
10
|
+
char_frequency,
|
|
11
|
+
sentence_count,
|
|
12
|
+
top_words,
|
|
13
|
+
is_palindrome,
|
|
14
|
+
reverse_text,
|
|
15
|
+
avg_word_length,
|
|
16
|
+
longest_word,
|
|
17
|
+
text_summary,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"word_count",
|
|
22
|
+
"char_count",
|
|
23
|
+
"char_frequency",
|
|
24
|
+
"sentence_count",
|
|
25
|
+
"top_words",
|
|
26
|
+
"is_palindrome",
|
|
27
|
+
"reverse_text",
|
|
28
|
+
"avg_word_length",
|
|
29
|
+
"longest_word",
|
|
30
|
+
"text_summary",
|
|
31
|
+
]
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""textstats.core - 文本统计分析的核心实现"""
|
|
3
|
+
|
|
4
|
+
import re
|
|
5
|
+
from collections import Counter
|
|
6
|
+
|
|
7
|
+
_WORD_RE = re.compile(r"[A-Za-z]+(?:'[A-Za-z]+)?")
|
|
8
|
+
_SENT_RE = re.compile(r"[.!?]+")
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def word_count(text):
|
|
12
|
+
"""统计文本中的英文单词总数"""
|
|
13
|
+
return len(_WORD_RE.findall(text))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def char_count(text, ignore_spaces=True):
|
|
17
|
+
"""统计字符数,ignore_spaces 为 True 时不计空格"""
|
|
18
|
+
if ignore_spaces:
|
|
19
|
+
return len(text.replace(" ", ""))
|
|
20
|
+
return len(text)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def char_frequency(text):
|
|
24
|
+
"""返回字符串中每个字符出现的次数(不区分大小写,忽略空格)"""
|
|
25
|
+
counter = Counter(text.lower().replace(" ", ""))
|
|
26
|
+
return dict(counter)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def sentence_count(text):
|
|
30
|
+
"""按 . ! ? 统计句子数量"""
|
|
31
|
+
parts = [p for p in _SENT_RE.split(text) if p.strip()]
|
|
32
|
+
return len(parts)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def top_words(text, n=5, stop_words=None):
|
|
36
|
+
"""返回出现频率最高的 n 个单词及次数
|
|
37
|
+
|
|
38
|
+
stop_words 为停用词列表,其中的单词不参与统计。
|
|
39
|
+
"""
|
|
40
|
+
if stop_words is None:
|
|
41
|
+
stop_words = []
|
|
42
|
+
stop = {w.lower() for w in stop_words}
|
|
43
|
+
words = [w.lower() for w in _WORD_RE.findall(text) if w.lower() not in stop]
|
|
44
|
+
return Counter(words).most_common(n)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def is_palindrome(text):
|
|
48
|
+
"""判断文本是否为回文(忽略大小写与非字母数字字符)"""
|
|
49
|
+
cleaned = re.sub(r"[^A-Za-z0-9]", "", text).lower()
|
|
50
|
+
return cleaned == cleaned[::-1] and len(cleaned) > 0
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def reverse_text(text):
|
|
54
|
+
"""将文本反转"""
|
|
55
|
+
return text[::-1]
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def avg_word_length(text):
|
|
59
|
+
"""计算单词的平均长度,保留两位小数"""
|
|
60
|
+
words = _WORD_RE.findall(text)
|
|
61
|
+
if not words:
|
|
62
|
+
return 0.0
|
|
63
|
+
return round(sum(len(w) for w in words) / len(words), 2)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def longest_word(text):
|
|
67
|
+
"""返回文本中最长的单词(相同长度取先出现的)"""
|
|
68
|
+
words = _WORD_RE.findall(text)
|
|
69
|
+
if not words:
|
|
70
|
+
return ""
|
|
71
|
+
return max(words, key=len)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def text_summary(text, top_n=3):
|
|
75
|
+
"""生成文本的综合统计摘要"""
|
|
76
|
+
return {
|
|
77
|
+
"words": word_count(text),
|
|
78
|
+
"chars": char_count(text),
|
|
79
|
+
"sentences": sentence_count(text),
|
|
80
|
+
"avg_word_length": avg_word_length(text),
|
|
81
|
+
"longest_word": longest_word(text),
|
|
82
|
+
"top_words": top_words(text, top_n, ["the", "a", "an", "of", "to", "and"]),
|
|
83
|
+
"is_palindrome": is_palindrome(text),
|
|
84
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: textstats-demo-student
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A lightweight English text statistics analysis package
|
|
5
|
+
Author: Student
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: text,statistics,nlp,demo
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# textstats-demo-student
|
|
17
|
+
|
|
18
|
+
A lightweight English text statistics analysis package.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install textstats-demo-student
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from textstats import text_summary, word_count, is_palindrome
|
|
30
|
+
|
|
31
|
+
print(word_count("Hello world, hello Python!")) # 4
|
|
32
|
+
print(is_palindrome("A man, a plan, a canal: Panama")) # True
|
|
33
|
+
print(text_summary("Python is fun. Python is easy!"))
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Functions
|
|
37
|
+
|
|
38
|
+
- `word_count(text)` - count English words
|
|
39
|
+
- `char_count(text)` - count characters
|
|
40
|
+
- `char_frequency(text)` - character frequency dict
|
|
41
|
+
- `sentence_count(text)` - count sentences
|
|
42
|
+
- `top_words(text, n)` - top-n frequent words
|
|
43
|
+
- `is_palindrome(text)` - palindrome check
|
|
44
|
+
- `reverse_text(text)` - reverse a string
|
|
45
|
+
- `avg_word_length(text)` - average word length
|
|
46
|
+
- `longest_word(text)` - the longest word
|
|
47
|
+
- `text_summary(text)` - full statistics summary
|
|
48
|
+
|
|
49
|
+
## License
|
|
50
|
+
|
|
51
|
+
MIT
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/textstats/__init__.py
|
|
5
|
+
src/textstats/core.py
|
|
6
|
+
src/textstats_demo_student.egg-info/PKG-INFO
|
|
7
|
+
src/textstats_demo_student.egg-info/SOURCES.txt
|
|
8
|
+
src/textstats_demo_student.egg-info/dependency_links.txt
|
|
9
|
+
src/textstats_demo_student.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
textstats
|