Search in sources :

Example 1 with GraphReadMethods

use of au.gov.asd.tac.constellation.graph.GraphReadMethods 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 2 with GraphReadMethods

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

the class GraphTaxonomy method reposition.

/**
 * Reposition the taxa with respect to the condensed graph.
 * <p>
 * Each vertex in the condensed graph represents a taxon in the taxonomy in
 * that each vertex in the condensation is the key of a taxon. The condensed
 * graph has been arranged, now we want to arrange the original graph to
 * match.
 * <p>
 * For each taxon, move the member vertices by the same distance that the
 * key has been moved.
 *
 * @param c The condensed graph and condensation data.
 *
 * @throws java.lang.InterruptedException If the thread was interrupted.
 */
public void reposition(final Condensation c) throws InterruptedException {
    final GraphReadMethods crg = c.wg;
    // The x,y,z attributes in the original graph; these values will be updated
    final int xAttr = VisualConcept.VertexAttribute.X.get(wg);
    final int yAttr = VisualConcept.VertexAttribute.Y.get(wg);
    final int zAttr = VisualConcept.VertexAttribute.Z.get(wg);
    // The post-arrangement x,y,z attributes of the vertices in the condensed graph.
    final int cxAttr = VisualConcept.VertexAttribute.X.get(crg);
    final int cyAttr = VisualConcept.VertexAttribute.Y.get(crg);
    final int czAttr = VisualConcept.VertexAttribute.Z.get(crg);
    // The x,y,z attributes containing the original values of the vertices in the condensed graph.
    final int cxOrigId = crg.getAttribute(GraphElementType.VERTEX, X_ORIG);
    final int cyOrigId = crg.getAttribute(GraphElementType.VERTEX, Y_ORIG);
    final int czOrigId = crg.getAttribute(GraphElementType.VERTEX, Z_ORIG);
    // For each taxon, reposition the original vertices to match the repositioning of the condensed graph vertices.
    final int cVxCount = crg.getVertexCount();
    for (int position = 0; position < cVxCount; position++) {
        final int cVxId = crg.getVertex(position);
        final float cx = crg.getFloatValue(cxAttr, cVxId);
        final float cy = crg.getFloatValue(cyAttr, cVxId);
        final float cz = crg.getFloatValue(czAttr, cVxId);
        final float cxorig = crg.getFloatValue(cxOrigId, cVxId);
        final float cyorig = crg.getFloatValue(cyOrigId, cVxId);
        final float czorig = crg.getFloatValue(czOrigId, cVxId);
        // How far did the taxon key vertex move? delta = newposition - oldposition.
        final float dx = cx - cxorig;
        final float dy = cy - cyorig;
        final float dz = cz - czorig;
        final int k = c.cVxIdToTaxonKey.get(cVxId);
        for (final int vxId : taxa.get(k)) {
            final float x = wg.getFloatValue(xAttr, vxId);
            final float y = wg.getFloatValue(yAttr, vxId);
            final float z = wg.getFloatValue(zAttr, vxId);
            wg.setFloatValue(xAttr, vxId, x + dx);
            wg.setFloatValue(yAttr, vxId, y + dy);
            wg.setFloatValue(zAttr, vxId, z + dz);
        }
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
    }
}
Also used : GraphReadMethods(au.gov.asd.tac.constellation.graph.GraphReadMethods)

Example 3 with GraphReadMethods

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

the class RecordStoreQueryPluginNGTest method testGetResult.

/**
 * Test of getResult method, of class RecordStoreQueryPlugin.
 */
@Test
public void testGetResult() throws InterruptedException, PluginException {
    System.out.println("getResult");
    final RecordStoreQueryPlugin instance = new RecordStoreQueryPluginMockImpl();
    final GraphReadMethods graph = new StoreGraph();
    final PluginInteraction interaction = null;
    final PluginParameters parameters = null;
    instance.read(graph, interaction, parameters);
    instance.query(interaction, parameters);
    final RecordStore result = instance.getResult();
    assertEquals(result.size(), 2);
}
Also used : GraphReadMethods(au.gov.asd.tac.constellation.graph.GraphReadMethods) PluginInteraction(au.gov.asd.tac.constellation.plugins.PluginInteraction) RecordStore(au.gov.asd.tac.constellation.graph.processing.RecordStore) GraphRecordStore(au.gov.asd.tac.constellation.graph.processing.GraphRecordStore) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Test(org.testng.annotations.Test)

Example 4 with GraphReadMethods

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

the class ShortAttributeDescriptionNGTest method testCopy.

/**
 * Test of copy method, of class ShortAttributeDescription.
 */
@Test
public void testCopy() {
    GraphReadMethods graph = new StoreGraph();
    AttributeDescription expResult = instance;
    AttributeDescription result = instance.copy(graph);
    assertEquals(result.getShort(0), expResult.getShort(0));
}
Also used : GraphReadMethods(au.gov.asd.tac.constellation.graph.GraphReadMethods) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Test(org.testng.annotations.Test)

Example 5 with GraphReadMethods

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

the class TimeAttributeDescriptionNGTest method testCopy.

/**
 * Test of copy method, of class TimeAttributeDescription.
 */
@Test
public void testCopy() {
    GraphReadMethods graph = new StoreGraph();
    AttributeDescription expResult = instance;
    AttributeDescription result = instance.copy(graph);
    assertEquals(result.getLong(0), expResult.getLong(0));
}
Also used : GraphReadMethods(au.gov.asd.tac.constellation.graph.GraphReadMethods) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Test(org.testng.annotations.Test)

Aggregations

GraphReadMethods (au.gov.asd.tac.constellation.graph.GraphReadMethods)20 Test (org.testng.annotations.Test)15 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)12 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)7 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)6 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)5 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)4 Graph (au.gov.asd.tac.constellation.graph.Graph)3 RecordStore (au.gov.asd.tac.constellation.graph.processing.RecordStore)3 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)3 File (java.io.File)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)2 GraphNode (au.gov.asd.tac.constellation.graph.node.GraphNode)2 GraphRecordStoreUtilities (au.gov.asd.tac.constellation.graph.processing.GraphRecordStoreUtilities)2 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)2 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)2 MultiChoiceParameterType (au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType)2