def generate_session_pool(language="EN"): """Generate a single session pool for catFR experiments. :param str language: Language to load words in. :param int num_lists: Number of lists to assign. :param int listno_start: Where to start numbering from. :returns: Shuffled, categorized word pool. """ # validate language if language.lower() not in ["en", "sp"]: raise exc.LanguageError( "Language must be 'EN' or 'SP'".format(language)) # Load and shuffle order of words in categories filename = "ram_categorized_{:s}.txt".format(language.lower()) pool = wordpool.shuffle_within_groups( wordpool.load(filename), "category") words = sort_pairs(assign_list_numbers(assign_word_numbers(pool))) all_words = wordpool.load('practice_cat_{:s}.txt'.format(language.lower())) all_words['listno'] = 0 all_words['type'] = "PRACTICE" all_words['wordno'] = range(12) all_words['category'] = "X" all_words['category_num'] = -999 all_words = wordpool.shuffle_words(all_words) return all_words.append(words).reset_index(drop=True)
def test_create(pool, catpool): assert "word" in pool assert "word" in catpool assert "category" in catpool output = subprocess.check_output("git rev-parse --show-toplevel".split()) root = output.decode().strip() other = wordpool.load(osp.join(root, "wordpool", "data", "ram_wordpool_en.txt"), False) assert "word" in other
def test_write_wordpool(tmpdir): fn = listgen.write_wordpool_txt # unsupported language with pytest.raises(exc.LanguageError): fn(tmpdir, "DA") # missing rec words for supported language with pytest.raises(exc.LanguageError): fn(tmpdir, "SP", True) # writing without lures with subdir(tmpdir) as path: ret = fn(path, "EN") assert len(os.listdir(path)) == 1 assert len(ret) == 1 assert ret[0] == osp.join(path, "RAM_wordpool.txt") with open(ret[0]) as f: words = pd.Series([l.strip() for l in f.readlines()]) assert (words == wordpool.load("ram_wordpool_en.txt").word).all() # Writing with lures with subdir(tmpdir) as path: ret = fn(path, "EN", True) assert len(os.listdir(path)) == 2 assert len(ret) == 2 assert ret[0] == osp.join(path, "RAM_wordpool.txt") assert ret[1] == osp.join(path, "RAM_lurepool.txt") # targets with open(ret[0]) as f: words = pd.Series([l.strip() for l in f.readlines()]) assert (words == wordpool.load("ram_wordpool_en.txt").word).all() # lures with open(ret[1]) as f: words = pd.Series([l.strip() for l in f.readlines()]) assert (words == wordpool.load("REC1_lures_en.txt").word).all()
def test_generate_rec1_blocks(self): pool = listgen.fr.generate_session_pool() assigned = listgen.assign_list_types(pool, 3, 6, 16, 0) lures = wordpool.load("REC1_lures_en.txt") blocks = listgen.generate_rec1_blocks(assigned, lures) assert isinstance(blocks, pd.DataFrame) assert not all( [s == u for s, u in zip(sorted(blocks.listno), blocks.listno)]) blocks2 = listgen.generate_rec1_blocks(assigned, lures) for n in range(len(blocks.word)): if blocks.word.iloc[0] != blocks2.word.iloc[0]: break assert n < len(blocks.word) # this should be the original index before being reset assert "index" in blocks.columns
def catpool(language="en"): yield wordpool.load("ram_categorized_{:s}.txt".format(language))
def pool(language="en"): yield wordpool.load("ram_wordpool_{:s}.txt".format(language))
def catpool(self): return wordpool.load("ram_categorized_en.txt")
"""FR list generation.""" import pandas as pd import wordpool RAM_LIST_EN = wordpool.load("ram_wordpool_en.txt") RAM_LIST_SP = wordpool.load("ram_wordpool_sp.txt") PRACTICE_LIST_EN = wordpool.load("practice_en.txt") PRACTICE_LIST_SP = wordpool.load("practice_sp.txt") def generate_session_pool(words_per_list=12, num_lists=25, language="EN"): """Generate the pool of words for a single task session. This does *not* assign stim, no-stim, or PS metadata since this part depends on the experiment. :param int words_per_list: Number of words in each list. :param int num_lists: Total number of lists excluding the practice list. :param str language: Session language (``EN`` or ``SP``). :returns: Word pool :rtype: pd.DataFrame """ assert language in ("EN", "SP") practice = PRACTICE_LIST_EN if language == "EN" else PRACTICE_LIST_SP practice["type"] = "PRACTICE" practice["listno"] = 0 practice = wordpool.shuffle_words(practice).reset_index(drop=True)
"""List generation and I/O.""" import random import os.path as osp import numpy.random as npr import pandas as pd import wordpool from .. import exc from . import fr from . import catfr from . import pal RAM_LIST_EN = wordpool.load("ram_wordpool_en.txt") RAM_LIST_SP = wordpool.load("ram_wordpool_sp.txt") CAT_LIST_EN = wordpool.load("ram_categorized_en.txt") CAT_LIST_SP = wordpool.load("ram_categorized_sp.txt") PRACTICE_LIST_EN = wordpool.load("practice_en.txt") PRACTICE_LIST_SP = wordpool.load("practice_sp.txt") LURES_LIST_EN = wordpool.load("REC1_lures_en.txt") def write_wordpool_txt(path, language="EN", include_lure_words=False, categorized=False): """Write `RAM_wordpool.txt` or `CatFR_WORDS.txt` to a file (why the naming is so inconsistent is beyond me). This is used in event post-processing.