Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AI4Finance Foundation FinGPT Split Sentence

From Leeroopedia
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

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']

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment