From 0a216a319e35f8f469db622ee5500c2de58acaf3 Mon Sep 17 00:00:00 2001
From: Blanche Miret <bmiret@teklia.com>
Date: Tue, 1 Jun 2021 20:39:11 +0200
Subject: [PATCH] Add test for entity boundaries

---
 tests/test_compute_matches.py | 90 +++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)

diff --git a/tests/test_compute_matches.py b/tests/test_compute_matches.py
index 8d5d28a..27910a7 100644
--- a/tests/test_compute_matches.py
+++ b/tests/test_compute_matches.py
@@ -143,6 +143,78 @@ expected_matches = {"All": 1, "PER": 1, "LOC": 0, "DAT": 0}
 expected_matches_nested_perfect = {"All": 3, "PER": 1, "LOC": 2}
 expected_matches_nested_false = {"All": 2, "PER": 1, "LOC": 1}
 
+fake_annot_backtrack_boundary = "The red dragon"
+
+fake_annot_tags_bk_boundary = [
+    "O",
+    "O",
+    "O",
+    "O",
+    "B-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+]
+
+fake_predict_tags_bk_boundary = [
+    "B-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+]
+
+expected_matches_bk_boundary = {"All": 0, "PER": 0}
+
+fake_annot_backtrack_boundary_2 = "A red dragon"
+
+fake_annot_tags_bk_boundary_2 = [
+    "O",
+    "O",
+    "B-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+]
+
+fake_predict_tags_bk_boundary_2 = [
+    "B-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+    "I-PER",
+]
+
+expected_matches_bk_boundary_2 = {"All": 1, "PER": 1}
+
 
 @pytest.mark.parametrize(
     "test_input, expected",
@@ -174,6 +246,24 @@ expected_matches_nested_false = {"All": 2, "PER": 1, "LOC": 1}
             ),
             expected_matches_nested_false,
         ),
+        (
+            (
+                fake_annot_backtrack_boundary,
+                fake_annot_backtrack_boundary,
+                fake_annot_tags_bk_boundary,
+                fake_predict_tags_bk_boundary,
+            ),
+            expected_matches_bk_boundary,
+        ),
+        (
+            (
+                fake_annot_backtrack_boundary_2,
+                fake_annot_backtrack_boundary_2,
+                fake_annot_tags_bk_boundary_2,
+                fake_predict_tags_bk_boundary_2,
+            ),
+            expected_matches_bk_boundary_2,
+        ),
     ],
 )
 def test_compute_matches(test_input, expected):
-- 
GitLab