public static Map<String, Integer> loadUnrankedDictionary(final String fileName)
    {
        Map<String, Integer> unranked = new HashMap<>();
        Set<String> unranked_set = new HashSet<>();

        String path = "/dictionaries/" + fileName;
        try (InputStream is = DictionaryUtil.class.getResourceAsStream(path);
             BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8")))
        {
            String line;
            int i = 0;
            while ((line = br.readLine()) != null)
            {
                unranked_set.add(line);
                i++;
            }

            i = i / 2;

            for (String value : unranked_set)
            {
                unranked.put(value, i);
            }
        }
        catch (IOException e)
        {
            System.out.println("Error while reading " + fileName);
        }

        return unranked;
    }
public static Map < String , Integer > loadUnrankedDictionary ( final String fileName ) { Map < String , Integer > unranked = new HashMap < > ( ) ; Set < String > unranked_set = new HashSet < > ( ) ; String path = "/dictionaries/" + fileName ; try ( InputStream is = DictionaryUtil . class . getResourceAsStream ( path ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( is , "UTF-8" ) ) ) { String line ; int i = 0 ; while ( ( line = br . readLine ( ) ) != null ) { unranked_set . add ( line ) ; i ++ ; } i = i / 2 ; for ( String value : unranked_set ) { unranked . put ( value , i ) ; } } catch ( IOException e ) { System . out . println ( "Error while reading " + fileName ) ; } return unranked ; }
Read a resource file with a list of entries (sorted by frequency) and use
it to create a ranked dictionary.
<p>
The dictionary must contain only lower case values for the matching to work properly.

@param fileName the name of the file
@return the ranked dictionary (a {@code HashMap} which associated a
rank to each entry