-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,13 @@ | ||
import regex as re | ||
|
||
|
||
def escape_newlines(text: str): | ||
return text.replace("\n", "\\n") | ||
|
||
def remove_references(text: str): | ||
""" | ||
Removes reference sections from a scientific paper. | ||
""" | ||
pattern = r"References\n([\s\S]*?)(?:\n\n|\Z)" | ||
new_text = re.sub(pattern, '', text) | ||
return new_text.strip() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from core.utils import remove_references | ||
import unittest | ||
|
||
class TestRemoveReferences(unittest.TestCase): | ||
|
||
def test_remove_without_following_section(self): | ||
text = """ | ||
Some initial text. | ||
References | ||
1. Reference one details. | ||
2. Reference two details. | ||
""" | ||
result = remove_references(text) | ||
self.assertNotIn("References", result) | ||
self.assertIn("Some initial text.", result) | ||
|
||
def test_no_references_section(self): | ||
text = """ | ||
Some initial text. | ||
No references here. | ||
""" | ||
result = remove_references(text) | ||
self.assertEqual(text.strip(), result) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |