This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package com.milind.word.to.pdf; | |
import com.itextpdf.text.Chunk; | |
import com.itextpdf.text.Document; | |
import com.itextpdf.text.DocumentException; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.milind.twitter.trends; | |
import java.io.IOException; | |
import twitter4j.Trend; | |
import twitter4j.Trends; | |
import twitter4j.Twitter; | |
import twitter4j.TwitterException; | |
import twitter4j.TwitterFactory; | |
import twitter4j.conf.ConfigurationBuilder; |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static List<String> getNegativeWords() throws IOException { | |
List<String> outputList = new ArrayList<String>(); | |
BufferedReader br = new BufferedReader(new FileReader( | |
"C:\\negative-words.txt")); | |
String line = null; | |
while ((line = br.readLine()) != null) { | |
outputList.add(line); | |
} | |
br.close(); | |
return outputList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static List<String> getPositiveWords() throws IOException { | |
List<String> outputList = new ArrayList<String>(); | |
BufferedReader br = new BufferedReader(new FileReader( | |
"C:\\positive-words.txt")); | |
String line = null; | |
while ((line = br.readLine()) != null) { | |
outputList.add(line); | |
} | |
br.close(); | |
return outputList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static List<String> getPeople(String sentence) { | |
TokenNameFinderModel model = null; | |
try { | |
model = new TokenNameFinderModel(new File("C:\\en-ner-person.bin")); | |
} catch (InvalidFormatException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
NameFinderME finder = new NameFinderME(model); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int getNumberOfSentences(SentenceModel sentenceModel, | |
String input) throws IOException { | |
SentenceDetectorME detector = new SentenceDetectorME(sentenceModel); | |
String sentences[] = detector.sentDetect(input); | |
return sentences.length; | |
} | |
String[] inputFilePathArray = new String[4]; | |
inputFilePathArray[0] = "C:\\input1.txt"; | |
inputFilePathArray[1] = "C:\\input2.txt"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int classifyNewText(DoccatModel sentimentModel, String input) | |
throws IOException { | |
DocumentCategorizerME myCategorizer = new DocumentCategorizerME( | |
sentimentModel); | |
double[] outcomes = myCategorizer.categorize(input); | |
return Integer.parseInt(myCategorizer.getBestCategory(outcomes)); | |
} | |
String[] inputFilePathArray = new String[4]; | |
inputFilePathArray[0] = "C:\\input1.txt"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static LinkedHashMap<String, Integer> sortHashMapByValues( | |
Map<String, Integer> wordCountMap) { | |
List<String> mapKeys = new ArrayList<String>(wordCountMap.keySet()); | |
List<Integer> mapValues = new ArrayList<Integer>(wordCountMap.values()); | |
Collections.sort(mapValues, Collections.reverseOrder()); | |
Collections.sort(mapKeys); | |
LinkedHashMap<String, Integer> sortedMap = new LinkedHashMap<String, Integer>(); | |
Iterator<Integer> valueIt = mapValues.iterator(); | |
while (valueIt.hasNext()) { | |
Integer val = valueIt.next(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Map<String, Integer> wordCountMap = new HashMap<String, Integer>(); | |
String[] inputFilePathArray = new String[4]; | |
inputFilePathArray[0] = "C:\\input1.txt"; | |
inputFilePathArray[1] = "C:\\input2.txt"; | |
inputFilePathArray[2] = "C:\\input3.txt"; | |
inputFilePathArray[3] = "C:\\input4.txt"; | |
for (String inputFilePath : inputFilePathArray) { | |
BufferedReader br = new BufferedReader( | |
new FileReader(inputFilePath)); | |
String line = null, mapKey = null; |
NewerOlder