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

Given an article, design an algorithm in pseudo code to find the top 150 most fr

ID: 3839326 • Letter: G

Question

Given an article, design an algorithm in pseudo code to find the top 150 most frequently co-occurring word-pairs in the article. Two words are said to co-occur if they appear in the same sentence. For example, the sentence, “It’s really a milestone in Chinese science fiction.” contain the following word pairs:

('It's', 'really')

('It's', 'a')

('It's', 'milestone')

('It's', 'in')

('It's', 'Chinese')

('It's', 'science')

('It's', 'fiction')

('really', 'a')

('really', 'milestone')

('really', 'in')

('really', 'Chinese')

('really', 'science')

('really', 'fiction')

('a', 'milestone')

('a', 'in')

('a', 'Chinese')

('a', 'science')

('a', 'fiction')

('milestone', 'in')

('milestone', 'Chinese')

('milestone', 'science')

('milestone', 'fiction')

('in', 'Chinese')

('in', 'science')

('in', 'fiction')

('Chinese', 'science')

('Chinese', 'fiction')

('science', 'fiction')

you can assume you have access to a subroutine, sentenceSplitter(article), that can accurately segment an article into separate sentences and return these sentences in an array-like structure.

You can also assume that you have access to another routine tokenizer( sentence), that can accurately identify the individual words contained in the input sentence and return these words in another array-like data structure.

Please describe rhe algorithm unambiguously using pseudo code with necessary comments in English.

Explanation / Answer

import java.io.*;

import java.util.*;

public class WordInFile {

           public static void main(String[] args) {

                ArrayList<ArrayList<String>> lines = new ArrayList<ArrayList<String>>();

        Scanner reader = new Scanner(System.in);       

System.out.println("What is the file to read from?");

        String infileName = reader.nextLine().trim();

           Scanner inputFile = null;

        try {

            inputFile = new Scanner(new File(infileName));

        } catch (FileNotFoundException ex) {

            System.out.println("Error opening the file " + infileName + " for reading");

            System.exit(0);

        }

                     while(inputFile.hasNextLine()){

            String line = inputFile.nextLine();

            ArrayList<String> wordsInLine = new ArrayList<String>();

lines.add(wordsInLine);

        Scanner lineScanner = new Scanner(line);

            while(lineScanner.hasNext()){

                String word = lineScanner.next();

                wordsInLine.add(word);

            }

        }

                inputFile.close();

                System.out.println("Please enter the line number and word number (the first line is 1).");

        int lineNumber = reader.nextInt();

        int wordNumber = reader.nextInt();

                ArrayList<String> theLine = lines.get(lineNumber-1);

        if(theLine == null){

            System.out.println("Sorry, that line does not exist.");

        } else {

            String theWord = theLine.get(wordNumber-1);

            if(theWord == null){

                System.out.println("Sorry, that line does not have that many words.");

            }

            else {

                System.out.println("The word is: " + theWord);

            }

        }      

    }

}

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