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.
In Neo4j Desktop, configure it to show all Edges that exist between the Nodes of a query result.
Look in Settings, "connect result nodes", "Auto-Complete" - or where Neo4j has implemented that feature for the version of Neo4j that you are using
Without this, all the Node queries shown here won't show the Edges unless you specifically return the matching Edges
Go to the Neo4 browser and enter the following Cypher query to view the generated graph.
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.
Use Neo4j Desktop to move, lock into position, hide, or expand the visual graph to suite your interests.
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.
Confirm that the Package Nodes shown match those appearing in the source sample SysML model.
Enter the following Cypher query to get the package structure in the graph:
match(p:Package) return p
match ( p : Package ) return count(p);
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.
Enter the following Cypher query to get all Block nodes in the graph:
match(b:Block) return b
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.
To see a more intuitive Assembly structure, ask Cypher for Blocks that relate to each with either a PartProperty or a Full Port relationship:
match ( b : Block )-[:PartProperty|:FullPort]->( c : Block )
return b,c
Enter the following Cypher query to get all the requirements in the graph:
match (r:Requirement) return r
This fetches all Requirement Nodes from the graph; also shown is the parent/child Containment relationships between those Requirements.
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.
Enter the following Cypher query to get all the immediate child requirements for a given requirement
match(r:Requirement{name:"cUAV Specification"})-[:Containment]->(rc:Requirement) return r,rc
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.
Refer to the SysML model and confirm that the Requirement 'cUAV Specification' has all the child Requirements shown and no more or less.
Enter the following Cypher query to get all relationships (ingoing and outgoing) for a named requirement
match(r:Requirement{name:"cUAV Specification"})-[rel]-(n) return r,rel,n
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.
Observe that a Requirements Package and a UAV Block, in addition to the contained Requirements, are now in the results.
Enter the following Cypher query to get all inheritance (generalization) relationships between Blocks.
Note: Turn off Auto-Complete ( "return connected results" ) to see only Generalization relationships.
match(b:Block)-[r:Generalization]->(p:Block) return b,r,p
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
match(b:Block)-[r:ValueProperty]->(t) return b,r,t
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
Run the following query to get all constraint properties of all blocks - match(b:Block)-[r:ConstraintProperty]-(t) return b,r,t
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
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"})
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:
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.
Behavior is assigned to the block through a dependency relationship, typically allocate.
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
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 (⇨)