Kesimpulan Saran BAB V

106 BufferedReader bufferedReader = new BufferedReadernew FileReaderfileLocation; while line = bufferedReader.readLine = null { StringTokenizer stringTokenizer = new StringTokenizerline; token = new ArrayList; while stringTokenizer.hasMoreTokens { String nextToken = stringTokenizer.nextToken; nextToken = nextToken.toLowerCase; for String lbl : label { if lbl.equalsIgnoreCasenextToken { nextToken = ; } } for String thisnoise : noise { if thisnoise.equalsIgnoreCasenextToken { nextToken = ; } } if nextToken.length 2 { nextToken = nextToken.replaceAllHASHTAG, nextToken.substring1; nextToken = nextToken.replaceAllHASHTAG, ; } nextToken = nextToken.replaceAllURL, ; nextToken = nextToken.replaceAllUSERNAME, ; nextToken = nextToken.replaceAllSTARTS_WITH_NUMBER, ; nextToken = nextToken.replaceAllCONSECUTIVE_CHAR, 1; nextToken = nextToken.replaceAllNUMBER, ; nextToken = nextToken.replaceAllNON_WORD, ; if nextToken.length = 2 { if nextToken.contains { String[] temp = nextToken.split ; token.addAllArrays.asListtemp; token.remove; } else { token.addnextToken; } } } if token.size 1 { map.putj, token; j++; } } return map; } } 107

2. RemoveStopword.java

package sentimentanalysis; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.StringTokenizer; public class RemoveStopword { private LinkedHashMapInteger, ArrayListString map; private ArrayListString stopWordsList; private final String fileLocation; public RemoveStopwordString location throws IOException { this.fileLocation = location; loadStopWords; System.out.printlnstopWordsList; } public LinkedHashMap getWordsHashMap throws IOException { for int key : map.keySet { ArrayListString list = map.getkey; ArrayListString helper = new ArrayList; for int i = 0; i stopWordsList.size; i++ { if list.containsstopWordsList.geti { helper.addstopWordsList.geti; } } 108 list.removeAllhelper; map.putkey, list; } return map; } public ArrayList loadStopWords throws FileNotFoundException, IOException { String words = ; String line; BufferedReader bufferedReader = new BufferedReadernew FileReaderfileLocation; while line = bufferedReader.readLine = null { words += line + \n; } StringTokenizer stringTokenizer = new StringTokenizerwords; stopWordsList = new ArrayList; int i = 0; while stringTokenizer.hasMoreTokens { String nextToken = stringTokenizer.nextToken.toLowerCase; if stopWordsList.containsnextToken { stopWordsList.addi, nextToken; i++; } } return stopWordsList; } public void setWordsHashMapLinkedHashMap allToken { this.map = allToken; } 109 }

3. Stemming.java

package sentimentanalysis; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.; public class Stemming { private String word, originalWord; private ArrayListString dictionary; private TreeMapString, String synonym; private final String dictLocation, synLocation; public StemmingString location1, String location2 throws IOException { this.dictLocation = location1; this.synLocation = location2; loadDictionary; loadSynonym; } public LinkedHashMap stemLinkedHashMapInteger, ArrayListString map { ArrayListString helper; for int key : map.keySet { helper = map.getkey; for int i = 0; i helper.size; i++ { setWordhelper.geti; String stem = getStemWord; 110 String stem2 = getSynonymstem; helper.seti, stem2; } map.putkey, helper; } return map; } public final ArrayList loadDictionary throws FileNotFoundException, IOException { String words = ; String line; BufferedReader bufferedReader = new BufferedReadernew FileReaderdictLocation; while line = bufferedReader.readLine = null { words += line + \n; } StringTokenizer stringTokenizer = new StringTokenizerwords; dictionary = new ArrayList; int i = 0; while stringTokenizer.hasMoreTokens { String nextToken = stringTokenizer.nextToken; dictionary.addi, nextToken.toLowerCase; i++; } return dictionary; } public final TreeMap loadSynonym throws FileNotFoundException, IOException { String line; synonym = new TreeMap; 111 BufferedReader bufferedReader = new BufferedReadernew FileReadersynLocation; String delimiter = ,; while line = bufferedReader.readLine = null { if line.equals { continue; } String[] strData = line.splitdelimiter; for int i = 1; i strData.length; i++ { synonym.putstrData[i], strData[0]; } } return synonym; } public String getStemWord { word = deleteReduplicate; word = deleteSuffix; if dictionary.containsword { word = originalWord; word = deletePrefix; word = deleteSuffix; word = deletePrefix; if dictionary.containsword { word = originalWord; } } return word; } private String getSynonymString w { if synonym.containsKeyw { word = synonym.getw; return word; 112 } else { return w; } } public void setWordString word { this.word = word; originalWord = word; } private String deletePrefix { try { if dictionary.containsword { if word.startsWithdi { word = word.substring2; } else if word.startsWithke { word = word.substring2; } else if word.startsWithse { word = word.substring2; } else if word.startsWithku { word = word.substring2; } } if dictionary.containsword { if word.startsWithber { if dictionary.containsword.substring3 { word = word.substring3; } else if dictionary.containsword.substring2 { word = word.substring2; } } if word.startsWithbel { if dictionary.containsword.substring3 {