本文整理汇总了Python中nltk.corpus.PlaintextCorpusReader.concordance方法的典型用法代码示例。如果您正苦于以下问题:Python PlaintextCorpusReader.concordance方法的具体用法?Python PlaintextCorpusReader.concordance怎么用?Python PlaintextCorpusReader.concordance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nltk.corpus.PlaintextCorpusReader
的用法示例。
在下文中一共展示了PlaintextCorpusReader.concordance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: raw_input
# 需要导入模块: from nltk.corpus import PlaintextCorpusReader [as 别名]
# 或者: from nltk.corpus.PlaintextCorpusReader import concordance [as 别名]
#file_name = sys.argv[1]
#search_word = sys.argv[2]
file_name = raw_input("\nChoose one of these files: ")
print "\nThe file that will be examined is {0}".format(file_name)
from nltk.corpus import PlaintextCorpusReader
corpus_root = '.'
search_text = PlaintextCorpusReader(corpus_root,file_name)
search_text = nltk.Text(search_text.words())
# KWIC concordance
search_word = raw_input("Specify a search word for a keyword in context concordance list: ")
search_text.concordance(search_word,80,lines=1000)
# Apply stopwords to search_text
from nltk.corpus import stopwords
stopwords = nltk.corpus.stopwords.words('bible')
#/Users/barrybandstra/nltk_data/corpora/stopwords
search_text = [word for word in search_text if word.lower() not in stopwords]
# Write search to output.txt file"
output_file = open("output.txt", "w")
for line in search_text:
output_file.write(line),"\n"
output_file.close()
# Frequency distribution vocabulary list; fd is a dictionary
fd = nltk.FreqDist(search_text)
示例2: PlaintextCorpusReader
# 需要导入模块: from nltk.corpus import PlaintextCorpusReader [as 别名]
# 或者: from nltk.corpus.PlaintextCorpusReader import concordance [as 别名]
wordlists = PlaintextCorpusReader(curr_dir, '/ASOIAF/*.txt')
wordlists = PlaintextCorpusReader(curr_dir+'/ASOIAF/', *.txt')
wordlists = PlaintextCorpusReader(curr_dir+'/ASOIAF/', '*.txt')
curr_dir = os.system('ls '+curr_dir+'/ASOIAF/')
os.system('ls '+curr_dir+'/ASOIAF/')
wordlists = PlaintextCorpusReader(curr_dir+'/ASOIAF/', '*.txt')
os.system("ls "+curr_dir)
os.system("ls "+curr_dir.str())
curr_dir
os.path.dirname(os.path.realpath(__file__))
os.getcwd()
curr_dir = os.getcwd()
os.system("ls "+curr_dir)
wordlists = PlaintextCorpusReader(curr_dir+'/ASOIAF/', '*.txt')
os.system("ls "+curr_dir+'/ASOIAF/', '*.txt')
os.system("ls "+curr_dir+'/ASOIAF/')
os.system("ls "+curr_dir+'/ASOIAF/')
wordlists = PlaintextCorpusReader(curr_dir+'/ASOIAF/', '*.txt')
wordlists = PlaintextCorpusReader(curr_dir+'/ASOIAF/', '.*\.txt')
wordlist
wordlists
wordlists.words()
wordlists.concordance("Arya")
wordlists.fileids()
#
# Can also import bracket parse corpora (penn tree bank)
get_ipython().magic('save -f january_26_2016.py 0 - *')
get_ipython().magic('save -f january_26_2016.py')
get_ipython().magic('save -f january_23_2016.py 0-*')
get_ipython().magic('save january_26_2016.py 0-1000000')
示例3: raw_input
# 需要导入模块: from nltk.corpus import PlaintextCorpusReader [as 别名]
# 或者: from nltk.corpus.PlaintextCorpusReader import concordance [as 别名]
import nltk
import os
# Retrieve a file list
files = os.listdir('.')
print "All the files in the directory:"
for file in files:
if file.endswith('.txt'):
print file
file_name = raw_input("Choose a file: ")
print "The file that was chosen is {0}".format(file_name)
from nltk.corpus import PlaintextCorpusReader
corpus_root = "."
search_text = PlaintextCorpusReader(corpus_root,file_name)
search_text = nltk.Text(search_text.words())
keyword = raw_input("Specify a search term: ")
search_text.concordance(keyword,80,lines=30)