Newer
Older
// Wrapper ofr strset value and strset variable
strset_var_val
[const Corpus2::Tagset& /*tagset*/, Variables& vars]
returns [boost::shared_ptr<Function<StrSet> > op]
: op = strset_value
| op = strset_variable [vars]
// ----------------------------------------------------------------------------
// Condition of the strset value
// if (Bool, StrSet, StrSet)
// ? StrSet ? Bool : []
strset_condition
[const Corpus2::Tagset& tagset, Variables& vars]
returns [boost::shared_ptr<Function<StrSet> > op]
boost::shared_ptr<Function<Bool> > test;
boost::shared_ptr<Function<StrSet> > p_true, p_false;
: "if" LPAREN test = bool_operator [tagset, vars] COMMA
p_true = strset_operator [tagset, vars]
(COMMA p_false = strset_operator [tagset, vars])?
RPAREN {
Paweł Kędzia
committed
if (p_false) {
op.reset(new Conditional<StrSet>(test, p_true, p_false));
Paweł Kędzia
committed
}
else {
op.reset(new Conditional<StrSet>(test, p_true));
Paweł Kędzia
committed
}
Paweł Kędzia
committed
| Q_MARK
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]
//
// annotation
| ret = bool_ann [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
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
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));
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
// ----------------------------------------------------------------------------
// Annotation operator.
bool_ann
[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;
}
: "ann" LPAREN
match_from = match_fit [tagset, vars] COMMA
(match_to = match_fit [tagset, vars] COMMA)?
name : STRING
RPAREN {
if (match_to) {
// TODO
// op.reset(new Ann(match_from, match_to, chan_name));
} else {
// TODO
// op.reset(new Ann(match_from, chan_name));
}
}
;
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
// ----------------------------------------------------------------------------
// 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
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
// ----------------------------------------------------------------------------
// 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));
}
)
|
ilor
committed
(
v = bool_operator [tagset, vars] {
ret.reset(new DebugPrint(v));
}
)
|
(
v = match_fit [tagset, vars] {
ret.reset(new DebugPrint(v));
}
)
ilor
committed
)
RPAREN
;
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
// ----------------------------------------------------------------------------
// 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));
}
;
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
// ----------------------------------------------------------------------------
// 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));
}
;
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
// ----------------------------------------------------------------------------
// 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));
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
}
)
)
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);
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
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
}
)
)
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));
}
;
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
// ----------------------------------------------------------------------------
// 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)
);
}
}
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
;
// 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]