Remove the hyperlink from the text. :param text: wikipedia text, with hyperlinks
(text, abstract=False)
| 38 | |
| 39 | |
| 40 | def remove_hyperlink(text, abstract=False): |
| 41 | """ |
| 42 | Remove the hyperlink from the text. |
| 43 | :param text: wikipedia text, with hyperlinks |
| 44 | """ |
| 45 | if abstract: |
| 46 | text = text.split("\n\n", 1) |
| 47 | if len(text) > 1: |
| 48 | text = text[1].split('\n')[0] |
| 49 | else: |
| 50 | text = "" |
| 51 | text = _normalize(text) |
| 52 | clean_text = re.sub(r'<a href="[^"]+">([^<]+)</a>', r'\1', text) |
| 53 | clean_text = re.sub(r'\n\n?', ' ', clean_text) |
| 54 | clean_text = clean_text.rstrip() |
| 55 | return clean_text |
no test coverage detected