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",...
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...
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...
Class Design – IntList (A.k.a. ArrayList (v0.0)) Let’s build a useful class that wraps up an...
Class Design – IntList (A.k.a. ArrayList (v0.0)) Let’s build a useful class that wraps up an array of integers. This class will store two data items; one an array of integers, and the other a counter to track the number of actual elements in the list. Start by defining a new class called IntList and copying the main driver code included below or in IntList.java. Then, add each of the following functions and data items indicated in the member sections....
Implement a class named Parade using an ArrayList, which will manage instances of class Clown. Each...
Implement a class named Parade using an ArrayList, which will manage instances of class Clown. Each Clown only needs to be identified by a String for her/his name. Always join a new Clown to the end of the Parade. Only the Clown at the head of the Parade (the first one) can leave the Parade. Create a test application to demonstrate building a parade of 3 or 4 clowns (include your own name), then removing 1 or 2, then adding...
import java.util.Stack; import java.util.ArrayList; import java.util.Scanner; class TreeNode{ int data; ArrayList<TreeNode> children = new ArrayList<>(); TreeNode...
import java.util.Stack; import java.util.ArrayList; import java.util.Scanner; class TreeNode{ int data; ArrayList<TreeNode> children = new ArrayList<>(); TreeNode parent = null;    public TreeNode(int d){ data = d; }    public TreeNode addChild(int d){ TreeNode n = new TreeNode(d); n.setParent(this); children.add(n); return n; }    public ArrayList<TreeNode> getChildren(){ return children; }    public void setParent(TreeNode p){ parent = p; }    public TreeNode getParent(){ return parent; } } class Main { public static void main(String[] args)    {        Scanner scan...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT