本文整理汇总了Java中opennlp.tools.util.InvalidFormatException类的典型用法代码示例。如果您正苦于以下问题:Java InvalidFormatException类的具体用法?Java InvalidFormatException怎么用?Java InvalidFormatException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InvalidFormatException类属于opennlp.tools.util包,在下文中一共展示了InvalidFormatException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import opennlp.tools.util.InvalidFormatException; //导入依赖的package包/类
/**
* tester
* @param args
* @throws InvalidFormatException
* @throws IOException
*/
public static void main(String[] args) throws InvalidFormatException, IOException {
if (args == null || args.length <= 0) {
System.out.println("No Data");
return;
}
OpenNLPService nameFinder = new OpenNLPService();
for (int j = 0; j < args.length; j++) {
System.out.println("Input: " + args[j]);
System.out.println(nameFinder.getPeople(CURRENT_DIR, args[j]));
System.out.println(nameFinder.getLocations(CURRENT_DIR, args[j]));
}
}
示例2: create
import opennlp.tools.util.InvalidFormatException; //导入依赖的package包/类
public static AgeClassifyFactory create(String subclassName, Tokenizer tokenizer,
FeatureGenerator[] featureGenerators) throws InvalidFormatException {
if (subclassName == null) {
// will create the default factory
return new AgeClassifyFactory(tokenizer, featureGenerators);
}
try {
AgeClassifyFactory factory = AgeClassifyFactory.INSTANCE;
factory.init(tokenizer, featureGenerators);
return factory;
} catch (Exception e) {
String msg = "Could not instantiate the " + subclassName
+ ". The initialization throw an exception.";
System.err.println(msg);
e.printStackTrace();
throw new InvalidFormatException(msg, e);
}
}
示例3: getAllNameEntitiesfromInput
import opennlp.tools.util.InvalidFormatException; //导入依赖的package包/类
public void getAllNameEntitiesfromInput(InputStream stream)
throws InvalidFormatException, IOException {
InputStream modelIn = new FileInputStream(nerModelPath);
TokenNameFinderModel model = new TokenNameFinderModel(modelIn);
NameFinderME nameFinder = new NameFinderME(model);
String[] in = IOUtils.toString(stream, "UTF-8").split(" ");
Span nameE[] = nameFinder.find(in);
String spanNames = Arrays.toString(Span.spansToStrings(nameE, in));
spanNames = spanNames.substring(1, spanNames.length() - 1);
modelIn.close();
String[] tmp = spanNames.split(",");
for (String name : tmp) {
name = name.trim();
this.locationNameEntities.add(name);
}
}
示例4: scoreStructure
import opennlp.tools.util.InvalidFormatException; //导入依赖的package包/类
public double scoreStructure(String ca, String q, String passage, boolean verbose) throws InvalidFormatException, IOException{
POSTaggerME parserModel = new POSTaggerME(new POSModel(new FileInputStream(new File("en-pos-model.bin"))));
Tokenizer tokenizer = new TokenizerME(new TokenizerModel(new FileInputStream(new File("en-token.bin"))));
Parser parser = ParserFactory.create(new ParserModel(new FileInputStream(new File("en-parser.bin"))));
double score = 0;
Parse[] questionParse = ParserTool.parseLine(q, parser, 1);
Parse[] passageParse = ParserTool.parseLine(q, parser, 1);
if (passage.contains(ca)) {
for (int i =0; i < questionParse.length; i++) {
score += matchChildren(questionParse[i],passageParse[i]);
}
}
return score;
}
示例5: parsePassageText
import opennlp.tools.util.InvalidFormatException; //导入依赖的package包/类
public static Parse[] parsePassageText(String p) throws InvalidFormatException{
//initialize
SentenceDetectorME sentenceDetector = new SentenceDetectorME(sentenceModel);
Parser parser = ParserFactory.create(
parserModel,
20, // beam size
0.95); // advance percentage
String[] sentences = sentenceDetector.sentDetect(p);
Parse[] results = new Parse[sentences.length];
for (int i=0;i<sentences.length;i++){
String[] tks = SimpleTokenizer.INSTANCE.tokenize(sentences[i]);
String sent= StringUtils.join(tks," ");
System.out.println("Found sentence " + sent);
Parse[] sentResults = ParserTool.parseLine(sent,parser, 1);
results[i]=sentResults[0];
}
return results;
}
示例6: parsePassageText
import opennlp.tools.util.InvalidFormatException; //导入依赖的package包/类
public Parse[] parsePassageText(String p) throws InvalidFormatException{
if (!modelsAreInitialized)init();
//initialize
SentenceDetectorME sentenceDetector = new SentenceDetectorME(this.sentenceModel);
Parser parser = ParserFactory.create(
this.parserModel,
20, // beam size
0.95); // advance percentage
//find sentences, tokenize each, parse each, return top parse for each
String[] sentences = sentenceDetector.sentDetect(p);
Parse[] results = new Parse[sentences.length];
for (int i=0;i<sentences.length;i++){
String[] tks = SimpleTokenizer.INSTANCE.tokenize(sentences[i]);
//StringTokenizer st = new StringTokenizer(tks[i]);
//There are several tokenizers available. SimpleTokenizer works best
String sent= StringUtils.join(tks," ");
System.out.println("Found sentence " + sent);
Parse[] sentResults = ParserTool.parseLine(sent,parser, 1);
results[i]=sentResults[0];
}
return results;
}
示例7: create
import opennlp.tools.util.InvalidFormatException; //导入依赖的package包/类
public static LemmatizerFactory create(String subclassName)
throws InvalidFormatException {
if (subclassName == null) {
// will create the default factory
return new LemmatizerFactory();
}
try {
LemmatizerFactory theFactory = ExtensionLoader.instantiateExtension(
LemmatizerFactory.class, subclassName);
return theFactory;
} catch (Exception e) {
String msg = "Could not instantiate the " + subclassName
+ ". The initialization throw an exception.";
System.err.println(msg);
e.printStackTrace();
throw new InvalidFormatException(msg, e);
}
}
示例8: parse
import opennlp.tools.util.InvalidFormatException; //导入依赖的package包/类
@Override
BratAnnotation parse(String[] values) throws IOException {
if (values.length > 4) {
String type = values[BratAnnotationParser.TYPE_OFFSET];
int endOffset = -1;
for (int i = END_OFFSET; i < values.length; i++) {
if (!values[i].contains(";")) {
endOffset = parseInt(values[i]);
break;
}
}
return new SpanAnnotation(
values[BratAnnotationParser.ID_OFFSET], type,
new Span(parseInt(values[BEGIN_OFFSET]), endOffset,
type), "");
} else {
throw new InvalidFormatException(
"Line must have at least 5 fields");
}
}
示例9: AgePredicterLocal
import opennlp.tools.util.InvalidFormatException; //导入依赖的package包/类
public AgePredicterLocal(String pathToClassifyModel, String pathToRegressionModel, String pathToSentenceModel, String pathToTokenModel) throws InvalidFormatException, IOException{
spark = SparkSession.builder().master("local").appName("AgePredict").getOrCreate();
classifyModel = new AgeClassifyModel(new File(pathToClassifyModel));
classify = new AgeClassifyME(classifyModel);
model = AgePredictModel.readModel(new File(pathToRegressionModel));
this.tokenizer = new SentenceTokenizer(pathToSentenceModel, pathToTokenModel);
}
示例10: WordNGramFeatureGenerator
import opennlp.tools.util.InvalidFormatException; //导入依赖的package包/类
/**
* Constructor for ngrams.
*
* @param minGram minGram value - which means minimum words in ngram features
* @param maxGram maxGram value - which means maximum words in ngram features
* @throws InvalidFormatException
*/
public WordNGramFeatureGenerator(int minGram, int maxGram) throws InvalidFormatException {
if (minGram > 0 && maxGram > 0) {
if (minGram <= maxGram) {
this.minGram = minGram;
this.maxGram = maxGram;
} else {
throw new InvalidFormatException("Minimum range value (minGram) should be less than or equal to maximum range value (maxGram)!");
}
} else {
throw new InvalidFormatException("Both minimum range value (minGram) & maximum range value (maxGram) should be greater than or equal to 1!");
}
}
示例11: loadResource
import opennlp.tools.util.InvalidFormatException; //导入依赖的package包/类
private void loadResource() throws InvalidFormatException, IOException {
if (parser == null) {
InputStream is = OpenNLPParser.class.getClassLoader().getResourceAsStream(PARSER_MODEL);
ParserModel model = new ParserModel(is);
parser = ParserFactory.create(model);
is.close();
}
}
示例12: validateArtifactMap
import opennlp.tools.util.InvalidFormatException; //导入依赖的package包/类
@Override protected void validateArtifactMap() throws InvalidFormatException {
super.validateArtifactMap();
if (!(artifactMap
.get(PROFILER_MODEL_ENTRY_NAME) instanceof AbstractModel)) {
throw new InvalidFormatException("problem in the model");
}
}
示例13: validateArtifactMap
import opennlp.tools.util.InvalidFormatException; //导入依赖的package包/类
@Override
public void validateArtifactMap() throws InvalidFormatException {
Object featExtractorsEntry = artifactProvider.getArtifact(FEATURE_EXTRACTORS_ENTRY_NAME);
if (featExtractorsEntry == null) {
throw new InvalidFormatException("No featureExtractors in artifacts map");
}
if (!(featExtractorsEntry instanceof FeatureExtractorsBasedContextGenerator)) {
throw new InvalidFormatException(String.format(
"Unknown type of feature extractors aggregate: %s",
featExtractorsEntry.getClass()));
}
}
示例14: validateArtifactMap
import opennlp.tools.util.InvalidFormatException; //导入依赖的package包/类
@Override
protected void validateArtifactMap() throws InvalidFormatException {
super.validateArtifactMap();
if (!(artifactMap.get(POS_MODEL_ENTRY_NAME) instanceof MaxentModel)) {
throw new InvalidFormatException("POS model is incomplete!");
}
}
示例15: initialize
import opennlp.tools.util.InvalidFormatException; //导入依赖的package包/类
public void initialize(String modelPathTokenize, String modelPathSentenize) throws InvalidFormatException, IOException {
InputStream modelInTokenize = new FileInputStream(modelPathTokenize);
TokenizerModel modelTokenize = new TokenizerModel(modelInTokenize);
tokenizer = new TokenizerME(modelTokenize);
InputStream modelInSentenize = new FileInputStream(modelPathSentenize);
SentenceModel modelSentenize = new SentenceModel(modelInSentenize);
sentenizer = new SentenceDetectorME(modelSentenize);
}