Inputs to the Graph Function
Parameters to pass to graph functions when using CGE.
Three types of inputs to a graph algorithm are possible:
- The graph itself – Each graph function expects input to come from the output of the preceding CONSTRUCT operator.
- Scalar inputs – Scalar values can be passed to the graph algorithm via a parenthesized list in the INVOKE clause.
- Vector inputs – Sets of values can be input to the graph algorithm by adding them to the graph that the CONSTRUCT operator builds. Generally these inputs are distinguished in the input graph by a triple with a type predicate and a special type object.
In the following example, the Bad Rank algorithm expects to receive a set of vertex IDs of vertices considered to be spam, i.e, it could represent some other undesirable attribute. Note that the WHERE clause associated with the CONSTRUCT clause includes a VALUES clause, that names a set of vertices that are to be considered spam by the Bad Rank algorithm. That set of vertices is added to the CONSTRUCT clause’s graph as a set of triples with a rdf:type predicate and the special object cray:spamNode. The scalar argument list of the INVOKE clause also specifies that this cray:spamNode object is to be used for identifying spam vertices. Similarly, a vector input to the graph algorithm can already be present in the database.
Using Vector Inputs for Graph Algorithm
PREFIX cray: <http://cray.com/>
SELECT ?vertex ?ranking
{
CONSTRUCT{
?sub ?pred ?obj .
?badNode a cray:spamNode .
}
WHERE {
{
?sub ?pred ?obj .
} UNION {
VALUES ?badNode {
<http://www.Department5.University0.edu/Course34>
<http://www.Department6.University0.edu/GraduateCourse34>
<http://www.Department14.University0.edu/GraduateCourse31>
<http://www.Department5.University0.edu/Course34>
<http://www.Department10.University0.edu/GraduateCourse25>
<http://www.Department11.University0.edu/Course11>
<http://www.Department13.University0.edu/GraduateStudent87>
}
}
}
INVOKE cray:graphAlgorithm.badrank (0.0001, .84, 0.01, cray:spamNode)
PRODUCING ?vertex ?ranking
}
ORDER BY DESC (?ranking)
LIMIT 100 The above example shows the invocation of the Bad Rank algorithm with a set of spam vertices present in the input graph.