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);
}
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);
});
}
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));
}
}
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);
}
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);
}
}
}
}
Aggregations