Java Code Examples for java.util.function.IntConsumer#andThen()

The following examples show how to use java.util.function.IntConsumer#andThen() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntConsumerTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void testAndThen_null() throws Exception {
  IntConsumer one = s -> {};
  try {
    one.andThen(null);
    fail();
  } catch (NullPointerException expected) {}
}
 
Example 2
Source File: HybridBatchLearner.java    From amr with GNU General Public License v2.0 4 votes vote down vote up
@Override
public HybridBatchLearner create(Parameters params,
		IResourceRepository repo) {

	final IDataCollection<LabeledAmrSentence> trainingData = repo
			.get(params.get("data"));
	final int numIterations = params.getAsInteger("iter");
	final int maxSentenceLength = params
			.getAsInteger("maxSentenceLength", Integer.MAX_VALUE);
	final boolean sortData = params.getAsBoolean("sortData", false);

	final ICategoryServices<LogicalExpression> categoryServices;
	final ILexiconGeneratorPrecise<LabeledAmrSentence, LogicalExpression, IJointModelImmutable<SituatedSentence<AMRMeta>, LogicalExpression, LogicalExpression>> genlex;
	if (params.contains("genlex")) {
		genlex = repo.get(params.get("genlex"));
		categoryServices = repo.get(
				ParameterizedExperiment.CATEGORY_SERVICES_RESOURCE);
	} else {
		genlex = null;
		categoryServices = null;
	}

	final IJointOutputLogger<LogicalExpression, LogicalExpression, LogicalExpression> parserOutputLogger;
	if (params.contains("parseLogger")) {
		parserOutputLogger = repo.get(params.get("parseLogger"));
	} else {
		parserOutputLogger = null;
	}

	final IJointInferenceFilterFactory<LabeledAmrSentence, LogicalExpression, LogicalExpression, LogicalExpression> filterFactory;
	if (params.contains("filterFactory")) {
		filterFactory = repo.get(params.get("filterFactory"));
	} else {
		filterFactory = new IJointInferenceFilterFactory<LabeledAmrSentence, LogicalExpression, LogicalExpression, LogicalExpression>() {
			private static final long serialVersionUID = 5208726408785946328L;

			@Override
			public Predicate<ParsingOp<LogicalExpression>> create(
					LabeledAmrSentence object) {
				return JointInferenceFilterUtils.stubTrue();
			}

			@Override
			public IJointInferenceFilter<LogicalExpression, LogicalExpression, LogicalExpression> createJointFilter(
					LabeledAmrSentence ibj) {
				return JointInferenceFilterUtils.stubTrue();
			}
		};

	}

	IntConsumer postIteration = (i) -> {
		return;
	};
	for (final String id : params.getSplit("postIteration")) {
		postIteration = postIteration.andThen(repo.get(id));
	}

	final BiFunction<Predicate<LexicalEntry<LogicalExpression>>, Map<LexicalEntry<LogicalExpression>, Double>, Set<LexicalEntry<LogicalExpression>>> votingProcedure;
	if (params.contains("voter")) {
		votingProcedure = repo.get(params.get("voter"));
	} else {
		votingProcedure = new StubVoting();
	}

	Integer conditionedInferenceBeam;
	if (params.contains("conditionedBeam")) {
		conditionedInferenceBeam = params
				.getAsInteger("conditionedBeam");
	} else {
		conditionedInferenceBeam = null;
	}

	final ILexiconGenerator<LabeledAmrSentence, LogicalExpression, IJointModelImmutable<SituatedSentence<AMRMeta>, LogicalExpression, LogicalExpression>> alignmentGenlex;
	if (params.contains("alignGenlex")) {
		alignmentGenlex = repo.get(params.get("alignGenlex"));
	} else {
		alignmentGenlex = null;
	}

	final ILexiconImmutable<LogicalExpression> keepEntries;
	if (params.contains("keepEntries")) {
		keepEntries = repo.get(params.get("keepEntries"));
	} else {
		keepEntries = new Lexicon<>();
	}

	return new HybridBatchLearner(numIterations, trainingData, sortData,
			maxSentenceLength,
			repo.get(ParameterizedExperiment.PARSER_RESOURCE),
			parserOutputLogger, categoryServices, genlex, filterFactory,
			postIteration, params.getAsBoolean("prune", false),
			votingProcedure,
			repo.<IWeightUpdateProcedure> get(params.get("estimator")),
			repo.get(params.get("gradient")), conditionedInferenceBeam,
			alignmentGenlex, params.getAsBoolean("resume", false),
			keepEntries);
}
 
