Search in sources :

Example 6 with SchemaTransactionType

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

the class MostLikelyCorrelatedQuestion method initialiseParameters.

@Override
public void initialiseParameters(final AnalyticPlugin<ScoreResult> plugin, final PluginParameters parameters) {
    // TRANSACTION_TYPES_PARAMETER always of type MultiChoiceParameter
    @SuppressWarnings("unchecked") final PluginParameter<MultiChoiceParameterValue> transactionTypeParameter = (PluginParameter<MultiChoiceParameterValue>) parameters.getParameters().get(ScoreAnalyticPlugin.TRANSACTION_TYPES_PARAMETER_ID);
    final List<TransactionTypeParameterValue> newChecked = new ArrayList<>();
    final List<ParameterValue> checked = transactionTypeParameter.getMultiChoiceValue().getChoicesData();
    checked.forEach(parameterValue -> {
        final TransactionTypeParameterValue transactionTypeParameterValue = (TransactionTypeParameterValue) parameterValue;
        final SchemaTransactionType transactionType = (SchemaTransactionType) transactionTypeParameterValue.getObjectValue();
        if (transactionType == null || !transactionType.isSubTypeOf(AnalyticConcept.TransactionType.SIMILARITY)) {
            newChecked.add(transactionTypeParameterValue);
        }
    });
    MultiChoiceParameterType.setChoicesData(transactionTypeParameter, newChecked);
    parameters.setBooleanValue(CosineSimilarityPlugin.INCLUDE_CONNECTIONS_IN_PARAMETER_ID, true);
    parameters.setBooleanValue(CosineSimilarityPlugin.INCLUDE_CONNECTIONS_OUT_PARAMETER_ID, true);
    parameters.setBooleanValue(CosineSimilarityPlugin.TREAT_UNDIRECTED_BIDIRECTIONAL_PARAMETER_ID, true);
}
Also used : SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) TransactionTypeParameterValue(au.gov.asd.tac.constellation.views.analyticview.analytics.ScoreAnalyticPlugin.TransactionTypeParameterValue) ParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.ParameterValue) MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) ArrayList(java.util.ArrayList) TransactionTypeParameterValue(au.gov.asd.tac.constellation.views.analyticview.analytics.ScoreAnalyticPlugin.TransactionTypeParameterValue) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)

Example 7 with SchemaTransactionType

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

the class MergeTransactionType method sortTransactions.

/**
 * Sort transactions by type and datetime in ascending order
 *
 * NOTE: This method is package protected so that unit testing can be done
 *
 * @param transactions
 * @param graph
 * @param typeAttributeId
 * @param dateTimeAttributeId
 * @param leadTransactionChooser
 */
public default void sortTransactions(Integer[] transactions, final GraphReadMethods graph, final int typeAttributeId, final int dateTimeAttributeId, Comparator<Long> leadTransactionChooser) {
    Arrays.sort(transactions, (Integer o1, Integer o2) -> {
        final SchemaTransactionType type1 = graph.getObjectValue(typeAttributeId, o1);
        final SchemaTransactionType type2 = graph.getObjectValue(typeAttributeId, o2);
        if (type1 == null) {
            if (type2 != null) {
                return 1;
            }
        } else if (type2 == null) {
            return -1;
        } else {
            final int typComparison = type1.compareTo(type2);
            if (typComparison != 0) {
                return typComparison;
            }
        }
        final long datetime1 = graph.getLongValue(dateTimeAttributeId, o1);
        final long datetime2 = graph.getLongValue(dateTimeAttributeId, o2);
        return leadTransactionChooser.compare(datetime1, datetime2);
    });
}
Also used : SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)

Example 8 with SchemaTransactionType

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

the class SplitNodesPlugin method updateParameters.

