In: Computer Science
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.
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();
}
}