Library Elements Graph_getNodeAttribute and Graph_getEdgeAttribute

Soley Studio comes with a multitude of pre-defined code building blocks – the library elements. Library elements cover import and analysis steps that are useful in many cases. Instead of coding the step every time, you can just copy paste the library element to your code and adapt it to your use case by setting the input arguments according to your data and metamodel. This article demonstrates the usage of the library function “Graph_getNodeAttribute” by means of an example. The library function “Graph_getEdgeAttribute” works the same way.

Graph_getNodeAttribute

When to use

This library element returns the value of an element´s attribute as an object. It can be used to retrieve a value if the basic data type of an attribute is not clear, e.g. when trying to write a very flexible rule.

Syntax

Graph_getNodeAttribute(NODE_INSTANCE,ATTRIBUTE_NAME):VALUE

This is a function and needs to be called accordingly in rules, sequences, functions or procedures.

Input Parameters

  • NODE_INSTANCE:Node – the identifier for a node instance
  • ATTRIBUTE_NAME:string – name of an attribute of the referenced node

Returns

  • VALUE:object – The library function returns the attribute value (e.g. true, “hello”, 3.32) of the given element and the defined attribute as an object. To access the value in the original data type a cast from type object to the respective data type, e.g. string or int, is required (see example below).

Graph_getEdgeAttribute

Equal to Graph_getNodeAttribute but for edge elements. Please see the description above.

Example

sequence {
[getNodeAttribute_example]
}
//Determine the value of a random element attribute
rule getNodeAttribute_example{
n: Product;
modify{
def var attValue: int = (int)Graph_getNodeAttribute(n, "maxTemp");
//Caution! Pay attention to the cast of type object to the respective datatype, in this case int
emit(attValue + "\n");
}}

This example rule looks for all nodes of class Product (if called in square brackets) in the graph (left-hand side). The returned object of the library function “Graph_getNodeAttribute” is explicitly cast to int and is assigned to the integer variable attValue. It is subsequently displayed in the output pad by using the emit statement. After running the sequence, the value of the attribute maxTemp is printed in the output window for each Product node.

Where to find the library elements

Both library elements are part of the Foundations/Graph library that comes with Soley Studio. Go to the Libraries tool and select the category Graph –> Handle Properties –> Graph_getNodeAttribute or Graph_getEdgeAttribute.

Was this article helpful?

Related Articles