use of au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType in project constellation by constellation-app.
the class EntityPathsLayer method getPathsForElement.
@Override
public List<Tuple<GraphElement, GraphElement>> getPathsForElement(final ReadableGraph graph, final GraphElement element) {
final List<Tuple<GraphElement, GraphElement>> paths = new ArrayList<>();
if (element.getType() == GraphElementType.VERTEX) {
final int vertexTypeAttributeId = AnalyticConcept.VertexAttribute.TYPE.get(graph);
final int transactionDateTimeAttributeId = TemporalConcept.TransactionAttribute.DATETIME.get(graph);
final SchemaVertexType vertexType = graph.getObjectValue(vertexTypeAttributeId, element.getId());
if (vertexType != null && vertexType.isSubTypeOf(AnalyticConcept.VertexType.LOCATION)) {
final int neighbourCount = graph.getVertexNeighbourCount(element.getId());
for (int neighbourPosition = 0; neighbourPosition < neighbourCount; neighbourPosition++) {
final int neighbourId = graph.getVertexNeighbour(element.getId(), neighbourPosition);
final SchemaVertexType neighbourType = graph.getObjectValue(vertexTypeAttributeId, neighbourId);
if (neighbourType != null && !neighbourType.isSubTypeOf(AnalyticConcept.VertexType.LOCATION)) {
final Set<Long> locationDateTimes = new HashSet<>();
final int neighbourLinkId = graph.getLink(element.getId(), neighbourId);
final int neighbourLinkTransactionCount = graph.getLinkTransactionCount(neighbourLinkId);
for (int neighbourLinkTransactionPosition = 0; neighbourLinkTransactionPosition < neighbourLinkTransactionCount; neighbourLinkTransactionPosition++) {
final int neighbourLinkTransactionId = graph.getLinkTransaction(neighbourLinkId, neighbourLinkTransactionPosition);
final long neighbourLinkTransactionDateTime = graph.getLongValue(transactionDateTimeAttributeId, neighbourLinkTransactionId);
locationDateTimes.add(neighbourLinkTransactionDateTime);
}
final List<Integer> validNeighbourNeighbours = new ArrayList<>();
final int neighbourNeighbourCount = graph.getVertexNeighbourCount(neighbourId);
for (int neighbourNeighbourPosition = 0; neighbourNeighbourPosition < neighbourNeighbourCount; neighbourNeighbourPosition++) {
final int neighbourNeighbourId = graph.getVertexNeighbour(neighbourId, neighbourNeighbourPosition);
final SchemaVertexType neighbourNeighbourType = graph.getObjectValue(vertexTypeAttributeId, neighbourNeighbourId);
if (neighbourNeighbourType != null && neighbourNeighbourType.isSubTypeOf(AnalyticConcept.VertexType.LOCATION)) {
validNeighbourNeighbours.add(neighbourNeighbourId);
}
}
locationDateTimes.forEach(locationDateTime -> {
int pathNeighbourNeighbour = GraphConstants.NOT_FOUND;
long closestTimeDifference = Long.MAX_VALUE;
for (final int neighbourNeighbourId : validNeighbourNeighbours) {
final int neighbourNeighbourLinkId = graph.getLink(neighbourId, neighbourNeighbourId);
final int neighbourNeighbourLinkTransactionCount = graph.getLinkTransactionCount(neighbourNeighbourLinkId);
for (int neighbourNeighbourLinkTransactionPosition = 0; neighbourNeighbourLinkTransactionPosition < neighbourNeighbourLinkTransactionCount; neighbourNeighbourLinkTransactionPosition++) {
final int neighbourNeighbourLinkTransactionId = graph.getLinkTransaction(neighbourNeighbourLinkId, neighbourNeighbourLinkTransactionPosition);
final long neighbourNeighbourLinkTransactionDateTime = graph.getLongValue(transactionDateTimeAttributeId, neighbourNeighbourLinkTransactionId);
final long timeDifference = neighbourNeighbourLinkTransactionDateTime - locationDateTime;
if (timeDifference > 0 && timeDifference < closestTimeDifference) {
closestTimeDifference = timeDifference;
pathNeighbourNeighbour = neighbourNeighbourId;
}
}
}
if (pathNeighbourNeighbour != GraphConstants.NOT_FOUND) {
paths.add(Tuple.create(element, new GraphElement(pathNeighbourNeighbour, GraphElementType.VERTEX)));
}
});
}
}
}
}
return paths;
}
use of au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType in project constellation by constellation-app.
the class LocationPathsLayer method getPathsForElement.
@Override
public List<Tuple<GraphElement, GraphElement>> getPathsForElement(final ReadableGraph graph, final GraphElement element) {
final List<Tuple<GraphElement, GraphElement>> paths = new ArrayList<>();
if (element.getType() == GraphElementType.VERTEX) {
final int vertexTypeAttributeId = AnalyticConcept.VertexAttribute.TYPE.get(graph);
final SchemaVertexType vertexType = graph.getObjectValue(vertexTypeAttributeId, element.getId());
if (vertexType != null && vertexType.isSubTypeOf(AnalyticConcept.VertexType.LOCATION)) {
final int neighbourCount = graph.getVertexNeighbourCount(element.getId());
for (int neighbourPosition = 0; neighbourPosition < neighbourCount; neighbourPosition++) {
final int neighbourId = graph.getVertexNeighbour(element.getId(), neighbourPosition);
final SchemaVertexType neighbourType = graph.getObjectValue(vertexTypeAttributeId, neighbourId);
if (neighbourType != null && neighbourType.isSubTypeOf(AnalyticConcept.VertexType.LOCATION)) {
final int neighbourLinkId = graph.getLink(element.getId(), neighbourId);
final int outgoingDirection = element.getId() < neighbourId ? GraphConstants.UPHILL : GraphConstants.DOWNHILL;
final int linkOutgoingTransactionCount = graph.getLinkTransactionCount(neighbourLinkId, outgoingDirection);
for (int i = 0; i < linkOutgoingTransactionCount; i++) {
paths.add(Tuple.create(element, new GraphElement(neighbourId, GraphElementType.VERTEX)));
}
}
}
}
}
return paths;
}
use of au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType in project constellation by constellation-app.
the class IdentifierInconsistentWithTypeRuleNGTest method testExecuteRuleValidIdentifierAndType.
/**
* Test of executeRule method, of class IdentifierInconsistentWithTypeRule.
*
* Return false when the identifier and type matches
*/
@Test
public void testExecuteRuleValidIdentifierAndType() {
final StoreGraph graph = new StoreGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
final int vx0 = graph.addVertex();
final String identifierName = "AUS";
// Set identifer and verify correct setup
final int identifierAttr = VisualConcept.VertexAttribute.IDENTIFIER.ensure(graph);
graph.setStringValue(identifierAttr, vx0, identifierName);
assertEquals(graph.getObjectValue(identifierAttr, vx0), identifierName);
final SchemaVertexType type = AnalyticConcept.VertexType.COUNTRY;
// Ensure there is a type attribute on the graph and check its value
final int typeAttr = AnalyticConcept.VertexAttribute.TYPE.ensure(graph);
graph.setObjectValue(typeAttr, vx0, type);
assertEquals(graph.getObjectValue(typeAttr, vx0), type);
// Running rule on vertex
final IdentifierInconsistentWithTypeRule instance = new IdentifierInconsistentWithTypeRule();
final boolean expResult = false;
final boolean result = instance.executeRule(graph, vx0);
assertEquals(result, expResult);
}
use of au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType in project constellation by constellation-app.
the class IdentifierInconsistentWithTypeRuleNGTest method testExecuteRuleNullIdentifier.
/**
* Test of executeRule method, of class IdentifierInconsistentWithTypeRule.
*
* Return false when the vx's identifier is null
*/
@Test
public void testExecuteRuleNullIdentifier() {
final StoreGraph graph = new StoreGraph(SchemaFactoryUtilities.getSchemaFactory(VisualSchemaFactory.VISUAL_SCHEMA_ID).createSchema());
final int vx0 = graph.addVertex();
final String identifierName = null;
// Set identifer and verify correct setup
final int identifierAttr = VisualConcept.VertexAttribute.IDENTIFIER.ensure(graph);
graph.setStringValue(identifierAttr, vx0, identifierName);
assertEquals(graph.getObjectValue(identifierAttr, vx0), identifierName);
final SchemaVertexType type = AnalyticConcept.VertexType.COUNTRY;
// Ensure there is a type attribute on the graph and check its value
final int typeAttr = AnalyticConcept.VertexAttribute.TYPE.ensure(graph);
graph.setObjectValue(typeAttr, vx0, type);
assertEquals(graph.getObjectValue(typeAttr, vx0), type);
// Running rule on vertex
final IdentifierInconsistentWithTypeRule instance = new IdentifierInconsistentWithTypeRule();
final boolean expResult = false;
final boolean result = instance.executeRule(graph, vx0);
assertEquals(result, expResult);
}
use of au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType in project constellation by constellation-app.
the class VertexTypeNodeProvider method newActiveGraph.
@Override
public void newActiveGraph(final Graph graph) {
// TODO: if the old graph and the new graph have the same schema, don't recalculate.
Platform.runLater(() -> {
detailsView.getChildren().clear();
final Label nameLabel = new Label("No type selected");
detailsView.getChildren().add(nameLabel);
vertexTypes.clear();
if (graph != null && graph.getSchema() != null && GraphNode.getGraphNode(graph) != null) {
final SchemaFactory schemaFactory = graph.getSchema().getFactory();
final Set<Class<? extends SchemaConcept>> concepts = schemaFactory.getRegisteredConcepts();
schemaLabel.setText(String.format("%s - %s", schemaFactory.getLabel(), GraphNode.getGraphNode(graph).getDisplayName()));
vertexTypes.addAll(SchemaVertexTypeUtilities.getTypes(concepts));
Collections.sort(vertexTypes, (final SchemaVertexType a, final SchemaVertexType b) -> a.getName().compareToIgnoreCase(b.getName()));
} else {
schemaLabel.setText("No schema available");
}
populateTree();
});
}
Aggregations