Run Queries on the Neo4j Graph

Return to the Top of the Tutorial (⇧) or Go back to the Prior part of the Tutorial (⇦)

This section continues the tutorial on using the Syndeia Plugin to export and import SysML content with Neo4j graphs. Here, you will run a few simple Cypher queries to visualize what information was exported from the sample SysML model.

  1. In Neo4j Desktop, configure it to show all Edges that exist between the Nodes of a query result.

    1. Look in Settings, "connect result nodes", "Auto-Complete" - or where Neo4j has implemented that feature for the version of Neo4j that you are using

    2. Without this, all the Node queries shown here won't show the Edges unless you specifically return the matching Edges

  2. Go to the Neo4 browser and enter the following Cypher query to view the generated graph.

    1. match (n)-[r]->(m) return n,r,m



      The top of the graph shows a color index of the different types of nodes and relationships in the graph, e.g. Activity, Block, ConstraintBlock, DataType, Interaction, InterfaceBlock, etc. These represent the concept areas of SysML that are being covered by the SysML -> Graph generation process.
      This example illustrates that all key SysML concepts are being exported.

  3. Use Neo4j Desktop to move, lock into position, hide, or expand the visual graph to suite your interests.

  4. After re-arranging the nodes, the graph will look similar to as shown below. We've chosen Blue as the color of the Package label. Nodes that are Packages represent the packages and their child packages from the SysML model. The children packages under the System package appear in our figure, from left to right, as: Structure, Interactions, Stereotypes, Requirements, Use Cases, Activities, State machines.

    1. Confirm that the Package Nodes shown match those appearing in the source sample SysML model.




  5. Enter the following Cypher query to get the package structure in the graph:

    1. match(p:Package) return p

    2. match ( p : Package ) return count(p);

      1. This counts the number of Package Nodes. Confirm that it matches what the visualization shows (e.g. 10) and the number of Packages from the scope of the SysML model.

  6. Enter the following Cypher query to get all Block nodes in the graph:

    1. match(b:Block) return b

      1. This fetches all the blocks in the graph and their inter-relationships, including generalization (inheritance), part/reference/shared properties, and full ports. All the blocks inherit from the System Block. The UAV block is the top-level structural element and it has several part properties.

  7. To see a more intuitive Assembly structure, ask Cypher for Blocks that relate to each with either a PartProperty or a Full Port relationship:

    1. match ( b : Block )-[:PartProperty|:FullPort]->( c : Block )
      return b,c

  8. Enter the following Cypher query  to get all the requirements in the graph:

    1. match (r:Requirement) return r

      1. This fetches all Requirement Nodes from the graph; also shown is the parent/child Containment relationships between those Requirements.

      2. Visit the SysML model in the modeling tool and confirm, for example, that the cUAV Specification Requirement does have, within it, the 7 child Requirements shown. Range, Payload Spec, etc.

  9. Enter the following Cypher query to get all the immediate child requirements for a given requirement

    1. match(r:Requirement{name:"cUAV Specification"})-[:Containment]->(rc:Requirement) return r,rc

      1. This reads "find all Requirements named 'cUAV Specification' that have a direct Containment Edge to a Requirement. Refer to the parent as r and the child as rc. Return all matching r and rc instances.

      2. Refer to the SysML model and confirm that the Requirement 'cUAV Specification' has all the child Requirements shown and no more or less.




  10. Enter the following Cypher query to get all relationships (ingoing and outgoing) for a named requirement

    1. match(r:Requirement{name:"cUAV Specification"})-[rel]-(n) return r,rel,n

    2. This reads "find all Requirements named 'cUAV Specification' that have any direct Edge to any kind of Node. Refer to the Requirement as r, the Edge as rel, and the peer as n. Return all matching r, rel, n instances.

    3. Observe that a Requirements Package and a UAV Block, in addition to the contained Requirements, are now in the results.

  11. Enter the following Cypher query to get all inheritance (generalization) relationships between Blocks.

    1. Note: Turn off Auto-Complete ( "return connected results" ) to see only Generalization relationships.

    2. match(b:Block)-[r:Generalization]->(p:Block) return b,r,p

  12. Enter the following Cypher query to get all value properties of all blocks. Turn on Auto-Complete to see the Generalization relationships. It shows the UAV block has its own value properties but will also inherit value properties from the System block

    1. match(b:Block)-[r:ValueProperty]->(t) return b,r,t

  13. Run the following query to get all full and proxy ports of all blocks. Turn on Auto-Complete if you want to see relationships between the blocks (e.g. PartProperty) - match(b)-[r:FullPort|ProxyPort]->(t) return b,r,t




  14. Run the following query to get all constraint properties of all blocks - match(b:Block)-[r:ConstraintProperty]-(t) return b,r,t





  15. Run the following query to get all relationships—outgoing and incoming—for a specific block (e.g. UAV). Turn off Auto-Complete of relations

    match(b:Block{name:"UAV"})-[r]-(t) return b,r,t





  16. Run the following query to check if there are any orphaned requirements, i.e. requirements that do not have any incoming or outgoing relations. There are none at this point.

     match(r:Requirement) where size((r)-[]-())=0 return r



    You can try creating a new isolated requirement using the command below and then re-run the query above.

    create(r:Requirement{name:"Test"})


  17. Run the following query to get all the behaviors (activities, state machines, and interactions) associated with all the blocks. 

    match(b:Block)-[r]-(f) where(f:Activity OR f:StateMachine OR f:Interaction) return b,r,f

    Only the UAV block has associated behaviors in the model. We have associated behaviors to the UAV SysML block in two different ways that represent typical modeling usage:

    1. Block element contains the behavior element. This is the case when the behavior is modeled as an owned behavior (or classifier behavior) of the block.

    2. Behavior is assigned to the block through a dependency relationship, typically allocate.

  18. Run the following query to get all the use cases in the model. Turn on Auto-Complete to view the Generalization relationships between use cases.

    match(u:UseCase) return u



  19. Run the following query to get applied stereotypes and tag values for the UAV block. If you select the relationship, you can see the values of the tags (target_life, budget, and owner) populated for the UAV block.

    match(b:Block{name:"UAV"})-[r]->(s:Stereotype) return b,r,s

Return to the Top of the Tutorial (⇧) or Continue to the Next part of the Tutorial (⇨)