@Override
public void updateParameters(final Graph graph, final PluginParameters parameters) {
    if (parameters != null && parameters.getParameters() != null && !parameters.getParameters().get(DUPLICATE_TRANSACTIONS_PARAMETER_ID).getBooleanValue()) {
        final List<String> types = new ArrayList<>();
        if (graph != null && graph.getSchema() != null) {
            for (final SchemaTransactionType type : SchemaTransactionTypeUtilities.getTypes(graph.getSchema().getFactory().getRegisteredConcepts())) {
                types.add(type.getName());
            }
            if (!types.isEmpty()) {
                types.sort(String::compareTo);
            }
        }
        // TRANSACTION_TYPE_PARAMETER is always of type SingleChoiceParameter
        @SuppressWarnings("unchecked") final PluginParameter<SingleChoiceParameterValue> transactionType = (PluginParameter<SingleChoiceParameterValue>) parameters.getParameters().get(TRANSACTION_TYPE_PARAMETER_ID);
        SingleChoiceParameterType.setOptions(transactionType, types);
        transactionType.suppressEvent(true, new ArrayList<>());
        if (transactionType.getSingleChoice() == null && types.contains(AnalyticConcept.TransactionType.CORRELATION.getName())) {
            SingleChoiceParameterType.setChoice(transactionType, AnalyticConcept.TransactionType.CORRELATION.getName());
        }
        transactionType.suppressEvent(false, new ArrayList<>());
        transactionType.setObjectValue(parameters.getObjectValue(TRANSACTION_TYPE_PARAMETER_ID));
    }
}
Also used : SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) ArrayList(java.util.ArrayList) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)

Example 9 with SchemaTransactionType

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

the class PlaceholderUtilities method collapsePlaceholders.

public static void collapsePlaceholders(final GraphWriteMethods graph, final Comparator<SchemaVertexType> dominanceComparator, final boolean debug) throws PluginException, InterruptedException {
    final List<Integer> placeholderIds = new ArrayList<>();
    final Map<Integer, List<Integer>> placeholderCorrelations = new HashMap<>();
    final Map<Integer, List<Integer>> placeholderActivity = new HashMap<>();
    final Map<Integer, Integer> placeholderNeighbours = new HashMap<>();
    final int vertexTypeAttributeId = AnalyticConcept.VertexAttribute.TYPE.get(graph);
    final int transactionTypeAttributeId = AnalyticConcept.TransactionAttribute.TYPE.get(graph);
    // collect placeholders, their transactions and their neighbours
    final int vertexCount = graph.getVertexCount();
    for (int vertexPosition = 0; vertexPosition < vertexCount; vertexPosition++) {
        final int vertexId = graph.getVertex(vertexPosition);
        final SchemaVertexType vertexType = graph.getObjectValue(vertexTypeAttributeId, vertexId);
        if (vertexType.isSubTypeOf(AnalyticConcept.VertexType.PLACEHOLDER)) {
            placeholderIds.add(vertexId);
            final List<Integer> placeholderCorrelationList = new ArrayList<>();
            final List<Integer> placeholderActivityList = new ArrayList<>();
            final int transactionCount = graph.getVertexTransactionCount(vertexId);
            for (int transactionPosition = 0; transactionPosition < transactionCount; transactionPosition++) {
                final int transactionId = graph.getVertexTransaction(vertexId, transactionPosition);
                final SchemaTransactionType transactionType = graph.getObjectValue(transactionTypeAttributeId, transactionId);
                if (transactionType.isSubTypeOf(AnalyticConcept.TransactionType.CORRELATION)) {
                    placeholderCorrelationList.add(transactionId);
                } else {
                    placeholderActivityList.add(transactionId);
                }
                final int neighbourId = graph.getTransactionSourceVertex(transactionId) == vertexId ? graph.getTransactionDestinationVertex(transactionId) : graph.getTransactionSourceVertex(transactionId);
                placeholderNeighbours.put(transactionId, neighbourId);
            }
            placeholderCorrelations.put(vertexId, placeholderCorrelationList);
            placeholderActivity.put(vertexId, placeholderActivityList);
        }
    }
    if (debug) {
        GraphOpener.getDefault().openGraph(new DualGraph((StoreGraph) graph.copy(), true), GraphNode.getGraphNode(graph.getId()).getName() + "-debug-stage1");
    }
    // choose lead vertices to replace placeholders
    placeholderIds.forEach(placeholderId -> {
        final int leadVertex;
        final List<Integer> placeholderCorrelationList = placeholderCorrelations.get(placeholderId);
        if (!placeholderCorrelationList.isEmpty()) {
            // calculate lead vertex
            final SchemaVertexType leadVertexType = placeholderCorrelationList.stream().map(placeholderNeighbours::get).map(neighbourId -> (SchemaVertexType) graph.getObjectValue(vertexTypeAttributeId, neighbourId)).sorted(dominanceComparator).findFirst().get();
            leadVertex = placeholderCorrelationList.stream().map(placeholderNeighbours::get).filter(neighbourId -> graph.getObjectValue(vertexTypeAttributeId, neighbourId).equals(leadVertexType)).findFirst().get();
            // move correlations from the placeholder to the lead vertex of the entity
            placeholderCorrelationList.forEach(correlationId -> {
                if (graph.getTransactionSourceVertex(correlationId) == placeholderId && graph.getTransactionDestinationVertex(correlationId) != leadVertex) {
                    graph.setTransactionSourceVertex(correlationId, leadVertex);
                } else if (graph.getTransactionDestinationVertex(correlationId) == placeholderId && graph.getTransactionSourceVertex(correlationId) != leadVertex) {
                    graph.setTransactionDestinationVertex(correlationId, leadVertex);
                } else {
                // Do nothing
                }
            });
            // move activity from the placeholder to the lead vertex of the entity
            final List<Integer> placeholderActivityList = placeholderActivity.get(placeholderId);
            placeholderActivityList.forEach(activityId -> {
                if (graph.getTransactionSourceVertex(activityId) == placeholderId) {
                    graph.setTransactionSourceVertex(activityId, leadVertex);
                } else {
                    graph.setTransactionDestinationVertex(activityId, leadVertex);
                }
            });
        }
    });
    if (debug) {
        GraphOpener.getDefault().openGraph(new DualGraph((StoreGraph) graph.copy(), true), GraphNode.getGraphNode(graph.getId()).getName() + "-debug-stage2");
    }
    // remove all placeholders
    placeholderIds.forEach(graph::removeVertex);
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) SchemaVertexTypeUtilities(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexTypeUtilities) DatumProcessor(au.gov.asd.tac.constellation.graph.processing.DatumProcessor) ProcessingException(au.gov.asd.tac.constellation.graph.processing.ProcessingException) RecordStore(au.gov.asd.tac.constellation.graph.processing.RecordStore) SchemaTransactionTypeUtilities(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionTypeUtilities) GraphOpener(au.gov.asd.tac.constellation.graph.file.opener.GraphOpener) GraphVertex(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphVertex) HashMap(java.util.HashMap) VisualConcept(au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept) ArrayList(java.util.ArrayList) Map(java.util.Map) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) GraphDirection(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphDirection) SeparatorConstants(au.gov.asd.tac.constellation.utilities.text.SeparatorConstants) GraphWrapper(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphWrapper) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) GraphRecordStoreUtilities(au.gov.asd.tac.constellation.graph.processing.GraphRecordStoreUtilities) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) Collectors(java.util.stream.Collectors) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) GraphTransaction(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphTransaction) PluginNotificationLevel(au.gov.asd.tac.constellation.plugins.PluginNotificationLevel) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) GraphStep(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphStep) List(java.util.List) AnalyticConcept(au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept) Record(au.gov.asd.tac.constellation.graph.processing.Record) Optional(java.util.Optional) GraphNode(au.gov.asd.tac.constellation.graph.node.GraphNode) Comparator(java.util.Comparator) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) ArrayList(java.util.ArrayList) List(java.util.List) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph)

