-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconstants.py
More file actions
101 lines (76 loc) · 2.84 KB
/
constants.py
File metadata and controls
101 lines (76 loc) · 2.84 KB
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
"""
Constants for the Discourses SDK.
This module defines API configuration values, endpoints, and enumerations
used throughout the SDK.
"""
from enum import Enum
# API Configuration
BASE_URL = "https://discourses.io/api/v1"
DEFAULT_TIMEOUT = 30 # seconds
# API Endpoints
ENDPOINTS = {
"analyze": "/analyze/era",
"compare_eras": "/analyze/compare-eras",
"batch": "/analyze/batch",
}
class Era(str, Enum):
"""
Financial language eras for sentiment analysis.
Each era captures distinct vocabulary and sentiment patterns
characteristic of that time period in financial markets.
Attributes:
PRIMITIVE: < 2016 - Historical filings, early Twitter, pre-social sentiment
- 5,557 tokens
- Traditional financial vocabulary
- Formal market language
RAMP: 2016-2019 - Fintech emergence, crypto adoption, algorithmic trading era
- 7,751 tokens
- Rise of fintech terminology
- Early crypto vocabulary
MEME: 2019-2023 - WSB, Reddit, meme stocks, retail revolution vernacular
- 9,822 tokens
- WSB culture and terminology
- Crypto/DeFi vocabulary
- Emoji-based sentiment (🚀, 💎, 🙌)
- "Diamond hands", "to the moon", "HODL"
PRESENT: > 2023 - Current analysis with aggregate of all eras
- 11,195 tokens
- Most comprehensive lexicon
- Hybrid vocabulary
Example:
>>> from discourses import Era
>>> client.analyze("Diamond hands!", era=Era.MEME)
"""
PRIMITIVE = "primitive"
RAMP = "ramp"
MEME = "meme"
PRESENT = "present"
def __str__(self) -> str:
return self.value
@classmethod
def all(cls) -> list:
"""Return list of all eras."""
return [era for era in cls]
@classmethod
def from_string(cls, value: str) -> "Era":
"""
Create Era from string value.
Args:
value: Era string (e.g., 'primitive', 'ramp', 'meme', 'present')
Returns:
Matching Era enum
Raises:
ValueError: If no matching era found
"""
value = value.lower().strip()
if value == "primitive":
return cls.PRIMITIVE
if value == "ramp":
return cls.RAMP
if value == "meme":
return cls.MEME
if value == "present":
return cls.PRESENT
raise ValueError(f"Unknown era: {value}. Valid eras: primitive, ramp, meme, present")
# Rate Limiting
RATE_LIMIT_REQUESTS = 100 # requests per minute (varies by plan)