Skip to content

Commit

Permalink
Allow extraction of compact tag string
Browse files Browse the repository at this point in the history
  • Loading branch information
petrpulc committed Mar 20, 2020
1 parent c05abbe commit 3e647df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ No dependencies outside standard Python and C++ build environment should be need
morph.tags = False # return just the lemma, do not process the tags
morph.tags = True # turn tag processing back on (default)

morph.compact_tag = True # return tag in compact form (as returned by Majka)
morph.compact_tag = False # do not return compact tag (default)

morph.first_only = True # return only the first entry
morph.first_only = False # return all entries (default)

Expand Down
9 changes: 9 additions & 0 deletions majkamodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ typedef struct {
fsa* majka;
int flags;
bool tags;
bool compact_tag;
bool first_only;
PyObject* negative;
} Majka;
Expand All @@ -32,6 +33,7 @@ static PyObject* Majka_new(PyTypeObject* type,
self = reinterpret_cast<Majka*>(type->tp_alloc(type, 0));
self->flags = 0;
self->tags = true;
self->compact_tag = false;
self->first_only = false;
self->negative = PyUnicode_FromString("-");
return reinterpret_cast<PyObject*>(self);
Expand Down Expand Up @@ -521,6 +523,11 @@ static PyObject* Majka_find(Majka* self, PyObject* args, PyObject* kwds) {
"lemma", lemma);
Py_DECREF(lemma);
}

if (self->compact_tag) {
dict_set_string(option, "compact_tag", colon+1);
}

list_append(ret, option);
}
delete [] results;
Expand All @@ -539,6 +546,8 @@ static PyMemberDef Majka_members[] = {
const_cast<char*>("Flags to run Majka with.")},
{const_cast<char*>("tags"), T_BOOL, offsetof(Majka, tags), 0,
const_cast<char*>("If tags should be extracted and converted.")},
{const_cast<char*>("compact_tag"), T_BOOL, offsetof(Majka, compact_tag), 0,
const_cast<char*>("If original compact tag string should be extracted and returned.")},
{const_cast<char*>("first_only"), T_BOOL, offsetof(Majka, first_only), 0,
const_cast<char*>("If only first match should be returned.")},
{const_cast<char*>("negative"), T_OBJECT, offsetof(Majka, negative), 0,
Expand Down

0 comments on commit 3e647df

Please sign in to comment.