public static Map < String , Double > readIdfs ( BufferedReader reader , int N ) throws IOException { HashMap < String , Double > idfs = new HashMap < String , Double > ( ) ; String nextLine ; while ( ( ( nextLine = reader . readLine ( ) ) != null ) ) { String [ ] parts = nextLine . split ( "\\t+" ) ; checkArgument ( parts . length >= 2 ) ; Double df = Double . parseDouble ( parts [ 1 ] ) ; idfs . put ( parts [ 0 ] , Math . log ( 1.0 + N / df ) ) ; // idf } return idfs ; }
Computes inverse document frequencies as a map of Strings to Doubles from a tab separated file of term document frequencies .