내 컴퓨터에서 제대로 작동하지만 다른 컴퓨터에서는 null을 반환하는 다음 코드를 작성했습니다. 이 문제를 해결할 수 있도록 도와 주시겠습니까?다른 컴퓨터의 NLTK 라이브러리와 관련된 파이썬 코드와 다른 결과
import string
import nltk
from nltk.tokenize import RegexpTokenizer
from nltk.corpus import stopwords
def preprocess(sentence):
sentence = sentence.lower()
specialChrs={'\xc2',''}
pattern=pattern = r'''(?x) # set flag to allow verbose regexps
([A-Z]\.)+ # abbreviations, e.g. U.S.A.
| \$?\d+%?
| \$?\d+(,|.\d+)*
| \w+([-'/]\w+)* # words w/ optional internal hyphens/apostrophe
|/\m+([-'/]\w+)*
'''
tokenizer = RegexpTokenizer(pattern)
tokens = tokenizer.tokenize(sentence)
print tokens
realToken= [e for e in tokens if len(e)>= 3 and len(e)<10]
stopWords = set(stopwords.words('english'))
stop_words = [w for w in realToken if not w in stopWords]
filtered_words = [w for w in stop_words if not w in specialChrs]
print filtered_words
# final_words = [w for w in filtered_words if not w[0]=='0' and w[1]=='x']
return filtered_words
str='I have one generalized rule, where in shellscript I check for all need packages, if any package does not exist, then install it other wise skip to next check. As I need to check and execute few other python as well shellscripts, I am using it. Is using shellscript for this is bad idea?'
preprocess(str)
이 내 컴퓨터 출력의 일부 :
[i는, '한', '일반적인', '규칙'가 ','여기서, ','년 ', '쉘 스크립트', '난', '의', '확인', '모든', '필요'....... '생각']
다른 컴퓨터 결과 :
[('', '', ''), ('', ' ('', '', '', ''), ('', '', '', '') ('', '', '', '') ('', '', '', ''), ...]
내 컴퓨터 정보
파이썬 2.7 .12 | 아나콘다 2.3.0 (64 비트) | (default, Jul 2 2016, 17:42:40) linux2의 [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] 에 대한 "help", "copyright", "credits"또는 "license"를 입력하십시오. 자세한 정보. Anaconda는 Continuum Analytics에서 제공합니다. 확인하시기 바랍니다 : http://continuum.io/thanks 및 https://anaconda.org
수입 NLTK
인쇄 ('는 NLTK 버전은 {}.'형식 (NLTK 버전을)..)
가 NLTK 버전은 3.2.1이다 .
내 친구 컴퓨터
파이썬 2.7.12 | 아나콘다 4.1.1 (64 비트) | (기본값, Jun 29 2016, 11:42:40) win32의 [MSC v.1500 64 비트 (AMD64)] 자세한 내용은 "help", "copyright", "credits"또는 "license"를 입력하십시오. Anaconda는 Continuum Analytics에서 제공합니다. 확인하시기 바랍니다 : http://continuum.io/thanks 및 https://anaconda.org
수입 NLTK
인쇄 ('는 NLTK 버전은 {}.'형식 (NLTK 버전을)..)
가 NLTK 버전은 3.2.1이다 .
또한 다른 컴퓨터에서 코드를 테스트 할 때도 동일한 결과가 나타납니다.
해당 컴퓨터의 정보는 다음과 같습니다
파이썬 2.7.3 (기본 2016 년 10 월 26 일 21시 1분 49초) [GCC 4.6.3] on linux2 자세한 내용은 "help", "copyright", "credits"또는 "license"를 입력하십시오.
Windows 시스템 (친구)에서는 문자열이 다르게 처리됩니다. – alvas
@alvas 내가 테스트하기 때문에 linux2는 어떻습니까? 나는 어떻게해야합니까? – user3092781