本文整理汇总了Java中edu.stanford.nlp.ie.crf.CRFClassifier.getClassifier方法的典型用法代码示例。如果您正苦于以下问题:Java CRFClassifier.getClassifier方法的具体用法?Java CRFClassifier.getClassifier怎么用?Java CRFClassifier.getClassifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.stanford.nlp.ie.crf.CRFClassifier
的用法示例。
在下文中一共展示了CRFClassifier.getClassifier方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ner
import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
public List<IntPair> ner(String s) {
try {
if (classifier == null) {
classifier = CRFClassifier.getClassifier(classifierFile);
}
List<List<CoreLabel>> result = classifier.classify(s);
int begin = 0;
String last = "";
boolean in = false;
int j = 0;
List<IntPair> rval = new ArrayList<>();
for (CoreLabel word : result.get(0)) {
String tag = word.get(CoreAnnotations.AnswerAnnotation.class);
if (tag.equals("O")) {
if (in) {
rval.add(new IntPair(begin, j));
}
in = false;
} else {
if (!in) {
begin = j;
in = true;
}
}
j++;
last = tag;
}
if (in) {
rval.add(new IntPair(begin, result.get(0).size()));
}
return rval;
} catch (IOException | ClassNotFoundException x) {
throw new RuntimeException(x);
}
}
示例2: init
import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
@Override
public Resource init() throws ResourceInstantiationException {
if(tagger == null) {
fireStatusChanged("Loading Stanford NER model");
try (InputStream in = modelFile.openStream();
GZIPInputStream gzipIn = new GZIPInputStream(in)){
tagger = CRFClassifier.getClassifier(gzipIn);
} catch(Exception e) {
throw new ResourceInstantiationException(e);
}
}
return this;
}
示例3: initialValue
import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
protected AbstractSequenceClassifier<CoreLabel> initialValue() {
try {
return CRFClassifier.getClassifier(classifierFilePath);
} catch (final Exception exception) {
LOGGER.error(MessageCatalog._00052_CLASSIFIER_LOAD_FAILURE, classifierFilePath);
return NULL_OBJECT_CLASSIFIER;
}
}
示例4: classifier
import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
@Override
AbstractSequenceClassifier<CoreLabel> classifier() {
synchronized(this) {
if (classifier == null) {
try {
classifier = CRFClassifier.getClassifier(classifierFilePath);
} catch (final Exception exception) {
LOGGER.error(MessageCatalog._00052_CLASSIFIER_LOAD_FAILURE, classifierFilePath);
classifier = NULL_OBJECT_CLASSIFIER;
}
}
return classifier;
}
}
示例5: init
import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
public void init() throws NamedEntityRecognizerException
{
if (initialized)
throw new NamedEntityRecognizerException(
"init() was called though the StanfordNamedEntityRecognizer was already initialized.");
try
{
this.crfClassifier = CRFClassifier.getClassifier(this.classifierPath.getPath());
this.initialized = true;
}
catch (Exception e)
{
throw new NamedEntityRecognizerException("Classifier load failed.",e);
}
}
示例6: NER
import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
public NER() {
try {
classifier = CRFClassifier.<CoreLabel> getClassifier(new File(SERIALIZED_CLASSIFIER));
} catch (ClassCastException | ClassNotFoundException | IOException e) {
Throwables.propagate(e);
}
}
示例7: setup
import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected void setup(Context context) throws IOException, InterruptedException {
super.setup(context);
numrecords = 0;
try {
classifier = ((AbstractSequenceClassifier<CoreLabel>) CRFClassifier.getClassifier(NERMapper.class.getResourceAsStream("/nl/surfsara/warcexamples/hadoop/wet/resources/english.all.3class.distsim.crf.ser")));
} catch (Exception e) {
logger.error(e);
}
}
示例8: init
import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
/**
* Initializes the StanfordNeTagger with a custom model.
*
* @param customSerializedClassifier path of the custom classifier to load
*/
public static boolean init(String customSerializedClassifier) {
try {
classifier =
CRFClassifier.getClassifier(customSerializedClassifier);
serializedClassifier = customSerializedClassifier;
return true;
} catch (Exception e) {
return false;
}
}
示例9: init
import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
@Override
public Resource init() throws ResourceInstantiationException {
if(tagger == null) {
fireStatusChanged("Loading Stanford NER model");
try {
// nasty workaround for stanford NER's path format inconsistency - tagger is content with uris beginning file:, ner labeller is not
tagger = CRFClassifier.getClassifier(modelFile.toString().substring(5));
} catch(Exception e) {
throw new ResourceInstantiationException(e);
}
}
return this;
}
示例10: createClassifier
import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
private AbstractSequenceClassifier<CoreLabel> createClassifier() throws ClassCastException, ClassNotFoundException, IOException {
String classifierPath = classifierFile.getAbsolutePath();
return CRFClassifier.getClassifier(classifierPath);
}
示例11: getCharacters
import edu.stanford.nlp.ie.crf.CRFClassifier; //导入方法依赖的package包/类
/**
* Get the characters.
*
* @return an ArrayList of characters
*/
public ArrayList<Person> getCharacters() {
ArrayList<Person> people = new ArrayList<Person>();
Genderize api = GenderizeIoAPI.create();
AbstractSequenceClassifier<CoreLabel> classifier;
String fileContents;
List<Triple<String, Integer, Integer>> list;
HashSet<String> existingNames;
try {
classifier = CRFClassifier.getClassifier(CLASSIFIER);
fileContents = IOUtils.slurpFile(filename);
list = classifier.classifyToCharacterOffsets(fileContents);
existingNames = new HashSet<String>();
for (Triple<String, Integer, Integer> item : list) {
if (item.first().equals("PERSON")) {
String nameStr = fileContents.substring(item.second(),
item.third());
nameStr = nameStr.replace("\n", " ")
.replace("\r", " ")
.replaceAll("\\s+", " ")
.trim();
if (!existingNames.contains(nameStr)) {
existingNames.add(nameStr);
String[] names = nameStr.split(" ");
Person p = new Person();
p.setFirstname(names[0]);
if (names.length > 1) {
p.setLastname(names[1]);
}
NameGender gender = api.getGender(p.getFirstname());
if (gender.getGender() != null) {
p.setGender(gender.isMale() ? male : female);
} else {
p.setGender(getRandomGender());
}
people.add(p);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return people;
}
示例12: 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();
}
}