Search in sources :

Example 6 with SchemaVertexType

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;
}
Also used : SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) ArrayList(java.util.ArrayList) GraphElement(au.gov.asd.tac.constellation.views.mapview.utilities.GraphElement) Tuple(au.gov.asd.tac.constellation.utilities.datastructure.Tuple) HashSet(java.util.HashSet)

Example 7 with SchemaVertexType

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;
}
Also used : SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) ArrayList(java.util.ArrayList) GraphElement(au.gov.asd.tac.constellation.views.mapview.utilities.GraphElement) Tuple(au.gov.asd.tac.constellation.utilities.datastructure.Tuple)

Example 8 with SchemaVertexType

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);
}
Also used : SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Test(org.testng.annotations.Test)

Example 9 with SchemaVertexType

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);
}
Also used : SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) StoreGraph(au.gov.asd.tac.constellation.graph.StoreGraph) Test(org.testng.annotations.Test)

Example 10 with SchemaVertexType

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();
    });
}
Also used : SchemaFactory(au.gov.asd.tac.constellation.graph.schema.SchemaFactory) SchemaVertexType(au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType) Label(javafx.scene.control.Label) SchemaConcept(au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept)

Aggregations

SchemaVertexType (au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexType)30 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)9 SchemaTransactionType (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)8 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)6 PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)6 Map (java.util.Map)6 SchemaConcept (au.gov.asd.tac.constellation.graph.schema.concept.SchemaConcept)5 SchemaVertexTypeUtilities (au.gov.asd.tac.constellation.graph.schema.type.SchemaVertexTypeUtilities)5 List (java.util.List)5 Test (org.testng.annotations.Test)5 Graph (au.gov.asd.tac.constellation.graph.Graph)4 AnalyticConcept (au.gov.asd.tac.constellation.graph.schema.analytic.concept.AnalyticConcept)4 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)4 MultiChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue)4 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)3 SchemaTransactionTypeUtilities (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionTypeUtilities)3 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)3 ParameterChange (au.gov.asd.tac.constellation.plugins.parameters.ParameterChange)3 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)3