1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
use super::cerror::ErrorList;
use super::{cast_mut, cstr, map_cerr};
use graphannis::update::{GraphUpdate, UpdateEvent};

/// Create a new graph (empty) update instance
#[no_mangle]
pub extern "C" fn annis_graphupdate_new() -> *mut GraphUpdate {
    let gu = GraphUpdate::new();
    Box::into_raw(Box::new(gu))
}

/// Add "add node" action to the graph update object.
///
/// - `ptr` - The graph update object.
/// - `node_name` - Name of the new node.
/// - `node_type` - Type of the new node, e.g. "node" or "corpus".
/// - `err` - Pointer to a list of errors. If any error occurred, this list will be non-empty.
#[no_mangle]
pub extern "C" fn annis_graphupdate_add_node(
    ptr: *mut GraphUpdate,
    node_name: *const libc::c_char,
    node_type: *const libc::c_char,
    err: *mut *mut ErrorList,
) {
    let u: &mut GraphUpdate = cast_mut(ptr);
    map_cerr(
        u.add_event(UpdateEvent::AddNode {
            node_name: String::from(cstr(node_name)),
            node_type: String::from(cstr(node_type)),
        }),
        err,
    );
}

/// Add "delete node" action to the graph update object.
///
/// - `ptr` - The graph update object.
/// - `node_name` - Name of node to delete.
/// - `err` - Pointer to a list of errors. If any error occurred, this list will be non-empty.
#[no_mangle]
pub extern "C" fn annis_graphupdate_delete_node(
    ptr: *mut GraphUpdate,
    node_name: *const libc::c_char,
    err: *mut *mut ErrorList,
) {
    let cs: &mut GraphUpdate = cast_mut(ptr);
    map_cerr(
        cs.add_event(UpdateEvent::DeleteNode {
            node_name: String::from(cstr(node_name)),
        }),
        err,
    );
}

/// Add "add node label" action to the graph update object.
///
/// - `ptr` - The graph update object.
/// - `node_name` - Name of the node the label is attached to.
/// - `annos_ns` - Namespace of the new annotation.
/// - `annos_name` - Name of the new annotation.
/// - `annos_value` - Value of the new annotation.
/// - `err` - Pointer to a list of errors. If any error occurred, this list will be non-empty.
#[no_mangle]
pub extern "C" fn annis_graphupdate_add_node_label(
    ptr: *mut GraphUpdate,
    node_name: *const libc::c_char,
    anno_ns: *const libc::c_char,
    anno_name: *const libc::c_char,
    anno_value: *const libc::c_char,
    err: *mut *mut ErrorList,
) {
    let cs: &mut GraphUpdate = cast_mut(ptr);
    map_cerr(
        cs.add_event(UpdateEvent::AddNodeLabel {
            node_name: String::from(cstr(node_name)),
            anno_ns: String::from(cstr(anno_ns)),
            anno_name: String::from(cstr(anno_name)),
            anno_value: String::from(cstr(anno_value)),
        }),
        err,
    );
}

/// Add "delete node label" action to the graph update object.
///
/// - `ptr` - The graph update object.
/// - `node_name` - Name of the node the label is attached to.
/// - `annos_ns` - Namespace of deleted new annotation.
/// - `annos_name` - Name of the deleted annotation.
/// - `err` - Pointer to a list of errors. If any error occurred, this list will be non-empty.
#[no_mangle]
pub extern "C" fn annis_graphupdate_delete_node_label(
    ptr: *mut GraphUpdate,
    node_name: *const libc::c_char,
    anno_ns: *const libc::c_char,
    anno_name: *const libc::c_char,
    err: *mut *mut ErrorList,
) {
    let cs: &mut GraphUpdate = cast_mut(ptr);
    map_cerr(
        cs.add_event(UpdateEvent::DeleteNodeLabel {
            node_name: String::from(cstr(node_name)),
            anno_ns: String::from(cstr(anno_ns)),
            anno_name: String::from(cstr(anno_name)),
        }),
        err,
    );
}

/// Add "add edge" action to the graph update object.
///
/// - `ptr` - The graph update object.
/// - `source_node` - Name of source node of the new edge.
/// - `target_node` - Name of target node of the new edge.
/// - `layer` - Layer of the new edge.
/// - `component_type` - Type of the component of the new edge.
/// - `component_name` - Name of the component of the new edge.
/// - `err` - Pointer to a list of errors. If any error occurred, this list will be non-empty.
#[no_mangle]
pub extern "C" fn annis_graphupdate_add_edge(
    ptr: *mut GraphUpdate,
    source_node: *const libc::c_char,
    target_node: *const libc::c_char,
    layer: *const libc::c_char,
    component_type: *const libc::c_char,
    component_name: *const libc::c_char,
    err: *mut *mut ErrorList,
) {
    let cs: &mut GraphUpdate = cast_mut(ptr);

    map_cerr(
        cs.add_event(UpdateEvent::AddEdge {
            source_node: String::from(cstr(source_node)),
            target_node: String::from(cstr(target_node)),
            layer: String::from(cstr(layer)),
            component_type: String::from(cstr(component_type)),
            component_name: String::from(cstr(component_name)),
        }),
        err,
    );
}

