555e282cc4
pi-agent-plugin checks / lint (push) Has been cancelled
pi-agent-plugin checks / test (20) (push) Has been cancelled
pi-agent-plugin checks / test (22) (push) Has been cancelled
pi-agent-plugin checks / build (push) Has been cancelled
TypeScript SDK CI / check_changes (push) Has been cancelled
TypeScript SDK CI / changelog_check (push) Has been cancelled
ci / changelog_check (push) Has been cancelled
ci / check_changes (push) Has been cancelled
ci / build_mem0 (3.10) (push) Has been cancelled
ci / build_mem0 (3.11) (push) Has been cancelled
ci / build_mem0 (3.12) (push) Has been cancelled
CLI Node CI / lint (push) Has been cancelled
CLI Node CI / test (20) (push) Has been cancelled
CLI Node CI / test (22) (push) Has been cancelled
CLI Node CI / build (push) Has been cancelled
CLI Python CI / lint (push) Has been cancelled
CLI Python CI / test (3.10) (push) Has been cancelled
CLI Python CI / test (3.11) (push) Has been cancelled
CLI Python CI / test (3.12) (push) Has been cancelled
CLI Python CI / build (push) Has been cancelled
openclaw checks / lint (push) Has been cancelled
openclaw checks / test (20) (push) Has been cancelled
openclaw checks / test (22) (push) Has been cancelled
openclaw checks / build (push) Has been cancelled
opencode-plugin checks / build (push) Has been cancelled
TypeScript SDK CI / build_ts_sdk (20) (push) Has been cancelled
TypeScript SDK CI / build_ts_sdk (22) (push) Has been cancelled
TypeScript SDK CI / integration_ts_sdk (20) (push) Has been cancelled
TypeScript SDK CI / integration_ts_sdk (22) (push) Has been cancelled
68 lines
2.3 KiB
Python
68 lines
2.3 KiB
Python
import pytest
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _ensure_spacy():
|
|
"""Skip tests if spaCy model is not available."""
|
|
try:
|
|
import spacy
|
|
spacy.load("en_core_web_sm")
|
|
except Exception:
|
|
pytest.skip("spaCy en_core_web_sm model not available")
|
|
|
|
|
|
class TestLemmatizeForBm25:
|
|
def test_basic_lemmatization(self):
|
|
from mem0.utils.lemmatization import lemmatize_for_bm25
|
|
|
|
result = lemmatize_for_bm25("The cats are running quickly")
|
|
assert "cat" in result
|
|
assert "run" in result or "running" in result
|
|
# Stop words and punctuation should be removed
|
|
assert "the" not in result.split()
|
|
|
|
def test_verb_forms_normalized(self):
|
|
from mem0.utils.lemmatization import lemmatize_for_bm25
|
|
|
|
result = lemmatize_for_bm25("she attended multiple meetings yesterday")
|
|
assert "attend" in result or "attended" in result
|
|
assert "meeting" in result # -ing form preserved alongside lemma
|
|
# "multiple" is kept (not a spaCy stop word)
|
|
|
|
def test_ing_preservation(self):
|
|
from mem0.utils.lemmatization import lemmatize_for_bm25
|
|
|
|
result = lemmatize_for_bm25("attending the morning meeting")
|
|
tokens = result.split()
|
|
# Should have both the lemma and the -ing form
|
|
assert "attending" in tokens or "attend" in tokens
|
|
|
|
def test_empty_string(self):
|
|
from mem0.utils.lemmatization import lemmatize_for_bm25
|
|
|
|
result = lemmatize_for_bm25("")
|
|
assert result == ""
|
|
|
|
def test_punctuation_removed(self):
|
|
from mem0.utils.lemmatization import lemmatize_for_bm25
|
|
|
|
result = lemmatize_for_bm25("Hello, world! How are you?")
|
|
assert "," not in result
|
|
assert "!" not in result
|
|
assert "?" not in result
|
|
|
|
def test_lowercased(self):
|
|
from mem0.utils.lemmatization import lemmatize_for_bm25
|
|
|
|
result = lemmatize_for_bm25("PYTHON Programming LANGUAGE")
|
|
for token in result.split():
|
|
assert token == token.lower()
|
|
|
|
def test_stop_words_removed(self):
|
|
from mem0.utils.lemmatization import lemmatize_for_bm25
|
|
|
|
result = lemmatize_for_bm25("this is a very simple test of the system")
|
|
tokens = result.split()
|
|
for stop in ["this", "is", "a", "very", "of", "the"]:
|
|
assert stop not in tokens
|