Search in sources :

Example 21 with MultiChoiceParameterValue

use of au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue in project constellation by constellation-app.

the class SmallWorldGraphBuilderPluginNGTest method testUpdateParameters.

/**
 * Test of updateParameters method, of class SmallWorldGraphBuilderPlugin.
 */
@Test
public void testUpdateParameters() {
    System.out.println("updateParameters");
    final SmallWorldGraphBuilderPlugin instance = new SmallWorldGraphBuilderPlugin();
    final PluginParameters params = instance.createParameters();
    final PluginParameter<MultiChoiceParameterValue> nAttribute = (PluginParameter<MultiChoiceParameterValue>) params.getParameters().get(NODE_TYPES_PARAMETER_ID);
    final PluginParameter<MultiChoiceParameterValue> tAttribute = (PluginParameter<MultiChoiceParameterValue>) params.getParameters().get(TRANSACTION_TYPES_PARAMETER_ID);
    assertTrue(MultiChoiceParameterType.getOptions(nAttribute).isEmpty());
    assertTrue(MultiChoiceParameterType.getOptions(tAttribute).isEmpty());
    instance.updateParameters(new DualGraph(graph.getSchema(), graph), params);
    assertEquals(MultiChoiceParameterType.getOptions(nAttribute).size(), 27);
    assertEquals(MultiChoiceParameterType.getChoices(nAttribute).size(), 1);
    assertEquals(MultiChoiceParameterType.getOptions(tAttribute).size(), 9);
    assertEquals(MultiChoiceParameterType.getChoices(tAttribute).size(), 1);
}
Also used : MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) Test(org.testng.annotations.Test)

Example 22 with MultiChoiceParameterValue

use of au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue in project constellation by constellation-app.

the class CompleteGraphBuilderPluginNGTest method testUpdateParameters.

/**
 * Test of updateParameters method, of class CompleteGraphBuilderPlugin.
 */
@Test
public void testUpdateParameters() {
    System.out.println("updateParameters");
    final CompleteGraphBuilderPlugin instance = new CompleteGraphBuilderPlugin();
    final PluginParameters params = instance.createParameters();
    final PluginParameter<MultiChoiceParameterValue> nAttribute = (PluginParameter<MultiChoiceParameterValue>) params.getParameters().get(NODE_TYPES_PARAMETER_ID);
    final PluginParameter<MultiChoiceParameterValue> tAttribute = (PluginParameter<MultiChoiceParameterValue>) params.getParameters().get(TRANSACTION_TYPES_PARAMETER_ID);
    assertTrue(MultiChoiceParameterType.getOptions(nAttribute).isEmpty());
    assertTrue(MultiChoiceParameterType.getOptions(tAttribute).isEmpty());
    instance.updateParameters(new DualGraph(graph.getSchema(), graph), params);
    assertEquals(MultiChoiceParameterType.getOptions(nAttribute).size(), 27);
    assertEquals(MultiChoiceParameterType.getChoices(nAttribute).size(), 1);
    assertEquals(MultiChoiceParameterType.getOptions(tAttribute).size(), 9);
    assertEquals(MultiChoiceParameterType.getChoices(tAttribute).size(), 1);
}
Also used : MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) Test(org.testng.annotations.Test)

Example 23 with MultiChoiceParameterValue

use of au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue in project constellation by constellation-app.

the class SmallWorldGraphBuilderPlugin method createParameters.

