public Map < String , List < String > > loadWords ( String path ) { InputStream stream = JLanguageTool . getDataBroker ( ) . getFromRulesDirAsStream ( path ) ; Map < String , List < String > > map = new HashMap <> ( ) ; try ( Scanner scanner = new Scanner ( stream , "utf-8" ) ) { while ( scanner . hasNextLine ( ) ) { String line = scanner . nextLine ( ) ; if ( line . isEmpty ( ) || line . charAt ( 0 ) == ' ' ) { // # = comment continue ; } String [ ] parts = line . split ( "=" ) ; if ( parts . length != 2 ) { throw new RuntimeException ( "Could not load simple replacement data from: " + path + ". " + "Error in line '" + line + "', expected format 'word=replacement'" ) ; } String [ ] wrongForms = parts [ 0 ] . split ( "\\|" ) ; List < String > replacements = Arrays . asList ( parts [ 1 ] . split ( "\\|" ) ) ; for ( String wrongForm : wrongForms ) { map . put ( wrongForm , replacements ) ; } } } return Collections . unmodifiableMap ( map ) ; }
Load replacement rules from a utf - 8 file in the classpath .