Question

In: Computer Science

Develop the getSuggestions(ArrayList wordCountList) method as the base method of the class. Develop the countWords(ArrayList wordList)...

Develop the getSuggestions(ArrayList wordCountList) method as the base method of the class.

Develop the countWords(ArrayList wordList) method to find the frequencies of all words in the text file.

Develop the getWordList(File[] fileArray) method to get all words in the text file. Ignore the words that have 3 or less characters.

Your customer wants you to develop a method that will find the sentences that contain a specific word. This is basically a word search, but your customer needs the list of the full sentence which has the search term. They are planning to use this method for sentiment analysis, which involves computationally identifying and categorizing opinions expressed in a piece of text.

They are planning to search the web (tweets, blogs, social media, and so on) for user opinions about a specific product or situation. Once they get the sentence with the search word in it, they will evaluate the attitude of the user using the whole sentence.

Solutions

Expert Solution

public class WordCounter {

private String word;
private int counter;
  
public WordCounter(String word) {
super();
this.word = word;
counter = 1;
}
  
public WordCounter(String word, int counter) {
super();
this.word = word;
this.counter = counter;
}

public String getWord() {
return word;
}

public int getCounter() {
return counter;
}
  
public void count() {
counter++;
}
}

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;
import javax.swing.JFileChooser;
import javax.swing.JFrame;

public class WordSuggestions {
  
/**
*
* @return
*
* @throws IOException
*/
public ArrayList<WordCounter> getWordFrequencies() throws IOException {
//Choose Files

//Read words in Files

//Count   
  
//sort   
  
return null;   
}
  
/**
*
* @param wordCountList
*
* @return
*
* @throws IOException
*/
public ArrayList<String[]> getSuggestions(ArrayList<WordCounter> wordCountList) throws IOException {
  
return null;   
}


/**
*
* @param wordList
*
* @return
*/
public ArrayList<WordCounter> countWords(ArrayList<String> wordList) {
  
  
return null;
}

/**
*
* @param fileArray
*
* @return
*
* @throws IOException
*/
public ArrayList<String> getWordList(File[] fileArray) throws IOException {

return null;
}

/**
*
* @return
*/
public File[] getFiles() {
  
return null;
}

/**This method checks if P exists in T
*
* @param P Pattern to match
* @param T Text to search
*
* @return true if P exists in T
*/
public boolean badCharacterRuleMatch(String P, String T) {
  
int n = T.length();
int m = P.length();

  
int e = 256;
int left[][] = new int[m][e];
  
for (int i = 0; i < m; i++)
for (int j = 0; j < e; j++)
left[i][j] = -1;
  
for (int i = 0; i < m; i++) {
if (i != 0)
for (int j = 0; j < e; j++)
left[i][j] = left[i - 1][j];
left[i][P.charAt(i)] = i;
}

  
boolean hasMatch = false;

int skip;
for (int i = 0; i < n - m + 1; i += skip) {
skip = 0;
for (int j = m - 1; j >= 0; j--) {
if (P.charAt(j) != T.charAt(i + j)) {
skip = Math.max(1, j - left[j][T.charAt(i + j)]);
break;
}
}
  
if (skip == 0) {
hasMatch = true;
break;
}
}
return hasMatch;
}

/**
* main() method stub
*/
public static void main(String args[]) {
WordSuggestions ws;
ws = new WordSuggestions();
ws.getFiles();
}

}


Related Solutions

