File size: 4,835 Bytes
9e0d3ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
"""
Component-based analysis of SEC filings
Identifies and analyzes key sections: Risk, Strategy, Financial Performance, Operations
"""

from typing import Dict, List


class ComponentAnalyzer:
    """
    Identifies and categorizes different components of SEC filings
    Each component has specific keywords for identification
    """

    def __init__(self):
        self.components = {
            "financial_performance": {
                "keywords": [
                    "revenue",
                    "net income",
                    "earnings",
                    "profit",
                    "loss",
                    "cash flow",
                    "operating income",
                    "EBITDA",
                    "gross margin",
                    "operating margin",
                    "financial results",
                    "fiscal year",
                    "quarter",
                    "YoY",
                    "year-over-year",
                ],
                "weight": 1.0,
            },
            "risk_factors": {
                "keywords": [
                    "risk",
                    "uncertainty",
                    "challenge",
                    "threat",
                    "adverse",
                    "volatile",
                    "fluctuation",
                    "litigation",
                    "regulatory",
                    "competition",
                    "competitive pressure",
                    "market condition",
                    "economic condition",
                    "material adverse effect",
                ],
                "weight": 1.2,  # Higher weight for risk analysis
            },
            "business_strategy": {
                "keywords": [
                    "strategy",
                    "strategic",
                    "initiative",
                    "growth",
                    "expansion",
                    "acquisition",
                    "partnership",
                    "innovation",
                    "competitive advantage",
                    "market opportunity",
                    "business model",
                    "long-term",
                    "investment",
                    "R&D",
                    "research and development",
                ],
                "weight": 1.0,
            },
            "operations": {
                "keywords": [
                    "operations",
                    "operational",
                    "production",
                    "capacity",
                    "efficiency",
                    "supply chain",
                    "customers",
                    "users",
                    "daily active users",
                    "engagement",
                    "platform",
                    "infrastructure",
                    "employee",
                    "workforce",
                ],
                "weight": 0.9,
            },
        }

    def identify_component(self, text: str) -> List[str]:
        """
        Identify which components a text snippet belongs to

        Args:
            text: Text snippet to analyze

        Returns:
            List of component names that match
        """
        text_lower = text.lower()
        matched_components = []

        for component_name, config in self.components.items():
            # Check if any keywords are present
            if any(keyword.lower() in text_lower for keyword in config["keywords"]):
                matched_components.append(component_name)

        return matched_components if matched_components else ["general"]

    def categorize_texts(self, texts: List[str]) -> Dict[str, List[str]]:
        """
        Categorize a list of text segments by component

        Args:
            texts: List of text segments

        Returns:
            Dictionary mapping component names to text lists
        """
        categorized = {component: [] for component in self.components.keys()}
        categorized["general"] = []

        for text in texts:
            components = self.identify_component(text)
            for component in components:
                categorized[component].append(text)

        # Remove empty categories
        return {k: v for k, v in categorized.items() if v}

    def get_component_weight(self, component_name: str) -> float:
        """Get the importance weight for a component"""
        return self.components.get(component_name, {}).get("weight", 1.0)

    def get_risk_keywords(self) -> List[str]:
        """Get all risk-related keywords for focused analysis"""
        return self.components["risk_factors"]["keywords"]

    def get_financial_keywords(self) -> List[str]:
        """Get all financial-related keywords"""
        return self.components["financial_performance"]["keywords"]