Example 10 with SchemaTransactionType

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

the class CreateCompositesFromDominantNodesPlugin method findCorrelations.

private void findCorrelations(final GraphReadMethods graph, final int vxTypeAttr, final int txTypeAttr, final int vxId, final Set<Integer> allCorrelatedVerts, final Set<Integer> correlationGroup) {
    for (int i = 0; i < graph.getVertexNeighbourCount(vxId); i++) {
        final int nxId = graph.getVertexNeighbour(vxId, i);
        if (!allCorrelatedVerts.contains(nxId)) {
            final int lxId = graph.getLink(vxId, nxId);
            boolean neighbourCorrelated = false;
            for (int j = 0; j < graph.getLinkTransactionCount(lxId); j++) {
                final int txId = graph.getLinkTransaction(lxId, j);
                final SchemaTransactionType txType = (SchemaTransactionType) graph.getObjectValue(txTypeAttr, txId);
                if (txType != null && txType.isSubTypeOf(AnalyticConcept.TransactionType.CORRELATION)) {
                    correlationGroup.add(nxId);
                    allCorrelatedVerts.add(nxId);
                    neighbourCorrelated = true;
                    break;
                }
            }
            if (neighbourCorrelated) {
                findCorrelations(graph, vxTypeAttr, txTypeAttr, nxId, allCorrelatedVerts, correlationGroup);
            }
        }
    }
}
Also used : SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)

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