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