Search in sources :

Example 1 with GraphElementType

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

the class FactAnalyticPlugin method computeResultsFromGraph.

protected final void computeResultsFromGraph(final GraphReadMethods graph, final PluginParameters parameters) {
    result = new FactResult();
    result.setIgnoreNullResults(ignoreDefaultValues());
    getAnalyticAttributes(parameters).forEach(schemaAttribute -> {
        int graphElementCount = 0;
        int identifierAttributeId = Graph.NOT_FOUND;
        final int factAttributeId = schemaAttribute.get(graph);
        if (factAttributeId == Graph.NOT_FOUND) {
            throw new RuntimeException("Expected attribute not found on graph: " + schemaAttribute.getName());
        }
        final GraphElementType graphElementType = schemaAttribute.getElementType();
        switch(graphElementType) {
            case VERTEX:
                graphElementCount = graph.getVertexCount();
                identifierAttributeId = VisualConcept.VertexAttribute.IDENTIFIER.get(graph);
                break;
            case TRANSACTION:
                graphElementCount = graph.getTransactionCount();
                identifierAttributeId = VisualConcept.TransactionAttribute.IDENTIFIER.get(graph);
                break;
            default:
                break;
        }
        for (int graphElementPosition = 0; graphElementPosition < graphElementCount; graphElementPosition++) {
            final int graphElementId;
            if (graphElementType == GraphElementType.VERTEX) {
                graphElementId = graph.getVertex(graphElementPosition);
            } else {
                graphElementId = graphElementType == GraphElementType.TRANSACTION ? graph.getTransaction(graphElementPosition) : Graph.NOT_FOUND;
            }
            final String identifier = graph.getStringValue(identifierAttributeId, graphElementId);
            final boolean fact = graph.getBooleanValue(factAttributeId, graphElementId);
            final boolean defaultFact = (boolean) graph.getAttributeDefaultValue(factAttributeId);
            final boolean isNull = ignoreDefaultValues() && fact == defaultFact;
            result.add(new ElementFact(graphElementType, graphElementId, identifier, isNull, schemaAttribute.getName(), fact));
        }
    });
}
Also used : FactResult(au.gov.asd.tac.constellation.views.analyticview.results.FactResult) ElementFact(au.gov.asd.tac.constellation.views.analyticview.results.FactResult.ElementFact) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType)

Example 2 with GraphElementType

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

the class ClusterAnalyticPlugin method computeResultsFromGraph.

protected final void computeResultsFromGraph(final GraphReadMethods graph, final PluginParameters parameters) {
    result = new ClusterResult();
    result.setIgnoreNullResults(ignoreDefaultValues());
    getAnalyticAttributes(parameters).forEach(schemaAttribute -> {
        int graphElementCount = 0;
        int identifierAttributeId = Graph.NOT_FOUND;
        final int clusterNumberAtributeId = schemaAttribute.get(graph);
        if (clusterNumberAtributeId == Graph.NOT_FOUND) {
            throw new RuntimeException("Expected attribute not found on graph: " + schemaAttribute.getName());
        }
        final GraphElementType graphElementType = schemaAttribute.getElementType();
        switch(graphElementType) {
            case VERTEX:
                graphElementCount = graph.getVertexCount();
                identifierAttributeId = VisualConcept.VertexAttribute.IDENTIFIER.get(graph);
                break;
            case TRANSACTION:
                graphElementCount = graph.getTransactionCount();
                identifierAttributeId = VisualConcept.TransactionAttribute.IDENTIFIER.get(graph);
                break;
            default:
                break;
        }
        for (int graphElementPosition = 0; graphElementPosition < graphElementCount; graphElementPosition++) {
            final int graphElementId;
            if (graphElementType == GraphElementType.VERTEX) {
                graphElementId = graph.getVertex(graphElementPosition);
            } else {
                graphElementId = graphElementType == GraphElementType.TRANSACTION ? graph.getTransaction(graphElementPosition) : Graph.NOT_FOUND;
            }
            final String identifier = graph.getStringValue(identifierAttributeId, graphElementId);
            final int clusterNumber = graph.getIntValue(clusterNumberAtributeId, graphElementId);
            final int defaultNumber = (int) graph.getAttributeDefaultValue(clusterNumberAtributeId);
            final boolean isNull = ignoreDefaultValues() && clusterNumber == defaultNumber;
            result.add(new ClusterData(graphElementType, graphElementId, identifier, isNull, clusterNumber));
        }
    });
}
Also used : ClusterData(au.gov.asd.tac.constellation.views.analyticview.results.ClusterResult.ClusterData) ClusterResult(au.gov.asd.tac.constellation.views.analyticview.results.ClusterResult) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType)

