Implementation:AI4Finance Foundation FinGPT Split Sentence
| Knowledge Sources | |
|---|---|
| Domains | NLP, Text_Processing, RAG |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
Concrete tool for splitting financial news sentences into ticker symbols, clean text, and resolved URLs provided by the FinGPT RAG multisource_retrieval subproject.
Description
The split_sentence module parses a sentence to extract: (1) stock ticker symbols prefixed with `$`, (2) the remaining clean text with URLs and formatting removed, and (3) the last HTTP URL resolved to its final redirected domain. It uses regex and HTTP HEAD redirects.
Usage
Import `split_sentence` when you need to extract structured information (tickers, URLs, clean text) from financial social media posts or news headlines for RAG preprocessing.
Code Reference
Source Location
- Repository: AI4Finance_Foundation_FinGPT
- File: fingpt/FinGPT_RAG/multisource_retrieval/sentence_processing/split_sentence.py
- Lines: 1-58
Signature
def get_redirected_domain(url) -> str | None:
"""Follow HTTP redirects and return the final URL."""
def split_sentence(sentence) -> tuple:
"""Split a sentence into ticker symbols, clean text, and resolved URL.
Args:
sentence: raw text (e.g., a tweet or news headline)
Returns:
(ticker: list[str], remaining_sentence: str, url: list[str])
"""
Import
from split_sentence import split_sentence
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| sentence | str | Yes | Raw text containing tickers, URLs, and content |
Outputs
| Name | Type | Description |
|---|---|---|
| ticker | list[str] | Stock ticker symbols (without $ prefix) |
| remaining_sentence | str | Clean text without tickers/URLs |
| url | list[str] | Resolved redirect URL(s) |
Usage Examples
Parse a Financial Tweet
from split_sentence import split_sentence
sentence = "$AAPL hitting new highs after earnings http://short.link/abc123"
ticker, text, url = split_sentence(sentence)
print(f"Ticker: {ticker}") # -> ['AAPL']
print(f"Text: {text}") # -> "hitting new highs after earnings"
print(f"URL: {url}") # -> ['https://final-redirected-url.com']