Search in sources :

Example 1 with SchemaAttribute

use of au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute 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 SchemaAttribute

use of au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute in project constellation by constellation-app.

the class SchemaFactory method ensureAttribute.

/**
 * Ensure that an {@link Attribute} is created on a graph. If the specified
 * attribute is registered to this SchemaFactory, the attribute will be
 * created on the specified graph and returned, otherwise the error value
 * {@link Graph#NOT_FOUND} will be returned.
 *
 * @param graph the {@link GraphWriteMethods} to add the attribute to.
 * @param elementType the {@link GraphElementType} the attribute applies to.
 * @param attributeName the name of the attribute you wish to add.
 *
 * @return an int representing the ensured attribute.
 */
public final int ensureAttribute(final GraphWriteMethods graph, final GraphElementType elementType, final String attributeName) {
    int attribute = graph.getAttribute(elementType, attributeName);
    if (attribute == Graph.NOT_FOUND) {
        final SchemaAttribute registeredAttribute = getRegisteredAttributes(elementType).get(attributeName);
        if (registeredAttribute == null) {
            return Graph.NOT_FOUND;
        }
        attribute = graph.addAttribute(elementType, registeredAttribute.getAttributeType(), registeredAttribute.getName(), registeredAttribute.getDescription(), registeredAttribute.getDefault(), registeredAttribute.getAttributeMergerId());
        graph.setAttributeIndexType(attribute, registeredAttribute.getIndexType());
    }
    return attribute;
}
Also used : SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)

Example 3 with SchemaAttribute

use of au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute in project constellation by constellation-app.

the class AttributeUtilities method getDateTimeAttributes.

/**
 * Return the date time attributes for a {@link GraphElementType} used by a
 * graph
 *
 * @param graph The graph
 * @param graphElementType The element type
 * @return Set of date time attributes used on a given graph
 */
public static Set<String> getDateTimeAttributes(final Graph graph, final GraphElementType graphElementType) {
    final Set<String> datetimeAttributes = new TreeSet<>();
    if (graph != null && graph.getSchema() != null) {
        final SchemaFactory factory = graph.getSchema().getFactory();
        final Map<String, SchemaAttribute> attributesMap = factory.getRegisteredAttributes(graphElementType);
        attributesMap.values().stream().forEach((SchemaAttribute schemaAttribute) -> {
            if (schemaAttribute.getAttributeType().equals(ZonedDateTimeAttributeDescription.ATTRIBUTE_NAME)) {
                datetimeAttributes.add(schemaAttribute.getName());
            }
        });
    }
    return datetimeAttributes;
}
Also used : SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) TreeSet(java.util.TreeSet) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)

Example 4 with SchemaAttribute

use of au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute in project constellation by constellation-app.

the class AttributeUtilities method getRegisteredAttributeIdsFromGraph.

/**
 * Return the attribute id's for a {@link GraphElementType} used by a graph
 *
 * @param graph The graph
 * @param graphElementType The element type
 * @return Set of attribute id's being used on a given graph
 */
public static Map<String, Integer> getRegisteredAttributeIdsFromGraph(final GraphReadMethods graph, final GraphElementType graphElementType) {
    final Map<String, Integer> attributeIds = new TreeMap<>();
    final Schema schema = graph.getSchema();
    if (schema != null) {
        final SchemaFactory factory = schema.getFactory();
        final Map<String, SchemaAttribute> attrsMap = factory.getRegisteredAttributes(graphElementType);
        attrsMap.values().stream().forEach(schemaAttribute -> {
            final int attributeId = graph.getAttribute(graphElementType, schemaAttribute.getName());
            if (attributeId != Graph.NOT_FOUND) {
                attributeIds.put(schemaAttribute.getName(), attributeId);
            }
        });
    }
    return attributeIds;
}
Also used : SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) Schema(au.gov.asd.tac.constellation.graph.schema.Schema) TreeMap(java.util.TreeMap) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)

Example 5 with SchemaAttribute

use of au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute in project constellation by constellation-app.

the class ImportController method updateAutoAddedAttributes.

/**
 * Get the attributes that will automatically be added to the attribute
 * list.
 *
 * @param elementType
 * @param attributes
 * @param rg
 */
private void updateAutoAddedAttributes(final GraphElementType elementType, final Map<String, Attribute> attributes, final GraphReadMethods rg, final boolean showSchemaAttributes) {
    attributes.clear();
    // Add attributes from the graph
    int attributeCount = rg.getAttributeCount(elementType);
    for (int i = 0; i < attributeCount; i++) {
        int attributeId = rg.getAttribute(elementType, i);
        Attribute attribute = new GraphAttribute(rg, attributeId);
        attributes.put(attribute.getName(), attribute);
    }
    // Add attributes from the schema
    if (showSchemaAttributes && rg.getSchema() != null) {
        final SchemaFactory factory = rg.getSchema().getFactory();
        for (final SchemaAttribute sattr : factory.getRegisteredAttributes(elementType).values()) {
            final Attribute attribute = new GraphAttribute(elementType, sattr.getAttributeType(), sattr.getName(), sattr.getDescription());
            if (!attributes.containsKey(attribute.getName())) {
                attributes.put(attribute.getName(), attribute);
            }
        }
    }
    // Add pseudo-attributes
    if (elementType == GraphElementType.TRANSACTION) {
        final Attribute attribute = new GraphAttribute(elementType, BooleanAttributeDescription.ATTRIBUTE_NAME, DIRECTED, "Is this transaction directed?");
        attributes.put(attribute.getName(), attribute);
    }
    // Add primary keys
    for (int key : rg.getPrimaryKey(elementType)) {
        keys.add(key);
    }
}
Also used : SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) Attribute(au.gov.asd.tac.constellation.graph.Attribute) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) GraphAttribute(au.gov.asd.tac.constellation.graph.GraphAttribute) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)

Aggregations

SchemaAttribute (au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute)17 SchemaFactory (au.gov.asd.tac.constellation.graph.schema.SchemaFactory)9 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)7 ArrayList (java.util.ArrayList)6 Graph (au.gov.asd.tac.constellation.graph.Graph)5 List (java.util.List)5 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)3 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)3 SchemaFactoryUtilities (au.gov.asd.tac.constellation.graph.schema.SchemaFactoryUtilities)3 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)3 Attribute (au.gov.asd.tac.constellation.graph.Attribute)2 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)2 GraphManager (au.gov.asd.tac.constellation.graph.manager.GraphManager)2 Schema (au.gov.asd.tac.constellation.graph.schema.Schema)2 AnalyticConcept (au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept)2 SchemaConcept (au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept)2 SchemaTransactionType (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)2 SchemaTransactionTypeUtilities (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionTypeUtilities)2 VisualSchemaFactory (au.gov.asd.tac.constellation.graph.schema.visual.VisualSchemaFactory)2 SchemaUpdateProvider (au.gov.asd.tac.constellation.graph.versioning.SchemaUpdateProvider)2