@Override
public PluginParameters createParameters() {
    final PluginParameters params = new PluginParameters();
    final PluginParameter<IntegerParameterValue> n = IntegerParameterType.build(N_PARAMETER_ID);
    n.setName("Number of nodes");
    n.setDescription("The number of nodes on the graph");
    n.setIntegerValue(10);
    IntegerParameterType.setMinimum(n, 0);
    params.addParameter(n);
    final PluginParameter<IntegerParameterValue> k = IntegerParameterType.build(K_PARAMETER_ID);
    k.setName("Nearest neighbours to attach");
    k.setDescription("The number of nearest neighbours to connect each node to");
    k.setIntegerValue(4);
    IntegerParameterType.setMinimum(k, 0);
    params.addParameter(k);
    final PluginParameter<FloatParameterValue> p = FloatParameterType.build(P_PARAMETER_ID);
    p.setName("Rewiring probability");
    p.setDescription("Probability of re-wiring each edge (low for a long shortest paths lattice structure, high for higher clustering coefficient random graph)");
    p.setFloatValue(0.5F);
    FloatParameterType.setMinimum(p, 0F);
    FloatParameterType.setMaximum(p, 1F);
    params.addParameter(p);
    final List<String> modes = new ArrayList<>();
    modes.add("Default");
    modes.add("Newman");
    modes.add(CONNECTED);
    final PluginParameter<SingleChoiceParameterValue> buildMode = SingleChoiceParameterType.build(BUILD_MODE_PARAMETER_ID);
    buildMode.setName("Build mode");
    buildMode.setDescription("Newman: Adds edges instead of rewiring. Connected: Attempts to build a connected graph.");
    SingleChoiceParameterType.setOptions(buildMode, modes);
    SingleChoiceParameterType.setChoice(buildMode, modes.get(0));
    params.addParameter(buildMode);
    final PluginParameter<IntegerParameterValue> t = IntegerParameterType.build(T_PARAMETER_ID);
    t.setName("Number of attempts to build connected graph");
    t.setDescription("Number of attempts to build a connected graph");
    t.setIntegerValue(100);
    IntegerParameterType.setMinimum(t, 1);
    t.setEnabled(false);
    params.addParameter(t);
    final PluginParameter<BooleanParameterValue> randomWeights = BooleanParameterType.build(RANDOM_WEIGHTS_PARAMETER_ID);
    randomWeights.setName("Random edge weight/direction");
    randomWeights.setDescription("Edges have a random number of transactions going in random directions");
    randomWeights.setBooleanValue(true);
    params.addParameter(randomWeights);
    final PluginParameter<MultiChoiceParameterValue> nodeTypes = MultiChoiceParameterType.build(NODE_TYPES_PARAMETER_ID);
    nodeTypes.setName("Node types");
    nodeTypes.setDescription("Node types to add to the graph");
    params.addParameter(nodeTypes);
    final PluginParameter<MultiChoiceParameterValue> transactionTypes = MultiChoiceParameterType.build(TRANSACTION_TYPES_PARAMETER_ID);
    transactionTypes.setName("Transaction types");
    transactionTypes.setDescription("Transaction types to add to the graph");
    params.addParameter(transactionTypes);
    params.addController(BUILD_MODE_PARAMETER_ID, (master, parameters, change) -> {
        if (change == ParameterChange.VALUE) {
            final String mode = master.getStringValue();
            parameters.get(T_PARAMETER_ID).setEnabled(mode.equals(CONNECTED));
        }
    });
    return params;
}
Also used : FloatParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.FloatParameterType.FloatParameterValue) MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) ArrayList(java.util.ArrayList) BooleanParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue) IntegerParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.IntegerParameterType.IntegerParameterValue) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)

Example 24 with MultiChoiceParameterValue

use of au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue in project constellation by constellation-app.

the class ScoreAnalyticPlugin method onPrerequisiteAttributeChange.

@Override
public void onPrerequisiteAttributeChange(final Graph graph, final PluginParameters parameters) {
    final Set<TransactionTypeParameterValue> transactionTypes = new HashSet<>();
    if (graph != null) {
        final ReadableGraph readableGraph = graph.getReadableGraph();
        try {
            final int typeAttributeId = AnalyticConcept.TransactionAttribute.TYPE.get(readableGraph);
            final int transactionCount = readableGraph.getTransactionCount();
            for (int transactionPosition = 0; transactionPosition < transactionCount; transactionPosition++) {
                final int transactionId = readableGraph.getTransaction(transactionPosition);
                if (typeAttributeId != Graph.NOT_FOUND) {
                    final SchemaTransactionType type = readableGraph.getObjectValue(typeAttributeId, transactionId);
                    transactionTypes.add(new TransactionTypeParameterValue(type));
                }
            }
        } finally {
            readableGraph.release();
        }
    }
    // TRANSACTION_TYPES_PARAMETER always of type MultiChoiceParameter
    @SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> transactionTypesParam = (PluginParameter<MultiChoiceParameterValue>) parameters.getParameters().get(TRANSACTION_TYPES_PARAMETER_ID);
    MultiChoiceParameterType.setOptionsData(transactionTypesParam, new ArrayList<>(transactionTypes));
    MultiChoiceParameterType.setChoicesData(transactionTypesParam, new ArrayList<>(transactionTypes));
}
Also used : ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) HashSet(java.util.HashSet)

Example 25 with MultiChoiceParameterValue

use of au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue in project constellation by constellation-app.

the class SelectTopNPlugin method createParameters.

