## section-graph_pattern

section-graph_pattern

## Functions

int | rasqal_graph_pattern_add_sub_graph_pattern ()
rasqal_expression * | rasqal_graph_pattern_get_filter_expression ()
int | rasqal_graph_pattern_set_filter_expression ()
raptor_sequence * | rasqal_graph_pattern_get_flattened_triples ()
int | rasqal_graph_pattern_get_index ()
rasqal_graph_pattern_operator | rasqal_graph_pattern_get_operator ()
rasqal_literal * | rasqal_graph_pattern_get_origin ()
rasqal_graph_pattern * | rasqal_graph_pattern_get_sub_graph_pattern ()
raptor_sequence * | rasqal_graph_pattern_get_sub_graph_pattern_sequence ()
rasqal_triple * | rasqal_graph_pattern_get_triple ()
raptor_sequence * | rasqal_graph_pattern_get_triples ()
rasqal_literal * | rasqal_graph_pattern_get_service ()
rasqal_variable * | rasqal_graph_pattern_get_variable ()
const char * | rasqal_graph_pattern_operator_as_string ()
int | rasqal_graph_pattern_print ()
int | rasqal_graph_pattern_variable_bound_in ()
int | (*rasqal_graph_pattern_visit_fn) ()
int | rasqal_graph_pattern_visit ()

## Types and Values

typedef | rasqal_graph_pattern
enum | rasqal_graph_pattern_operator

## Description

## Functions

### rasqal_graph_pattern_add_sub_graph_pattern ()

    int
    rasqal_graph_pattern_add_sub_graph_pattern
                                   (rasqal_graph_pattern *graph_pattern,
                                    rasqal_graph_pattern *sub_graph_pattern);

Add a sub graph pattern to a graph pattern.

#### Parameters

graph_pattern | graph pattern to add to |
sub_graph_pattern | graph pattern to add inside |

#### Returns

non-0 on failure

### rasqal_graph_pattern_get_filter_expression ()

    rasqal_expression *
    rasqal_graph_pattern_get_filter_expression
                                   (rasqal_graph_pattern *gp);

Get a filter graph pattern's constraint expression

#### Parameters

gp | rasqal_graph_pattern query object |

#### Returns

expression or NULL on failure

### rasqal_graph_pattern_set_filter_expression ()

    int
    rasqal_graph_pattern_set_filter_expression
                                   (rasqal_graph_pattern *gp,
                                    rasqal_expression *expr);

Set a filter graph pattern constraint expression

#### Parameters

gp | rasqal_graph_pattern query object |
expr | rasqal_expression expr - ownership taken |

#### Returns

non-0 on failure

### rasqal_graph_pattern_get_flattened_triples ()

    raptor_sequence *
    rasqal_graph_pattern_get_flattened_triples
                                   (rasqal_query *query,
                                    rasqal_graph_pattern *graph_pattern);

Get the triples inside a tree of graph patterns (BASIC + GRAPH) as a single sequence with GRAPHs turned into triple origin.

The returned sequence and all the rasqal_triple in it are owned by the caller (hold references).

#### Parameters

query | query |
graph_pattern | graph pattern |

#### Returns

new sequence of raptor_triple or NULL on failure

### rasqal_graph_pattern_get_index ()

    int
    rasqal_graph_pattern_get_index (rasqal_graph_pattern *gp);

Get the graph pattern absolute index in the array of graph patterns.

The graph pattern index is assigned when `rasqal_query_prepare()` is run on a query containing a graph pattern.

#### Parameters

gp | rasqal_graph_pattern graph pattern |

#### Returns

index or <0 if no index has been assigned yet

### rasqal_graph_pattern_get_operator ()

    rasqal_graph_pattern_operator
    rasqal_graph_pattern_get_operator (rasqal_graph_pattern *graph_pattern);

Get the graph pattern operator .

The operator for the given graph pattern. See also `rasqal_graph_pattern_operator_as_string()`.

#### Parameters

graph_pattern | rasqal_graph_pattern graph pattern object |

#### Returns

graph pattern operator

### rasqal_graph_pattern_get_origin ()

    rasqal_literal *
    rasqal_graph_pattern_get_origin (rasqal_graph_pattern *graph_pattern);

Get the graph pattern literal for RASQAL_GRAPH_PATTERN_OPERATOR_GRAPH graph pattern

#### Parameters

graph_pattern | rasqal_graph_pattern graph pattern object |

#### Returns

graph literal parameter or NULL if wrong graph pattern type or not defined

### rasqal_graph_pattern_get_sub_graph_pattern ()

    rasqal_graph_pattern *
    rasqal_graph_pattern_get_sub_graph_pattern
                                   (rasqal_graph_pattern *graph_pattern,
                                    int idx);

Get a sub-graph pattern inside a graph pattern.

#### Parameters

graph_pattern | rasqal_graph_pattern graph pattern object |
idx | index into the sequence of sub graph_patterns in the graph pattern |

#### Returns

rasqal_graph_pattern or NULL if out of range

### rasqal_graph_pattern_get_sub_graph_pattern_sequence ()

    raptor_sequence *
    rasqal_graph_pattern_get_sub_graph_pattern_sequence
                                   (rasqal_graph_pattern *graph_pattern);

Get the sequence of graph patterns inside a graph pattern .

#### Parameters

graph_pattern | rasqal_graph_pattern graph pattern object |

#### Returns

a raptor_sequence of rasqal_graph_pattern pointers.