/// Add "delete edge" action to the graph update object.
///
/// - `ptr` - The graph update object.
/// - `source_node` - Name of source node of the edge to delete.
/// - `target_node` - Name of target node of the edge to delete.
/// - `layer` - Layer of the edge to delete.
/// - `component_type` - Type of the component of the edge to delete.
/// - `component_name` - Name of the component of the edge to delete.
/// - `err` - Pointer to a list of errors. If any error occurred, this list will be non-empty.
#[no_mangle]
pub extern "C" fn annis_graphupdate_delete_edge(
    ptr: *mut GraphUpdate,
    source_node: *const libc::c_char,
    target_node: *const libc::c_char,
    layer: *const libc::c_char,
    component_type: *const libc::c_char,
    component_name: *const libc::c_char,
    err: *mut *mut ErrorList,
) {
    let cs: &mut GraphUpdate = cast_mut(ptr);
    map_cerr(
        cs.add_event(UpdateEvent::DeleteEdge {
            source_node: String::from(cstr(source_node)),
            target_node: String::from(cstr(target_node)),
            layer: String::from(cstr(layer)),
            component_type: String::from(cstr(component_type)),
            component_name: String::from(cstr(component_name)),
        }),
        err,
    );
}

/// Add "add edge label" action to the graph update object.
///
/// - `ptr` - The graph update object.
/// - `source_node` - Name of source node of the edge.
/// - `target_node` - Name of target node of the edge.
/// - `layer` - Layer of the edge.
/// - `component_type` - Type of the component of the edge.
/// - `component_name` - Name of the component of the edge.
/// - `annos_ns` - Namespace of the new annotation.
/// - `annos_name` - Name of the new annotation.
/// - `annos_value` - Value of the new annotation.
/// - `err` - Pointer to a list of errors. If any error occurred, this list will be non-empty.
#[no_mangle]
pub extern "C" fn annis_graphupdate_add_edge_label(
    ptr: *mut GraphUpdate,
    source_node: *const libc::c_char,
    target_node: *const libc::c_char,
    layer: *const libc::c_char,
    component_type: *const libc::c_char,
    component_name: *const libc::c_char,
    anno_ns: *const libc::c_char,
    anno_name: *const libc::c_char,
    anno_value: *const libc::c_char,
    err: *mut *mut ErrorList,
) {
    let cs: &mut GraphUpdate = cast_mut(ptr);

    map_cerr(
        cs.add_event(UpdateEvent::AddEdgeLabel {
            source_node: String::from(cstr(source_node)),
            target_node: String::from(cstr(target_node)),
            layer: String::from(cstr(layer)),
            component_type: String::from(cstr(component_type)),
            component_name: String::from(cstr(component_name)),
            anno_ns: String::from(cstr(anno_ns)),
            anno_name: String::from(cstr(anno_name)),
            anno_value: String::from(cstr(anno_value)),
        }),
        err,
    );
}

/// Add "delete edge label" action to the graph update object.
///
/// - `ptr` - The graph update object.
/// - `source_node` - Name of source node of the edge.
/// - `target_node` - Name of target node of the edge.
/// - `layer` - Layer of the edge.
/// - `component_type` - Type of the component of the edge.
/// - `component_name` - Name of the component of the edge.
/// - `annos_ns` - Namespace of the annotation to delete.
/// - `annos_name` - Name of the annotation to delete.
/// - `err` - Pointer to a list of errors. If any error occurred, this list will be non-empty.
#[no_mangle]
pub extern "C" fn annis_graphupdate_delete_edge_label(
    ptr: *mut GraphUpdate,
    source_node: *const libc::c_char,
    target_node: *const libc::c_char,
    layer: *const libc::c_char,
    component_type: *const libc::c_char,
    component_name: *const libc::c_char,
    anno_ns: *const libc::c_char,
    anno_name: *const libc::c_char,
    err: *mut *mut ErrorList,
) {
    let cs: &mut GraphUpdate = cast_mut(ptr);

    map_cerr(
        cs.add_event(UpdateEvent::DeleteEdgeLabel {
            source_node: String::from(cstr(source_node)),
            target_node: String::from(cstr(target_node)),
            layer: String::from(cstr(layer)),
            component_type: String::from(cstr(component_type)),
            component_name: String::from(cstr(component_name)),
            anno_ns: String::from(cstr(anno_ns)),
            anno_name: String::from(cstr(anno_name)),
        }),
        err,
    );
}