Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given an article such as this one at nytimes.com, design an algorithm to find th

ID: 3676628 • Letter: G

Question

Given an article such as this one at nytimes.com, design an algorithm to find the most frequently co-occurring word-pair in this article. Two words are said to co-occur if they appear in the same sentence. If the words appear multiple times in a single sentence, that still counts as one co-occurrence. You can assume you have access to a subroutine, sentenceSplitter(article), that can accurately segment an article into separate sentences. You can also assume you have access to a subroutine called wordSplitter(sentence) that can accurately split a sentence into words. Please describe your algorithm unambiguously using pseudo code with necessary comments in English. Assume you start with an "article" variable that already contains the full text of an article.

Explanation / Answer

In any language .. this problem solves in similar fashion.

Firstly we have to get all possible pairs and then make each pair count to 1
In next iteration, check for each pair in the all lines and count their occurences and store their count.
Finally sort thrm and get the most frequent word pair.

Here is the pseudocode:
------------------------
def wordSplitter(article):
copair_count = Counter()
for eachline in article:
messageTokens = sorted(set(eachline)) # it will exclude repeated words in same line
wordPairs = combinations(messageTokens, 2) #it will pair all combinations of words
copair_count += Counter(wordPairs) #it will store counts of cowords occur in text
return copair_count #return results..

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote