Example #1
0
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]),
        )
Example #2
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')
Example #3
0
def new_quiz(request):
    """
    Create a new quiz but doesn't create any 'card' models.
    Card models will only be used for cardbox in future.
    """
    body = json.loads(request.body)
    logger.debug(body)
    lexicon = Lexicon.objects.get(lexiconName=body['lexicon'])
    try:
        search_description = build_search_criteria(request.user, lexicon,
                                                   body['searchCriteria'])
    except GameInitException as e:
        return response(str(e), status=400)

    questions = word_search(search_description, expand=True)
    if questions.size() == 0:
        return response('No questions were found.', status=400)
    wl = WordList()
    wl.initialize_list(list(questions.to_python()),
                       lexicon,
                       None,
                       shuffle=True,
                       save=False)
    q_map = generate_question_map(questions)
    quiz_name = temporary_list_name(search_description, lexicon.lexiconName)
    # XXX add 1000-question limit?
    return response({
        'list': wl.to_python(),
        'q_map': q_map,
        'quiz_name': quiz_name,
    })
Example #4
0
def search(request, lex_id, paramsb64):
    if request.method == 'GET':
        return render(request, 'whitleyCards/quiz.html')
    elif request.method == 'POST':
        action = request.POST['action']
        lex = Lexicon.objects.get(pk=lex_id)
        search_params = build_search_criteria(
            request.user, lex, search_criteria_from_b64(paramsb64))
        questions = word_search(search_params, expand=True)

        if action == 'getInitialSet':
            data = getQuizChunkByQuestions(lex, questions, 0, is_q_obj=True)
            return response({
                'data': data[0],
                'nextMinP': data[1],
                'nextMaxP': data[2],
                'numAlphas': questions.size(),
            })

        elif action == 'getNextSet':
            # minP and maxP are more like indices now.
            minP = int(request.POST['minP'])

            if minP == -1:  # quiz is over
                return response({'data': []})

            maxP = int(request.POST['maxP'])
            logger.info("getting set %s, %s", minP, maxP)
            data = getQuizChunkByQuestions(lex, questions, minP, is_q_obj=True)
            return response({
                'data': data[0],
                'nextMinP': data[1],
                'nextMaxP': data[2]
            })
Example #5
0
    def initialize_by_search_params(
        self,
        user,
        search_description,
        time_secs,
        questions_per_round=None,
        use_table=None,
        multiplayer=None,
    ):
        try:
            lexicon = Lexicon.objects.get(
                lexiconName=search_description[0].stringvalue.value)
        except Lexicon.DoesNotExist:
            raise GameInitException(
                "Search description not properly initialized")

        try:
            wl = self.initialize_word_list(word_search(search_description),
                                           lexicon, user)
        except WDBError as e:
            raise GameInitException(e)
        wgm = self.create_or_update_game_instance(
            user,
            lexicon,
            wl,
            use_table,
            multiplayer,
            timerSecs=time_secs,
            temp_list_name=temporary_list_name(search_description,
                                               lexicon.lexiconName),
            questionsToPull=questions_per_round,
        )
        return wgm.pk  # this is a table number id!
Example #6
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,
            }]
        })
Example #7
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)
Example #8
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)
Example #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)
Example #10
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)
Example #11
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]),
        )
Example #12
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]),
        )