Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split Multiple Positive Filters when Distributing #27

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 46 additions & 20 deletions src/lexdcompiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ bool tag_filter_t::try_apply(tags_t &tags) const
unionset_inplace(tags, pos());
return true;
}
vector<vector<pos_tag_filter_t>> tag_filter_t::distribute_pos(size_t n) const
{
vector<vector<pos_tag_filter_t>> ret;
ret.resize(1);
ret[0].resize(n);
for (auto& tag : _pos) {
vector<vector<pos_tag_filter_t>> ret2;
for (auto& seq : ret) {
for (size_t i = 0; i < n; i++) {
auto seq2 = seq;
seq2[i].insert(tag);
ret2.push_back(seq2);
}
}
ret.swap(ret2);
}
return ret;
}
bool pattern_element_t::compatible(const lex_seg_t &tok) const
{
return left.name.empty() || right.name.empty() || tag_filter.compatible(tok.tags);
Expand Down Expand Up @@ -1193,35 +1211,43 @@ LexdCompiler::buildPattern(const pattern_element_t &tok)
tempMatch.swap(matchedParts);
for(auto &pat_untagged : patterns[tok.left.name])
{
for(unsigned int i = 0; i < pat_untagged.second.size(); i++)
{
auto pat = pat_untagged;
bool taggable = true;
for (unsigned int j = 0; j < pat.second.size(); j++) {
auto& pair = pat.second[j];
if(!pair.tag_filter.combine(tok.tag_filter.neg())) {
auto pat_line = pat_untagged.first;
auto pat_minus = pat_untagged.second;
bool taggable = true;
for (auto& it : pat_minus) {
if (!it.tag_filter.combine(tok.tag_filter.neg())) {
taggable = false;
if (verbose) {
cerr << "Warning: The tags of " << to_ustring(printPattern(tok));
cerr << " conflict with " << to_ustring(printPattern(it));
cerr << " on line " << pat_line << "." << endl;
}
break;
}
}
if (!taggable) continue;
size_t len = pat_minus.size();
auto pos_tags = tok.tag_filter.distribute_pos(len);
for (auto& pos_tag_seq : pos_tags) {
taggable = true;
auto pat = pat_minus;
for (size_t i = 0; i < len; i++) {
if (!pat[i].tag_filter.combine(pos_tag_seq[i])) {
taggable = false;
if (verbose) {
cerr << "Warning: The tags of " << to_ustring(printPattern(tok));
cerr << " conflict with " << to_ustring(printPattern(pat_untagged.second[j]));
cerr << " on line " << pat.first << "." << endl;
cerr << " conflict with " << to_ustring(printPattern(pat[i]));
cerr << " on line " << pat_line << "." << endl;
}
}
}
if(!pat.second[i].tag_filter.combine(tok.tag_filter.pos())) {
taggable = false;
if (verbose) {
cerr << "Warning: The tags of " << to_ustring(printPattern(tok));
cerr << " conflict with " << to_ustring(printPattern(pat_untagged.second[i]));
cerr << " on line " << pat.first << "." << endl;
break;
}
}
if (!taggable) continue;

matchedParts.clear();
lineNumber = pat.first;
vector<int> is_free = determineFreedom(pat.second);
buildPattern(t->getInitial(), t, pat.second, is_free, 0);
lineNumber = pat_line;
vector<int> is_free = determineFreedom(pat);
buildPattern(t->getInitial(), t, pat, is_free, 0);
}
}
tempMatch.swap(matchedParts);
Expand Down
2 changes: 2 additions & 0 deletions src/lexdcompiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ struct tag_filter_t {
return filters;
}

vector<vector<pos_tag_filter_t>> distribute_pos(size_t n) const;

private:
pos_tag_filter_t _pos;
neg_tag_filter_t _neg;
Expand Down
1 change: 1 addition & 0 deletions tests/feature/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ tests = \
lexname-space \
lextag \
lexnegtag \
multipos \
nontree \
oneside \
opt \
Expand Down
19 changes: 19 additions & 0 deletions tests/feature/test-multipos.lexd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
PATTERNS
Subject ObjectPrefix VStemBase[tv,cl3]
Subject VStemBase[iv,cl3]

LEXICON Subject
<s_sg1>:ni>

LEXICON ObjectPrefix
<o_sg1>:nech>

PATTERN VStemBase
VerbRootIV [<v><iv>:[iv]]
VerbRootTV [<v><tv>:[tv]]

LEXICON VerbRootIV
blah[cl3]

LEXICON VerbRootTV
ihtoa:{i}htoa[cl3]
2 changes: 2 additions & 0 deletions tests/feature/test-multipos.lexd.txt.strings.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<s_sg1><o_sg1>ihtoa<v><tv>:ni>nech>{i}htoa
<s_sg1>blah<v><iv>:ni>blah