private void readAffixFile(InputStream affixStream,CharsetDecoder decoder) throws IOException, ParseException {
  TreeMap<String,List<Integer>> prefixes=new TreeMap<>();
  TreeMap<String,List<Integer>> suffixes=new TreeMap<>();
  Map<String,Integer> seenPatterns=new HashMap<>();
  seenPatterns.put(".*",0);
  patterns.add(null);
  Map<String,Integer> seenStrips=new LinkedHashMap<>();
  seenStrips.put("",0);
  LineNumberReader reader=new LineNumberReader(new InputStreamReader(affixStream,decoder));
  String line=null;
  while ((line=reader.readLine()) != null) {
    if (reader.getLineNumber() == 1 && line.startsWith("\uFEFF")) {
      line=line.substring(1);
    }
    if (line.startsWith(ALIAS_KEY)) {
      parseAlias(line);
    }
 else     if (line.startsWith(MORPH_ALIAS_KEY)) {
      parseMorphAlias(line);
    }
 else     if (line.startsWith(PREFIX_KEY)) {
      parseAffix(prefixes,line,reader,PREFIX_CONDITION_REGEX_PATTERN,seenPatterns,seenStrips);
    }
 else     if (line.startsWith(SUFFIX_KEY)) {
      parseAffix(suffixes,line,reader,SUFFIX_CONDITION_REGEX_PATTERN,seenPatterns,seenStrips);
    }
 else     if (line.startsWith(FLAG_KEY)) {
      flagParsingStrategy=getFlagParsingStrategy(line);
    }
 else     if (line.equals(COMPLEXPREFIXES_KEY)) {
      complexPrefixes=true;
    }
 else     if (line.startsWith(CIRCUMFIX_KEY)) {
      String parts[]=line.split("\\s+");
      if (parts.length != 2) {
        throw new ParseException("Illegal CIRCUMFIX declaration",reader.getLineNumber());
      }
      circumfix=flagParsingStrategy.parseFlag(parts[1]);
    }
 else     if (line.startsWith(KEEPCASE_KEY)) {
      String parts[]=line.split("\\s+");
      if (parts.length != 2) {
        throw new ParseException("Illegal KEEPCASE declaration",reader.getLineNumber());
      }
      keepcase=flagParsingStrategy.parseFlag(parts[1]);
    }
 else     if (line.startsWith(NEEDAFFIX_KEY) || line.startsWith(PSEUDOROOT_KEY)) {
      String parts[]=line.split("\\s+");
      if (parts.length != 2) {
        throw new ParseException("Illegal NEEDAFFIX declaration",reader.getLineNumber());
      }
      needaffix=flagParsingStrategy.parseFlag(parts[1]);
    }
 else     if (line.startsWith(ONLYINCOMPOUND_KEY)) {
      String parts[]=line.split("\\s+");
      if (parts.length != 2) {
        throw new ParseException("Illegal ONLYINCOMPOUND declaration",reader.getLineNumber());
      }
      onlyincompound=flagParsingStrategy.parseFlag(parts[1]);
    }
 else     if (line.startsWith(IGNORE_KEY)) {
      String parts[]=line.split("\\s+");
      if (parts.length != 2) {
        throw new ParseException("Illegal IGNORE declaration",reader.getLineNumber());
      }
      ignore=parts[1].toCharArray();
      Arrays.sort(ignore);
      needsInputCleaning=true;
    }
 else     if (line.startsWith(ICONV_KEY) || line.startsWith(OCONV_KEY)) {
      String parts[]=line.split("\\s+");
      String type=parts[0];
      if (parts.length != 2) {
        throw new ParseException("Illegal " + type + " declaration",reader.getLineNumber());
      }
      int num=Integer.parseInt(parts[1]);
      FST<CharsRef> res=parseConversions(reader,num);
      if (type.equals("ICONV")) {
        iconv=res;
        needsInputCleaning|=iconv != null;
      }
 else {
        oconv=res;
        needsOutputCleaning|=oconv != null;
      }
    }
 else     if (line.startsWith(FULLSTRIP_KEY)) {
      fullStrip=true;
    }
 else     if (line.startsWith(LANG_KEY)) {
      language=line.substring(LANG_KEY.length()).trim();
      alternateCasing="tr_TR".equals(language) || "az_AZ".equals(language);
    }
  }
  this.prefixes=affixFST(prefixes);
  this.suffixes=affixFST(suffixes);
  int totalChars=0;
  for (  String strip : seenStrips.keySet()) {
    totalChars+=strip.length();
  }
  stripData=new char[totalChars];
  stripOffsets=new int[seenStrips.size() + 1];
  int currentOffset=0;
  int currentIndex=0;
  for (  String strip : seenStrips.keySet()) {
    stripOffsets[currentIndex++]=currentOffset;
    strip.getChars(0,strip.length(),stripData,currentOffset);
    currentOffset+=strip.length();
  }
  assert currentIndex == seenStrips.size();
  stripOffsets[currentIndex]=currentOffset;
}

