donfu commited on
Commit
370ce50
1 Parent(s): 43c446b

Remove links from text

Browse files
Files changed (2) hide show
  1. ai.parquet +2 -2
  2. process.py +14 -3
ai.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:8b8d4055e44cf7246550549c51b1eb71cf383c7288ff4a986064e55b5887c4d6
3
- size 6185529
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f1d8d35caaac6e4767be16b6af1d4cf9591d7b5830b49cbe2102571046fd8bd8
3
+ size 5848563
process.py CHANGED
@@ -7,6 +7,7 @@ import pandas as pd
7
  import os
8
  import glob
9
  import sys
 
10
  from html2text import html2text
11
  from datasets import load_dataset
12
 
@@ -184,9 +185,19 @@ def filter_scores_above(
184
  ]
185
 
186
 
187
- to_markdown = (
188
- lambda row: html2text(row, bodywidth=0).strip() if isinstance(row, str) else ""
189
- )
 
 
 
 
 
 
 
 
 
 
190
 
191
 
192
  def convert_html_to_markdown(df, column: str = "Body"):
 
7
  import os
8
  import glob
9
  import sys
10
+ import re
11
  from html2text import html2text
12
  from datasets import load_dataset
13
 
 
185
  ]
186
 
187
 
188
+ remove_markdown_links_pattern = r"\[([^\]]+)\]\(([^\)]+)\)"
189
+ remove_remaining_links = r"https?:\/\/[^\s]+"
190
+
191
+
192
+ # Replace HTML content to markdown but remove links
193
+ def to_markdown(text):
194
+ text = html2text(text, bodywidth=0).strip()
195
+ text = re.sub(remove_markdown_links_pattern, r"\1", text)
196
+ text = re.sub(remove_remaining_links, "", text)
197
+
198
+ if "http" in text:
199
+ raise "Found http in markdown: " + text
200
+ return text
201
 
202
 
203
  def convert_html_to_markdown(df, column: str = "Body"):