Search in sources :

Example 1 with Record

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

the class PlaceholderUtilities method collapsePlaceholders.

public static StoreGraph collapsePlaceholders(final StoreGraphRecordStore graph, final Record record, final DatumProcessor<Record, ?> rowProcessor, final Comparator<GraphVertex> dominanceComparator, final boolean cleanupGraph, final boolean debug) throws PluginException, InterruptedException {
    graph.complete();
    graph.validateKeys();
    GraphWrapper g = new GraphWrapper(graph);
    // remove all transactions with type 'unknown' and all nodes with identifier 'unknown'
    if (cleanupGraph) {
        g.streamTransactions().filter(transaction -> transaction.getTypeValue().equals(SchemaTransactionTypeUtilities.getDefaultType())).forEach(GraphTransaction::deferRemove);
        g.streamVertices().filter(vertex -> "unknown".equals(vertex.getStringValue(VisualConcept.VertexAttribute.IDENTIFIER))).forEach(GraphVertex::deferRemove);
        g.completeDeferred();
    }
    if (debug) {
        GraphOpener.getDefault().openGraph(new DualGraph(graph, true), rowProcessor.getClass().getSimpleName() + "-debug-stage1");
    }
    // connect all nodes with type 'placeholder'
    g.streamVertices().filter(v -> v.getTypeValue().equals(AnalyticConcept.VertexType.PLACEHOLDER)).map(v -> v.walkNeighbours(s -> s.getTransaction().getTypeValue().isSubTypeOf(AnalyticConcept.TransactionType.CORRELATION) && s.getDestinationVertex().getTypeValue().equals(AnalyticConcept.VertexType.PLACEHOLDER), true).map(GraphStep::getDestinationVertex).collect(Collectors.toSet())).distinct().forEach(c -> {
        String newIdentifier = c.stream().map(v -> v.getStringValue(VisualConcept.VertexAttribute.IDENTIFIER)).collect(Collectors.joining(SeparatorConstants.HYPHEN));
        c.stream().forEach(v -> {
            v.setStringValue(VisualConcept.VertexAttribute.IDENTIFIER, newIdentifier);
            v.completeWithSchema();
        });
    });
    g.validateKeys();
    if (debug) {
        GraphOpener.getDefault().openGraph(new DualGraph(graph, true), rowProcessor.getClass().getSimpleName() + "-debug-stage2");
    }
    // replace nodes with type 'placeholder' with the dominant correlated node
    g.streamVertices().filter(v -> v.getTypeValue().equals(AnalyticConcept.VertexType.PLACEHOLDER)).forEach(v -> {
        Optional<GraphVertex> dominant = v.streamNeighbours().filter(n -> n.getDirection() != GraphDirection.LOOPBACK).filter(n -> n.getTransaction().getTypeValue().isSubTypeOf(AnalyticConcept.TransactionType.CORRELATION)).map(n -> n.getDestinationVertex()).distinct().sorted(dominanceComparator).findFirst();
        // TODO: needed to create a special case for 'unknown' type vertices, but not sure why...
        if (dominant.isPresent() && !dominant.get().getTypeValue().equals(SchemaVertexTypeUtilities.getDefaultType())) {
            v.setStringValue(VisualConcept.VertexAttribute.IDENTIFIER, dominant.get().getStringValue(VisualConcept.VertexAttribute.IDENTIFIER));
            v.setTypeValue(dominant.get().getTypeValue());
            v.setRawValue(dominant.get().getRawValue());
            v.completeWithSchema();
        } else {
            v.deferRemove();
        }
    });
    g.completeDeferred();
    g.validateKeys();
    if (debug) {
        GraphOpener.getDefault().openGraph(new DualGraph(graph, true), rowProcessor.getClass().getSimpleName() + "-debug-stage3");
    }
    // remove transactions that correlate nodes with themselves
    g.streamTransactions().filter(t -> t.getTypeValue().isSubTypeOf(AnalyticConcept.TransactionType.CORRELATION)).filter(t -> t.getSourceVertex().equals(t.getDestinationVertex())).forEach(GraphTransaction::deferRemove);
    g.completeDeferred();
    return graph;
}
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) GraphVertex(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphVertex) GraphStep(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphStep) GraphWrapper(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphWrapper) GraphTransaction(au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphTransaction) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph)

Aggregations

GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)1 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)1 GraphOpener (au.gov.asd.tac.constellation.graph.file.opener.GraphOpener)1 DualGraph (au.gov.asd.tac.constellation.graph.locking.DualGraph)1 GraphNode (au.gov.asd.tac.constellation.graph.node.GraphNode)1 DatumProcessor (au.gov.asd.tac.constellation.graph.processing.DatumProcessor)1 GraphRecordStoreUtilities (au.gov.asd.tac.constellation.graph.processing.GraphRecordStoreUtilities)1 ProcessingException (au.gov.asd.tac.constellation.graph.processing.ProcessingException)1 Record (au.gov.asd.tac.constellation.graph.processing.Record)1 RecordStore (au.gov.asd.tac.constellation.graph.processing.RecordStore)1 Schema (au.gov.asd.tac.constellation.graph.schema.Schema)1 AnalyticConcept (au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept)1 SchemaTransactionType (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)1 SchemaTransactionTypeUtilities (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionTypeUtilities)1 SchemaVertexType (au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType)1 SchemaVertexTypeUtilities (au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexTypeUtilities)1 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)1 GraphDirection (au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphDirection)1 GraphStep (au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphStep)1 GraphTransaction (au.gov.asd.tac.constellation.graph.utilities.wrapper.GraphTransaction)1