Search in sources :

Example 1 with SchemaTransactionType

use of au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType in project constellation by constellation-app.

the class MultiplexityPlugin method edit.

@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException {
    final boolean topLevelType = parameters.getBooleanValue(NORMALISE_AVAILABLE_PARAMETER_ID);
    final boolean normaliseByAvailable = parameters.getBooleanValue(NORMALISE_AVAILABLE_PARAMETER_ID);
    final int typeAttribute = TYPE_ATTRIBUTE.ensure(graph);
    // calculate multiplexity for every pair of vertices on the graph
    float maxMultiplexity = 0;
    final Map<Integer, Float> multiplexities = new HashMap<>();
    final int linkCount = graph.getLinkCount();
    for (int linkPosition = 0; linkPosition < linkCount; linkPosition++) {
        final int linkId = graph.getLink(linkPosition);
        final int linkLowId = graph.getLinkLowVertex(linkId);
        final int linkHighId = graph.getLinkHighVertex(linkId);
        final HashSet<SchemaTransactionType> types = new HashSet<>();
        if (linkLowId != linkHighId) {
            final int transactionCount = graph.getLinkTransactionCount(linkId);
            for (int transactionPosition = 0; transactionPosition < transactionCount; transactionPosition++) {
                final int transactionId = graph.getLinkTransaction(linkId, transactionPosition);
                SchemaTransactionType type = graph.getObjectValue(typeAttribute, transactionId);
                if (type != null) {
                    if (topLevelType) {
                        type = (SchemaTransactionType) type.getTopLevelType();
                    }
                    types.add(type);
                }
            }
            final float multiplexity = (float) types.size();
            multiplexities.put(linkId, multiplexity);
            maxMultiplexity = Math.max(multiplexity, maxMultiplexity);
        }
    }
    // update the graph with multiplexity values
    final int multiplexityAttribute = MULTIPLEXITY_ATTRIBUTE.ensure(graph);
    for (final Map.Entry<Integer, Float> entry : multiplexities.entrySet()) {
        final int transactionCount = graph.getLinkTransactionCount(entry.getKey());
        for (int transactionPosition = 0; transactionPosition < transactionCount; transactionPosition++) {
            final int transactionId = graph.getLinkTransaction(entry.getKey(), transactionPosition);
            if (normaliseByAvailable && maxMultiplexity > 0) {
                graph.setFloatValue(multiplexityAttribute, transactionId, entry.getValue() / maxMultiplexity);
            } else {
                graph.setFloatValue(multiplexityAttribute, transactionId, entry.getValue());
            }
        }
    }
}
Also used : SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with SchemaTransactionType

use of au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType in project constellation by constellation-app.

the class FactAnalyticPlugin 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);
                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 3 with SchemaTransactionType

use of au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType in project constellation by constellation-app.

the class FactAnalyticPlugin method edit.

@Override
protected final void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    try {
        // prepare the graph
        prepareGraph(graph, parameters);
        // ensure the required analytic attributes exists on the graph
        getAnalyticAttributes(parameters).forEach(schemaAttribute -> schemaAttribute.ensure(graph));
        // TRANSACTION_TYPES_PARAMETER always of type MultiChoiceParameter
        @SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> transactionTypesParameter = (PluginParameter<MultiChoiceParameterValue>) parameters.getParameters().get(TRANSACTION_TYPES_PARAMETER_ID);
        final List<ParameterValue> allTransactionTypes = MultiChoiceParameterType.getOptionsData(transactionTypesParameter);
        final List<? extends ParameterValue> chosenTransactionTypes = MultiChoiceParameterType.getChoicesData(transactionTypesParameter);
        if (chosenTransactionTypes.equals(allTransactionTypes)) {
            // run analytic plugin on the entire graph and compute results
            PluginExecution.withPlugin(getAnalyticPlugin().getDeclaredConstructor().newInstance()).withParameters(parameters).executeNow(graph);
            computeResultsFromGraph(graph, parameters);
        } else {
            // create subgraph
            final Set<SchemaTransactionType> transactionTypes = new HashSet<>();
            chosenTransactionTypes.forEach(parameterValue -> transactionTypes.add((SchemaTransactionType) ((TransactionTypeParameterValue) parameterValue).getObjectValue()));
            assert transactionTypes.size() > 0 : "You must select at least one transaction type";
            final StoreGraph subgraph = getSubgraph(graph, SchemaFactoryUtilities.getDefaultSchemaFactory(), transactionTypes);
            // run analytic plugin on the subgraph and compute results
            PluginExecution.withPlugin(getAnalyticPlugin().getDeclaredConstructor().newInstance()).withParameters(parameters).executeNow(subgraph);
            copySubgraphToGraph(graph, subgraph);
            computeResultsFromGraph(graph, parameters);
        }
    } catch (final IllegalAccessException | IllegalArgumentException | InstantiationException | NoSuchMethodException | SecurityException | InvocationTargetException ex) {
        LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
    }
}
Also used : MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) ParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.ParameterValue) MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) InvocationTargetException(java.lang.reflect.InvocationTargetException) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) HashSet(java.util.HashSet) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph)

