2014-06-12 4 views
-2

텍스트를 분류하고 싶습니다 : 양수, 음수 또는 중립. 나는 긍정적이고 부정적인 단어 목록을 가지고 있습니다. 파이썬에서하고 싶습니다. 여기서 I는 이러한 종류의 코드에 대해 설명단어 목록에 따른 분류 Python

경우 positive_words 검색된 텍스트 단어 다음 counterpos = pos_count [I]는 + = 1

negative_words 검색된 텍스트 단어 다음 counterneg = neg_count 경우 [I ] + = 1

TOTALCOUNT = pos_count + neg_count

경우 (LEN (TOTALCOUNT)> 0) : 양의 데이터베이스 ELIF에 저장소 (LEN (TOTALCOUNT) < 0) : 다른 부정적인 데이터베이스에 가기 :

store in neutral database 

이것은 일반적인 생각이다, 내 코딩 hability가 null입니다. mongodb에 저장 중이므로 저장하는 데 문제가 없습니다. 아직도 나는 분류를 할 수 없다. 누군가 나를 도울 수 있습니까?

+0

문자열 및 제어 흐름 명령문에 대한 자습서를 읽은 후에도 매우 어려운 작업은 아닙니다. https://docs.python.org/2/library/string.html & https://docs.python.org/2/tutorial/controlflow.html 및 mongodb http://docs.mongodb.org/manual/ –

+0

그래, 파이썬은 배우기가 매우 쉽다는 것을 알고 있는데, 시간적 여유가 있고 함께 내 물건을 가져갈 수 없다는 것, 감사합니다 :) – user3572183

답변

0

문자열 비교 및 ​​제어 흐름 명령문 외에도 list comprehension이 유용합니다.

text = "seeking help on possible homework task" 
raw_words = text.split(" ") 

positive_words = ['seeking','help'] 
negative_words = ['homework'] 

positive_score = len([word for word in raw_words if word in positive_words]) 
negative_score = len([word for word in raw_words if word in negative_words]) 

total_score = positive_score - negative_score 

total_score1의 값을 가지는 될 것이다.

+0

대단히 감사합니다 :) – user3572183