Beispiel #1
0
    def test_tag_single(self):
        self.create_some_tags()

        qs = word_search([
            SearchDescription.lexicon(self.csw19),
            SearchDescription.length(8, 8),
            SearchDescription.has_tags(['D4'], self.cesar, self.csw19)
        ], expand=True)

        self.assertEqual(qs.size(), 1)
        self.assertEqual(['AELMOSTU'], qs.alphagram_string_list())
        # Check that it fully populated the question
        logger.debug(qs.questions_array()[0].to_python_full())
        self.assertEqual(qs.questions_array()[0].to_python_full(), {
            'question': 'AELMOSTU',
            'probability': 2481,
            'answers': [{
                'word': 'SOULMATE',
                'def': 'a person with whom one is perfectly suited [n -S]',
                'f_hooks': '',
                'b_hooks': 'S',
                'symbols': '',
                'f_inner': False,
                'b_inner': False,
            }]
        })
def create_polish_lists():
    lex = Lexicon.objects.get(lexiconName="OSPS42")
    for i in range(2, 16):
        logger.debug("Creating WL for lex %s, length %s", lex.lexiconName, i)
        length_counts = json.loads(lex.lengthCounts)
        num_for_this_length = length_counts[str(i)]

        create_named_list(
            lex,
            num_for_this_length,
            i,
            True,
            json.dumps([1, num_for_this_length]),
            "The " + friendly_number_map[i],
        )
        if i >= 7 and i <= 8:
            # create 'every x' list
            for p in range(1, num_for_this_length + 1, LIST_GRANULARITY):
                min_p = p
                max_p = min(p + LIST_GRANULARITY - 1, num_for_this_length)
                create_named_list(
                    lex,
                    max_p - min_p + 1,
                    i,
                    True,
                    json.dumps([min_p, max_p]),
                    "{} ({} to {})".format(friendly_number_map[i], p, max_p),
                )

        if i >= 4 and i <= 8:
            qs = word_search([
                SearchDescription.lexicon(lex),
                SearchDescription.matching_anagram("[ĄĆĘŃÓŚŹŻ]" + "?" *
                                                   (i - 1)),
            ]).to_python()
            create_named_list(
                lex,
                len(qs),
                i,
                False,
                json.dumps(qs),
                friendly_number_map[i] + " with any of ĄĆĘŃÓŚŹŻ",
            )

        # New words
        qs = word_search([
            SearchDescription.lexicon(lex),
            SearchDescription.length(i, i),
            SearchDescription.not_in_lexicon("update"),
        ]).to_python()
        create_named_list(
            lex,
            len(qs),
            i,
            False,
            json.dumps(qs),
            "OSPS42 {} not in OSPS40".format(friendly_number_map[i]),
        )
Beispiel #3
0
 def test_tag_no_match(self):
     self.create_some_tags()
     with self.assertRaises(WDBError) as e:
         word_search([
             SearchDescription.lexicon(self.nwl18),
             SearchDescription.length(8, 8),
             SearchDescription.has_tags(['D4'], self.cesar, self.nwl18)
         ])
     self.assertEqual(str(e.exception), 'query returns no results')
Beispiel #4
0
def questions_from_probability_list(lexicon: Lexicon,
                                    plist: List[int],
                                    wl: int,
                                    expand: bool = False):
    qs = word_search([
        SearchDescription.lexicon(lexicon),
        SearchDescription.length(wl, wl),
        SearchDescription.probability_list(plist),
    ], expand)
    return qs
Beispiel #5
0
def questions_from_probability_range(lexicon: Lexicon,
                                     pmin: int,
                                     pmax: int,
                                     wl: int,
                                     expand: bool = False):
    qs = word_search([
        SearchDescription.lexicon(lexicon),
        SearchDescription.length(wl, wl),
        SearchDescription.probability_range(pmin, pmax),
    ], expand)
    return qs
