maryjess / exSpent

A one-stop Finance app.
1 stars 0 forks source link

API (Application Programming Interface) #18

Open maryjess opened 3 weeks ago

maryjess commented 3 weeks ago

NLTK

import nltk
import re

# Sample receipt text
text = """
    Walmart
    Date: 01/09/2024
    Milk: $3.00
    Bread: $2.50
    Eggs: $1.75
    Total: $7.25
"""

# Tokenize text
tokens = nltk.word_tokenize(text)

# Use regex to find items and prices
pattern = re.compile(r'([A-Za-z]+):\s\$(\d+\.\d{2})')
matches = pattern.findall(text)

# Extract data
items = [{'item': match[0], 'price': float(match[1])} for match in matches]
print(items)

Choices:

Resolves #4

maryjess commented 6 days ago

How?