private void readAffixFile ( InputStream affixStream , CharsetDecoder decoder ) throws IOException , ParseException { TreeMap < String , List < Integer > > prefixes = new TreeMap < > ( ) ; TreeMap < String , List < Integer > > suffixes = new TreeMap < > ( ) ; Map < String , Integer > seenPatterns = new HashMap < > ( ) ; seenPatterns . put ( ".*" , 0 ) ; patterns . add ( null ) ; Map < String , Integer > seenStrips = new LinkedHashMap < > ( ) ; seenStrips . put ( "" , 0 ) ; LineNumberReader reader = new LineNumberReader ( new InputStreamReader ( affixStream , decoder ) ) ; String line = null ; while ( ( line = reader . readLine ( ) ) != null ) { if ( reader . getLineNumber ( ) == 1 && line . startsWith ( "﻿" ) ) { line = line . substring ( 1 ) ; } if ( line . startsWith ( ALIAS_KEY ) ) { parseAlias ( line ) ; } else if ( line . startsWith ( MORPH_ALIAS_KEY ) ) { parseMorphAlias ( line ) ; } else if ( line . startsWith ( PREFIX_KEY ) ) { parseAffix ( prefixes , line , reader , PREFIX_CONDITION_REGEX_PATTERN , seenPatterns , seenStrips ) ; } else if ( line . startsWith ( SUFFIX_KEY ) ) { parseAffix ( suffixes , line , reader , SUFFIX_CONDITION_REGEX_PATTERN , seenPatterns , seenStrips ) ; } else if ( line . startsWith ( FLAG_KEY ) ) { flagParsingStrategy = getFlagParsingStrategy ( line ) ; } else if ( line . equals ( COMPLEXPREFIXES_KEY ) ) { complexPrefixes = true ; } else if ( line . startsWith ( CIRCUMFIX_KEY ) ) { String parts [ ] = line . split ( "\\s+" ) ; if ( parts . length != 2 ) { throw new ParseException ( "Illegal CIRCUMFIX declaration" , reader . getLineNumber ( ) ) ; } circumfix = flagParsingStrategy . parseFlag ( parts [ 1 ] ) ; } else if ( line . startsWith ( KEEPCASE_KEY ) ) { String parts [ ] = line . split ( "\\s+" ) ; if ( parts . length != 2 ) { throw new ParseException ( "Illegal KEEPCASE declaration" , reader . getLineNumber ( ) ) ; } keepcase = flagParsingStrategy . parseFlag ( parts [ 1 ] ) ; } else if ( line . startsWith ( NEEDAFFIX_KEY ) || line . startsWith ( PSEUDOROOT_KEY ) ) { String parts [ ] = line . split ( "\\s+" ) ; if ( parts . length != 2 ) { throw new ParseException ( "Illegal NEEDAFFIX declaration" , reader . getLineNumber ( ) ) ; } needaffix = flagParsingStrategy . parseFlag ( parts [ 1 ] ) ; } else if ( line . startsWith ( ONLYINCOMPOUND_KEY ) ) { String parts [ ] = line . split ( "\\s+" ) ; if ( parts . length != 2 ) { throw new ParseException ( "Illegal ONLYINCOMPOUND declaration" , reader . getLineNumber ( ) ) ; } onlyincompound = flagParsingStrategy . parseFlag ( parts [ 1 ] ) ; } else if ( line . startsWith ( IGNORE_KEY ) ) { String parts [ ] = line . split ( "\\s+" ) ; if ( parts . length != 2 ) { throw new ParseException ( "Illegal IGNORE declaration" , reader . getLineNumber ( ) ) ; } ignore = parts [ 1 ] . toCharArray ( ) ; Arrays . sort ( ignore ) ; needsInputCleaning = true ; } else if ( line . startsWith ( ICONV_KEY ) || line . startsWith ( OCONV_KEY ) ) { String parts [ ] = line . split ( "\\s+" ) ; String type = parts [ 0 ] ; if ( parts . length != 2 ) { throw new ParseException ( "Illegal " + type + " declaration" , reader . getLineNumber ( ) ) ; } int num = Integer . parseInt ( parts [ 1 ] ) ; FST < CharsRef > res = parseConversions ( reader , num ) ; if ( type . equals ( "ICONV" ) ) { iconv = res ; needsInputCleaning |= iconv != null ; } else { oconv = res ; needsOutputCleaning |= oconv != null ; } } else if ( line . startsWith ( FULLSTRIP_KEY ) ) { fullStrip = true ; } else if ( line . startsWith ( LANG_KEY ) ) { language = line . substring ( LANG_KEY . length ( ) ) . trim ( ) ; alternateCasing = "tr_TR" . equals ( language ) || "az_AZ" . equals ( language ) ; } } this . prefixes = affixFST ( prefixes ) ; this . suffixes = affixFST ( suffixes ) ; int totalChars = 0 ; for ( String strip : seenStrips . keySet ( ) ) { totalChars += strip . length ( ) ; } stripData = new char [ totalChars ] ; stripOffsets = new int [ seenStrips . size ( ) + 1 ] ; int currentOffset = 0 ; int currentIndex = 0 ; for ( String strip : seenStrips . keySet ( ) ) { stripOffsets [ currentIndex ++ ] = currentOffset ; strip . getChars ( 0 , strip . length ( ) , stripData , currentOffset ) ; currentOffset += strip . length ( ) ; } assert currentIndex == seenStrips . size ( ) ; stripOffsets [ currentIndex ] = currentOffset ; }
reads the affix file through the provided inputstream , building up the prefix and suffix maps