@Override
public PluginParameters createParameters() {
    final PluginParameters params = new PluginParameters();
    final List<String> modes = new ArrayList<>();
    modes.add(NODE);
    modes.add(TRANSACTION);
    final PluginParameter<SingleChoiceParameterValue> modeParameter = SingleChoiceParameterType.build(MODE_PARAMETER_ID);
    modeParameter.setName("Mode");
    modeParameter.setDescription("Select either the Node or Transaction mode");
    SingleChoiceParameterType.setOptions(modeParameter, modes);
    params.addParameter(modeParameter);
    final PluginParameter<SingleChoiceParameterValue> typeCategoryParameter = SingleChoiceParameterType.build(TYPE_CATEGORY_PARAMETER_ID);
    typeCategoryParameter.setName("Type Category");
    typeCategoryParameter.setDescription("The high level type category");
    params.addParameter(typeCategoryParameter);
    final PluginParameter<MultiChoiceParameterValue> typeParameter = MultiChoiceParameterType.build(TYPE_PARAMETER_ID);
    typeParameter.setName("Specific Types");
    typeParameter.setDescription("The specific types to include when calculating the top N");
    params.addParameter(typeParameter);
    final PluginParameter<IntegerParameterValue> limitParameter = IntegerParameterType.build(LIMIT_PARAMETER_ID);
    limitParameter.setName("Limit");
    limitParameter.setDescription("The limit, default being 10");
    limitParameter.setIntegerValue(10);
    params.addParameter(limitParameter);
    params.addController(MODE_PARAMETER_ID, (PluginParameter<?> master, Map<String, PluginParameter<?>> parameters, ParameterChange change) -> {
        if (change == ParameterChange.VALUE) {
            final String mode = parameters.get(MODE_PARAMETER_ID).getStringValue();
            if (mode != null) {
                final List<String> types = new ArrayList<>();
                switch(mode) {
                    case NODE:
                        for (final SchemaVertexType type : SchemaVertexTypeUtilities.getTypes()) {
                            if (type.isTopLevelType()) {
                                types.add(type.getName());
                            }
                        }
                        break;
                    case TRANSACTION:
                        for (final SchemaTransactionType type : SchemaTransactionTypeUtilities.getTypes()) {
                            if (type.isTopLevelType()) {
                                types.add(type.getName());
                            }
                        }
                        break;
                    default:
                        LOGGER.severe("Invalid mode provided. Mode values accepted are " + NODE + " or " + TRANSACTION);
                }
                // TYPE_CATEGORY_PARAMETER will always be of type SingleChoiceParameter
                @SuppressWarnings("unchecked") final PluginParameter<SingleChoiceParameterValue> typeCategoryParamter = (PluginParameter<SingleChoiceParameterValue>) parameters.get(TYPE_CATEGORY_PARAMETER_ID);
                types.sort(String::compareTo);
                SingleChoiceParameterType.setOptions(typeCategoryParamter, types);
            }
        }
    });
    params.addController(TYPE_CATEGORY_PARAMETER_ID, (PluginParameter<?> master, Map<String, PluginParameter<?>> parameters, ParameterChange change) -> {
        if (change == ParameterChange.VALUE) {
            final String mode = parameters.get(MODE_PARAMETER_ID).getStringValue();
            final String typeCategory = parameters.get(TYPE_CATEGORY_PARAMETER_ID).getStringValue();
            if (mode != null && typeCategory != null) {
                final List<String> types = new ArrayList<>();
                switch(mode) {
                    case NODE:
                        final SchemaVertexType typeCategoryVertexType = SchemaVertexTypeUtilities.getType(typeCategory);
                        for (final SchemaVertexType type : SchemaVertexTypeUtilities.getTypes()) {
                            if (type.getSuperType().equals(typeCategoryVertexType)) {
                                types.add(type.getName());
                            }
                        }
                        break;
                    case TRANSACTION:
                        final SchemaTransactionType typeCategoryTransactionType = SchemaTransactionTypeUtilities.getType(typeCategory);
                        for (final SchemaTransactionType type : SchemaTransactionTypeUtilities.getTypes()) {
                            if (type.getSuperType().equals(typeCategoryTransactionType)) {
                                types.add(type.getName());
                            }
                        }
                        break;
                    default:
                        break;
                }
                // update the sub level types
                // TYPE_PARAMETER will always be of type MultiChoiceParameter
                @SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> typeParamter = (PluginParameter<MultiChoiceParameterValue>) parameters.get(TYPE_PARAMETER_ID);
                types.sort(String::compareTo);
                MultiChoiceParameterType.setOptions(typeParamter, types);
                MultiChoiceParameterType.setChoices(typeParamter, types);
            }
        }
    });
    return params;
}
Also used : ParameterChange(au.gov.asd.tac.constellation.plugins.parameters.ParameterChange) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) ArrayList(java.util.ArrayList) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) IntegerParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.IntegerParameterType.IntegerParameterValue) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)

Aggregations

MultiChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue)34 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)25 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)19 ArrayList (java.util.ArrayList)16 Test (org.testng.annotations.Test)12 SchemaTransactionType (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)9 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)8 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)7 SingleChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)6 TextPluginInteraction (au.gov.asd.tac.constellation.plugins.text.TextPluginInteraction)6 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)5 BooleanParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue)5 IntegerParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.IntegerParameterType.IntegerParameterValue)5 SchemaVertexType (au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType)4 ParameterChange (au.gov.asd.tac.constellation.plugins.parameters.ParameterChange)4 ParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.ParameterValue)4 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Graph (au.gov.asd.tac.constellation.graph.Graph)3 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)3