Newer
Older
p_true = strset_operator [tagset, vars]
Paweł Kędzia
committed
Q_MARK
test = bool_operator [tagset, vars] {
op.reset(new Conditional<StrSet>(test, p_true));
Paweł Kędzia
committed
}
///////////////////////////////////////////////////////////////////////////////
// Boool operator
// Returns boost::shared_ptr<Function<Bool> >
///////////////////////////////////////////////////////////////////////////////
bool_operator
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > ret]
: ret = bool_and [tagset, vars]
| ret = bool_or [tagset, vars]
| ret = bool_nor [tagset, vars]
| ret = bool_var_val [tagset, vars]
| ret = bool_regex [tagset, vars]
| ret = bool_inout [tagset, vars]
| ret = bool_condition [tagset, vars]
// setvar:
| ret = setvar_operator [tagset, vars]
// equal/in/inter:
| ret = equal_operator [tagset, vars]
| ret = in_operator [tagset, vars]
| ret = inter_operator [tagset, vars]
// iterations
| ret = bool_iteration [tagset, vars]
// agreement
| ret = bool_agreement [tagset, vars]
//
ilor
committed
// debug operators
| ret = debug_print_operator [tagset, vars]
| LPAREN ret = bool_operator [tagset, vars] RPAREN
// ----------------------------------------------------------------------------
// comma-separated predicates (bool operators)
bool_operator_comma_sep
[const Corpus2::Tagset& tagset, Variables& vars]
returns
[boost::shared_ptr<std::vector<boost::shared_ptr<Function<Bool> > > > ret_v]
boost::shared_ptr<Function<Bool> > pred;
new std::vector<boost::shared_ptr<Function<Bool> > >
: pred = bool_operator [tagset, vars] {
ret_v->push_back(pred);
}
(
COMMA pred = bool_operator [tagset, vars] {
ret_v->push_back(pred);
}
)*
// ----------------------------------------------------------------------------
// And operator.
bool_and
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > op]
boost::shared_ptr<std::vector<boost::shared_ptr<Function<Bool> > > > ret_v;
: "and" LPAREN ret_v = bool_operator_comma_sep [tagset, vars] RPAREN {
op.reset(new And(ret_v));
// ----------------------------------------------------------------------------
// Or operator
bool_or
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > op]
boost::shared_ptr<std::vector<boost::shared_ptr<Function<Bool> > > > ret_v;
: "or" LPAREN ret_v = bool_operator_comma_sep [tagset, vars] RPAREN {
op.reset(new Or(ret_v));
// ----------------------------------------------------------------------------
// Nor/Not operator
bool_nor
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > op]
boost::shared_ptr<std::vector<boost::shared_ptr<Function<Bool> > > > ret_v;
: "not" LPAREN ret_v = bool_operator_comma_sep [tagset, vars] RPAREN {
op.reset(new Nor(ret_v));
// ----------------------------------------------------------------------------
// Wrapper for bool value and bool variable
bool_var_val
[const Corpus2::Tagset& /*tagset*/, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > op]
: op = bool_value
| op = bool_variable [vars]
// ----------------------------------------------------------------------------
// Regex operator
bool_regex
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > op]
{
boost::shared_ptr<Function<StrSet> > expr;
}
: "regex"
LPAREN
expr = strset_operator [tagset, vars] COMMA reg: STRING
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
RPAREN {
op.reset(new Regex(expr, token_ref_to_ustring(reg)));
}
;
// ----------------------------------------------------------------------------
// Input/output operator
bool_inout
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > op]
{
boost::shared_ptr<Function<Position> > ret_pos;
}
: "inside" LPAREN ret_pos = position_operator [tagset, vars] RPAREN {
op.reset(new IsInside(ret_pos));
}
| "outside" LPAREN ret_pos = position_operator [tagset, vars] RPAREN {
op.reset(new IsOutside(ret_pos));
}
;
// ----------------------------------------------------------------------------
// if (Bool, Bool, Bool)
// ? Bool ? Bool : False
bool_condition
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > op]
{
boost::shared_ptr<Function<Bool> > test, p_true, p_false;
}
: "if" LPAREN test = bool_operator [tagset, vars] COMMA
p_true = bool_operator [tagset, vars]
(COMMA p_false = bool_operator [tagset, vars])?
RPAREN {
if (p_false) {
op.reset(new Conditional<Bool>(test, p_true, p_false));
}
else {
op.reset(new Conditional<Bool>(test, p_true));
}
}
| Q_MARK
p_true = bool_operator [tagset, vars]
Q_MARK
test = bool_operator [tagset, vars] {
op.reset(new Conditional<Bool>(test, p_true));
}
;
// ----------------------------------------------------------------------------
// Equal operator
equal_operator
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > op]
boost::shared_ptr<Function<TSet> > t1, t2;
boost::shared_ptr<Function<Bool> > b1, b2;
boost::shared_ptr<Function<StrSet> > s1, s2;
boost::shared_ptr<Function<Position> > p1, p2;
: "equal" LPAREN
(position_operator [tagset, vars]) =>
p1 = position_operator [tagset, vars] COMMA
p2 = position_operator [tagset, vars] {
op.reset(new Equals<Position>(p1, p2));
|
(symset_operator [tagset, vars]) =>
t1 = symset_operator [tagset, vars] COMMA
t2 = symset_operator [tagset, vars] {
op.reset(new Equals<TSet>(t1, t2));
}
)
|
(strset_operator [tagset, vars]) =>
s1 = strset_operator [tagset, vars] COMMA
s2 = strset_operator [tagset, vars] {
op.reset(new Equals<StrSet>(s1, s2));
}
)
|
(
b1 = bool_operator [tagset, vars] COMMA
b2 = bool_operator [tagset, vars] {
op.reset(new Equals<Bool>(b1, b2));
// ----------------------------------------------------------------------------
// In operator
in_operator
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > op]
boost::shared_ptr<Function<TSet> > t1, t2;
boost::shared_ptr<Function<StrSet> > s1, s2;
Paweł Kędzia
committed
}
:
"in" LPAREN
(symset_operator [tagset, vars]) =>
t1 = symset_operator [tagset, vars] COMMA
t2 = symset_operator [tagset, vars] {
op.reset(new IsSubsetOf<TSet>(t1, t2));
s1 = strset_operator [tagset, vars] COMMA
s2 = strset_operator [tagset, vars] {
op.reset(new IsSubsetOf<StrSet>(s1, s2));
;
// ----------------------------------------------------------------------------
// Inter operator
inter_operator
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > op]
boost::shared_ptr<Function<TSet> > t1, t2;
boost::shared_ptr<Function<StrSet> > s1, s2;
:
"inter" LPAREN
(symset_operator [tagset, vars]) =>
t1 = symset_operator [tagset, vars] COMMA
t2 = symset_operator [tagset, vars] {
op.reset(new Intersects<TSet>(t1, t2));
s1 = strset_operator [tagset, vars] COMMA
s2 = strset_operator [tagset, vars] {
op.reset(new Intersects<StrSet>(s1, s2));
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
// ----------------------------------------------------------------------------
// Annotation-sub operator.
bool_annsub
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > op]
{
boost::shared_ptr< Function<Match> > match_from;
boost::shared_ptr< Function<Match> > match_to;
std::string chan_name;
}
: "annsub" LPAREN
match_from = match_fit [tagset, vars] COMMA
(match_to = match_fit [tagset, vars] COMMA)?
name : STRING
RPAREN
{
if (match_to) {
op.reset(new AnnSub(match_from, match_to, chan_name));
} else {
op.reset(new AnnSub(match_from, chan_name));
}
}
;
ilor
committed
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
// ----------------------------------------------------------------------------
// Debug printing:
debug_print_operator
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > ret]
{
boost::shared_ptr<FunctionBase> v;
}
: "debug" LPAREN
(
(position_operator [tagset, vars]) =>
(
v = position_operator [tagset, vars] {
ret.reset(new DebugPrint(v));
}
)
|
(symset_operator [tagset, vars]) =>
(
v = symset_operator [tagset, vars] {
ret.reset(new DebugPrint(v));
}
)
|
(strset_operator [tagset, vars]) =>
(
v = strset_operator [tagset, vars] {
ret.reset(new DebugPrint(v));
}
)
|
(
v = bool_operator [tagset, vars] {
ret.reset(new DebugPrint(v));
}
)
)
RPAREN
;
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
// ----------------------------------------------------------------------------
// Iterations:
bool_iteration
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > ret]
{
int min_match = 0;
boost::shared_ptr<Function<Bool> > expr;
boost::shared_ptr<Function<Position> > lpos, rpos;
boost::shared_ptr<VariableAccessor<Position> > pacc;
}
: "only" LPAREN
lpos = position_operator [tagset, vars] COMMA
rpos = position_operator [tagset, vars] COMMA
pacc = position_variable_acc [vars] COMMA
expr = bool_operator [tagset, vars]
RPAREN {
ret.reset(new Only(lpos, rpos, *pacc, expr));
}
| "atleast" LPAREN
lpos = position_operator [tagset, vars] COMMA
rpos = position_operator [tagset, vars] COMMA
pacc = position_variable_acc [vars] COMMA
expr = bool_operator [tagset, vars] COMMA
min_match = number
RPAREN {
ret.reset(new AtLeast(lpos, rpos, *pacc, expr, min_match));
}
| "llook" LPAREN //note inverted rpos/lpos order
rpos = position_operator [tagset, vars] COMMA
lpos = position_operator [tagset, vars] COMMA
pacc = position_variable_acc [vars] COMMA
expr = bool_operator [tagset, vars]
RPAREN {
ret.reset(new LeftLook(lpos, rpos, *pacc, expr));
}
| "rlook" LPAREN
lpos = position_operator [tagset, vars] COMMA
rpos = position_operator [tagset, vars] COMMA
pacc = position_variable_acc [vars] COMMA
expr = bool_operator [tagset, vars]
RPAREN {
ret.reset(new RightLook(lpos, rpos, *pacc, expr));
}
;
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
// ----------------------------------------------------------------------------
// Agreement operator: agr, agrpp, wagr
bool_agreement
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > ret]
{
boost::shared_ptr<Function<TSet> > expr;
boost::shared_ptr<Function<Position> > lpos, rpos;
}
: "agr" LPAREN
lpos = position_operator [tagset, vars] COMMA
rpos = position_operator [tagset, vars] COMMA
expr = symset_operator [tagset, vars]
RPAREN {
ret.reset(new StrongAgreement(lpos, rpos, expr, tagset));
}
| "agrpp" LPAREN
lpos = position_operator [tagset, vars] COMMA
rpos = position_operator [tagset, vars] COMMA
expr = symset_operator [tagset, vars]
RPAREN {
ret.reset(new PointAgreement(lpos, rpos, expr, tagset));
}
| "wagr" LPAREN
lpos = position_operator [tagset, vars] COMMA
rpos = position_operator [tagset, vars] COMMA
expr = symset_operator [tagset, vars]
RPAREN {
ret.reset(new WeakAgreement(lpos, rpos, expr, tagset));
}
;
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
// ----------------------------------------------------------------------------
// Parse operator on L1 level
bool_phrase
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > ret]
: ret = bool_phrase_annotation [tagset, vars]
| ret = bool_phrase_iteration [tagset, vars]
;
// ----------------------------------------------------------------------------
// Annotation operator: phrase, phrase_beg, phrase_end, phrase_whole, phrase_pp
bool_phrase_annotation
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > ret]
{
boost::shared_ptr<Function<Position> > lpos, rpos;
}
: "phrase" LPAREN
lpos = position_operator [tagset, vars] COMMA n1: STRING
RPAREN {
// TODO
}
| "phrase_beg" LPAREN
lpos = position_operator [tagset, vars] COMMA n2: STRING
RPAREN {
// TODO
}
| "phrase_end" LPAREN
lpos = position_operator [tagset, vars] COMMA n3: STRING
RPAREN {
// TODO
}
| "phrase_whole" LPAREN
lpos = position_operator [tagset, vars] COMMA
rpos = position_operator [tagset, vars] COMMA n4: STRING
RPAREN {
// TODO
}
| "phrase_pp" LPAREN
lpos = position_operator [tagset, vars] COMMA
rpos = position_operator [tagset, vars] COMMA n5: STRING
RPAREN {
// TODO
}
;
// ----------------------------------------------------------------------------
// Phrase iteration operator: lphrase, rphrase
bool_phrase_iteration
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > ret]
{
boost::shared_ptr<Function<Position> > position;
boost::shared_ptr<VarGetter<Position> > var_position;
}
: "lphrase" LPAREN
position = position_operator [tagset, vars] COMMA
var_position = position_variable [vars] COMMA
n1: STRING
RPAREN {
// TODO
}
| "rphrase" LPAREN
position = position_operator [tagset, vars] COMMA
var_position = position_variable [vars] COMMA
n2: STRING
RPAREN {
// TODO
}
;
// ----------------------------------------------------------------------------
// Setvar operator
// Returns boost::shared_ptr<Function<Bool> >
// ----------------------------------------------------------------------------
setvar_operator
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > ret]
: "setvar" LPAREN
(
ret = position_setvar [tagset, vars]
| ret = bool_setvar [tagset, vars]
| ret = strset_setvar [tagset, vars]
| ret = symset_setvar [tagset, vars]
)
RPAREN
;
// ----------------------------------------------------------------------------
// Setvar for position
position_setvar
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > op]
boost::shared_ptr<Function<Position> > ret_op;
boost::shared_ptr<VariableAccessor<Position> > ret_acc;
: ret_acc = position_variable_acc [vars]
COMMA
ret_op = position_operator [tagset, vars] {
op.reset(new VarSetter<Position>(*ret_acc, ret_op));
// ----------------------------------------------------------------------------
// Setvar for bool
bool_setvar
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > op]
boost::shared_ptr<Function<Bool> > ret_op;
boost::shared_ptr<VariableAccessor<Bool> > ret_acc;
: ret_acc = bool_variable_acc [vars]
COMMA
ret_op = bool_operator [tagset, vars] {
op.reset(new VarSetter<Bool>(*ret_acc, ret_op));
// ----------------------------------------------------------------------------
// Setvar for strset
strset_setvar
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > op]
boost::shared_ptr<Function<StrSet> > ret_op;
boost::shared_ptr<VariableAccessor<StrSet> > ret_acc;
: ret_acc = strset_variable_acc [vars]
COMMA
ret_op = strset_operator [tagset, vars] {
op.reset(new VarSetter<StrSet>(*ret_acc, ret_op));
Paweł Kędzia
committed
}
// ----------------------------------------------------------------------------
// Setvar for symset
symset_setvar
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<Bool> > op]
boost::shared_ptr<Function<TSet> > ret_op;
boost::shared_ptr<VariableAccessor<TSet> > ret_acc;
: ret_acc = symset_variable_acc [vars]
COMMA
ret_op = symset_operator [tagset, vars] {
op.reset(new VarSetter<TSet>(*ret_acc, ret_op));
}
;
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Tagging actions and rules:
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Single action such as select, delete, relabel or unify
action
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<TagAction> act]
: act = action_select [tagset, vars]
| act = action_delete [tagset, vars]
| act = action_relabel [tagset, vars]
| act = action_unify [tagset, vars]
| act = action_mark [tagset, vars]
| act = action_unmark [tagset, vars]
// Action sequence - the actions are separated with commas:
// select(...), select(...), delete(...)
action_sequence
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<std::vector<boost::shared_ptr<TagAction> > > v_act]
boost::shared_ptr<TagAction> act;
v_act.reset(new std::vector<boost::shared_ptr<TagAction> >);
}
: act = action[tagset, vars] {
v_act->push_back(act);
}
(
COMMA act = action[tagset, vars] {
v_act->push_back(act);
}
)*
;
// ----------------------------------------------------------------------------
// Single rule:
// rule(NAME, ACTIONS) or rule(NAME, COND, ACTIONS)
rule
[const Corpus2::Tagset& tagset, Variables& vars]
{
boost::shared_ptr<Function<Bool> > condition;
boost::shared_ptr<std::vector<boost::shared_ptr<TagAction> > > actions;
: "rule" LPAREN name: STRING COMMA
(condition = bool_operator [tagset, vars] COMMA)?
actions = action_sequence [tagset, vars]
RPAREN {
if (condition) {
rle.reset(
new TagRule(token_ref_to_std_string(name), vars, actions, condition));
}
else {
rle.reset(
new TagRule(token_ref_to_std_string(name), vars, actions));
: "rule" LPAREN name: STRING COMMA
(
(bool_operator[tagset, vars]) =>
(
condition = bool_operator [tagset, vars] COMMA
actions = action_sequence [tagset, vars] {
// rule(NAME, COND, ACTIONS)
rle.reset(
new TagRule(token_ref_to_std_string(name), vars, actions, condition));
}
)
|
(
actions = action_sequence [tagset, vars] {
// rule(NAME, ACTIONS)
rle.reset(new TagRule(token_ref_to_std_string(name), vars, actions));
}
)
)
RPAREN
;
// Rule sequence
rule_sequence
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<RuleSequence> rule_seq]
{
// FIXME czy tutaj przypadkiem nie powinno byc shared_ptr?
}
: rle = rule [tagset, vars] {
}
(
COMMA rle = rule [tagset, vars] {
}
)*
;
// Temporary name.
// This is wrapper for rule_sequence in rules section in the wccl file
rules
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<RuleSequence> rule_seq]
: "rules" LPAREN rule_seq = rule_sequence [tagset, vars] RPAREN {
//
}
;
// ----------------------------------------------------------------------------
// Select action:
// select(position, predicate) or select(predicate);
action_select
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Select> action]
{
boost::shared_ptr<Function<Position> > pos;
boost::shared_ptr<Function<Bool> > condition;
}
: "select" LPAREN
(
(position_operator [tagset, vars]) =>
(
pos = position_operator [tagset, vars] COMMA
condition = bool_operator [tagset, vars] {
// select(positon, condition);
action.reset(new Select(condition, pos));
}
)
|
(
condition = bool_operator [tagset, vars] {
// select(condition);
action.reset(new Select(condition));
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
}
)
)
RPAREN
;
// ----------------------------------------------------------------------------
// Delete action
// delete(position, predicate) or delete(predicate);
action_delete
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Delete> action]
{
boost::shared_ptr<Function<Position> > pos;
boost::shared_ptr<Function<Bool> > condition;
}
: "delete" LPAREN
(
(position_operator [tagset, vars]) =>
(
pos = position_operator [tagset, vars] COMMA
condition = bool_operator [tagset, vars] {
// delete(positon, condition);
}
)
|
(
condition = bool_operator [tagset, vars] {
// delete(condition);
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
}
)
)
RPAREN
;
// ----------------------------------------------------------------------------
// Relabel action
// relabel(pos, symset, predicate) or relabel(symset, predicate)
action_relabel
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Relabel> action]
{
boost::shared_ptr<Function<Position> > pos;
boost::shared_ptr<Function<Bool> > condition;
boost::shared_ptr<Function<TSet> > replace_with;
}
: "relabel" LPAREN
(
(position_operator [tagset, vars]) =>
(
pos = position_operator [tagset, vars] COMMA
replace_with = symset_operator [tagset, vars] COMMA
condition = bool_operator [tagset, vars] {
// relabel(pos, symset, predicate)
action.reset(new Relabel(replace_with, condition, pos));
}
)
|
(
replace_with = symset_operator [tagset, vars] COMMA
condition = bool_operator [tagset, vars] {
// relabel(symset, predicate)
action.reset(new Relabel(replace_with, condition));
}
)
)
RPAREN
;
// ----------------------------------------------------------------------------
// Unify action
action_unify
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Unify> action]
{
boost::shared_ptr<Function<TSet> > attribs_expr;
boost::shared_ptr<Function<Position> > pos_begin, pos_end;
}
: "unify" LPAREN
pos_begin = position_operator [tagset, vars] COMMA
pos_end = position_operator [tagset, vars] COMMA
attribs_expr = symset_operator [tagset, vars]
RPAREN {
action.reset(new Unify(pos_begin, pos_end, attribs_expr));
}
;
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
// ----------------------------------------------------------------------------
// Mark action
action_mark
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Mark> action]
{
boost::shared_ptr<Function<Position> > pos_begin, pos_end, pos_head;
}
: "mark" LPAREN
pos_begin = position_operator [tagset, vars] COMMA
pos_end = position_operator [tagset, vars] COMMA
(pos_head = position_operator [tagset, vars] COMMA)?
chan_name: STRING
RPAREN {
action.reset(new Mark(pos_begin, pos_end, pos_head, ((antlr::Token*)chan_name)->getText()));
}
;
// ----------------------------------------------------------------------------
// Unmark action
action_unmark
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Unmark> action]
{
boost::shared_ptr<Function<Position> > pos;
}
: "unmark" LPAREN
pos = position_operator [tagset, vars] COMMA
chan_name: STRING
RPAREN {
action.reset(new Unmark(pos, ((antlr::Token*)chan_name)->getText()));
}
;
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Match rules
ilor
committed
// Returns boost::shared_ptr<MatchRule>
match_rule_operator
[const Corpus2::Tagset& tagset, Variables& vars]
ilor
committed
returns [boost::shared_ptr<MatchRule> ret_op]
ilor
committed
boost::shared_ptr<ApplyOperator> apply;
ilor
committed
: apply = match_apply_operator [tagset, vars] {
ret_op = boost::make_shared<MatchRule>(vars, apply);
}
;
// Match apply operator:
// apply(match(), cond(conditions), actions(actions))
// apply(match(), actions(actions))
// Returns boost::shared_ptr<ApplyOperator>
match_apply_operator
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<ApplyOperator> ret_op]
{
VariableAccessor<Match> matches = vars.create_accessor<Match>("_M");;
boost::shared_ptr<const MatchOperator> match_op;
boost::shared_ptr<std::vector<boost::shared_ptr<MatchAction> > > actions;
boost::shared_ptr<std::vector<boost::shared_ptr<Function<Bool> > > > conditions;
: "apply" LPAREN
match_op = match_operator[tagset, vars] COMMA
("cond" LPAREN conditions = bool_operator_comma_sep [tagset, vars] RPAREN COMMA)?
"actions" LPAREN actions = match_action_comma_sep [tagset, vars] RPAREN
RPAREN {
if (conditions) {
ret_op.reset(
new ApplyOperator(matches, match_op, actions, conditions)
);
}
else {
ret_op.reset(
new ApplyOperator(matches, match_op, actions)
);
}
}
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
;
// Match operator: match(match_conditions)
// Returns boost::shared_ptr<MatchOperator>
match_operator
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<MatchOperator> op]
{
boost::shared_ptr<ConjConditions> match_cond;
}
: "match" LPAREN match_cond = match_condition [tagset,vars] RPAREN {
op.reset(new MatchOperator(match_cond));
}
;
// Match conditions. Wrapper for vector of the match conditions
match_condition
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<ConjConditions> condition]
{
std::vector<boost::shared_ptr<const MatchCondition> > m_cond;
}
: m_cond = match_condition_in [tagset, vars] {
condition.reset(new ConjConditions(m_cond));
}
;
// Match conditions.
// Retutns std::vector< boost::shared_ptr<const MatchCondition> >
match_condition_in
[const Corpus2::Tagset& tagset, Variables& vars]
returns [std::vector< boost::shared_ptr<const MatchCondition> > ret]
{
boost::shared_ptr<const MatchCondition> r_cond;
}
: r_cond = match_cond_all[tagset, vars] {
ret.push_back(r_cond);
}
(
COMMA
r_cond = match_cond_all[tagset, vars] {
ret.push_back(r_cond);
}
)*
;
// One of the match condition
// Returns boost::shared_ptr<const MatchCondition>
match_cond_all
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<const MatchCondition> ret]
: ret = match_cond_optional [tagset, vars]
| ret = match_cond_repeate [tagset, vars]
| ret = match_cond_token [tagset, vars]
// Match condition - token (wraps a L0 predicate)
// Returns boost::shared_ptr<const MatchCondition>
match_cond_token
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<const TokenCondition> ret]
{
boost::shared_ptr<Function<Bool> > bool_op;
}
: bool_op = bool_operator [tagset, vars] {
ret = boost::make_shared<TokenCondition>(bool_op);
}
;
// Match condition - optional
// Returns boost::shared_ptr<OptionalMatch>
match_cond_optional
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<OptionalMatch> mtch]
{
boost::shared_ptr<ConjConditions> m_cond;
}
: "optional" LPAREN m_cond = match_condition [tagset, vars] RPAREN {
mtch.reset(new OptionalMatch(m_cond));
}
;
// Match condition - repeat
// Returns boost::shared_ptr<RepeatedMatch>
match_cond_repeate
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<RepeatedMatch> mtch]
{
boost::shared_ptr<ConjConditions> m_cond;
}
: "repeat" LPAREN m_cond = match_condition [tagset, vars] RPAREN {
mtch.reset(new RepeatedMatch(m_cond));
}
;
// ----------------------------------------------------------------------------
// Match actions. Match action can be mark or unmark
// Returns boost::shared_ptr<MatchAction>
match_action
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<MatchAction> m_act]
: m_act = match_mark_action [tagset, vars]
| m_act = match_unmark_action [tagset, vars]
;
// Match mark action
match_mark_action
[const Corpus2::Tagset& tagset, Variables& vars]
{
boost::shared_ptr<Function<Match> > match_to;
boost::shared_ptr<Function<Match> > match_from;
boost::shared_ptr<Function<Match> > head_match;