Beispiel #6
0
 def test_tag_search(self):
     self.create_some_tags()
     t = time.time()
     qs = word_search([
         SearchDescription.lexicon(self.nwl18),
         SearchDescription.length(8, 8),
         SearchDescription.probability_range(5001, 7500),
         SearchDescription.has_tags(['D4'], self.cesar, self.nwl18),
     ], expand=True)
     logger.debug('Tag search completed in %s seconds', time.time() - t)
     self.assertEqual(qs.size(), 2500)
Beispiel #7
0
    def test_more_tags(self):
        self.create_some_tags()

        qs = word_search([
            SearchDescription.lexicon(self.nwl18),
            SearchDescription.length(5, 5),
            SearchDescription.has_tags(['D2', 'D5'], self.cesar, self.nwl18)
        ], expand=True)

        self.assertEqual(qs.size(), 2)
        self.assertEqual(['AEILT', 'CINOZ'], qs.alphagram_string_list())
        self.assertTrue(len(qs.questions_array()[0].answers[0].definition) > 0)
Beispiel #8
0
def questions_from_alphagrams(lexicon: Lexicon,
                              alphas: List[str],
                              expand: bool = False) -> Questions:
    """
    Given a list of alphagrams, get optionally fully populated questions.

    """
    # build search request
    qs = word_search([
        SearchDescription.lexicon(lexicon),
        SearchDescription.alphagram_list(alphas),
    ], expand)
    return qs
Beispiel #9
0
    def test_tag_list(self):
        self.create_some_tags()

        qs = word_search([
            SearchDescription.lexicon(self.nwl18),
            SearchDescription.length(8, 8),
            SearchDescription.has_tags(['D2', 'D3', 'D4', 'D5'], self.cesar,
                                       self.nwl18)
        ], expand=True)

        logger.debug('Found qs: %s', qs)
        self.assertEqual(qs.size(), 2)
        self.assertEqual(['AEEGLNOT', 'CEILNOPR'], qs.alphagram_string_list())
        self.assertTrue(len(qs.questions_array()[0].answers[0].definition) > 0)
 def setup_quiz(self, p_min=10, p_max=90, length=8):
     """
     A helper function to start a quiz.
     """
     wwg = WordwallsGame()
     user = User.objects.get(username='******')
     lex = Lexicon.objects.get(lexiconName='NWL18')
     search = [
         SearchDescription.lexicon(lex),
         SearchDescription.length(length, length),
         SearchDescription.probability_range(p_min, p_max)
     ]
     logger.debug('In setup_quiz, word lists: %s', WordList.objects.all())
     table_id = wwg.initialize_by_search_params(user, search, 240)
     return table_id, user
Beispiel #11
0
    def create_some_tags(self):
        self.nwl18 = Lexicon.objects.get(lexiconName='NWL18')
        self.cesar = User.objects.get(username='******')
        t = time.time()

        qs = word_search([
            SearchDescription.lexicon(self.nwl18),
            SearchDescription.length(8, 8),
            SearchDescription.probability_range(5001, 8500),
        ], expand=True)
        logger.debug('Initial word search completed in %s seconds',
                     time.time() - t)
        self.assertEqual(qs.size(), 3500)
        # Create hella tags.
        for q in qs.questions_array():
            AlphagramTag.objects.create(user=self.cesar, lexicon=self.nwl18,
                                        tag='D4',
                                        alphagram=q.alphagram.alphagram)
        logger.debug('And time elapsed after tag creation: %s',
                     time.time() - t)
