Search in sources :

Example 1 with GraphElementMerger

use of au.gov.asd.tac.constellation.graph.GraphElementMerger in project constellation by constellation-app.

the class CompositeUtilities method destroyComposite.

/**
 * Destroys a single composite node which the specified node either is, or
 * is a constituent of.
 *
 * @param graph The graph.
 * @param compositeStateAttr The graph ID of the composite state attribute
 * for nodes.
 * @param uniqueIdAttr The graph ID of the uniqueId attribute for
 * transactions.
 * @param vxId The ID of the specified node.
 * @return A list of IDs of any newly expanded nodes. This will be an empty
 * list if no composite was destroyed, or if the destroyed composite was
 * already expanded.
 */
public static List<Integer> destroyComposite(final GraphWriteMethods graph, final int compositeStateAttr, final int uniqueIdAttr, final int vxId) {
    final List<Integer> resultingNodes = new ArrayList<>();
    final CompositeNodeState compositeState = (CompositeNodeState) graph.getObjectValue(compositeStateAttr, vxId);
    if (compositeState != null) {
        if (compositeState.isComposite()) {
            final ContractedCompositeNodeState contractedState = compositeState.contractedState;
            resultingNodes.addAll(contractedState.expand(graph, vxId));
            while (true) {
                try {
                    graph.validateKey(GraphElementType.VERTEX, false);
                    break;
                } catch (final DuplicateKeyException ex) {
                    LOGGER.log(Level.INFO, "Duplicate Key has been found. Merging duplicate nodes");
                    final GraphElementMerger merger = new PrioritySurvivingGraphElementMerger();
                    merger.mergeElement(graph, GraphElementType.VERTEX, ex.getNewId(), ex.getExistingId());
                }
            }
            resultingNodes.forEach(id -> {
                simplifyCompositeTransactions(graph, uniqueIdAttr, id);
                graph.setObjectValue(compositeStateAttr, id, null);
            });
        } else {
            final int vertexCount = graph.getVertexCount();
            for (int i = 0; i < vertexCount; i++) {
                final int nxId = graph.getVertex(i);
                final CompositeNodeState cns = ((CompositeNodeState) graph.getObjectValue(compositeStateAttr, nxId));
                if (cns != null && cns.expandedState != null && cns.expandedState.getCompositeId().equals(compositeState.expandedState.getCompositeId())) {
                    simplifyCompositeTransactions(graph, uniqueIdAttr, nxId);
                    graph.setObjectValue(compositeStateAttr, nxId, null);
                }
            }
        }
    }
    return resultingNodes;
}
Also used : CompositeNodeState(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.CompositeNodeState) ExpandedCompositeNodeState(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.ExpandedCompositeNodeState) ContractedCompositeNodeState(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.ContractedCompositeNodeState) PrioritySurvivingGraphElementMerger(au.gov.asd.tac.constellation.graph.mergers.PrioritySurvivingGraphElementMerger) ArrayList(java.util.ArrayList) ContractedCompositeNodeState(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.ContractedCompositeNodeState) DuplicateKeyException(au.gov.asd.tac.constellation.graph.DuplicateKeyException) GraphElementMerger(au.gov.asd.tac.constellation.graph.GraphElementMerger) PrioritySurvivingGraphElementMerger(au.gov.asd.tac.constellation.graph.mergers.PrioritySurvivingGraphElementMerger)

Example 2 with GraphElementMerger

use of au.gov.asd.tac.constellation.graph.GraphElementMerger in project constellation by constellation-app.

the class CompositeUtilities method expandComposite.

/**
 * Expands a single composite node.
 *
 * @param graph The graph.
 * @param compositeStateAttr The graph ID of the composite state attribute
 * for nodes.
 * @param vxId The id of the specified node.
 * @return A list of the id's of the expanded constituent nodes. This will
 * be empty if the specified node was not a composite.
 */
public static List<Integer> expandComposite(final GraphWriteMethods graph, final int compositeStateAttr, final int vxId) {
    final List<Integer> expandedNodes = new ArrayList<>();
    final CompositeNodeState compositeState = (CompositeNodeState) graph.getObjectValue(compositeStateAttr, vxId);
    if (compositeState != null && compositeState.isComposite()) {
        final ContractedCompositeNodeState contractedState = compositeState.contractedState;
        expandedNodes.addAll(contractedState.expand(graph, vxId));
        while (true) {
            try {
                graph.validateKey(GraphElementType.VERTEX, false);
                break;
            } catch (final DuplicateKeyException ex) {
                LOGGER.log(Level.INFO, "Duplicate Key has been found. Merging duplicate nodes");
                final GraphElementMerger merger = new PrioritySurvivingGraphElementMerger();
                merger.mergeElement(graph, GraphElementType.VERTEX, ex.getNewId(), ex.getExistingId());
            }
        }
    }
    return expandedNodes;
}
Also used : CompositeNodeState(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.CompositeNodeState) ExpandedCompositeNodeState(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.ExpandedCompositeNodeState) ContractedCompositeNodeState(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.ContractedCompositeNodeState) PrioritySurvivingGraphElementMerger(au.gov.asd.tac.constellation.graph.mergers.PrioritySurvivingGraphElementMerger) ArrayList(java.util.ArrayList) ContractedCompositeNodeState(au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.ContractedCompositeNodeState) DuplicateKeyException(au.gov.asd.tac.constellation.graph.DuplicateKeyException) GraphElementMerger(au.gov.asd.tac.constellation.graph.GraphElementMerger) PrioritySurvivingGraphElementMerger(au.gov.asd.tac.constellation.graph.mergers.PrioritySurvivingGraphElementMerger)

