swarmauri_tool_sentencecomplexity 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_sentencecomplexity-0.6.0.dev154/PKG-INFO +20 -0
- swarmauri_tool_sentencecomplexity-0.6.0.dev154/README.md +1 -0
- swarmauri_tool_sentencecomplexity-0.6.0.dev154/pyproject.toml +57 -0
- swarmauri_tool_sentencecomplexity-0.6.0.dev154/swarmauri_tool_sentencecomplexity/SentenceComplexityTool.py +84 -0
- swarmauri_tool_sentencecomplexity-0.6.0.dev154/swarmauri_tool_sentencecomplexity/__init__.py +16 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: swarmauri_tool_sentencecomplexity
|
|
3
|
+
Version: 0.6.0.dev154
|
|
4
|
+
Summary: This repository includes an example of a First Class Swarmauri Example.
|
|
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
|
+
Project-URL: Repository, http://github.com/swarmauri/swarmauri-sdk
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# Swarmauri Example Community Package
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Swarmauri Example Community Package
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "swarmauri_tool_sentencecomplexity"
|
|
3
|
+
version = "0.6.0.dev154"
|
|
4
|
+
description = "This repository includes an example of a First Class Swarmauri Example."
|
|
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
|
+
nltk = "^3.9.1"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
[tool.poetry.group.dev.dependencies]
|
|
28
|
+
flake8 = "^7.0"
|
|
29
|
+
pytest = "^8.0"
|
|
30
|
+
pytest-asyncio = ">=0.24.0"
|
|
31
|
+
pytest-xdist = "^3.6.1"
|
|
32
|
+
pytest-json-report = "^1.5.0"
|
|
33
|
+
python-dotenv = "*"
|
|
34
|
+
requests = "^2.32.3"
|
|
35
|
+
|
|
36
|
+
[build-system]
|
|
37
|
+
requires = ["poetry-core>=1.0.0"]
|
|
38
|
+
build-backend = "poetry.core.masonry.api"
|
|
39
|
+
|
|
40
|
+
[tool.pytest.ini_options]
|
|
41
|
+
norecursedirs = ["combined", "scripts"]
|
|
42
|
+
|
|
43
|
+
markers = [
|
|
44
|
+
"test: standard test",
|
|
45
|
+
"unit: Unit tests",
|
|
46
|
+
"integration: Integration tests",
|
|
47
|
+
"acceptance: Acceptance tests",
|
|
48
|
+
"experimental: Experimental tests"
|
|
49
|
+
]
|
|
50
|
+
log_cli = true
|
|
51
|
+
log_cli_level = "INFO"
|
|
52
|
+
log_cli_format = "%(asctime)s [%(levelname)s] %(message)s"
|
|
53
|
+
log_cli_date_format = "%Y-%m-%d %H:%M:%S"
|
|
54
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
55
|
+
|
|
56
|
+
[tool.poetry.plugins."swarmauri.tools"]
|
|
57
|
+
SentenceComplexityTool = "swarmauri_tool_sentencecomplexity.SentenceComplexityTool:SentenceComplexityTool"
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
from typing import List, Literal, Dict
|
|
2
|
+
import nltk
|
|
3
|
+
from nltk.tokenize import sent_tokenize, word_tokenize
|
|
4
|
+
from pkgs.core.swarmauri_core import ComponentBase
|
|
5
|
+
from pydantic import Field
|
|
6
|
+
from swarmauri_base.tools.ToolBase import ToolBase
|
|
7
|
+
from swarmauri_standard.tools.Parameter import Parameter
|
|
8
|
+
|
|
9
|
+
# Download required NLTK data once during module load
|
|
10
|
+
|
|
11
|
+
nltk.download("punkt_tab", quiet=True)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@ComponentBase.register_type(ToolBase, "SentenceComplexityTool")
|
|
15
|
+
class SentenceComplexityTool(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 to analyze for sentence complexity.",
|
|
23
|
+
required=True,
|
|
24
|
+
)
|
|
25
|
+
]
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
name: str = "SentenceComplexityTool"
|
|
29
|
+
description: str = (
|
|
30
|
+
"Evaluates sentence complexity based on average sentence length and the number of clauses."
|
|
31
|
+
)
|
|
32
|
+
type: Literal["SentenceComplexityTool"] = "SentenceComplexityTool"
|
|
33
|
+
|
|
34
|
+
def __call__(self, text: str) -> Dict[str, float]:
|
|
35
|
+
"""
|
|
36
|
+
Evaluate sentence complexity based on average sentence length and the number of clauses.
|
|
37
|
+
|
|
38
|
+
Parameters:
|
|
39
|
+
- text (str): The text to analyze.
|
|
40
|
+
|
|
41
|
+
Returns:
|
|
42
|
+
- dict: A dictionary containing average sentence length and average number of clauses per sentence.
|
|
43
|
+
"""
|
|
44
|
+
if not text.strip():
|
|
45
|
+
raise ValueError("Input text cannot be empty.")
|
|
46
|
+
|
|
47
|
+
sentences = sent_tokenize(text)
|
|
48
|
+
num_sentences = len(sentences)
|
|
49
|
+
|
|
50
|
+
if num_sentences == 0:
|
|
51
|
+
return {"average_sentence_length": 0.0, "average_clauses_per_sentence": 0.0}
|
|
52
|
+
|
|
53
|
+
total_words = 0
|
|
54
|
+
total_clauses = 0
|
|
55
|
+
|
|
56
|
+
for sentence in sentences:
|
|
57
|
+
words = word_tokenize(sentence)
|
|
58
|
+
total_words += len(words)
|
|
59
|
+
|
|
60
|
+
# Improved clause counting method
|
|
61
|
+
|
|
62
|
+
clauses = sentence.count(",") + sentence.count(";")
|
|
63
|
+
clauses += sum(
|
|
64
|
+
sentence.lower().count(conj)
|
|
65
|
+
for conj in [
|
|
66
|
+
"and",
|
|
67
|
+
"but",
|
|
68
|
+
"or",
|
|
69
|
+
"because",
|
|
70
|
+
"although",
|
|
71
|
+
"though",
|
|
72
|
+
"while",
|
|
73
|
+
"if",
|
|
74
|
+
]
|
|
75
|
+
)
|
|
76
|
+
total_clauses += clauses + 1
|
|
77
|
+
|
|
78
|
+
avg_sentence_length = total_words / num_sentences
|
|
79
|
+
avg_clauses_per_sentence = total_clauses / num_sentences
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
"average_sentence_length": avg_sentence_length,
|
|
83
|
+
"average_clauses_per_sentence": avg_clauses_per_sentence,
|
|
84
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from .SentenceComplexityTool import SentenceComplexityTool
|
|
2
|
+
|
|
3
|
+
__version__ = "0.6.0.dev26"
|
|
4
|
+
__long_desc__ = """
|
|
5
|
+
|
|
6
|
+
# Swarmauri SentenceComplexity Plugin
|
|
7
|
+
|
|
8
|
+
This repository includes a SentenceComplexity 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
|
+
"""
|
|
15
|
+
|
|
16
|
+
|