Beispiel #12
0
def build_search_criteria(user, lexicon, fe_search_criteria):
    search = [
        SearchDescription.lexicon(lexicon),
    ]
    hold_until_end = None
    for criterion in fe_search_criteria:
        if isinstance(criterion["searchType"], str):
            # XXX: Remove a bit after deploy.
            raise GameInitException(
                "Please refresh the app; there has been an update."
            )
        try:
            criterion_fn = SearchCriterionFn(criterion["searchType"])
        except AttributeError:
            raise GameInitException(
                f'Cannot handle search type {criterion["searchType"]}'
            )

        if criterion["searchType"] in MIN_MAX_DESCRIPTIONS:
            search.append(
                criterion_fn(
                    int(criterion["minValue"]), int(criterion["maxValue"])
                )
            )

        elif criterion["searchType"] in SINGLE_NUMBER_DESCRIPTIONS:
            search.append(criterion_fn(criterion["value"]))

        elif criterion["searchType"] == TAGS_DESCRIPTION:
            tags = criterion["value"].split(",")
            new_tags = []
            for t in tags:
                stripped = t.strip()
                if stripped != "":
                    new_tags.append(stripped)

            if hold_until_end:
                raise GameInitException("You can only specify one set of tags")
            hold_until_end = criterion_fn(new_tags, user, lexicon)
        elif criterion["searchType"] in SINGLE_STRING_DESCRIPTIONS:
            search.append(criterion_fn(criterion["value"].strip()))

    if hold_until_end:
        search.append(hold_until_end)
    return search
Beispiel #13
0
def create_wl_lists(i, lex):
    """Create word lists for words with length `i`."""
    logger.debug("Creating WL for lex %s, length %s", lex.lexiconName, i)
    length_counts = json.loads(lex.lengthCounts)
    num_for_this_length = length_counts[str(i)]
    create_named_list(
        lex,
        num_for_this_length,
        i,
        True,
        json.dumps([1, num_for_this_length]),
        "The " + friendly_number_map[i],
    )
    if i >= 7 and i <= 8:
        # create 'every x' list
        for p in range(1, num_for_this_length + 1, LIST_GRANULARITY):
            min_p = p
            max_p = min(p + LIST_GRANULARITY - 1, num_for_this_length)
            create_named_list(
                lex,
                max_p - min_p + 1,
                i,
                True,
                json.dumps([min_p, max_p]),
                "{} ({} to {})".format(friendly_number_map[i], p, max_p),
            )

    if i >= 4 and i <= 8:
        qs = word_search([
            SearchDescription.lexicon(lex),
            SearchDescription.matching_anagram("[JQXZ]" + "?" * (i - 1)),
        ]).to_python()

        create_named_list(
            lex,
            len(qs),
            i,
            False,
            json.dumps(qs),
            "JQXZ " + friendly_number_map[i],
        )

    if i == 7:
        # 4+ vowel 7s
        qs = word_search([
            SearchDescription.lexicon(lex),
            SearchDescription.matching_anagram(
                "[AEIOU][AEIOU][AEIOU][AEIOU]???"),
        ]).to_python()
        create_named_list(
            lex,
            len(qs),
            i,
            False,
            json.dumps(qs),
            "Sevens with 4 or more vowels",
        )
    if i == 8:
        # 5+ vowel 8s
        qs = word_search([
            SearchDescription.lexicon(lex),
            SearchDescription.matching_anagram(
                "[AEIOU][AEIOU][AEIOU][AEIOU][AEIOU]???"),
        ]).to_python()
        create_named_list(
            lex,
            len(qs),
            i,
            False,
            json.dumps(qs),
            "Eights with 5 or more vowels",
        )

    if lex.lexiconName == "NWL18":
        qs = word_search([
            SearchDescription.lexicon(lex),
            SearchDescription.length(i, i),
            SearchDescription.not_in_lexicon("update"),
        ]).to_python()

        create_named_list(
            lex,
            len(qs),
            i,
            False,
            json.dumps(qs),
            "NWL18 {} not in America".format(friendly_number_map[i]),
        )

        qs = word_search([
            SearchDescription.lexicon(lex),
            SearchDescription.length(i, i),
            SearchDescription.not_in_lexicon("other_english"),
        ]).to_python()
        create_named_list(
            lex,
            len(qs),
            i,
            False,
            json.dumps(qs),
            "NWL18 {} not in CSW19".format(friendly_number_map[i]),
        )

        if i >= 4 and i <= 6:
            qs = word_search([
                SearchDescription.lexicon(lex),
                SearchDescription.not_in_lexicon("update"),
                SearchDescription.matching_anagram("[JQXZ]" + "?" * (i - 1)),
            ]).to_python()

            create_named_list(
                lex,
                len(qs),
                i,
                False,
                json.dumps(qs),
                f"NWL18 JQXZ {i}s not in America",
            )

    if lex.lexiconName == "CSW19":
        qs = word_search([
            SearchDescription.lexicon(lex),
            SearchDescription.length(i, i),
            SearchDescription.not_in_lexicon("update"),
        ]).to_python()
        create_named_list(
            lex,
            len(qs),
            i,
            False,
            json.dumps(qs),
            "CSW19 {} not in CSW15".format(friendly_number_map[i]),
        )

        qs = word_search([
            SearchDescription.lexicon(lex),
            SearchDescription.length(i, i),
            SearchDescription.not_in_lexicon("other_english"),
        ]).to_python()
        create_named_list(
            lex,
            len(qs),
            i,
            False,
            json.dumps(qs),
            "CSW19 {} not in NWL18".format(friendly_number_map[i]),
        )