### rasqal_graph_pattern_get_triple ()

    rasqal_triple *
    rasqal_graph_pattern_get_triple (rasqal_graph_pattern *graph_pattern,
                                     int idx);

Get a triple inside a graph pattern.

#### Parameters

graph_pattern | rasqal_graph_pattern graph pattern object |
idx | index into the sequence of triples in the graph pattern |

#### Returns

rasqal_triple or NULL if out of range

### rasqal_graph_pattern_get_triples ()

    raptor_sequence *
    rasqal_graph_pattern_get_triples (rasqal_query *query,
                                      rasqal_graph_pattern *graph_pattern);

Get the triples inside this graph pattern (if any).

The returned sequence and all the rasqal_triple in it are owned by the caller (hold references).

#### Parameters

query | query |
graph_pattern | graph pattern |

#### Returns

new sequence of raptor_triple or NULL on failure or no triples

### rasqal_graph_pattern_get_service ()

    rasqal_literal *
    rasqal_graph_pattern_get_service (rasqal_graph_pattern *graph_pattern);

Get the literal for RASQAL_GRAPH_PATTERN_OPERATOR_SERVICE graph pattern

#### Parameters

graph_pattern | rasqal_graph_pattern graph pattern object |

#### Returns

graph variable or NULL if wrong graph pattern or not defined

### rasqal_graph_pattern_get_variable ()

    rasqal_variable *
    rasqal_graph_pattern_get_variable (rasqal_graph_pattern *graph_pattern);

Get the variable for RASQAL_GRAPH_PATTERN_OPERATOR_LET graph pattern

#### Parameters

graph_pattern | rasqal_graph_pattern graph pattern object |

#### Returns

graph variable or NULL if wrong graph pattern or not defined

### rasqal_graph_pattern_operator_as_string ()

    const char *
    rasqal_graph_pattern_operator_as_string
                                   (rasqal_graph_pattern_operator op);

Get a string for the query verb.

#### Parameters

op | the rasqal_graph_pattern_operator verb of the query |

#### Returns

pointer to a shared string label for the query verb

### rasqal_graph_pattern_print ()

    int
    rasqal_graph_pattern_print (rasqal_graph_pattern *gp,
                                FILE *fh);

Print a rasqal_graph_pattern in a debug format.

The print debug format may change in any release.

#### Parameters

gp | the rasqal_graph_pattern object |
fh | the FILE* handle to print to |

#### Returns

non-0 on failure

### rasqal_graph_pattern_variable_bound_in ()

    int
    rasqal_graph_pattern_variable_bound_in
                                   (rasqal_graph_pattern *gp,
                                    rasqal_variable *v);

Is the variable bound in this graph pattern (not including children)?

#### Parameters

gp | graph pattern |
v | variable |

#### Returns

non-0 if variable is bound in the given graph pattern.

### rasqal_graph_pattern_visit_fn ()

    int
    (*rasqal_graph_pattern_visit_fn) (rasqal_query *query,
                                      rasqal_graph_pattern *gp,
                                      void *user_data);

User function to visit an graph_pattern and operate on it with `rasqal_graph_pattern_visit()` or `rasqal_query_graph_pattern_visit()`

#### Parameters

query | rasqal_query containing the graph pattern |
gp | current graph_pattern |
user_data | user data passed in |

#### Returns

non-0 to truncate the visit

### rasqal_graph_pattern_visit ()

    int
    rasqal_graph_pattern_visit (rasqal_query *query,
                                rasqal_graph_pattern *gp,
                                rasqal_graph_pattern_visit_fn fn,
                                void *user_data);

Visit a user function over a rasqal_graph_pattern

If the user function `fn` returns 0, the visit is truncated.

#### Parameters

query | rasqal_query to operate on |
gp | rasqal_graph_pattern graph pattern |
fn | pointer to function to apply that takes user data and graph pattern parameters |
user_data | user data for applied function |

#### Returns

0 if the visit was truncated.

## Types and Values

### rasqal_graph_pattern

    rasqal_graph_pattern* graph_pattern;

Rasqal graph pattern class.

### enum rasqal_graph_pattern_operator

Graph pattern operators

#### Members

RASQAL_GRAPH_PATTERN_OPERATOR_UNKNOWN | Internal. |
RASQAL_GRAPH_PATTERN_OPERATOR_BASIC | Just triple patterns and constraints. |
RASQAL_GRAPH_PATTERN_OPERATOR_OPTIONAL | Set of graph patterns (ANDed) and constraints. |
RASQAL_GRAPH_PATTERN_OPERATOR_UNION | Set of graph patterns (UNIONed) and constraints. |
RASQAL_GRAPH_PATTERN_OPERATOR_GROUP | Set of graph patterns (ANDed) and constraints. |
RASQAL_GRAPH_PATTERN_OPERATOR_GRAPH | A graph term + a graph pattern and constraints. |
RASQAL_GRAPH_PATTERN_OPERATOR_FILTER | A filter graph pattern with an expression |
RASQAL_GRAPH_PATTERN_OPERATOR_LET | LET ?var := Expression (LAQRS) |
RASQAL_GRAPH_PATTERN_OPERATOR_SELECT | SELECT graph pattern |
RASQAL_GRAPH_PATTERN_OPERATOR_SERVICE | SERVICE graph pattern |
RASQAL_GRAPH_PATTERN_OPERATOR_MINUS | MINUS graph pattern |
RASQAL_GRAPH_PATTERN_OPERATOR_VALUES | VALUES graph pattern |
RASQAL_GRAPH_PATTERN_OPERATOR_LAST | Internal. |