Esempio n. 1
0
def _getAvailableDicts(private):
    global g_availableDicts, g_dictsSortedByName
    assert None != g_dictsSortedByName
    initDictionary()
    if g_fDisabled:
        return (MODULE_DOWN, None)

    df = Definition()
    df.TextElement("Home", link="dictform:main")
    df.TextElement(" / Select dictionary")
    df.LineBreakElement(1,2)

    dicts = []
    for name in g_dictsSortedByName:
        dicts.append(g_availableDicts[name])
    dicts.sort(_sortByOrder)

    for item in dicts:
        if not item[5] or private:
            df.BulletElement(False)
            df.TextElement(item[2], link="s+dictstats:%s" % item[0])
            df.PopParentElement()

    udf = universalDataFormatWithDefinition(df, [["H", "Change dictionary"]])
    return (DICT_DEF, udf)
Esempio n. 2
0
def getDictionaryRandom(randomUrl, fDebug=False):
    global g_wnWords, g_fDisabled
    initDictionary()
    if g_fDisabled:
        return (MODULE_DOWN, None)

    parts = randomUrl.split(":")
    dictCode = parts[0]
    flags = parts[1]
    
    if WORDNET_CODE == dictCode:
        totalWords = len(g_wnWords)
        randomWordNo = g_random.randint(0, totalWords-1)
        word = g_wnWords[randomWordNo]
        nearbyWords = _getNearbyWords(g_wnWords, word, NEARBY_WORDS_TO_SHOW)
        wordDef = _wnGetDef(word)
    elif THESAURUS_CODE == dictCode:
        totalWords = len(g_thWords)
        randomWordNo = g_random.randint(0, totalWords-1)
        word = g_thWords[randomWordNo]
        nearbyWords = _getNearbyWords(g_thWords, word, NEARBY_WORDS_TO_SHOW)
        wordDef = _thGetDef(word)
    else:
        return (INVALID_REQUEST, None)

    assert None != wordDef
    df = buildDefinitionFound(word, wordDef, nearbyWords, dictCode, flags)
    udf = universalDataFormatWithDefinition(df, [["H", word]])

    if fDebug:
        print "random word is %s" % word
    return (DICT_DEF, udf)
Esempio n. 3
0
def _getAvailableDicts(private):
    global g_availableDicts, g_dictsSortedByName
    assert None != g_dictsSortedByName
    initDictionary()
    if g_fDisabled:
        return (MODULE_DOWN, None)

    df = Definition()
    df.TextElement("Home", link="dictform:main")
    df.TextElement(" / Select dictionary")
    df.LineBreakElement(1, 2)

    dicts = []
    for name in g_dictsSortedByName:
        dicts.append(g_availableDicts[name])
    dicts.sort(_sortByOrder)

    for item in dicts:
        if not item[5] or private:
            df.BulletElement(False)
            df.TextElement(item[2], link="s+dictstats:%s" % item[0])
            df.PopParentElement()

    udf = universalDataFormatWithDefinition(df, [["H", "Change dictionary"]])
    return (DICT_DEF, udf)
Esempio n. 4
0
def getDictionaryRandom(randomUrl, fDebug=False):
    global g_wnWords, g_fDisabled
    initDictionary()
    if g_fDisabled:
        return (MODULE_DOWN, None)

    parts = randomUrl.split(":")
    dictCode = parts[0]
    flags = parts[1]

    if WORDNET_CODE == dictCode:
        totalWords = len(g_wnWords)
        randomWordNo = g_random.randint(0, totalWords - 1)
        word = g_wnWords[randomWordNo]
        nearbyWords = _getNearbyWords(g_wnWords, word, NEARBY_WORDS_TO_SHOW)
        wordDef = _wnGetDef(word)
    elif THESAURUS_CODE == dictCode:
        totalWords = len(g_thWords)
        randomWordNo = g_random.randint(0, totalWords - 1)
        word = g_thWords[randomWordNo]
        nearbyWords = _getNearbyWords(g_thWords, word, NEARBY_WORDS_TO_SHOW)
        wordDef = _thGetDef(word)
    else:
        return (INVALID_REQUEST, None)

    assert None != wordDef
    df = buildDefinitionFound(word, wordDef, nearbyWords, dictCode, flags)
    udf = universalDataFormatWithDefinition(df, [["H", word]])

    if fDebug:
        print "random word is %s" % word
    return (DICT_DEF, udf)
