是否可以在NLTK中使用Stanford Parser?(我不是在谈论斯坦福POS.)
我们需要管理员来安装一些软件,它们需要将近一个月的时间才能为我们安装.所以我想找一些可以在没有管理员的情况下安装的Python IDE(Windows 7).有什么建议?
我在http://ricardianambivalence.com/2011/08/14/beautifulsoup-in-python-with-windows-7/找到了帖子
(我使用python 2.6并下载了beautifulsoup4-4.1.3)
运行"setup.py"后我找不到"BeautifulSoup.pyc"
有什么建议?
import re
sums = dict()
fh= open('wordcount.txt','r')
for line in fh:
words = [word.lower() for word in re.findall(r'\b\w+\b', line)]
for word in (words):
if word in sums:
sums[word] += 1
else:
sums[word] = 1
print sums
fh.close
Run Code Online (Sandbox Code Playgroud)
结果显示
{'and': 1, 'heart': 1, 'love': 2, 'is': 1, 'pass': 1, 'rest': 1, 'wounded': 1, 'at': 3,
'in': 3, 'lie': 1, 'winchelsea': 1, 'there': 1, 'easy': 1, 'you': 2, 'body': 1, 'be':
1, 'rise': 1, 'shall': 4, 'may': 2, 'sussex': 1, 'montparnasse': 1, …Run Code Online (Sandbox Code Playgroud) 在"test_wordss.txt"中
A
sentence
is
a
grammatical
unit
consisting
of
one
or
more
words
A
Run Code Online (Sandbox Code Playgroud)
我的代码:
for line2 in open('C://Users/Desktop/test_wordss.txt'):
fields2 = line2.rstrip('\n').split('\t')
print fields2.sort()
Run Code Online (Sandbox Code Playgroud)
我的代码的结果显示为无......
我做错什么了吗?有关在文本文件中排序单词的任何建议吗?
在文件中:
Hello........girlllllllllll
W.o.W
Run Code Online (Sandbox Code Playgroud)
我试过:
for line in file.split('\n'):
line = re.sub('[.]+', ' ', line)
line = re.sub('[.]', '', line)
print line
Run Code Online (Sandbox Code Playgroud)
结果显示:
Hello girlllllllllll
W o W
Run Code Online (Sandbox Code Playgroud)
是否有可能得到如下结果?
Hello girlllllllllll
WoW
Run Code Online (Sandbox Code Playgroud)
有什么建议吗?
我是 dict() 的新手。我尝试使用defaultdict的示例。(Python 2.6)
from collections import defaultdict
s = 'happy sad happy cry crazy mad sad'
d = defaultdict(int)
for k in s.split():
d[k] += 1
print d.items()
Run Code Online (Sandbox Code Playgroud)
结果:
[('crazy', 1), ('sad', 2), ('mad', 1), ('cry', 1), ('happy', 2)]
Run Code Online (Sandbox Code Playgroud)
我只是想知道这一点。有没有可能获取每个字典的ID?有什么建议吗?
预期结果:
[(1, 'crazy', 1), (2, 'sad', 2), (3, 'mad', 1), (4, 'cry', 1), (5, 'happy', 2)]
Run Code Online (Sandbox Code Playgroud) Sentence = "the heart was made to be broken"
Run Code Online (Sandbox Code Playgroud)
如何使用Python分割句子以在单独的行中显示?(每行4个字)
Line1: the heart was made
Line2: to be broken
Run Code Online (Sandbox Code Playgroud)
有什么建议?