private static synchronized Tree getCollocationProcessedTree ( Tree tree , HeadFinder hf ) { if ( wnc == null ) { try { Class < ? > cl = Class . forName ( "edu.stanford.nlp.trees.WordNetInstance" ) ; wnc = ( WordNetConnection ) cl . newInstance ( ) ; } catch ( Exception e ) { System . err . println ( "Couldn't open WordNet Connection. Aborting collocation detection." ) ; e . printStackTrace ( ) ; wnc = null ; } } if ( wnc != null ) { CollocationFinder cf = new CollocationFinder ( tree , wnc , hf ) ; tree = cf . getMangledTree ( ) ; } else { System . err . println ( "ERROR: WordNetConnection unavailable for collocations." ) ; } return tree ; }
For the input tree collapse any collocations in it that exist in WordNet and are contiguous in the tree into a single node . A single static Wordnet connection is used by all instances of this class . Reflection to check that a Wordnet connection exists . Otherwise we print an error and do nothing .