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