Datasets:
Tasks:
Text Classification
Sub-tasks:
topic-classification
Languages:
English
Size:
100K<n<1M
License:
thesofakillers
commited on
Commit
•
194af0e
1
Parent(s):
16b2056
file for parsing raw semcor xml files into csv
Browse files
parse.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Parses raw semcor into csv files
|
2 |
+
import pandas as pd
|
3 |
+
import os
|
4 |
+
from bs4 import BeautifulSoup
|
5 |
+
|
6 |
+
|
7 |
+
def process_split(split_name, parent_path="semcor3.0"):
|
8 |
+
data = []
|
9 |
+
for file in os.listdir(os.path.join(parent_path, split_name, "tagfiles")):
|
10 |
+
file_path = os.path.join(parent_path, split_name, "tagfiles", file)
|
11 |
+
with open(file_path, "r") as f:
|
12 |
+
raw_file = f.read()
|
13 |
+
parsed_file = BeautifulSoup(raw_file, "html.parser")
|
14 |
+
for p in parsed_file.contextfile.context.find_all("p"):
|
15 |
+
pnum = p.get("pnum")
|
16 |
+
for s in p.find_all("s"):
|
17 |
+
snum = s.get("snum")
|
18 |
+
for child in s.find_all(text=False):
|
19 |
+
child_data = {
|
20 |
+
"tagfile": file,
|
21 |
+
"pnum": pnum,
|
22 |
+
"snum": snum,
|
23 |
+
"tag": child.name,
|
24 |
+
"lemma": child.get("lemma"),
|
25 |
+
"lexsn": child.get("lexsn"),
|
26 |
+
"wnsn": child.get("wnsn"),
|
27 |
+
"value": child.string,
|
28 |
+
"cmd": child.get("cmd"),
|
29 |
+
"dc": child.get("dc"),
|
30 |
+
"ot": child.get("ot"),
|
31 |
+
"pn": child.get("pn"),
|
32 |
+
"pos": child.get("pos"),
|
33 |
+
"rdf": child.get("rdf"),
|
34 |
+
"sep": child.get("sep"),
|
35 |
+
}
|
36 |
+
data.append(child_data)
|
37 |
+
df = pd.DataFrame(data)
|
38 |
+
return df
|
39 |
+
|
40 |
+
|
41 |
+
if __name__ == "__main__":
|
42 |
+
for split in ["brown1", "brown2", "brownv"]:
|
43 |
+
print(f"processing split {split}")
|
44 |
+
df = process_split(split)
|
45 |
+
df.to_csv(f"data/{split}-00000-of-00001.csv", index=False)
|
46 |
+
print("Done. Saved to disk.")
|