public final void annotate ( final InputStream inputStream , final OutputStream outputStream ) throws IOException , JDOMException { BufferedReader breader = new BufferedReader ( new InputStreamReader ( inputStream , UTF_8 ) ) ; BufferedWriter bwriter = new BufferedWriter ( new OutputStreamWriter ( outputStream , UTF_8 ) ) ; // read KAF document from inputstream KAFDocument kaf = KAFDocument . createFromStream ( breader ) ; // load parameters into a properties String model = parsedArguments . getString ( MODEL ) ; String outputFormat = parsedArguments . getString ( "outputFormat" ) ; String lexer = parsedArguments . getString ( "lexer" ) ; String dictTag = parsedArguments . getString ( "dictTag" ) ; String dictPath = parsedArguments . getString ( "dictPath" ) ; String clearFeatures = parsedArguments . getString ( "clearFeatures" ) ; // language parameter String lang = null ; if ( parsedArguments . getString ( "language" ) != null ) { lang = parsedArguments . getString ( "language" ) ; if ( ! kaf . getLang ( ) . equalsIgnoreCase ( lang ) ) { System . err . println ( "Language parameter in NAF and CLI do not match!!" ) ; } } else { lang = kaf . getLang ( ) ; } Properties properties = setAnnotateProperties ( model , lang , lexer , dictTag , dictPath , clearFeatures ) ; KAFDocument . LinguisticProcessor newLp = kaf . addLinguisticProcessor ( "entities" , IXA_PIPE_NERC + Files . getNameWithoutExtension ( model ) , version + "-" + commit ) ; newLp . setBeginTimestamp ( ) ; Annotate annotator = new Annotate ( properties ) ; annotator . annotateNEsToKAF ( kaf ) ; newLp . setEndTimestamp ( ) ; String kafToString = null ; if ( outputFormat . equalsIgnoreCase ( "conll03" ) ) { kafToString = annotator . annotateNEsToCoNLL2003 ( kaf ) ; } else if ( outputFormat . equalsIgnoreCase ( "conll02" ) ) { kafToString = annotator . annotateNEsToCoNLL2002 ( kaf ) ; } else if ( outputFormat . equalsIgnoreCase ( "opennlp" ) ) { kafToString = annotator . annotateNEsToOpenNLP ( kaf ) ; } else { kafToString = kaf . toString ( ) ; } bwriter . write ( kafToString ) ; bwriter . close ( ) ; breader . close ( ) ; }
Main method to do Named Entity tagging .