本文整理汇总了Java中opennlp.tools.util.InvalidFormatException类的典型用法代码示例。如果您正苦于以下问题:Java InvalidFormatException类的具体用法?Java InvalidFormatException怎么用?Java InvalidFormatException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InvalidFormatException类属于opennlp.tools.util包,在下文中一共展示了InvalidFormatException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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]));
}
}
开发者ID:tspannhw,项目名称:nifi-nlp-processor,代码行数:23,代码来源:OpenNLPService.java
示例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);
}
}
开发者ID:USCDataScience,项目名称:AgePredictor,代码行数:20,代码来源:AgeClassifyFactory.java
示例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);
}
}
开发者ID:anyayunli,项目名称:GeoParsingNSF,代码行数:23,代码来源:NameEntityExtractor.java
示例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;
}
开发者ID:SeanTater,项目名称:uncc2014watsonsim,代码行数:18,代码来源:JM_Scorer.java
示例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;
}
开发者ID:SeanTater,项目名称:uncc2014watsonsim,代码行数:23,代码来源:POSStructureScorer.java
示例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;
}
开发者ID:SeanTater,项目名称:uncc2014watsonsim,代码行数:24,代码来源:OpenNlpTests.java
示例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);
}
}
开发者ID:ixa-ehu,项目名称:ixa-pipe-pos,代码行数:19,代码来源:LemmatizerFactory.java
示例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");
}
}
开发者ID:NUNLP,项目名称:uima-components,代码行数:25,代码来源:BratAnnotationStream.java
示例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);
}
开发者ID:USCDataScience,项目名称:AgePredictor,代码行数:10,代码来源:AgePredicterLocal.java
示例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!");
}
}
开发者ID:USCDataScience,项目名称:AgePredictor,代码行数:20,代码来源:WordNGramFeatureGenerator.java
示例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();
}
}
开发者ID:TekstoSense,项目名称:word-root-finder,代码行数:10,代码来源:OpenNLPParser.java
示例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");
}
}
开发者ID:beylerian,项目名称:profiler,代码行数:9,代码来源:ProfilerModel.java
示例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()));
}
}
开发者ID:textocat,项目名称:textokit-core,代码行数:13,代码来源:POSTaggerFactory.java
示例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!");
}
}
开发者ID:textocat,项目名称:textokit-core,代码行数:9,代码来源:POSModel.java
示例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);
}
开发者ID:infolis,项目名称:infoLink,代码行数:10,代码来源:TokenizerOpenNLP.java
示例16: getTokenizedSentences
import opennlp.tools.util.InvalidFormatException; //导入依赖的package包/类
public List<String> getTokenizedSentences(String text) throws InvalidFormatException, IOException {
String[] sentences = sentenize(text);
List<String> tokenizedSentences = new ArrayList<>();
for (String sentence : sentences) {
tokenizedSentences.add(tokenize(sentence));
}
return tokenizedSentences;
}
开发者ID:infolis,项目名称:infoLink,代码行数:9,代码来源:TokenizerOpenNLP.java
示例17: testStanfordTokenize
import opennlp.tools.util.InvalidFormatException; //导入依赖的package包/类
@Test
public void testStanfordTokenize() throws InvalidFormatException, IOException{
Execution exec = new Execution();
exec.setInputFiles(uris);
exec.setAlgorithm(TokenizerStanford.class);
exec.setTokenizeNLs(true);
exec.setPtb3Escaping(true);
exec.instantiateAlgorithm(dataStoreClient, fileResolver).run();
List<InfolisFile> outFiles = dataStoreClient.get(InfolisFile.class, exec.getOutputFiles());
for (InfolisFile outFile : outFiles) {
InputStream is = fileResolver.openInputStream(outFile);
String content = IOUtils.toString(is);
log.debug("output stanford: " + content);
}
}
开发者ID:infolis,项目名称:infoLink,代码行数:16,代码来源:TokenizerTest.java
示例18: testOpenNLPTokenize
import opennlp.tools.util.InvalidFormatException; //导入依赖的package包/类
@Ignore
public void testOpenNLPTokenize() throws InvalidFormatException, IOException {
Execution exec = new Execution();
exec.setInputFiles(uris);
exec.setAlgorithm(TokenizerOpenNLP.class);
exec.instantiateAlgorithm(dataStoreClient, fileResolver).run();
List<InfolisFile> outFiles = dataStoreClient.get(InfolisFile.class, exec.getOutputFiles());
for (InfolisFile outFile : outFiles) {
InputStream is = fileResolver.openInputStream(outFile);
String content = IOUtils.toString(is);
log.debug("output openNLP: " + content);
}
}
开发者ID:infolis,项目名称:infoLink,代码行数:14,代码来源:TokenizerTest.java
示例19: SentenceDetect
import opennlp.tools.util.InvalidFormatException; //导入依赖的package包/类
public static void SentenceDetect(String sent_model) throws InvalidFormatException, IOException {
String paragraph = "Hi. How are you? This is Mike.";
// always start with a model, a model is learned from training data
InputStream is = new FileInputStream(sent_model);
SentenceModel model = new SentenceModel(is);
is.close();
SentenceDetectorME sdetector = new SentenceDetectorME(model);
String sentences[] = sdetector.sentDetect(paragraph);
System.out.println(sentences[0]);
System.out.println(sentences[1]);
}
开发者ID:jackeylu,项目名称:NLP_with_Java_zh,代码行数:15,代码来源:SentenceTest.java
示例20: classify
import opennlp.tools.util.InvalidFormatException; //导入依赖的package包/类
public static void classify(String modelFile, String inputText) throws InvalidFormatException, IOException {
InputStream modelIn = new FileInputStream(modelFile);
DoccatModel model = new DoccatModel(modelIn);
DocumentCategorizerME categorizer = new DocumentCategorizerME(model);
double[] outcomes = categorizer.categorize(inputText);
for (int i = 0; i < categorizer.getNumberOfCategories(); i++)
{
System.out.println(categorizer.getCategory(i) + " - " + outcomes[i]);
}
System.out.println(categorizer.getBestCategory(outcomes));
System.out.println(categorizer.getAllResults(outcomes));
}
开发者ID:jackeylu,项目名称:NLP_with_Java_zh,代码行数:16,代码来源:SentenceTest.java
注:本文中的opennlp.tools.util.InvalidFormatException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论