Esempio n. 5
0
def getDictionaryDef(searchTerm, fDebug=False):
    global g_wnWords, g_fDisabled
    initDictionary()
    if g_fDisabled:
        return (MODULE_DOWN, None)

    parts = searchTerm.split(":", 2)
    if 3 != len(parts):
        return (INVALID_REQUEST, None)
    assert 3 == len(parts)
    (dictCode, flags, word) = parts
    word = word.strip()

    if WORDNET_CODE == dictCode:
        words = g_wnWords
        wordDef = _wnGetDef(word)
    elif THESAURUS_CODE == dictCode:
        words = g_thWords
        wordDef = _thGetDef(word)
    else:
        return (INVALID_REQUEST, None)

    nearbyWords = _getNearbyWords(words, word, NEARBY_WORDS_TO_SHOW)

    if fDebug:
        if None == wordDef:
            print "definition of '%s' not found" % word
            print nearbyWords
        else:
            print wordDef

    if None == wordDef:
        # ispell
        suggestionsUnfiltred = getSpellcheckSuggestions(word)
        suggestions = []
        if suggestionsUnfiltred != None:
            for sug in suggestionsUnfiltred:
                if sug in words:
                    suggestions.append(sug)
        # lupy
        if WORDNET_CODE == dictCode:
            toLupyWords = word
            if len(word.split()) > 3:
                toLupyWords = string.join(word.split()[:3])
            lupyResults = g_lupyIndex.getWords(toLupyWords, dictCode)
        else:
            lupyResults = []

        df = buildDefinitionNotFound(word, nearbyWords, dictCode, flags,
                                     suggestions, lupyResults)
    else:
        df = buildDefinitionFound(word, wordDef, nearbyWords, dictCode, flags)

    udf = universalDataFormatWithDefinition(df, [["H", word]])

    return (DICT_DEF, udf)
Esempio n. 6
0
def getDictionaryDef(searchTerm, fDebug=False):
    global g_wnWords, g_fDisabled
    initDictionary()
    if g_fDisabled:
        return (MODULE_DOWN, None)

    parts = searchTerm.split(":", 2)
    if 3 != len(parts):
        return (INVALID_REQUEST, None)
    assert 3 == len(parts)
    (dictCode, flags, word) = parts
    word = word.strip()

    if WORDNET_CODE == dictCode:
        words = g_wnWords
        wordDef = _wnGetDef(word)
    elif THESAURUS_CODE == dictCode:
        words = g_thWords
        wordDef = _thGetDef(word)
    else:
        return (INVALID_REQUEST, None)

    nearbyWords = _getNearbyWords(words, word, NEARBY_WORDS_TO_SHOW)

    if fDebug:
        if None == wordDef:
            print "definition of '%s' not found" % word
            print nearbyWords
        else:
            print wordDef

    if None == wordDef:
        # ispell
        suggestionsUnfiltred = getSpellcheckSuggestions(word)
        suggestions = []
        if suggestionsUnfiltred != None:
            for sug in suggestionsUnfiltred:
                if sug in words:
                    suggestions.append(sug)
        # lupy
        if WORDNET_CODE == dictCode:
            toLupyWords = word
            if len(word.split()) > 3:
                toLupyWords = string.join(word.split()[:3])
            lupyResults = g_lupyIndex.getWords(toLupyWords, dictCode)
        else:
            lupyResults = []

        df = buildDefinitionNotFound(word, nearbyWords, dictCode, flags, suggestions, lupyResults)
    else:
        df = buildDefinitionFound(word, wordDef, nearbyWords, dictCode, flags)

    udf = universalDataFormatWithDefinition(df, [["H", word]])

    return (DICT_DEF, udf)