Example 3
Source File: DistributeMiniBatchLearner.java    From amr with GNU General Public License v2.0 4 votes vote down vote up
@Override
public DistributeMiniBatchLearner create(Parameters params,
		IResourceRepository repo) {

	final IDataCollection<LabeledAmrSentence> trainingData = repo
			.get(params.get("data"));
	final int numIterations = params.getAsInteger("iter");
	final int maxSentenceLength = params
			.getAsInteger("maxSentenceLength", Integer.MAX_VALUE);
	final boolean sortData = params.getAsBoolean("sortData", false);

	final ICategoryServices<LogicalExpression> categoryServices;
	final ILexiconGeneratorPrecise<LabeledAmrSentence, LogicalExpression, IJointModelImmutable<SituatedSentence<AMRMeta>, LogicalExpression, LogicalExpression>> genlex;
	if (params.contains("genlex")) {
		genlex = repo.get(params.get("genlex"));
		categoryServices = repo.get(
				ParameterizedExperiment.CATEGORY_SERVICES_RESOURCE);
	} else {
		genlex = null;
		categoryServices = null;
	}

	final IJointOutputLogger<LogicalExpression, LogicalExpression, LogicalExpression> parserOutputLogger;
	if (params.contains("parseLogger")) {
		parserOutputLogger = repo.get(params.get("parseLogger"));
	} else {
		parserOutputLogger = null;
	}

	final IJointInferenceFilterFactory<LabeledAmrSentence, LogicalExpression, LogicalExpression, LogicalExpression> filterFactory;
	if (params.contains("filterFactory")) {
		filterFactory = repo.get(params.get("filterFactory"));
	} else {
		filterFactory = new IJointInferenceFilterFactory<LabeledAmrSentence, LogicalExpression, LogicalExpression, LogicalExpression>() {
			private static final long serialVersionUID = -8410588783722286647L;

			@Override
			public Predicate<ParsingOp<LogicalExpression>> create(
					LabeledAmrSentence object) {
				return JointInferenceFilterUtils.stubTrue();
			}

			@Override
			public IJointInferenceFilter<LogicalExpression, LogicalExpression, LogicalExpression> createJointFilter(
					LabeledAmrSentence ibj) {
				return JointInferenceFilterUtils.stubTrue();
			}
		};

	}

	IntConsumer postIteration = (i) -> {
		return;
	};
	for (final String id : params.getSplit("postIteration")) {
		postIteration = postIteration.andThen(repo.get(id));
	}

	final BiFunction<Predicate<LexicalEntry<LogicalExpression>>, Map<LexicalEntry<LogicalExpression>, Double>, Set<LexicalEntry<LogicalExpression>>> votingProcedure;
	if (params.contains("voter")) {
		votingProcedure = repo.get(params.get("voter"));
	} else {
		votingProcedure = new StubVoting();
	}

	Integer conditionedInferenceBeam;
	if (params.contains("conditionedBeam")) {
		conditionedInferenceBeam = params
				.getAsInteger("conditionedBeam");
	} else {
		conditionedInferenceBeam = null;
	}

	final ILexiconGenerator<LabeledAmrSentence, LogicalExpression, IJointModelImmutable<SituatedSentence<AMRMeta>, LogicalExpression, LogicalExpression>> alignmentGenlex;
	if (params.contains("alignGenlex")) {
		alignmentGenlex = repo.get(params.get("alignGenlex"));
	} else {
		alignmentGenlex = null;
	}

	final ILexiconImmutable<LogicalExpression> keepEntries;
	if (params.contains("keepEntries")) {
		keepEntries = repo.get(params.get("keepEntries"));
	} else {
		keepEntries = new Lexicon<>();
	}

	return new DistributeMiniBatchLearner(numIterations, trainingData,
			sortData, maxSentenceLength,
			repo.get(ParameterizedExperiment.PARSER_RESOURCE),
			parserOutputLogger, categoryServices, genlex, filterFactory,
			postIteration, params.getAsBoolean("prune", false),
			votingProcedure, repo.get(params.get("manager")),
			params.getAsInteger("batch"),
			repo.get(params.get("estimator")),
			repo.get(params.get("gradient")), conditionedInferenceBeam,
			alignmentGenlex, params.getAsBoolean("resume", false),
			keepEntries);
}
 