Example 3 with GraphElementMerger

use of au.gov.asd.tac.constellation.graph.GraphElementMerger in project constellation by constellation-app.

the class MergeTransactionsPlugin method edit.

@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    int mergedCount = 0;
    interaction.setProgress(0, 0, "Merging transactions...", true);
    final String mergeTransactionTypeName = parameters.getParameters().get(MERGE_TYPE_PARAMETER_ID).getStringValue();
    if (mergeTransactionTypeName == null) {
        throw new PluginException(PluginNotificationLevel.ERROR, "Select a Merge By option.");
    }
    if (!MERGE_TYPES.containsKey(mergeTransactionTypeName)) {
        throw new PluginException(PluginNotificationLevel.FATAL, String.format("Merge node type %s not found.", mergeTransactionTypeName));
    }
    final int threshold = parameters.getParameters().get(THRESHOLD_PARAMETER_ID).getIntegerValue();
    final GraphElementMerger merger = MERGERS.get(parameters.getParameters().get(MERGER_PARAMETER_ID).getStringValue());
    String leadTransactionChooserName = parameters.getParameters().get(LEAD_PARAMETER_ID).getStringValue();
    final Comparator<Long> leadTransactionChooser = LEAD_TRANSACTION_CHOOSERS.get(leadTransactionChooserName);
    final boolean selectedOnly = parameters.getParameters().get(SELECTED_PARAMETER_ID).getBooleanValue();
    final MergeTransactionType mergeTransactionType = MERGE_TYPES.get(mergeTransactionTypeName);
    final Map<Integer, Set<Integer>> transactionsToMerge;
    try {
        transactionsToMerge = mergeTransactionType.getTransactionsToMerge(graph, leadTransactionChooser, threshold, selectedOnly);
    } catch (MergeException ex) {
        throw new PluginException(PluginNotificationLevel.ERROR, ex);
    }
    for (final Map.Entry<Integer, Set<Integer>> entry : transactionsToMerge.entrySet()) {
        mergedCount += mergeTransactions(graph, entry.getValue(), entry.getKey(), merger);
    }
    interaction.setProgress(1, 0, "Merged " + mergedCount + " transactions.", true);
    PluginExecution.withPlugin(VisualSchemaPluginRegistry.COMPLETE_SCHEMA).executeNow(graph);
}
Also used : Set(java.util.Set) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) MergeException(au.gov.asd.tac.constellation.views.dataaccess.plugins.clean.MergeTransactionType.MergeException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) IgnoreSurvivingGraphElementMerger(au.gov.asd.tac.constellation.graph.mergers.IgnoreSurvivingGraphElementMerger) PriorityMergedGraphElementMerger(au.gov.asd.tac.constellation.graph.mergers.PriorityMergedGraphElementMerger) GraphElementMerger(au.gov.asd.tac.constellation.graph.GraphElementMerger) PrioritySurvivingGraphElementMerger(au.gov.asd.tac.constellation.graph.mergers.PrioritySurvivingGraphElementMerger) IgnoreMergedGraphElementMerger(au.gov.asd.tac.constellation.graph.mergers.IgnoreMergedGraphElementMerger)

Example 4 with GraphElementMerger

use of au.gov.asd.tac.constellation.graph.GraphElementMerger in project constellation by constellation-app.

the class MergeNodesPlugin method edit.

