# Path: lantern/fitness/corpus.py
# class Corpus:
#     """Scoring function based on existance of words in a corpus.
# 
#     Todo:
#         This is fairly broken. I'm not happy with this implementation
#         and will be changing it in the future when I revisit weighted mean scoring
#     """
# 
#     def __init__(self, corpus):
#         """Build function with set of words from a corpus.
# 
#         Args:
#             corpus (collection): collection of words to use
#         """
#         self.words = corpus
#         self.floor = log10(0.01 / len(self.words))
# 
#     def __call__(self, text):
#         """Score based on number of words not in the corpus.
# 
#         Example:
#             >>> fitness = Corpus(["example"])
#             >>> fitness("example")
#             0
# 
#             >>> fitness("different")
#             -2.0
# 
#         Args:
#             text (str): The text to score
# 
#         Returns:
#             Corpus score for text
#         """
#         text = remove(text, string.punctuation)
#         words = text.split()
# 
#         invalid_words = list(filter(lambda word: word and word.lower() not in self.words, words))
#         return len(invalid_words) * self.floor


from math import log10
from lantern.fitness import Corpus




def _test_corpus_constructor(words):
    corpus = Corpus(words)
    assert corpus.words == words
    assert corpus.floor == log10(0.01 / len(words))


def test_corpus_constructor_with_set():
    """Testing corpus constructor with set"""
    words = set(["hello", "other", "english", "words"])
    _test_corpus_constructor(words)


def test_corpus_constructor_with_list():
    """Testing corpus constructor with list"""
    words = ["hello", "other", "english", "words"]
    _test_corpus_constructor(words)


def test_corpus_all_english_one_word():
    """Testing english words returns 0 score"""
    english_scorer = Corpus(set(["hello", "other", "english", "words"]))
    assert english_scorer("Hello") == 0


def test_corpus_one_non_english():
    """Testing incorrect words get assigned floor value"""

# Path: lantern/fitness/corpus.py
# class Corpus:
#     """Scoring function based on existance of words in a corpus.
# 
#     Todo:
#         This is fairly broken. I'm not happy with this implementation
#         and will be changing it in the future when I revisit weighted mean scoring
#     """
# 
#     def __init__(self, corpus):
#         """Build function with set of words from a corpus.
# 
#         Args:
#             corpus (collection): collection of words to use
#         """
#         self.words = corpus
#         self.floor = log10(0.01 / len(self.words))
# 
#     def __call__(self, text):
#         """Score based on number of words not in the corpus.
# 
#         Example:
#             >>> fitness = Corpus(["example"])
#             >>> fitness("example")
#             0
# 
#             >>> fitness("different")
#             -2.0
# 
#         Args:
#             text (str): The text to score
# 
#         Returns:
#             Corpus score for text
#         """
#         text = remove(text, string.punctuation)
#         words = text.split()
# 
#         invalid_words = list(filter(lambda word: word and word.lower() not in self.words, words))
#         return len(invalid_words) * self.floor


# Path: tests/fitness/test_corpus.py
from math import log10
from lantern.fitness import Corpus





def _test_corpus_constructor(words):
    corpus = Corpus(words)
    assert corpus.words == words
    assert corpus.floor == log10(0.01 / len(words))


def test_corpus_constructor_with_set():
    """Testing corpus constructor with set"""
    words = set(["hello", "other", "english", "words"])
    _test_corpus_constructor(words)


def test_corpus_constructor_with_list():
    """Testing corpus constructor with list"""
    words = ["hello", "other", "english", "words"]
    _test_corpus_constructor(words)


def test_corpus_all_english_one_word():
    """Testing english words returns 0 score"""
    english_scorer = Corpus(set(["hello", "other", "english", "words"]))
    assert english_scorer("Hello") == 0


def test_corpus_one_non_english():
    """Testing incorrect words get assigned floor value"""

    english_scorer = Corpus(set(["hello", "other", "english", "words"]))