本文整理汇总了Java中opennlp.tools.parser.ParserFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Java ParserFactory.create方法的具体用法?Java ParserFactory.create怎么用?Java ParserFactory.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opennlp.tools.parser.ParserFactory
的用法示例。
在下文中一共展示了ParserFactory.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doInitialize
import opennlp.tools.parser.ParserFactory; //导入方法依赖的package包/类
@Override
public void doInitialize(final UimaContext aContext) throws ResourceInitializationException {
try {
parserChunkingModel.loadModel(ParserModel.class, getClass().getResourceAsStream("en-parser-chunking.bin"));
} catch (final BaleenException be) {
getMonitor().error("Unable to load OpenNLP Language Models", be);
throw new ResourceInitializationException(be);
}
try {
parser = ParserFactory.create((ParserModel) parserChunkingModel.getModel());
} catch (final Exception e) {
getMonitor().error("Unable to create OpenNLP parser", e);
throw new ResourceInitializationException(e);
}
}
示例2: doInitialize
import opennlp.tools.parser.ParserFactory; //导入方法依赖的package包/类
@Override
public void doInitialize(final UimaContext aContext) throws ResourceInitializationException {
try {
parserChunkingModel.loadModel(ParserModel.class, getClass().getResourceAsStream("en_parser_chunking.bin"));
} catch (final BaleenException be) {
getMonitor().error("Unable to load OpenNLP Language Models", be);
throw new ResourceInitializationException(be);
}
try {
parser = ParserFactory.create((ParserModel) parserChunkingModel.getModel());
} catch (final Exception e) {
getMonitor().error("Unable to create OpenNLP parser", e);
throw new ResourceInitializationException(e);
}
}
示例3: scoreStructure
import opennlp.tools.parser.ParserFactory; //导入方法依赖的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;
}
示例4: parserTest1
import opennlp.tools.parser.ParserFactory; //导入方法依赖的package包/类
public void parserTest1() throws IOException {
if (!this.modelsAreInitialized) init();
Parser parser = ParserFactory.create(
this.parserModel,
20, // beam size
0.95);
Parse[] results = ParserTool.parseLine("Jane Austen was very modest about her own genius ."+this.q,
parser, 1);
Parse[] qResults = ParserTool.parseLine(this.q,parser, 1);
Parse[] rChn = (results[0].getChildren())[0].getChildren();
results[0].expandTopNode(results[0]);
for (int i = 0; i < results.length; i++) {
results[i].show();
}
for (int i = 0; i < qResults.length; i++) {
qResults[i].show();
}
System.out.print("\n\n");
for (int i = 0; i < rChn.length; i++) {
rChn[i].show();
System.out.print("\n");
}
}
示例5: parsePassageText
import opennlp.tools.parser.ParserFactory; //导入方法依赖的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.parser.ParserFactory; //导入方法依赖的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: EnglishIndexer
import opennlp.tools.parser.ParserFactory; //导入方法依赖的package包/类
public EnglishIndexer() throws Exception {
mDicts = new EnglishDictionaries();
mBeamSize = ConfigurationManager.getConfiguration().getInt("BeamSize");
InputStream modelStream = null;
modelStream = getClass().getResourceAsStream("/opennlp15model-sa/en-sent.bin");
SentenceModel model = new SentenceModel(modelStream);
mSentenceDetector = new SentenceDetectorME(model);
modelStream.close();
modelStream = getClass().getResourceAsStream("/opennlp15model-sa/en-token.bin");
mTokenizer = new EnglishTokenizer(modelStream, mDicts);
modelStream.close();
// The parser model is about 15x the size of chunking model.
// Keep this in mind when using Deep Parsing.
modelStream = getClass().getResourceAsStream("/opennlp15model-sa/en-pos-maxent.bin");
//POSModel posModel = POSTaggerUtils.createPOSModel(modelStream);
POSModel posModel = new POSModel(modelStream);
mTagDictionary = posModel.getTagDictionary();
mPosTagger = new POSTaggerME(posModel);
modelStream.close();
modelStream = getClass().getResourceAsStream("/opennlp15model-sa/en-chunker.bin");
ChunkerModel chunkerModel = new ChunkerModel(modelStream);
mChunker = new ChunkerME(chunkerModel);
modelStream.close();
modelStream = getClass().getResourceAsStream("/opennlp15model-sa/en-parser-chunking.bin");
ParserModel parserModel = new ParserModel(modelStream);
mParser = ParserFactory.create(parserModel);
modelStream.close();
}
示例8: loadResource
import opennlp.tools.parser.ParserFactory; //导入方法依赖的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();
}
}
示例9: parse
import opennlp.tools.parser.ParserFactory; //导入方法依赖的package包/类
public static Parse parse(String input) {
ParserModel model = (ParserModel) models.get(ParserModel.class);
Parser parser = ParserFactory.create(model);
Parse topParses[] = ParserTool.parseLine(input, parser, tokenizer(), 1);
return topParses[0];
}
示例10: OpenNLP
import opennlp.tools.parser.ParserFactory; //导入方法依赖的package包/类
public OpenNLP() throws Exception {
tagger = new POSTaggerME(new POSModel(this.getClass().getClassLoader()
.getResourceAsStream("models/en-pos-maxent.bin")));
parser = ParserFactory.create(new ParserModel(this.getClass().getClassLoader()
.getResourceAsStream("models/en-parser-chunking.bin")));
tokenizer = new TokenizerME(new TokenizerModel(this.getClass().getClassLoader()
.getResourceAsStream("models/en-token.bin")));
stemmer = new EnglishStemmer();
log.info("OpenNLP models loaded");
}
示例11: ParserExtractor
import opennlp.tools.parser.ParserFactory; //导入方法依赖的package包/类
public ParserExtractor() {
sentenceDetector = new SentenceDetector(Consts.EN_SENT_MODEL);
try (InputStream modelIn = ParserExtractor.class.getClassLoader()
.getResourceAsStream(Consts.EN_PARSER_MODEL);){
ParserModel model = new ParserModel(modelIn);
parser = ParserFactory.create(model);
} catch (IOException e) {
e.printStackTrace();
}
}
示例12: SentenceSimilarity
import opennlp.tools.parser.ParserFactory; //导入方法依赖的package包/类
public SentenceSimilarity() {
File modelsDir = new File(this.modelsPath);
this.parserMFile = new File(modelsDir, "en-parser-chunking.bin");
this.sentDetectorMFile = new File(modelsDir, "en-sent.bin");
this.posMFile = new File(modelsDir,"en-pos-maxent.bin");
InputStream sentModelIn = null;
FileInputStream parserStream;
try {
//for finding sentences
sentModelIn = new FileInputStream(sentDetectorMFile);
this.sentenceModel = new SentenceModel(sentModelIn);
//for finding POS
FileInputStream posModelStream = new FileInputStream(posMFile);
POSModel model = new POSModel(posModelStream);
this.tagger = new POSTaggerME(model);
//for parsing
parserStream = new FileInputStream(parserMFile);
this.parserModel = new ParserModel(parserStream);
} catch (FileNotFoundException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sentenceDetector = new SentenceDetectorME(this.sentenceModel);
parser = ParserFactory.create(
this.parserModel,
20, // beam size
0.95); // advance percentage
}
示例13: parsePassageText
import opennlp.tools.parser.ParserFactory; //导入方法依赖的package包/类
public Parse[] parsePassageText(String p) throws InvalidFormatException{
if (!modelsAreInitialized)init();
//initialize
SentenceDetectorME sentenceDetector = new SentenceDetectorME(this.sentenceModel);
NameFinderME nameFinder = new NameFinderME(this.nerModel);
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
Tokenizer tokenizer = SimpleTokenizer.INSTANCE;
for (int si = 0; si < sentences.length; si++) {
Span[] tokenSpans = tokenizer.tokenizePos(sentences[si]);
String[] tokens = Span.spansToStrings(tokenSpans, sentences[si]);
Span[] names = nameFinder.find(tokens);
for (int ni = 0; ni < names.length; ni++) {
Span startSpan = tokenSpans[names[ni].getStart()];
int nameStart = startSpan.getStart();
Span endSpan = tokenSpans[names[ni].getEnd() - 1];
int nameEnd = endSpan.getEnd();
String name = sentences[si].substring(nameStart, nameEnd);
System.out.println(name);
}
}
String sent= StringUtils.join(tokenizer," ");
System.out.println("Found sentence " + sent);
Parse[] sentResults = ParserTool.parseLine(sent,parser, 1);
results[i]=sentResults[0];
}
return results;
}
示例14: loadLexParser
import opennlp.tools.parser.ParserFactory; //导入方法依赖的package包/类
public void loadLexParser() throws IOException {
String model_file = prop.getProperty("parse.model");
System.err.printf("Loading parser from %s ... ", model_file);
parser = ParserFactory.create(new ParserModel(new FileInputStream(model_file)));
System.err.println("done");
}
示例15: scorePassage
import opennlp.tools.parser.ParserFactory; //导入方法依赖的package包/类
@Override
public double scorePassage(Phrase q, Answer a, Passage p) {
int countOfQuestionNPsInPassage = 0;
try {
//prep NLP tools
if (!this.modelsAreInitialized) init();
Parser parser = ParserFactory.create(this.parserModel, 20, 0.95);
//create question parse
Parse[] questionParse = ParserTool.parseLine(q.text, parser, 1);
//create passage parses (one for each sentence)
String[] passageSentences = this.DivideIntoSentences(p);
Parse[] passageParses = new Parse[passageSentences.length];
Parse[] tempParse;
for (int i=0; i < passageSentences.length; i++) {
tempParse = ParserTool.parseLine(passageSentences[i], parser, 1);
passageParses[i] = tempParse[0];
}
//retrieve NPs from the question parse
navigateTree(questionParse, 0, questionNPs);
//retrieve NPs from the passage parse
for (int i=0; i < passageParses.length; i++) {
navigateTree(passageParses, i, passageNPs);
}
//count the number of question NPs that are in the passage NP set (A)
for (String qNP: questionNPs) {
for (String pNP: passageNPs) {
//System.out.println("comparing " + qNP + " with " + pNP);
if (qNP.equals(pNP)) {
//System.out.println("match found");
countOfQuestionNPsInPassage++;
}
}
}
//System.out.println(countOfQuestionNPsInPassage);
//count the number of all NPs that are in the passage NP set (B)
//passageNPs.size();
} catch (InvalidFormatException e) {
e.printStackTrace();
}
//calculate A/B and return as the score
//System.out.print("******** score: " + (double)countOfQuestionNPsInPassage/passageNPs.size() + " *******");
//System.out.println(" count: " + passageNPs.size() + " *******");
if (passageNPs.size() == 0)
return 0;
else
return (double)countOfQuestionNPsInPassage/passageNPs.size();
}