@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    int mergedCount = 0;
    interaction.setProgress(0, 0, "Merging nodes...", true);
    final String mergeNodeTypeName = parameters.getParameters().get(MERGE_TYPE_PARAMETER_ID).getStringValue();
    if (mergeNodeTypeName == null) {
        throw new PluginException(PluginNotificationLevel.ERROR, "Select a Merge By option.");
    }
    if (!MERGE_TYPES.containsKey(mergeNodeTypeName)) {
        throw new PluginException(PluginNotificationLevel.FATAL, String.format("Merge node type %s not found.", mergeNodeTypeName));
    }
    final int threshold = parameters.getParameters().get(THRESHOLD_PARAMETER_ID).getIntegerValue();
    final GraphElementMerger merger = MERGERS.get(parameters.getParameters().get(MERGER_PARAMETER_ID).getStringValue());
    final Comparator<String> leadNodeChooser = VERTEX_CHOOSER.get(parameters.getParameters().get(LEAD_PARAMETER_ID).getStringValue());
    final boolean selectedOnly = parameters.getParameters().get(SELECTED_PARAMETER_ID).getBooleanValue();
    final MergeNodeType mergeNodeType = MERGE_TYPES.get(mergeNodeTypeName);
    final Map<Integer, Set<Integer>> nodesToMerge;
    try {
        nodesToMerge = mergeNodeType.getNodesToMerge(graph, leadNodeChooser, threshold, selectedOnly);
    } catch (MergeException ex) {
        throw new PluginException(PluginNotificationLevel.ERROR, ex);
    }
    // perform the merge
    for (final Map.Entry<Integer, Set<Integer>> entry : nodesToMerge.entrySet()) {
        mergedCount += mergeVertices(graph, entry.getValue(), entry.getKey(), merger);
    }
    interaction.setProgress(1, 0, "Merged " + mergedCount + " nodes.", true);
    PluginExecution.withPlugin(VisualSchemaPluginRegistry.COMPLETE_SCHEMA).executeNow(graph);
}
Also used : Set(java.util.Set) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) MergeException(au.gov.asd.tac.constellation.views.dataaccess.plugins.clean.MergeNodeType.MergeException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) IgnoreSurvivingGraphElementMerger(au.gov.asd.tac.constellation.graph.mergers.IgnoreSurvivingGraphElementMerger) PriorityMergedGraphElementMerger(au.gov.asd.tac.constellation.graph.mergers.PriorityMergedGraphElementMerger) GraphElementMerger(au.gov.asd.tac.constellation.graph.GraphElementMerger) PrioritySurvivingGraphElementMerger(au.gov.asd.tac.constellation.graph.mergers.PrioritySurvivingGraphElementMerger) IgnoreMergedGraphElementMerger(au.gov.asd.tac.constellation.graph.mergers.IgnoreMergedGraphElementMerger)

Example 5 with GraphElementMerger

use of au.gov.asd.tac.constellation.graph.GraphElementMerger in project constellation by constellation-app.

the class SWritableGraph method mergeVertices.

/**
 * Merge more than two vertices together.
 *
 * @param leadVertex the id of the consuming vertex.
 * @param vertices the consumed vertices as a {@link SCollection}.
 */
public void mergeVertices(final int leadVertex, final SCollection vertices) {
    GraphElementMerger merger = new PrioritySurvivingGraphElementMerger();
    final BitSet mergeVertices = vertices.elementIds();
    for (int vertexId = mergeVertices.nextSetBit(0); vertexId >= 0; vertexId = mergeVertices.nextSetBit(vertexId + 1)) {
        if (vertexId != leadVertex) {
            merger.mergeElement(getWritableGraph(), GraphElementType.VERTEX, leadVertex, vertexId);
        }
    }
}
Also used : PrioritySurvivingGraphElementMerger(au.gov.asd.tac.constellation.graph.mergers.PrioritySurvivingGraphElementMerger) BitSet(java.util.BitSet) GraphElementMerger(au.gov.asd.tac.constellation.graph.GraphElementMerger) PrioritySurvivingGraphElementMerger(au.gov.asd.tac.constellation.graph.mergers.PrioritySurvivingGraphElementMerger)

Aggregations

GraphElementMerger (au.gov.asd.tac.constellation.graph.GraphElementMerger)5 PrioritySurvivingGraphElementMerger (au.gov.asd.tac.constellation.graph.mergers.PrioritySurvivingGraphElementMerger)5 DuplicateKeyException (au.gov.asd.tac.constellation.graph.DuplicateKeyException)2 IgnoreMergedGraphElementMerger (au.gov.asd.tac.constellation.graph.mergers.IgnoreMergedGraphElementMerger)2 IgnoreSurvivingGraphElementMerger (au.gov.asd.tac.constellation.graph.mergers.IgnoreSurvivingGraphElementMerger)2 PriorityMergedGraphElementMerger (au.gov.asd.tac.constellation.graph.mergers.PriorityMergedGraphElementMerger)2 CompositeNodeState (au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.CompositeNodeState)2 ContractedCompositeNodeState (au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.ContractedCompositeNodeState)2 ExpandedCompositeNodeState (au.gov.asd.tac.constellation.graph.schema.analytic.attribute.objects.ExpandedCompositeNodeState)2 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 Set (java.util.Set)2 MergeException (au.gov.asd.tac.constellation.views.dataaccess.plugins.clean.MergeNodeType.MergeException)1 MergeException (au.gov.asd.tac.constellation.views.dataaccess.plugins.clean.MergeTransactionType.MergeException)1 BitSet (java.util.BitSet)1