private static void resolveStanfordEntities ( ) throws IOException , ClavinException { /*##################################################################### * * Start with Stanford NER -- no need to get CLAVIN involved for now. * *###################################################################*/ // instantiate Stanford NER entity extractor InputStream mpis = WorkflowDemoNERD . class . getClassLoader ( ) . getResourceAsStream ( "models/english.all.3class.distsim.prop" ) ; Properties mp = new Properties ( ) ; mp . load ( mpis ) ; AbstractSequenceClassifier < CoreMap > namedEntityRecognizer = CRFClassifier . getJarClassifier ( "/models/english.all.3class.distsim.crf.ser.gz" , mp ) ; // Unstructured text file about Somalia to be geoparsed File inputFile = new File ( "src/test/resources/sample-docs/Somalia-doc.txt" ) ; // Grab the contents of the text file as a String String inputString = TextUtils . fileToString ( inputFile ) ; // extract entities from input text using Stanford NER List < Triple < String , Integer , Integer > > entitiesFromNER = namedEntityRecognizer . classifyToCharacterOffsets ( inputString ) ; /*##################################################################### * * Now, CLAVIN comes into play... * *###################################################################*/ // convert Stanford NER output to ClavinLocationResolver input List < LocationOccurrence > locationsForCLAVIN = convertNERtoCLAVIN ( entitiesFromNER , inputString ) ; // instantiate the CLAVIN location resolver ClavinLocationResolver clavinLocationResolver = new ClavinLocationResolver ( new LuceneGazetteer ( new File ( "./IndexDirectory" ) ) ) ; // resolve location entities extracted from input text List < ResolvedLocation > resolvedLocations = clavinLocationResolver . resolveLocations ( locationsForCLAVIN , 1 , 1 , false ) ; // Display the ResolvedLocations found for the location names for ( ResolvedLocation resolvedLocation : resolvedLocations ) System . out . println ( resolvedLocation ) ; }
Sometimes you might already be using Stanford NER elsewhere in your application and you d like to just pass the output from Stanford NER directly into CLAVIN without having to re - run the input through Stanford NER just to use CLAVIN . This example shows you how to very easily do exactly that .