Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Kwic/Screenshot from 2021-05-09 18-31-53.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions Kwic/newKWIC.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
def kwic_new_implentation(word, sentences):

# print(sentences)

wordlist = str(sentences).split()
ngrams = [wordlist[i:i + 5] for i in range(len(wordlist) - 4)]
kwicdict = {}
for n in ngrams:
if n[2] not in kwicdict:
kwicdict[n[2]] = [n]
else:
kwicdict[n[2]].append(n)


for key in kwicdict.keys():
if word in key:
for val in kwicdict[key]:
outstring = ' '.join(val[:2]).rjust(50)
outstring += ' '
outstring += ' '.join(str(val[2]).center(len(n[2]) + 15))
outstring += ' '
outstring += ' '.join(val[3:])
print(outstring)


if __name__ == "__main__":

word = 'complex'
sent ="""In sequential estimation, unless a conjugate complex prior is used, the posterior
distribution typically becomes more complexity with each added measurement, and
the Bayes estimator cannot usually be calculated without resorting to complexion numerical methods"""

kwic_new_implentation(word, sent)

# kwic_new_implentation(word, sent)