forked from larsjuhljensen/tagger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tagger_swig.i
66 lines (59 loc) · 1.7 KB
/
tagger_swig.i
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
%module tagger_swig
%typemap(in) int* entity_types {
int size = PyList_Size($input);
$1 = new int[size];
for (int i = 0; i < size; i++) {
$1[i] = PyInt_AsLong(PyList_GetItem($input, i));
}
}
%typemap(freearg) int* entity_types {
delete $1;
}
%typemap(out) Entities {
PyObject* entities = PyTuple_New((int)$1.size());
for (int i = 0; i < (int)$1.size(); i++) {
PyObject* entity = PyTuple_New(2);
PyTuple_SetItem(entity, 0, PyInt_FromLong($1.at(i).type));
if ($1.serials_only) {
PyTuple_SetItem(entity, 1, PyInt_FromLong($1.at(i).id.serial));
}
else {
PyTuple_SetItem(entity, 1, PyString_FromString($1.at(i).id.string));
}
PyTuple_SetItem(entities, i, entity);
}
$result = entities;
}
%typemap(out) Matches {
PyObject* matches = PyList_New((int)$1.size());
for (int i = 0; i < (int)$1.size(); i++) {
PyObject* match = PyTuple_New(3);
PyTuple_SetItem(match, 0, PyInt_FromLong($1.at(i)->start));
PyTuple_SetItem(match, 1, PyInt_FromLong($1.at(i)->stop));
if ($1.at(i)->size > 0) {
PyObject* entities = PyTuple_New((int)$1.at(i)->size);
for (int j = 0; j < (int)$1.at(i)->size; j++) {
PyObject* entity = PyTuple_New(2);
PyTuple_SetItem(entity, 0, PyInt_FromLong($1.at(i)->entities[j].type));
if ($1.serials_only) {
PyTuple_SetItem(entity, 1, PyInt_FromLong($1.at(i)->entities[j].id.serial));
}
else {
PyTuple_SetItem(entity, 1, PyString_FromString($1.at(i)->entities[j].id.string));
}
PyTuple_SetItem(entities, j, entity);
}
PyTuple_SetItem(match, 2, entities);
}
else {
Py_INCREF(Py_None);
PyTuple_SetItem(match, 2, Py_None);
}
PyList_SetItem(matches, i, match);
}
$result = matches;
}
%include "tagger.h"
%{
#include "tagger.h"
%}