Example 3 with GraphElementType

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

the class ScoreAnalyticPlugin method computeResultsFromGraph.

protected final void computeResultsFromGraph(final GraphReadMethods graph, final PluginParameters parameters) {
    result = new ScoreResult();
    result.setIgnoreNullResults(ignoreDefaultValues());
    int graphElementCount = 0;
    int identifierAttributeId = Graph.NOT_FOUND;
    final Set<GraphElementType> graphElementTypes = getAnalyticAttributes(parameters).stream().map(attribute -> attribute.getElementType()).collect(Collectors.toSet());
    for (final GraphElementType graphElementType : graphElementTypes) {
        switch(graphElementType) {
            case VERTEX:
                graphElementCount = graph.getVertexCount();
                identifierAttributeId = VisualConcept.VertexAttribute.IDENTIFIER.get(graph);
                break;
            case TRANSACTION:
                graphElementCount = graph.getTransactionCount();
                identifierAttributeId = VisualConcept.TransactionAttribute.IDENTIFIER.get(graph);
                break;
            default:
                break;
        }
        for (int graphElementPosition = 0; graphElementPosition < graphElementCount; graphElementPosition++) {
            final int graphElementId;
            if (graphElementType == GraphElementType.VERTEX) {
                graphElementId = graph.getVertex(graphElementPosition);
            } else {
                graphElementId = graphElementType == GraphElementType.TRANSACTION ? graph.getTransaction(graphElementPosition) : Graph.NOT_FOUND;
            }
            final String identifier = graph.getStringValue(identifierAttributeId, graphElementId);
            final Map<String, Float> namedScores = new HashMap<>();
            boolean isNull = true;
            for (final SchemaAttribute analyticAttribute : getAnalyticAttributes(parameters)) {
                final int scoreAttributeId = analyticAttribute.get(graph);
                if (scoreAttributeId == Graph.NOT_FOUND) {
                    throw new RuntimeException("Expected attribute not found on graph: " + analyticAttribute.getName());
                }
                final float score = graph.getFloatValue(scoreAttributeId, graphElementId);
                final float defaultScore = (float) graph.getAttributeDefaultValue(scoreAttributeId);
                if (isNull) {
                    isNull = ignoreDefaultValues() && score == defaultScore;
                }
                namedScores.put(analyticAttribute.getName(), score);
            }
            result.add(new ElementScore(graphElementType, graphElementId, identifier, isNull, namedScores));
        }
    }
}
Also used : GraphWriteMethods(au.gov.asd.tac.constellation.graph.GraphWriteMethods) SchemaTransactionType(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType) TRANSACTION(au.gov.asd.tac.constellation.graph.GraphElementType.TRANSACTION) ReadableGraph(au.gov.asd.tac.constellation.graph.ReadableGraph) ElementScore(au.gov.asd.tac.constellation.views.analyticview.results.ScoreResult.ElementScore) RecordStore(au.gov.asd.tac.constellation.graph.processing.RecordStore) SchemaTransactionTypeUtilities(au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionTypeUtilities) MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) ScoreResult(au.gov.asd.tac.constellation.views.analyticview.results.ScoreResult) HashMap(java.util.HashMap) SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) VisualConcept(au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Graph(au.gov.asd.tac.constellation.graph.Graph) HashSet(java.util.HashSet) SchemaFactoryUtilities(au.gov.asd.tac.constellation.graph.schema.SchemaFactoryUtilities) VERTEX(au.gov.asd.tac.constellation.graph.GraphElementType.VERTEX) Plugin(au.gov.asd.tac.constellation.plugins.Plugin) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Map(java.util.Map) SubgraphUtilities(au.gov.asd.tac.constellation.graph.utilities.SubgraphUtilities) GraphReadMethods(au.gov.asd.tac.constellation.graph.GraphReadMethods) PluginExecution(au.gov.asd.tac.constellation.plugins.PluginExecution) PluginRegistry(au.gov.asd.tac.constellation.plugins.PluginRegistry) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) MultiChoiceParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) Set(java.util.Set) ParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.ParameterValue) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) GraphRecordStoreUtilities(au.gov.asd.tac.constellation.graph.processing.GraphRecordStoreUtilities) Logger(java.util.logging.Logger) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) Collectors(java.util.stream.Collectors) AnalyticResult(au.gov.asd.tac.constellation.views.analyticview.results.AnalyticResult) InvocationTargetException(java.lang.reflect.InvocationTargetException) Objects(java.util.Objects) List(java.util.List) AnalyticConcept(au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept) HashMap(java.util.HashMap) ElementScore(au.gov.asd.tac.constellation.views.analyticview.results.ScoreResult.ElementScore) ScoreResult(au.gov.asd.tac.constellation.views.analyticview.results.ScoreResult) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)