Create a PoemDriver.java class with a main method. In the main method, create an ArrayList of...
Create a PoemDriver.java class with a main method. In the main method, create an ArrayList of Poem objects, read in the information from PoemInfo.txt and create Poem objects to populate the ArrayList. After all data from the file is read in and the Poem objects added to the ArrayList- print the contents of the ArrayList. Paste your PoemDriver.java text (CtrlC to copy, CtrlV to paste) into the open space before. You should not change Poem.java or PoemInfo.txt. Watch your time...
Method: ArrayList<Integer> diff(ArrayList<Integer> list1, ArrayList<Integer> list2) diff() method accepts two ArrayLists of Integer and returns the...
Method: ArrayList<Integer> diff(ArrayList<Integer> list1, ArrayList<Integer> list2) diff() method accepts two ArrayLists of Integer and returns the union of elements in two lists. For example: list1 contains elements [1, 2, 3, 4, 5] list2 contains elements [3, 4, 5, 6, 7] Diff() method should return an array list with elements [1, 2, 3, 4, 5, 6, 7].
We have created an ArrayList of Person class. write a method called push that pushes all...
We have created an ArrayList of Person class. write a method called push that pushes all the people with the even length last name to the end of the ArrayList Content of the ArrayList before push [alex Bus, Mary Phillips, Nik Lambard, Rose Rodd, Esa khan, Jose Martinex, Nik Patte] content of the ArrayList after the push method [alex Bus, Nik Lambard, Nik Patte, Mary Phillips, Rose Rodd, Esa khan, Jose Martinex] import java.util.*; class Person { private String name;...
Find a method of ArrayList that is not in the List interface, specifically a method that...
Find a method of ArrayList that is not in the List interface, specifically a method that trims the internal array down to fit exactly. A Google search for this did work, but the JDK API of course is the definitive source. Give the method header for the method. Add a call to this method to TestArrayList.java (which is available online in TestArrayList.zip), and see that it compiles and runs fine. Now change the line creating the ArrayList to use type...
Make a class called CashRegister that has the method public static double getTotalCostOfOfferings(ArrayList<Offering> o) Make this...
Make a class called CashRegister that has the method public static double getTotalCostOfOfferings(ArrayList<Offering> o) Make this method calculate the total cost of all Offering objects in the ArrayList. Submit Product, Service, and CashRegister. Given Files: import java.util.ArrayList; public class Demo3 { public static void crunch(ArrayList<Offering> o) { System.out.println("Adding up the following offerings:"); for (Offering current : o) { System.out.println(current); } System.out.printf("Total for all: $%,.2f\n", CashRegister.getTotalCostOfOfferings(o)); System.out.println("---------------------------------\n"); } public static void main(String[] args) { ArrayList<Offering> offeringList = new ArrayList<>(); offeringList.add(new Product("iPhone",...
import java.util.*; class Main { static ArrayList<String> list; public static List<String> createList(ArrayList<String> arrayList) { list =...
import java.util.*; class Main { static ArrayList<String> list; public static List<String> createList(ArrayList<String> arrayList) { list = arrayList; return list; } public static void printList(ArrayList<String> arrayList) { System.out.println("Printing in 4 ways\n"); // 1 System.out.println(arrayList); //2 for(String s:arrayList) System.out.print(s+" "); System.out.println(); //3 System.out.println(Arrays.deepToString(list.toArray())); //4 for(int i=0;i<arrayList.size();i++) System.out.print(arrayList.get(i)+" "); System.out.println(); } public static void filterList(ArrayList<String> arrayList) { System.out.println("Filtered in 2 ways\n"); ArrayList<String> copyArrayList = arrayList; //1 for(int i=0;i<arrayList.size();i++) { if(arrayList.get(i).contains("chuck")) { arrayList.remove(i); i--; } } System.out.println(arrayList); //2 copyArrayList.removeIf(str -> str.contains("chunk")); System.out.println(copyArrayList); }   ...
***Given a class called Student and a class called Course that contains an ArrayList of Student....
***Given a class called Student and a class called Course that contains an ArrayList of Student. Write a method called dropStudent() as described below. Refer to Student.java below to learn what methods are available.*** Course.java import java.util.*; import java.io.*; /****************************************************** * A list of students in a course *****************************************************/ public class Course{ /** collection of Students */ private ArrayList<Student> roster; /***************************************************** Constructor for objects of class Course *****************************************************/ public Course(){ roster = new ArrayList<Student>(); } /***************************************************** Remove student with the...
class Company uses an ArrayList of class Employee to manage its employees. Your job is to...
class Company uses an ArrayList of class Employee to manage its employees. Your job is to create two classes , Company and Employee, with appropriate instance fields, constructors, and methods as been described in the set of questions that follows . A sample use case of the classes is shown below: public class CompanyTester{ public static void main(String[] args){ Company myCompany = new Company(); myCompany.add( new Employee("james","gasling")); myCompany.add( new Employee("bill","gate")); myCompany.add( new Employee("dennis","ritchie")); System.out.println(myCompany); } } The sample output of...
Let's try to develop a C++ Reverse Polish Notation (RPN) calculator! Create a base class called...
Let's try to develop a C++ Reverse Polish Notation (RPN) calculator! Create a base class called Operand Give it a virtual destructor to avoid any weird problems later on! Derive a class called Number from Operand Maintain a double member variable in class Number For simplicity, you may make the member variable public if you would like Derive a class called Operator from Operand Derive a class called Add from Operator (2 + 3 = 5) Derive a class called...
Step 4: Create a class called BabyNamesDatabase This class maintains an ArrayList of BabyName objects. Instance...
Step 4: Create a class called BabyNamesDatabase This class maintains an ArrayList of BabyName objects. Instance Variables Declare an ArrayList of BabyName objects. Constructor public BabyNamesDatabase () - instantiate the ArrayList of BabyName objects. You will not insert the items yet. This method will be one line of code. Mutator Methods public void readBabyNameData(String filename) - open the provided filename given as input parameter, use a loop to read all the data in the file, create a BabyName object for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT