Search in sources :

Example 56 with Function

use of java.util.function.Function in project intellij-community by JetBrains.

the class UnusedPropertyInspection method buildPropertyGroupVisitor.

@NotNull
@Override
public Function<IProperty[], ResourceBundleEditorProblemDescriptor[]> buildPropertyGroupVisitor(@NotNull ResourceBundle resourceBundle) {
    final Module module = ModuleUtilCore.findModuleForPsiElement(resourceBundle.getDefaultPropertiesFile().getContainingFile());
    if (module == null)
        return x -> null;
    final UnusedPropertiesSearchHelper helper = new UnusedPropertiesSearchHelper(module);
    return properties -> !isPropertyUsed((Property) properties[0], helper, true) ? new ResourceBundleEditorProblemDescriptor[] { new ResourceBundleEditorProblemDescriptor(ProblemHighlightType.LIKE_UNUSED_SYMBOL, PropertiesBundle.message("unused.property.problem.descriptor.name"), new RemovePropertiesFromAllLocalesFix((Property) properties[0])) } : null;
}
Also used : PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) ContainerUtil(com.intellij.util.containers.ContainerUtil) Function(java.util.function.Function) ResourceBundleEditorProblemDescriptor(com.intellij.lang.properties.editor.inspections.ResourceBundleEditorProblemDescriptor) Nls(org.jetbrains.annotations.Nls) Project(com.intellij.openapi.project.Project) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) Extensions(com.intellij.openapi.extensions.Extensions) ProgressManager(com.intellij.openapi.progress.ProgressManager) ReferencesSearch(com.intellij.psi.search.searches.ReferencesSearch) Property(com.intellij.lang.properties.psi.Property) PsiSearchHelper(com.intellij.psi.search.PsiSearchHelper) FileModificationService(com.intellij.codeInsight.FileModificationService) PropertySearcher(com.intellij.lang.properties.findUsages.PropertySearcher) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Set(java.util.Set) com.intellij.codeInspection(com.intellij.codeInspection) com.intellij.lang.properties(com.intellij.lang.properties) Objects(java.util.Objects) ASTNode(com.intellij.lang.ASTNode) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) com.intellij.psi(com.intellij.psi) ResourceBundleEditorInspection(com.intellij.lang.properties.editor.inspections.ResourceBundleEditorInspection) NotNull(org.jetbrains.annotations.NotNull) FilteringIterator(com.intellij.util.containers.FilteringIterator) ResourceBundleEditorProblemDescriptor(com.intellij.lang.properties.editor.inspections.ResourceBundleEditorProblemDescriptor) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 57 with Function

use of java.util.function.Function in project enhydrator by AdamBien.

the class Pump method applyRowTransformations.

static Row applyRowTransformations(List<Function<Row, Row>> trafos, Row convertedColumns) {
    if (trafos == null || trafos.isEmpty()) {
        return convertedColumns;
    }
    final Function<Row, Row> composition = trafos.stream().reduce((i, j) -> i.andThen(j)).get();
    Row result = composition.apply(convertedColumns);
    if (result == null) {
        return null;
    } else {
        return result;
    }
}
Also used : LogSink(com.airhacks.enhydrator.out.LogSink) Memory(com.airhacks.enhydrator.transform.Memory) FunctionScriptLoader(com.airhacks.enhydrator.transform.FunctionScriptLoader) HashMap(java.util.HashMap) ColumnTransformation(com.airhacks.enhydrator.flexpipe.ColumnTransformation) Source(com.airhacks.enhydrator.in.Source) Sink(com.airhacks.enhydrator.out.Sink) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) JsonValue(javax.json.JsonValue) Expression(com.airhacks.enhydrator.transform.Expression) List(java.util.List) FilterExpression(com.airhacks.enhydrator.transform.FilterExpression) RowTransformer(com.airhacks.enhydrator.transform.RowTransformer) Map(java.util.Map) NamedSink(com.airhacks.enhydrator.out.NamedSink) Optional(java.util.Optional) Pipeline(com.airhacks.enhydrator.flexpipe.Pipeline) ColumnTransformer(com.airhacks.enhydrator.transform.ColumnTransformer) Row(com.airhacks.enhydrator.in.Row) Row(com.airhacks.enhydrator.in.Row)

Example 58 with Function

use of java.util.function.Function in project aic-expresso by aic-sri-international.

the class Compilation method compile.

/**
	 * Compiles an expression to a normalized (decision-tree-like) expression.
	 * @param inputExpression
	 * @param mapFromVariableNameToTypeName
	 * @param mapFromCategoricalTypeNameToSizeString
	 * @param additionalTypes
	 * @param solverListener if not null, invoked on solver used for compilation, before and after compilation starts; returned solver on 'before' invocation is used (it may be the same one used as argument, of course).
	 * @return
	 */
public static Expression compile(Expression inputExpression, Theory theory, Map<String, String> mapFromVariableNameToTypeName, Map<String, String> mapFromUniquelyNamedConstantToTypeName, Map<String, String> mapFromCategoricalTypeNameToSizeString, Collection<Type> additionalTypes, Function<MultiIndexQuantifierEliminator, MultiIndexQuantifierEliminator> solverListener) {
    // the group actually does not matter, because we are not going to have any indices.
    AssociativeCommutativeGroup group = new Max();
    // The solver for the parameters above.
    MultiIndexQuantifierEliminator solver = new SGDPLLT();
    if (solverListener != null) {
        solver = solverListener.apply(solver);
    }
    // We use the Prolog convention of small-letter initials for constants, but we need an exception for the random variables.
    Predicate<Expression> isPrologConstant = new PrologConstantPredicate();
    Predicate<Expression> isUniquelyNamedConstantPredicate = e -> isPrologConstant.apply(e) && !mapFromVariableNameToTypeName.containsKey(e);
    Map<String, String> mapFromSymbolNameToTypeName = new LinkedHashMap<>(mapFromVariableNameToTypeName);
    mapFromSymbolNameToTypeName.putAll(mapFromUniquelyNamedConstantToTypeName);
    // Solve the problem.
    // no indices; we want to keep all variables
    List<Expression> indices = Util.list();
    Expression result = solver.solve(group, inputExpression, indices, mapFromSymbolNameToTypeName, mapFromCategoricalTypeNameToSizeString, additionalTypes, isUniquelyNamedConstantPredicate, theory);
    if (solverListener != null) {
        solverListener.apply(null);
    }
    return result;
}
Also used : Type(com.sri.ai.expresso.api.Type) MultiIndexQuantifierEliminator(com.sri.ai.grinder.sgdpllt.api.MultiIndexQuantifierEliminator) SGDPLLT(com.sri.ai.grinder.sgdpllt.core.solver.SGDPLLT) Collection(java.util.Collection) Expression(com.sri.ai.expresso.api.Expression) Function(java.util.function.Function) Theory(com.sri.ai.grinder.sgdpllt.api.Theory) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) Predicate(com.google.common.base.Predicate) Max(com.sri.ai.grinder.sgdpllt.group.Max) Map(java.util.Map) Util(com.sri.ai.util.Util) AssociativeCommutativeGroup(com.sri.ai.grinder.sgdpllt.group.AssociativeCommutativeGroup) PrologConstantPredicate(com.sri.ai.grinder.core.PrologConstantPredicate) MultiIndexQuantifierEliminator(com.sri.ai.grinder.sgdpllt.api.MultiIndexQuantifierEliminator) Max(com.sri.ai.grinder.sgdpllt.group.Max) SGDPLLT(com.sri.ai.grinder.sgdpllt.core.solver.SGDPLLT) PrologConstantPredicate(com.sri.ai.grinder.core.PrologConstantPredicate) Expression(com.sri.ai.expresso.api.Expression) AssociativeCommutativeGroup(com.sri.ai.grinder.sgdpllt.group.AssociativeCommutativeGroup) LinkedHashMap(java.util.LinkedHashMap)

Example 59 with Function

use of java.util.function.Function in project aima-java by aimacode.

the class SimulatedAnnealingMaximumFinderApp method simulate.

/** Starts the experiment. */
@SuppressWarnings("unchecked")
public void simulate() {
    List<Action> actions = new ArrayList<>(1);
    actions.add(new DynamicAction("Move"));
    Problem<Double, Action> problem = new GeneralProblem<>(getRandomState(), s -> actions, (s, a) -> getSuccessor(s), s -> false);
    Function<Double, Double> func = (Function<Double, Double>) simPaneCtrl.getParamValue(PARAM_FUNC_SELECT);
    Scheduler scheduler = new Scheduler(simPaneCtrl.getParamAsInt(PARAM_K), simPaneCtrl.getParamAsDouble(PARAM_LAMBDA), simPaneCtrl.getParamAsInt(PARAM_MAX_ITER));
    search = new SimulatedAnnealingSearch<>(n -> 1 - func.apply(n.getState()), scheduler);
    search.addNodeListener(n -> updateStateView(n.getState()));
    search.findActions(problem);
    updateStateView(search.getLastSearchState());
}
Also used : Color(javafx.scene.paint.Color) java.util(java.util) IntegrableApplication(aima.gui.fx.framework.IntegrableApplication) Canvas(javafx.scene.canvas.Canvas) Action(aima.core.agent.Action) GeneralProblem(aima.core.search.framework.problem.GeneralProblem) SimulationPaneBuilder(aima.gui.fx.framework.SimulationPaneBuilder) Function(java.util.function.Function) Platform(javafx.application.Platform) Scheduler(aima.core.search.local.Scheduler) Parameter(aima.gui.fx.framework.Parameter) Paint(javafx.scene.paint.Paint) SimulationPaneCtrl(aima.gui.fx.framework.SimulationPaneCtrl) FunctionPlotterCtrl(aima.gui.fx.views.FunctionPlotterCtrl) BorderPane(javafx.scene.layout.BorderPane) DynamicAction(aima.core.agent.impl.DynamicAction) Problem(aima.core.search.framework.problem.Problem) SimulatedAnnealingSearch(aima.core.search.local.SimulatedAnnealingSearch) Pane(javafx.scene.layout.Pane) Function(java.util.function.Function) Action(aima.core.agent.Action) DynamicAction(aima.core.agent.impl.DynamicAction) Scheduler(aima.core.search.local.Scheduler) DynamicAction(aima.core.agent.impl.DynamicAction) GeneralProblem(aima.core.search.framework.problem.GeneralProblem)

Example 60 with Function

use of java.util.function.Function in project Alpha by alpha-asp.

the class AbstractSolverTests method factories.

@Parameters(name = "{0}")
public static Collection<Object[]> factories() {
    boolean enableAdditionalInternalChecks = false;
    Collection<Object[]> factories = new ArrayList<>();
    factories.add(new Object[] { "NaiveSolver", (Function<Grounder, Solver>) NaiveSolver::new });
    for (Heuristic heuristic : Heuristic.values()) {
        String name = "DefaultSolver (random " + heuristic + ")";
        Function<Grounder, Solver> instantiator = g -> {
            return new DefaultSolver(g, new Random(), heuristic, enableAdditionalInternalChecks);
        };
        factories.add(new Object[] { name, instantiator });
        name = "DefaultSolver (deterministic " + heuristic + ")";
        instantiator = g -> {
            return new DefaultSolver(g, new Random(0), heuristic, enableAdditionalInternalChecks);
        };
        factories.add(new Object[] { name, instantiator });
    }
    return factories;
}
Also used : java.util(java.util) Heuristic(at.ac.tuwien.kr.alpha.solver.heuristics.BranchingHeuristicFactory.Heuristic) Parameter(org.junit.runners.Parameterized.Parameter) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) Grounder(at.ac.tuwien.kr.alpha.grounder.Grounder) Function(java.util.function.Function) Parameterized(org.junit.runners.Parameterized) Grounder(at.ac.tuwien.kr.alpha.grounder.Grounder) Heuristic(at.ac.tuwien.kr.alpha.solver.heuristics.BranchingHeuristicFactory.Heuristic) Parameters(org.junit.runners.Parameterized.Parameters)

Aggregations

Function (java.util.function.Function)176 List (java.util.List)75 ArrayList (java.util.ArrayList)55 Map (java.util.Map)51 Test (org.junit.Test)47 IOException (java.io.IOException)44 HashMap (java.util.HashMap)37 Set (java.util.Set)36 Collectors (java.util.stream.Collectors)33 Arrays (java.util.Arrays)30 Collections (java.util.Collections)26 Collection (java.util.Collection)25 File (java.io.File)20 HashSet (java.util.HashSet)19 Supplier (java.util.function.Supplier)19 BiFunction (java.util.function.BiFunction)18 Consumer (java.util.function.Consumer)16 Test (org.testng.annotations.Test)16 Stream (java.util.stream.Stream)14 Assert.assertEquals (org.junit.Assert.assertEquals)13