swarmauri_tool_lexicaldensity 0.6.0.dev154__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.
- swarmauri_tool_lexicaldensity-0.6.0.dev154/PKG-INFO +21 -0
- swarmauri_tool_lexicaldensity-0.6.0.dev154/README.md +1 -0
- swarmauri_tool_lexicaldensity-0.6.0.dev154/pyproject.toml +58 -0
- swarmauri_tool_lexicaldensity-0.6.0.dev154/swarmauri_tool_lexicaldensity/LexicalDensityTool.py +103 -0
- swarmauri_tool_lexicaldensity-0.6.0.dev154/swarmauri_tool_lexicaldensity/__init__.py +14 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: swarmauri_tool_lexicaldensity
|
|
3
|
+
Version: 0.6.0.dev154
|
|
4
|
+
Summary: Lexical Density Tool for Swarmauri.
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Author: Jacob Stewart
|
|
7
|
+
Author-email: jacob@swarmauri.com
|
|
8
|
+
Requires-Python: >=3.10,<3.13
|
|
9
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Requires-Dist: nltk (>=3.9.1,<4.0.0)
|
|
15
|
+
Requires-Dist: swarmauri_base (>=0.6.0.dev154,<0.7.0)
|
|
16
|
+
Requires-Dist: swarmauri_core (>=0.6.0.dev154,<0.7.0)
|
|
17
|
+
Requires-Dist: textstat (>=0.7.4,<0.8.0)
|
|
18
|
+
Project-URL: Repository, http://github.com/swarmauri/swarmauri-sdk
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# Swarmauri Example Community Package
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Swarmauri Example Community Package
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "swarmauri_tool_lexicaldensity"
|
|
3
|
+
version = "0.6.0.dev154"
|
|
4
|
+
description = "Lexical Density Tool for Swarmauri."
|
|
5
|
+
authors = ["Jacob Stewart <jacob@swarmauri.com>"]
|
|
6
|
+
license = "Apache-2.0"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
repository = "http://github.com/swarmauri/swarmauri-sdk"
|
|
9
|
+
classifiers = [
|
|
10
|
+
"License :: OSI Approved :: Apache Software License",
|
|
11
|
+
"Programming Language :: Python :: 3.10",
|
|
12
|
+
"Programming Language :: Python :: 3.11",
|
|
13
|
+
"Programming Language :: Python :: 3.12"
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[tool.poetry.dependencies]
|
|
17
|
+
python = ">=3.10,<3.13"
|
|
18
|
+
|
|
19
|
+
# Swarmauri
|
|
20
|
+
swarmauri_core = {version = "^0.6.0.dev154"}
|
|
21
|
+
swarmauri_base = {version = "^0.6.0.dev154"}
|
|
22
|
+
|
|
23
|
+
# Dependencies
|
|
24
|
+
textstat = "^0.7.4"
|
|
25
|
+
nltk = "^3.9.1"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
[tool.poetry.group.dev.dependencies]
|
|
29
|
+
flake8 = "^7.0"
|
|
30
|
+
pytest = "^8.0"
|
|
31
|
+
pytest-asyncio = ">=0.24.0"
|
|
32
|
+
pytest-xdist = "^3.6.1"
|
|
33
|
+
pytest-json-report = "^1.5.0"
|
|
34
|
+
python-dotenv = "*"
|
|
35
|
+
requests = "^2.32.3"
|
|
36
|
+
|
|
37
|
+
[build-system]
|
|
38
|
+
requires = ["poetry-core>=1.0.0"]
|
|
39
|
+
build-backend = "poetry.core.masonry.api"
|
|
40
|
+
|
|
41
|
+
[tool.pytest.ini_options]
|
|
42
|
+
norecursedirs = ["combined", "scripts"]
|
|
43
|
+
|
|
44
|
+
markers = [
|
|
45
|
+
"test: standard test",
|
|
46
|
+
"unit: Unit tests",
|
|
47
|
+
"integration: Integration tests",
|
|
48
|
+
"acceptance: Acceptance tests",
|
|
49
|
+
"experimental: Experimental tests"
|
|
50
|
+
]
|
|
51
|
+
log_cli = true
|
|
52
|
+
log_cli_level = "INFO"
|
|
53
|
+
log_cli_format = "%(asctime)s [%(levelname)s] %(message)s"
|
|
54
|
+
log_cli_date_format = "%Y-%m-%d %H:%M:%S"
|
|
55
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
56
|
+
|
|
57
|
+
[tool.poetry.plugins."swarmauri.tools"]
|
|
58
|
+
LexicalDensityTool = "swarmauri_tool_lexicaldensity.LexicalDensityTool:LexicalDensityTool"
|
swarmauri_tool_lexicaldensity-0.6.0.dev154/swarmauri_tool_lexicaldensity/LexicalDensityTool.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import nltk
|
|
2
|
+
from swarmauri_core.ComponentBase import ComponentBase
|
|
3
|
+
import textstat
|
|
4
|
+
from typing import List, Literal, Dict
|
|
5
|
+
from pydantic import Field
|
|
6
|
+
from swarmauri_base.tools.ToolBase import ToolBase
|
|
7
|
+
from swarmauri_standard.tools.Parameter import Parameter
|
|
8
|
+
|
|
9
|
+
# Download necessary NLTK resources
|
|
10
|
+
nltk.download("punkt_tab")
|
|
11
|
+
nltk.download("averaged_perceptron_tagger_eng")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@ComponentBase.register_type(ToolBase, "LexicalDensityTool")
|
|
15
|
+
class LexicalDensityTool(ToolBase):
|
|
16
|
+
version: str = "0.1.dev2"
|
|
17
|
+
parameters: List[Parameter] = Field(
|
|
18
|
+
default_factory=lambda: [
|
|
19
|
+
Parameter(
|
|
20
|
+
name="text",
|
|
21
|
+
type="string",
|
|
22
|
+
description="The text for which to calculate the Lexical Density.",
|
|
23
|
+
required=True,
|
|
24
|
+
)
|
|
25
|
+
]
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
name: str = "LexicalDensityTool"
|
|
29
|
+
description: str = (
|
|
30
|
+
"Calculates the lexical density of a text, indicating the proportion of lexical words."
|
|
31
|
+
)
|
|
32
|
+
type: Literal["LexicalDensityTool"] = "LexicalDensityTool"
|
|
33
|
+
|
|
34
|
+
def __call__(self, text: str) -> Dict[str, float]:
|
|
35
|
+
"""
|
|
36
|
+
Calculates the Lexical Density score for the given text.
|
|
37
|
+
|
|
38
|
+
Parameters:
|
|
39
|
+
- text (str): The text to analyze.
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
- Dict[str, float]: A dictionary containing the Lexical Density score.
|
|
43
|
+
"""
|
|
44
|
+
return {"lexical_density": self.calculate_lexical_density(text)}
|
|
45
|
+
|
|
46
|
+
def calculate_lexical_density(self, text: str) -> float:
|
|
47
|
+
"""
|
|
48
|
+
Calculates the Lexical Density score for the given text.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
text (str): The text to analyze.
|
|
52
|
+
|
|
53
|
+
Returns:
|
|
54
|
+
float: The Lexical Density score as a percentage.
|
|
55
|
+
"""
|
|
56
|
+
# Total number of words in the text
|
|
57
|
+
total_words = textstat.lexicon_count(text, removepunct=True)
|
|
58
|
+
|
|
59
|
+
# Total number of lexical words (content words)
|
|
60
|
+
lexical_words = self.count_lexical_words(text)
|
|
61
|
+
|
|
62
|
+
# Calculate lexical density
|
|
63
|
+
if total_words == 0:
|
|
64
|
+
return 0.0
|
|
65
|
+
|
|
66
|
+
lexical_density = (lexical_words / total_words) * 100
|
|
67
|
+
return lexical_density
|
|
68
|
+
|
|
69
|
+
def count_lexical_words(self, text: str) -> int:
|
|
70
|
+
"""
|
|
71
|
+
Counts the number of lexical words (nouns, verbs, adjectives, adverbs) in the text.
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
text (str): The text to analyze.
|
|
75
|
+
|
|
76
|
+
Returns:
|
|
77
|
+
int: The number of lexical words in the text.
|
|
78
|
+
"""
|
|
79
|
+
words = nltk.word_tokenize(text)
|
|
80
|
+
pos_tags = nltk.pos_tag(words)
|
|
81
|
+
|
|
82
|
+
# POS tags for lexical words (nouns, verbs, adjectives, adverbs)
|
|
83
|
+
lexical_pos_tags = {
|
|
84
|
+
"NN",
|
|
85
|
+
"NNS",
|
|
86
|
+
"NNP",
|
|
87
|
+
"NNPS",
|
|
88
|
+
"VB",
|
|
89
|
+
"VBD",
|
|
90
|
+
"VBG",
|
|
91
|
+
"VBN",
|
|
92
|
+
"VBP",
|
|
93
|
+
"VBZ",
|
|
94
|
+
"JJ",
|
|
95
|
+
"JJR",
|
|
96
|
+
"JJS",
|
|
97
|
+
"RB",
|
|
98
|
+
"RBR",
|
|
99
|
+
"RBS",
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
lexical_words = [word for word, pos in pos_tags if pos in lexical_pos_tags]
|
|
103
|
+
return len(lexical_words)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from .LexicalDensityTool import LexicalDensityTool
|
|
2
|
+
|
|
3
|
+
__version__ = "0.6.0.dev26"
|
|
4
|
+
__long_desc__ = """
|
|
5
|
+
|
|
6
|
+
# Swarmauri LexicalDensity Plugin
|
|
7
|
+
|
|
8
|
+
This repository includes a LexicalDensity of a Swarmauri Plugin.
|
|
9
|
+
|
|
10
|
+
Visit us at: https://swarmauri.com
|
|
11
|
+
Follow us at: https://github.com/swarmauri
|
|
12
|
+
Star us at: https://github.com/swarmauri/swarmauri-sdk
|
|
13
|
+
|
|
14
|
+
"""
|