Example #1
0
def get_sub_element_by_text(p_text, parent, translate_url, conversant_word_map, user=None):
    """
    进行 英文字符处理
    """
    result = []

    return_p_text = ''
    cur_u = None

    has_add_p_text = False

    for word in StringUtil.get_split_words(p_text):
            word_lower_case = word.lower()
            if_is_word = RegexUtil.is_word(word)

            if if_is_word:
                #添加到词频记录
                if not conversant_word_map.has_key(word_lower_case):
                    #没有在熟词列表内
                    result.append(return_p_text)
                    return_p_text = ''
                    has_add_p_text = True

                    cur_u = lxml.etree.SubElement(parent, "a")
                    jump_link = get_translate_word_url(word_lower_case, translate_url)
                    # cur_u.attrib['href'] = jump_link
                    # style="color:#DD4C53"

                    # cur_u.attrib['target'] = r"_blank"
                    # title_list = get_format_meaning(word_lower_case)

                    cur_u.attrib['class'] = 'recall_word'
                    cur_u.attrib['value'] = word_lower_case

                    # if not title_list:
                        # cur_u.attrib['style'] = r"color:#DD4CA0"
                        # cur_u.attrib['translate'] = u"未找到对应的翻译"
                    # else:
                        # cur_u.attrib['style'] = r"color:#FF0000"
                        # cur_u.attrib['translate'] = title_list

                    onclick = "return popitup2('%s')" %jump_link
                    # cur_u.attrib['onclick'] = onclick
                    cur_u.text = word
                    cur_u.tail = ''
                    result.append(cur_u)
                else:
                    return_p_text = return_p_text + word
                    has_add_p_text = False
            else:
                return_p_text = return_p_text + word
                has_add_p_text = False

    if not has_add_p_text:
        result.append(return_p_text)

    return result
Example #2
0
def __add_word_repeated_count(text, result):
    if text:
        word_list = StringUtil.get_split_words(text, word_only=True, lower=True)

        for word in word_list:
            if result.has_key(word):
                result[word] = result[word] + 1
            else:
                result[word] = 1

    return result