我正在尝试使用regex标记tweet。这里的tokens和emoticon是2个regex对象
def tokenize(s):
return tokens_re.findall(s)
def preprocess(s, lowercase=False):
tokens = tokenize(s)
if lowercase:
tokens = [token if emoticon_re.search(token) else token.lower() for token in tokens]
return tokens
with open('twitterdata.json', 'r') as f:
for line in f:
tweet = json.loads(line)
tokens = preprocess(tweet['text'])
s
在这里必须是字符串,但是tweet['text']
是什么字符串?在
我认为你没有正确地使用索引。如果您能提供一个JSON数据的示例,那就更好了。 不管怎样,你可以试试这个。在
tokens=预处理(tweet[0]['text'])
这里0是第一个索引。 你可以把这个放在一个循环里。在
希望有帮助。在
相关问题 更多 >
编程相关推荐