Skip to content

Commit 842bc9f

Browse files
authored
Make TOP relation's value constant (#30)
* Add tests/ subdirectory with one test file * Make TOP relation value constant Fixes #25 * Clarify CHANGELOG entry
1 parent bca14a8 commit 842bc9f

File tree

4 files changed

+81
-2
lines changed

4 files changed

+81
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
* Add CI/CD configuration (see PR [#23][])
88
* Better handle deinversion of special roles ([#10][])
99
* Get `smatch-table.py` working again (part of PR [#27][])
10+
* Add `tests/` subdirectory and `test_top.py` ([#25])
11+
* Make TOP relation's value a constant string and not the top node's
12+
concept to avoid double-penalizing different top concepts ([#25])
1013

1114
## [1.0.2][]
1215

@@ -166,5 +169,6 @@ The following are taken from an old `update_log` file:
166169
[#19]: https://github.com/snowblink14/smatch/issues/19
167170
[#22]: https://github.com/snowblink14/smatch/issues/22
168171
[#23]: https://github.com/snowblink14/smatch/pull/23
172+
[#25]: https://github.com/snowblink14/smatch/pull/25
169173
[#27]: https://github.com/snowblink14/smatch/pull/27
170174

amr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,8 @@ def update_triple(node_relation_dict, u, r, v):
420420
# each node has a relation list and attribute list
421421
relation_list.append(node_rel_list)
422422
attribute_list.append(node_attr_list)
423-
# add TOP as an attribute. The attribute value is the top node value
424-
attribute_list[0].append(["TOP", node_value_list[0]])
423+
# add TOP as an attribute. The attribute value just needs to be constant
424+
attribute_list[0].append(["TOP", 'top'])
425425
result_amr = AMR(node_name_list, node_value_list, relation_list, attribute_list)
426426
return result_amr
427427

tests/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
# smatch tests
3+
4+
This directory contains test cases to verify the correct behavior of
5+
smatch. Run the tests with [pytest](https://pytest.org/). This will
6+
require you to install both pytest and smatch:
7+
8+
```console
9+
$ pip install pytest
10+
$ pip install -e . # current directory is smatch
11+
$ pytest
12+
```
13+
14+
**Note:** As smatch is inherently non-deterministic due to its
15+
hill-climbing implementation, the tests can be "flaky" (i.e.,
16+
sometimes pass, sometimes fail). To mitigate the possibility of flaky
17+
tests, test cases should use *minimal* AMRs so it becomes trivial for
18+
smatch to get the optimal solution.

tests/test_top.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
"""
3+
The top node in an AMR determines the focus of the encoded
4+
meaning. For example, the following have the same dependencies but a
5+
different node at the top:
6+
7+
(w / white-03
8+
:ARG1 (m / marble))
9+
10+
The above AMR means "the marble is white" or "the whiteness of the
11+
marble".
12+
13+
(m / marble
14+
:ARG1-of (w / white-03))
15+
16+
This AMR means "the marble that is white" or "the white marble".
17+
18+
For this reason, AMRs that differ only in which node is the top will
19+
get smatch scores less than 1.0.
20+
21+
For more information see:
22+
23+
https://github.com/amrisi/amr-guidelines/blob/master/amr.md#focus
24+
"""
25+
26+
import smatch
27+
28+
a = '(a / alpha :ARG0 (b / beta))'
29+
b = '(a / alternative :ARG0 (b / beta))'
30+
c = '(a / alpha :ARG0 (b / b-side))'
31+
d = '(b / beta :ARG0-of (a / alpha))'
32+
33+
34+
def get_amr_match(amr1, amr2):
35+
vals = smatch.get_amr_match(amr1, amr2)
36+
smatch.match_triple_dict.clear()
37+
return vals
38+
39+
40+
def test_same():
41+
assert get_amr_match(a, a) == (4, 4, 4)
42+
smatch.match_triple_dict.clear()
43+
44+
45+
def test_same_top_different_top_concept():
46+
assert get_amr_match(a, b) == (3, 4, 4)
47+
smatch.match_triple_dict.clear()
48+
49+
50+
def test_same_top_different_dependent_concept():
51+
assert get_amr_match(a, c) == (3, 4, 4)
52+
smatch.match_triple_dict.clear()
53+
54+
55+
def test_same_different_top():
56+
assert get_amr_match(a, d) == (3, 4, 4)
57+
smatch.match_triple_dict.clear()

0 commit comments

Comments
 (0)