本文整理汇总了Java中edu.stanford.nlp.ie.crf.CRFClassifier.getJarClassifier方法的典型用法代码示例。如果您正苦于以下问题:Java CRFClassifier.getJarClassifier方法的具体用法?Java CRFClassifier.getJarClassifier怎么用?Java CRFClassifier.getJarClassifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.stanford.nlp.ie.crf.CRFClassifier
的用法示例。
在下文中一共展示了CRFClassifier.getJarClassifier方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testConvertNERtoCLAVIN
import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
/**
* 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());
}
示例2: StanfordNlpNerService
import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
public StanfordNlpNerService(String serializedClassifier) {
this.classifier = CRFClassifier.getJarClassifier(
"/edu/stanford/nlp/models/ner/" + serializedClassifier, null);
}
示例3: main
import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
/**
* Starts this server on the specified port. The classifier used can be
* either a default one stored in the jar file from which this code is
* invoked or you can specify it as a filename or as another classifier
* resource name, which must correspond to the name of a resource in the
* /classifiers/ directory of the jar file.
* <p>
* Usage: <code>java edu.stanford.nlp.ie.NERServer [-loadClassifier file|-loadJarClassifier resource|-client] -port portNumber</code>
*
* @param args Command-line arguments (described above)
* @throws Exception If file or Java class problems with serialized classifier
*/
@SuppressWarnings({"StringEqualsEmptyString"})
public static void main (String[] args) throws Exception {
Properties props = StringUtils.argsToProperties(args);
String loadFile = props.getProperty("loadClassifier");
String loadJarFile = props.getProperty("loadJarClassifier");
String client = props.getProperty("client");
String portStr = props.getProperty("port");
props.remove("port"); // so later code doesn't complain
if (portStr == null || portStr.equals("")) {
System.err.println(USAGE);
return;
}
String charset = "utf-8";
String encoding = props.getProperty("encoding");
if (encoding != null && ! "".equals(encoding)) {
charset = encoding;
}
int port;
try {
port = Integer.parseInt(portStr);
} catch (NumberFormatException e) {
System.err.println("Non-numerical port");
System.err.println(USAGE);
return;
}
// default output format for if no output format is specified
if (props.getProperty("outputFormat") == null) {
props.setProperty("outputFormat", "slashTags");
}
if (client != null && ! client.equals("")) {
// run a test client for illustration/testing
String host = props.getProperty("host");
NERClient.communicateWithNERServer(host, port, charset);
} else {
AbstractSequenceClassifier asc;
if (loadFile != null && ! loadFile.equals("")) {
asc = CRFClassifier.getClassifier(loadFile, props);
} else if (loadJarFile != null && ! loadJarFile.equals("")) {
asc = CRFClassifier.getJarClassifier(loadJarFile, props);
} else {
asc = CRFClassifier.getDefaultClassifier(props);
}
new NERServer(port, asc, charset).run();
}
}
示例4: resolveStanfordEntities
import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
/**
* 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);
}
示例5: initializeWithModelFiles
import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
/**
* Builds a {@link StanfordNamedEntityExtractor} 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
* @throws ClassNotFoundException
* @throws ClassCastException
*/
//@SuppressWarnings("unchecked")
private void initializeWithModelFiles(String NERmodel, String NERprop) throws IOException, ClassCastException, ClassNotFoundException {
InputStream mpis = this.getClass().getClassLoader().getResourceAsStream("models/" + NERprop);
Properties mp = new Properties();
mp.load(mpis);
namedEntityRecognizer = (AbstractSequenceClassifier<CoreMap>)
CRFClassifier.getJarClassifier("/models/" + NERmodel, mp);
}
示例6: StanfordExtractor
import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
/**
* 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);
}