Работа со строками в списках (Python Sentiment Analysis) - PullRequest
0 голосов
/ 04 июля 2018

Мне нравится делать небольшой анализ настроений по поводу отзывов об отелях.

Пример (stop_word_filter:

[«Даже», «хотя», «фотографии», «шоу», «чистые», «комнаты», «фактические», «комнаты», «уйти», «грязные», «пережил», «также ',' check ',' 15 ',' clock ',' room ',' not ',' ready ',' time ']

Я понял, что речь идет о "гостиничном номере" и о "чистом". Я хочу соединить закрывающее «отрицательное» слово с «чистым», которое должно быть «грязным». Я интегрировал список негативных слов. Я вешаю на реализацию ...

Код:

bullets = [] #output
distances = []
bad_word_locations = []
rubrik_word_location = [] #category_word

#if there is a category word in the review

if len(rubrik_uR_list) == 1:

    #get the index of that one 
        rubrik_word_location = stop_words_filter.index(rubrik_uR_list[0])

        #go throu all negative words and if one of them in my sentence get the index of that word
        for w in negativ_words_list:  
            if w in stop_words_filter:
                bad_word_locations.append(stop_words_filter.index(w)) 

            #NOW ITS GETTING CRUCIAL 
            #if we found one 
            if len(bad_word_locations) > 0:

                #I need to some how catch now the closest word, my code is not doing this
                distances.append(abs(rubrik_word_location-bad_word_locations[0])) 

                bullets.append(stop_words_filter[min(distances)])

                #if I got more categories in one review I need to remind that somehow...
                blacklist.append(stop_words_filter[min(distances)])

Понятно, я плохо программирую. Буду признателен за вашу помощь с уважением.

Заранее спасибо, Никлас

1 Ответ

0 голосов
/ 05 июля 2018

Я просто мог понять это сам.

def getBulletPoint(pos_filter,stop_words_filter, rubrik_uR_list):      

    index_of_category_word = 0
    distance = 0
    count = 0 

    #Finde alle negaive Wörter 
    for w in negativ_words_list:             
        if w in stop_words_filter:
            bad_words.append(w) 

    #finde die Indexe der negativen Wörter        
    for w in bad_words:
        word_index.append(stop_words_filter.index(w))

    if len(rubrik_uR_list) > 0 and len(bad_words) > 0 : #Wenn wir überhaupt ein Rubrikwort haben



#-------------Loop-------------------                
        for w in rubrik_uR_list:     

            saved_distance = 1000 

#            bullets.append(rubrik_list[count])
#            bullets.append(rubrik_uR_list[count])

            index_of_category_word = stop_words_filter.index(rubrik_uR_list[count])

            for i in word_index:
                distance = abs(i-index_of_category_word)

                if distance < saved_distance:
                    current_bullet = (stop_words_filter[i])
                    saved_distance = distance

            bullets.append(current_bullet)

            count = count + 1

С уважением, Никлас

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...