Exemplo n.º 1
0
    def preprocess(self,text):   
        check = re.search(r'([a-z])\1+',text)
        if check:
            if len(check.group())>2:
                text = re.sub(r'([a-z])\1+', lambda m: m.group(1), text, flags=re.IGNORECASE) #remove các ký tự kéo dài như hayyy,ngonnnn...

        text = text.strip() #loại dấu cách đầu câu
        text = text.lower() #chuyển tất cả thành chữ thường

        text = re.sub('< a class.+</a>',' ',text)

        for k, v in self.replace_list.items():       #replace các từ có trong replace_list
            text = text.replace(k, v)       

        text = re.sub(r'_',' ',text)  
        
        text = ' '.join(i for i in flatten(tokenize(text).split(" ")))             #gán từ ghép
        
        for i in self.Pos_list:                                    #thêm feature positive
            if re.search(' '+i+' ',text): 
                text = re.sub(i,i+' positive ',text)
        for i in self.Neg_list:                                    #thêm feature negative
            if re.search(' '+i+' ',text):
                text = re.sub(i,i+' negative ',text)
        return text
def tokenize_content(_string):
    _string = string_format(_string)
    _string = tokenize(_string)
    # for token in _string.split(' '):
    #     if token in positive_emoticons:
    #         _string = _string.replace(token, 'pos')
    #     if token in negative_emoticons:
    #         _string = _string.replace(token, 'neg')
    #     if token in punctuation:
    #         _string = _string.replace(token, 'punc')
    return _string
Exemplo n.º 3
0
def word_segment(sent):
    sent = tokenize(sent)
    return sent
Exemplo n.º 4
0
def word_segment(sent):
    sent = tokenize(sent.decode('utf-8'))
    return sent