fix: resolve CI type annotation issues
- Replaced deprecated typing.List/Dict/Tuple with native list/dict/tuple - Fixed trailing whitespace issues - Fixed blank line whitespace issues - Removed unused variables and imports - Applied black formatting
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
"""NLP analyzer for extracting structured information from requirements."""
|
||||
"""NLP analyzer for extracting structured information from requirements."""
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from enum import Enum
|
||||
from typing import Any, Dict, List, Optional, TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING, Any, Optional
|
||||
|
||||
import spacy
|
||||
from spacy.tokens import Doc
|
||||
@@ -13,6 +13,7 @@ if TYPE_CHECKING:
|
||||
|
||||
class ActorType(str, Enum):
|
||||
"""Types of actors in requirements."""
|
||||
|
||||
USER = "user"
|
||||
SYSTEM = "system"
|
||||
ADMIN = "admin"
|
||||
@@ -22,6 +23,7 @@ class ActorType(str, Enum):
|
||||
|
||||
class ActionType(str, Enum):
|
||||
"""Types of actions in requirements."""
|
||||
|
||||
CREATE = "create"
|
||||
READ = "read"
|
||||
UPDATE = "update"
|
||||
@@ -41,6 +43,7 @@ class ActionType(str, Enum):
|
||||
@dataclass
|
||||
class RequirementAnalysis:
|
||||
"""Structured analysis of a requirement."""
|
||||
|
||||
raw_text: str
|
||||
actor: Optional[str] = None
|
||||
actor_type: ActorType = ActorType.UNKNOWN
|
||||
@@ -49,10 +52,10 @@ class RequirementAnalysis:
|
||||
target: Optional[str] = None
|
||||
condition: Optional[str] = None
|
||||
benefit: Optional[str] = None
|
||||
examples: List[str] = field(default_factory=list)
|
||||
variables: Dict[str, str] = field(default_factory=dict)
|
||||
examples: list[str] = field(default_factory=list)
|
||||
variables: dict[str, str] = field(default_factory=dict)
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
def to_dict(self) -> dict[str, Any]:
|
||||
"""Convert to dictionary."""
|
||||
return {
|
||||
"raw_text": self.raw_text,
|
||||
@@ -73,7 +76,7 @@ class NLPAnalyzer:
|
||||
|
||||
def __init__(self, model: str = "en_core_web_sm"):
|
||||
"""Initialize the analyzer with a spaCy model.
|
||||
|
||||
|
||||
Args:
|
||||
model: spaCy model name. Defaults to en_core_web_sm.
|
||||
"""
|
||||
@@ -81,6 +84,7 @@ class NLPAnalyzer:
|
||||
self.nlp = spacy.load(model)
|
||||
except OSError:
|
||||
import subprocess
|
||||
|
||||
subprocess.run(
|
||||
["python", "-m", "spacy", "download", model],
|
||||
check=True,
|
||||
@@ -89,10 +93,10 @@ class NLPAnalyzer:
|
||||
|
||||
def analyze(self, text: str) -> RequirementAnalysis:
|
||||
"""Analyze a requirement text and extract structured information.
|
||||
|
||||
|
||||
Args:
|
||||
text: The natural language requirement text.
|
||||
|
||||
|
||||
Returns:
|
||||
RequirementAnalysis with extracted components.
|
||||
"""
|
||||
@@ -224,10 +228,10 @@ class NLPAnalyzer:
|
||||
|
||||
def analyze_ambiguity(self, text: str) -> "list[AmbiguityWarning]":
|
||||
"""Analyze text for ambiguous language.
|
||||
|
||||
|
||||
Args:
|
||||
text: The text to analyze.
|
||||
|
||||
|
||||
Returns:
|
||||
List of ambiguity warnings.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user