Datasets:
Matthew Franglen
commited on
Commit
·
eae18d7
1
Parent(s):
ab0195f
Read xml documents by using xpath to get text
Browse files- src/data.py +5 -1
src/data.py
CHANGED
|
@@ -2,10 +2,14 @@ import ast
|
|
| 2 |
from pathlib import Path
|
| 3 |
|
| 4 |
import pandas as pd
|
|
|
|
| 5 |
|
| 6 |
|
| 7 |
def read_sem_eval_file(file: str | Path) -> pd.DataFrame:
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
| 9 |
return df
|
| 10 |
|
| 11 |
|
|
|
|
| 2 |
from pathlib import Path
|
| 3 |
|
| 4 |
import pandas as pd
|
| 5 |
+
from lxml import etree
|
| 6 |
|
| 7 |
|
| 8 |
def read_sem_eval_file(file: str | Path) -> pd.DataFrame:
|
| 9 |
+
root = etree.parse(file)
|
| 10 |
+
documents = root.xpath("//text/text()")
|
| 11 |
+
assert isinstance(documents, list), f"cannot parse text from {file}"
|
| 12 |
+
df = pd.DataFrame({"text": documents})
|
| 13 |
return df
|
| 14 |
|
| 15 |
|