Example 4
Source File: HybridDistributedBatchLearner.java    From amr with GNU General Public License v2.0 4 votes vote down vote up
@Override
public HybridDistributedBatchLearner create(Parameters params,
		IResourceRepository repo) {

	final IDataCollection<LabeledAmrSentence> trainingData = repo
			.get(params.get("data"));
	final int numIterations = params.getAsInteger("iter");
	final int maxSentenceLength = params
			.getAsInteger("maxSentenceLength", Integer.MAX_VALUE);
	final boolean sortData = params.getAsBoolean("sortData", false);

	final ICategoryServices<LogicalExpression> categoryServices;
	final ILexiconGeneratorPrecise<LabeledAmrSentence, LogicalExpression, IJointModelImmutable<SituatedSentence<AMRMeta>, LogicalExpression, LogicalExpression>> genlex;
	if (params.contains("genlex")) {
		genlex = repo.get(params.get("genlex"));
		categoryServices = repo.get(
				ParameterizedExperiment.CATEGORY_SERVICES_RESOURCE);
	} else {
		genlex = null;
		categoryServices = null;
	}

	final IJointOutputLogger<LogicalExpression, LogicalExpression, LogicalExpression> parserOutputLogger;
	if (params.contains("parseLogger")) {
		parserOutputLogger = repo.get(params.get("parseLogger"));
	} else {
		parserOutputLogger = null;
	}

	final IJointInferenceFilterFactory<LabeledAmrSentence, LogicalExpression, LogicalExpression, LogicalExpression> filterFactory;
	if (params.contains("filterFactory")) {
		filterFactory = repo.get(params.get("filterFactory"));
	} else {
		filterFactory = new IJointInferenceFilterFactory<LabeledAmrSentence, LogicalExpression, LogicalExpression, LogicalExpression>() {
			private static final long serialVersionUID = -8410588783722286647L;

			@Override
			public Predicate<ParsingOp<LogicalExpression>> create(
					LabeledAmrSentence object) {
				return JointInferenceFilterUtils.stubTrue();
			}

			@Override
			public IJointInferenceFilter<LogicalExpression, LogicalExpression, LogicalExpression> createJointFilter(
					LabeledAmrSentence ibj) {
				return JointInferenceFilterUtils.stubTrue();
			}
		};

	}

	IntConsumer postIteration = (i) -> {
		return;
	};
	for (final String id : params.getSplit("postIteration")) {
		postIteration = postIteration.andThen(repo.get(id));
	}

	final BiFunction<Predicate<LexicalEntry<LogicalExpression>>, Map<LexicalEntry<LogicalExpression>, Double>, Set<LexicalEntry<LogicalExpression>>> votingProcedure;
	if (params.contains("voter")) {
		votingProcedure = repo.get(params.get("voter"));
	} else {
		votingProcedure = new StubVoting();
	}

	Integer conditionedInferenceBeam;
	if (params.contains("conditionedBeam")) {
		conditionedInferenceBeam = params
				.getAsInteger("conditionedBeam");
	} else {
		conditionedInferenceBeam = null;
	}

	final ILexiconGenerator<LabeledAmrSentence, LogicalExpression, IJointModelImmutable<SituatedSentence<AMRMeta>, LogicalExpression, LogicalExpression>> alignmentGenlex;
	if (params.contains("alignGenlex")) {
		alignmentGenlex = repo.get(params.get("alignGenlex"));
	} else {
		alignmentGenlex = null;
	}

	final ILexiconImmutable<LogicalExpression> keepEntries;
	if (params.contains("keepEntries")) {
		keepEntries = repo.get(params.get("keepEntries"));
	} else {
		keepEntries = new Lexicon<>();
	}

	return new HybridDistributedBatchLearner(numIterations,
			trainingData, sortData, maxSentenceLength,
			repo.get(ParameterizedExperiment.PARSER_RESOURCE),
			parserOutputLogger, categoryServices, genlex, filterFactory,
			postIteration, params.getAsBoolean("prune", false),
			votingProcedure, repo.get(params.get("manager")),
			repo.get(params.get("estimator")),
			repo.get(params.get("gradient")), conditionedInferenceBeam,
			alignmentGenlex, params.getAsBoolean("resume", false),
			keepEntries);
}