public ParserModel(String languageCode, MaxentModel buildModel, MaxentModel checkModel, MaxentModel attachModel, POSModel parserTagger, ChunkerModel chunkerTagger, opennlp.tools.parser.HeadRules headRules, ParserType modelType, Map<String, String> manifestInfoEntries) { super(COMPONENT_NAME, languageCode, manifestInfoEntries); setManifestProperty(PARSER_TYPE, modelType.name()); artifactMap.put(BUILD_MODEL_ENTRY_NAME, buildModel); artifactMap.put(CHECK_MODEL_ENTRY_NAME, checkModel); if (ParserType.CHUNKING.equals(modelType)) { if (attachModel != null) throw new IllegalArgumentException("attachModel must be null for chunking parser!"); } else if (ParserType.TREEINSERT.equals(modelType)) { Objects.requireNonNull(attachModel, "attachModel must not be null"); artifactMap.put(ATTACH_MODEL_ENTRY_NAME, attachModel); } else { throw new IllegalStateException("Unknown ParserType '" + modelType + "'!"); } artifactMap.put(PARSER_TAGGER_MODEL_ENTRY_NAME, parserTagger); artifactMap.put(CHUNKER_TAGGER_MODEL_ENTRY_NAME, chunkerTagger); artifactMap.put(HEAD_RULES_MODEL_ENTRY_NAME, headRules); checkArtifactMap(); }
public static Parser create(ParserModel model, int beamSize, double advancePercentage) { if (ParserType.CHUNKING.equals(model.getParserType())) { return new opennlp.tools.parser.chunking.Parser(model, beamSize, advancePercentage); } else if (ParserType.TREEINSERT.equals(model.getParserType())) { return new opennlp.tools.parser.treeinsert.Parser(model, beamSize, advancePercentage); } else { throw new IllegalStateException("Unexpected ParserType: " + model.getParserType().name()); } }
if (ParserType.CHUNKING.equals(modelType)) { if (artifactMap.get(ATTACH_MODEL_ENTRY_NAME) != null) throw new InvalidFormatException("attachModel must be null for chunking parser!"); else if (ParserType.TREEINSERT.equals(modelType)) { if (!(artifactMap.get(ATTACH_MODEL_ENTRY_NAME) instanceof AbstractModel)) throw new InvalidFormatException("attachModel must not be null!");
public void evaluate(ObjectStream<Parse> samples, int nFolds) throws IOException { CrossValidationPartitioner<Parse> partitioner = new CrossValidationPartitioner<>(samples, nFolds); while (partitioner.hasNext()) { CrossValidationPartitioner.TrainingSampleStream<Parse> trainingSampleStream = partitioner.next(); ParserModel model; if (ParserType.CHUNKING.equals(parserType)) { model = opennlp.tools.parser.chunking.Parser.train(languageCode, samples, rules, params); } else if (ParserType.TREEINSERT.equals(parserType)) { model = opennlp.tools.parser.treeinsert.Parser.train(languageCode, samples, rules, params); } else { throw new IllegalStateException("Unexpected parser type: " + parserType); } ParserEvaluator evaluator = new ParserEvaluator(ParserFactory.create(model), monitors); evaluator.evaluate(trainingSampleStream.getTestSampleStream()); fmeasure.mergeInto(evaluator.getFMeasure()); } }
public ParserModel(String languageCode, MaxentModel buildModel, MaxentModel checkModel, MaxentModel attachModel, POSModel parserTagger, ChunkerModel chunkerTagger, opennlp.tools.parser.HeadRules headRules, ParserType modelType, Map<String, String> manifestInfoEntries) { super(COMPONENT_NAME, languageCode, manifestInfoEntries); setManifestProperty(PARSER_TYPE, modelType.name()); artifactMap.put(BUILD_MODEL_ENTRY_NAME, buildModel); artifactMap.put(CHECK_MODEL_ENTRY_NAME, checkModel); if (ParserType.CHUNKING.equals(modelType)) { if (attachModel != null) throw new IllegalArgumentException("attachModel must be null for chunking parser!"); } else if (ParserType.TREEINSERT.equals(modelType)) { Objects.requireNonNull(attachModel, "attachModel must not be null"); artifactMap.put(ATTACH_MODEL_ENTRY_NAME, attachModel); } else { throw new IllegalStateException("Unknown ParserType '" + modelType + "'!"); } artifactMap.put(PARSER_TAGGER_MODEL_ENTRY_NAME, parserTagger); artifactMap.put(CHUNKER_TAGGER_MODEL_ENTRY_NAME, chunkerTagger); artifactMap.put(HEAD_RULES_MODEL_ENTRY_NAME, headRules); checkArtifactMap(); }
public ParserModel(String languageCode, MaxentModel buildModel, MaxentModel checkModel, MaxentModel attachModel, POSModel parserTagger, ChunkerModel chunkerTagger, opennlp.tools.parser.HeadRules headRules, ParserType modelType, Map<String, String> manifestInfoEntries) { super(COMPONENT_NAME, languageCode, manifestInfoEntries); setManifestProperty(PARSER_TYPE, modelType.name()); artifactMap.put(BUILD_MODEL_ENTRY_NAME, buildModel); artifactMap.put(CHECK_MODEL_ENTRY_NAME, checkModel); if (ParserType.CHUNKING.equals(modelType)) { if (attachModel != null) throw new IllegalArgumentException("attachModel must be null for chunking parser!"); } else if (ParserType.TREEINSERT.equals(modelType)) { Objects.requireNonNull(attachModel, "attachModel must not be null"); artifactMap.put(ATTACH_MODEL_ENTRY_NAME, attachModel); } else { throw new IllegalStateException("Unknown ParserType '" + modelType + "'!"); } artifactMap.put(PARSER_TAGGER_MODEL_ENTRY_NAME, parserTagger); artifactMap.put(CHUNKER_TAGGER_MODEL_ENTRY_NAME, chunkerTagger); artifactMap.put(HEAD_RULES_MODEL_ENTRY_NAME, headRules); checkArtifactMap(); }
public static Parser create(ParserModel model, int beamSize, double advancePercentage) { if (ParserType.CHUNKING.equals(model.getParserType())) { return new opennlp.tools.parser.chunking.Parser(model, beamSize, advancePercentage); } else if (ParserType.TREEINSERT.equals(model.getParserType())) { return new opennlp.tools.parser.treeinsert.Parser(model, beamSize, advancePercentage); } else { throw new IllegalStateException("Unexpected ParserType: " + model.getParserType().name()); } }
public static Parser create(ParserModel model, int beamSize, double advancePercentage) { if (ParserType.CHUNKING.equals(model.getParserType())) { return new opennlp.tools.parser.chunking.Parser(model, beamSize, advancePercentage); } else if (ParserType.TREEINSERT.equals(model.getParserType())) { return new opennlp.tools.parser.treeinsert.Parser(model, beamSize, advancePercentage); } else { throw new IllegalStateException("Unexpected ParserType: " + model.getParserType().name()); } }
if (ParserType.CHUNKING.equals(modelType)) { if (artifactMap.get(ATTACH_MODEL_ENTRY_NAME) != null) throw new InvalidFormatException("attachModel must be null for chunking parser!"); else if (ParserType.TREEINSERT.equals(modelType)) { if (!(artifactMap.get(ATTACH_MODEL_ENTRY_NAME) instanceof AbstractModel)) throw new InvalidFormatException("attachModel must not be null!");
if (ParserType.CHUNKING.equals(modelType)) { if (artifactMap.get(ATTACH_MODEL_ENTRY_NAME) != null) throw new InvalidFormatException("attachModel must be null for chunking parser!"); else if (ParserType.TREEINSERT.equals(modelType)) { if (!(artifactMap.get(ATTACH_MODEL_ENTRY_NAME) instanceof AbstractModel)) throw new InvalidFormatException("attachModel must not be null!");
public void evaluate(ObjectStream<Parse> samples, int nFolds) throws IOException { CrossValidationPartitioner<Parse> partitioner = new CrossValidationPartitioner<>(samples, nFolds); while (partitioner.hasNext()) { CrossValidationPartitioner.TrainingSampleStream<Parse> trainingSampleStream = partitioner.next(); ParserModel model; if (ParserType.CHUNKING.equals(parserType)) { model = opennlp.tools.parser.chunking.Parser.train(languageCode, samples, rules, params); } else if (ParserType.TREEINSERT.equals(parserType)) { model = opennlp.tools.parser.treeinsert.Parser.train(languageCode, samples, rules, params); } else { throw new IllegalStateException("Unexpected parser type: " + parserType); } ParserEvaluator evaluator = new ParserEvaluator(ParserFactory.create(model), monitors); evaluator.evaluate(trainingSampleStream.getTestSampleStream()); fmeasure.mergeInto(evaluator.getFMeasure()); } }
public void evaluate(ObjectStream<Parse> samples, int nFolds) throws IOException { CrossValidationPartitioner<Parse> partitioner = new CrossValidationPartitioner<>(samples, nFolds); while (partitioner.hasNext()) { CrossValidationPartitioner.TrainingSampleStream<Parse> trainingSampleStream = partitioner.next(); ParserModel model; if (ParserType.CHUNKING.equals(parserType)) { model = opennlp.tools.parser.chunking.Parser.train(languageCode, samples, rules, params); } else if (ParserType.TREEINSERT.equals(parserType)) { model = opennlp.tools.parser.treeinsert.Parser.train(languageCode, samples, rules, params); } else { throw new IllegalStateException("Unexpected parser type: " + parserType); } ParserEvaluator evaluator = new ParserEvaluator(ParserFactory.create(model), monitors); evaluator.evaluate(trainingSampleStream.getTestSampleStream()); fmeasure.mergeInto(evaluator.getFMeasure()); } }