Java Code Examples for edu.stanford.nlp.ie.crf.CRFClassifier#getJarClassifier()
The following examples show how to use
edu.stanford.nlp.ie.crf.CRFClassifier#getJarClassifier() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StanfordExtractorTest.java From CLAVIN-NERD with GNU General Public License v2.0 | 6 votes |
/** * Checks conversion of Stanford NER output format into * {@link com.bericotech.clavin.resolver.ClavinLocationResolver} * input format. * * @throws IOException */ @Test public void testConvertNERtoCLAVIN() throws IOException { InputStream mpis = this.getClass().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); String text = "I was born in Springfield and grew up in Boston."; List<Triple<String, Integer, Integer>> entitiesFromNER = namedEntityRecognizer.classifyToCharacterOffsets(text); List<LocationOccurrence> locationsForCLAVIN = convertNERtoCLAVIN(entitiesFromNER, text); assertEquals("wrong number of entities", 2, locationsForCLAVIN.size()); assertEquals("wrong text for first entity", "Springfield", locationsForCLAVIN.get(0).getText()); assertEquals("wrong position for first entity", 14, locationsForCLAVIN.get(0).getPosition()); assertEquals("wrong text for second entity", "Boston", locationsForCLAVIN.get(1).getText()); assertEquals("wrong position for second entity", 41, locationsForCLAVIN.get(1).getPosition()); }
Example 2
Source File: WorkflowDemoNERD.java From CLAVIN-NERD with GNU General Public License v2.0 | 4 votes |
/** * 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. * * @throws IOException * @throws ClavinException */ 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); }
Example 3
Source File: StanfordExtractor.java From CLAVIN-NERD with GNU General Public License v2.0 | 3 votes |
/** * Builds a {@link StanfordExtractor} by instantiating the * Stanford NER named entity recognizer with a specified * language model. * * @param NERmodel path to Stanford NER language model * @param NERprop path to property file for Stanford NER language model * @throws IOException Error by contract * @throws ClassNotFoundException Error by contract * @throws ClassCastException Error by contract */ //@SuppressWarnings("unchecked") public StanfordExtractor(String NERmodel, String NERprop) throws IOException, ClassCastException, ClassNotFoundException { InputStream mpis = this.getClass().getClassLoader().getResourceAsStream("models/" + NERprop); Properties mp = new Properties(); mp.load(mpis); namedEntityRecognizer = CRFClassifier.getJarClassifier("/models/" + NERmodel, mp); }