Example 4 with GraphElementType

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

the class AnalyticResultNGTest method testSort.

/**
 * Test of sort method, of class AnalyticResult.
 */
@Test
public void testSort() {
    System.out.println("sort");
    LinkedHashMap<IdentificationData, ElementScore> testResult = new LinkedHashMap<>();
    AnalyticResultImpl instance = new AnalyticResultImpl();
    // Create unsorted ElementScore results
    GraphElementType vertex = GraphElementType.VERTEX;
    final IdentificationData idData1 = new IdentificationData(vertex, 1, "Node1");
    final IdentificationData idData2 = new IdentificationData(vertex, 2, "Node2");
    final IdentificationData idData3 = new IdentificationData(vertex, 3, "Node3");
    final IdentificationData idData4 = new IdentificationData(vertex, 4, "Node4");
    final IdentificationData idData5 = new IdentificationData(vertex, 5, "Node5");
    final Map<String, Float> namedScores1 = new HashMap<>();
    namedScores1.put("Centrality.OutBetweenness", (float) .8);
    final Map<String, Float> namedScores2 = new HashMap<>();
    namedScores2.put("Centrality.OutBetweenness", (float) 1.2);
    final Map<String, Float> namedScores3 = new HashMap<>();
    namedScores3.put("Centrality.OutBetweenness", (float) .7);
    final Map<String, Float> namedScores4 = new HashMap<>();
    namedScores4.put("Centrality.OutBetweenness", (float) 1.1);
    final Map<String, Float> namedScores5 = new HashMap<>();
    namedScores5.put("Centrality.OutBetweenness", (float) .6);
    final ElementScore elementScore1 = new ElementScore(vertex, 1, "Node1", false, namedScores1);
    final ElementScore elementScore2 = new ElementScore(vertex, 2, "Node1", false, namedScores2);
    final ElementScore elementScore3 = new ElementScore(vertex, 3, "Node1", false, namedScores3);
    final ElementScore elementScore4 = new ElementScore(vertex, 4, "Node1", false, namedScores4);
    final ElementScore elementScore5 = new ElementScore(vertex, 5, "Node1", false, namedScores5);
    instance.getResult().put(idData1, elementScore1);
    instance.getResult().put(idData2, elementScore2);
    instance.getResult().put(idData3, elementScore3);
    instance.getResult().put(idData4, elementScore4);
    instance.getResult().put(idData5, elementScore5);
    // Populte the unsorted values in hashmap
    testResult.put(idData1, elementScore1);
    testResult.put(idData2, elementScore2);
    testResult.put(idData3, elementScore3);
    testResult.put(idData4, elementScore4);
    testResult.put(idData5, elementScore5);
    // Compare the unsorted map to the instance map to verify
    assertEquals(instance.result, testResult);
    // Do the instance sort
    instance.sort();
    // Populte the sorted values in hashmap
    testResult.clear();
    testResult.put(idData2, elementScore2);
    testResult.put(idData4, elementScore4);
    testResult.put(idData1, elementScore1);
    testResult.put(idData3, elementScore3);
    testResult.put(idData5, elementScore5);
    // Compare the sorted map to the instance map to verify
    assertEquals(instance.result, testResult);
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ElementScore(au.gov.asd.tac.constellation.views.analyticview.results.ScoreResult.ElementScore) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 5 with GraphElementType

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

the class AttributeReader method populateValues.

private boolean populateValues(final List<GraphElementType> elementTypes, final boolean selectionChanged, final boolean attributeModified, final boolean preferenceChanged, final ReadableGraph rg) {
    boolean valueChanged = false;
    if (selectionChanged) {
        elementAttributeValues.clear();
    }
    for (final GraphElementType type : ACCEPTED_ELEMENT_TYPES) {
        // for graphElement Type (graph,vertex,transaction)
        final List<AttributeData> attributes = elementAttributeData.get(type);
        final IntArray selectedElement;
        if (type.equals(GraphElementType.VERTEX)) {
            selectedElement = selectedNodes;
        } else if (type.equals(GraphElementType.TRANSACTION)) {
            selectedElement = selectedTransactions;
        } else {
            selectedElement = null;
        }
        for (final AttributeData data : attributes) {
            if (!elementTypes.contains(type)) {
                final String attributeValuesKey = type.getLabel() + data.getAttributeName();
                elementAttributeValues.put(attributeValuesKey, null);
                continue;
            }
            if (preferenceChanged || selectionChanged || attributeModified || data.attibuteValueHasChanged(rg.getValueModificationCounter(data.getAttributeId()))) {
                final Set<Object> values = new HashSet<>();
                int valueCountLimit = 11;
                // only load 10 values first... if the user wants more then another request is made. we load 11 to know that there are more than 10
                if ("boolean".equals(data.getDataType())) {
                    valueCountLimit = 2;
                // boolean only has two possibilities.
                }
                if (selectedElement != null) {
                    for (int i = 0; i < selectedElement.size() && values.size() < valueCountLimit; i++) {
                        values.add(rg.getObjectValue(data.getAttributeId(), selectedElement.get(i)));
                    }
                } else {
                    // assumed to be graphelementtype of graph.
                    values.add(rg.getObjectValue(data.getAttributeId(), 0));
                }
                if (!values.isEmpty()) {
                    valueChanged = true;
                }
                final String attributeValuesKey = type.getLabel() + data.getAttributeName();
                elementAttributeValues.remove(attributeValuesKey);
                elementAttributeValues.put(attributeValuesKey, sortHashMap(values));
            }
        }
    }
    return valueChanged;
}
Also used : IntArray(au.gov.asd.tac.constellation.utilities.graphics.IntArray) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType) HashSet(java.util.HashSet)

Aggregations

GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)85 Test (org.testng.annotations.Test)34 ArrayList (java.util.ArrayList)28 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)17 Attribute (au.gov.asd.tac.constellation.graph.Attribute)16 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)12 HashMap (java.util.HashMap)11 AdvancedFindTab (au.gov.asd.tac.constellation.views.find2.components.AdvancedFindTab)10 FindCriteriaValues (au.gov.asd.tac.constellation.views.find2.components.advanced.criteriavalues.FindCriteriaValues)9 GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)8 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)8 Graph (au.gov.asd.tac.constellation.graph.Graph)7 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)5 SchemaAttribute (au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)5 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)5 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)5 FindViewController (au.gov.asd.tac.constellation.views.find2.FindViewController)5 AdvancedCriteriaBorderPane (au.gov.asd.tac.constellation.views.find2.components.advanced.AdvancedCriteriaBorderPane)5 BasicFindReplaceParameters (au.gov.asd.tac.constellation.views.find2.utilities.BasicFindReplaceParameters)5 List (java.util.List)5