Example 4 with SchemaTransactionType

use of au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType in project constellation by constellation-app.

the class TransactionTypeIOProvider method writeObject.

@Override
public void writeObject(final Attribute attribute, final int elementId, final JsonGenerator jsonGenerator, final GraphReadMethods graph, final GraphByteWriter byteWriter, final boolean verbose) throws IOException {
    if (verbose || !graph.isDefaultValue(attribute.getId(), elementId)) {
        final SchemaTransactionType attributeValue = graph.getObjectValue(attribute.getId(), elementId);
        if (attributeValue == null) {
            jsonGenerator.writeNullField(attribute.getName());
        } else {
            jsonGenerator.writeObjectFieldStart(attribute.getName());
            writeTypeObject(attributeValue, jsonGenerator);
            jsonGenerator.writeEndObject();
        }
    }
}
Also used : SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)

Example 5 with SchemaTransactionType

use of au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType in project constellation by constellation-app.

the class ScoreAnalyticPlugin method edit.

@Override
protected final void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    try {
        // prepare the graph
        prepareGraph(graph, parameters);
        // ensure the required analytic attributes exists on the graph
        getAnalyticAttributes(parameters).forEach(analyticAttribute -> analyticAttribute.ensure(graph));
        // Transaction types parameter is created as a multiChoiceParameter in this class on line 166.
        @SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> transactionTypesParameter = (PluginParameter<MultiChoiceParameterValue>) parameters.getParameters().get(TRANSACTION_TYPES_PARAMETER_ID);
        final List<? extends ParameterValue> allTransactionTypes = MultiChoiceParameterType.getOptionsData(transactionTypesParameter);
        final List<? extends ParameterValue> chosenTransactionTypes = MultiChoiceParameterType.getChoicesData(transactionTypesParameter);
        if (chosenTransactionTypes.equals(allTransactionTypes)) {
            // run analytic plugin on the entire graph and compute results
            PluginExecution.withPlugin(getAnalyticPlugin().getDeclaredConstructor().newInstance()).withParameters(parameters).executeNow(graph);
            computeResultsFromGraph(graph, parameters);
        } else {
            // create subgraph
            final Set<SchemaTransactionType> transactionTypes = new HashSet<>();
            parameters.getMultiChoiceValue(TRANSACTION_TYPES_PARAMETER_ID).getChoicesData().forEach(parameterValue -> transactionTypes.add((SchemaTransactionType) ((TransactionTypeParameterValue) parameterValue).getObjectValue()));
            assert transactionTypes.size() > 0 : "You must select at least one transaction type";
            final StoreGraph subgraph = getSubgraph(graph, SchemaFactoryUtilities.getDefaultSchemaFactory(), transactionTypes);
            // run analytic plugin and compute results
            PluginExecution.withPlugin(getAnalyticPlugin().getDeclaredConstructor().newInstance()).withParameters(parameters).executeNow(subgraph);
            copySubgraphToGraph(graph, subgraph);
            computeResultsFromGraph(graph, parameters);
        }
    } catch (final IllegalAccessException | IllegalArgumentException | InstantiationException | NoSuchMethodException | SecurityException | InvocationTargetException ex) {
        LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
    }
}
Also used : MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) InvocationTargetException(java.lang.reflect.InvocationTargetException) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) HashSet(java.util.HashSet) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph)

Aggregations

SchemaTransactionType (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)29 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)11 ArrayList (java.util.ArrayList)11 MultiChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue)10 SchemaVertexType (au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType)8 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)7 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)5 SchemaConcept (au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept)4 Map (java.util.Map)4 RecordStore (au.gov.asd.tac.constellation.graph.processing.RecordStore)3 AnalyticConcept (au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept)3 SchemaTransactionTypeUtilities (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionTypeUtilities)3 SchemaVertexTypeUtilities (au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexTypeUtilities)3 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)3 SingleChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)3 List (java.util.List)3 Graph (au.gov.asd.tac.constellation.graph.Graph)2 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)2 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)2