Beispiel #14
0
def create_spanish_lists():
    lex = Lexicon.objects.get(lexiconName="FISE2")
    for i in range(2, 16):
        logger.debug("Creating WL for lex %s, length %s", lex.lexiconName, i)
        length_counts = json.loads(lex.lengthCounts)
        num_for_this_length = length_counts[str(i)]

        create_named_list(
            lex,
            num_for_this_length,
            i,
            True,
            json.dumps([1, num_for_this_length]),
            "Los " + mapa_amigable[i],
        )
        if i >= 7 and i <= 8:
            # create 'every x' list
            for p in range(1, num_for_this_length + 1, LIST_GRANULARITY):
                min_p = p
                max_p = min(p + LIST_GRANULARITY - 1, num_for_this_length)
                create_named_list(
                    lex,
                    max_p - min_p + 1,
                    i,
                    True,
                    json.dumps([min_p, max_p]),
                    "{} ({} a {})".format(mapa_amigable[i], p, max_p),
                )

        if i >= 4 and i <= 8:
            qs = word_search([
                SearchDescription.lexicon(lex),
                SearchDescription.matching_anagram("[JQXZ]" + "?" * (i - 1)),
            ]).to_python()
            create_named_list(
                lex,
                len(qs),
                i,
                False,
                json.dumps(qs),
                "JQXZ " + mapa_amigable[i],
            )

            qs = word_search([
                SearchDescription.lexicon(lex),
                SearchDescription.matching_anagram("[123Ñ]" + "?" * (i - 1)),
            ]).to_python()
            create_named_list(
                lex,
                len(qs),
                i,
                False,
                json.dumps(qs),
                "(ᴄʜ)(ʟʟ)(ʀʀ)Ñ " + mapa_amigable[i],
            )

        if i == 7:
            # 4+ vowel 7s
            qs = word_search([
                SearchDescription.lexicon(lex),
                SearchDescription.matching_anagram(
                    "[AEIOU][AEIOU][AEIOU][AEIOU]???"),
            ]).to_python()
            create_named_list(
                lex,
                len(qs),
                i,
                False,
                json.dumps(qs),
                "Sietes con 4 o más vocales",
            )
        if i == 8:
            # 5+ vowel 8s
            qs = word_search([
                SearchDescription.lexicon(lex),
                SearchDescription.matching_anagram(
                    "[AEIOU][AEIOU][AEIOU][AEIOU][AEIOU]???"),
            ]).to_python()
            create_named_list(
                lex,
                len(qs),
                i,
                False,
                json.dumps(qs),
                "Ochos con 5 o más vocales",
            )

        qs = word_search([
            SearchDescription.lexicon(lex),
            SearchDescription.length(i, i),
            SearchDescription.not_in_lexicon("update"),
        ]).to_python()
        create_named_list(
            lex,
            len(qs),
            i,
            False,
            json.dumps(qs),
            "FISE2 {} nuevos".format(mapa_amigable[i]),
        )