use of au.gov.asd.tac.constellation.graph.GraphElementType.VERTEX 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));
}
}
}
Aggregations