shamikbose89 commited on
Commit
d1074a4
1 Parent(s): 05438d7

Upload lampeter_corpus.py

Browse files

Changed date to datasets.Value("date64")

Files changed (1) hide show
  1. lampeter_corpus.py +31 -24
lampeter_corpus.py CHANGED
@@ -19,6 +19,7 @@ areas of everyday life and, last but not least, the standardisation of British E
19
 
20
  from bs4 import BeautifulSoup
21
  import datasets
 
22
 
23
  _CITATION = """ @misc{20.500.12024/3193,
24
  title = {The Lampeter Corpus of Early Modern English Tracts},
@@ -39,7 +40,15 @@ _LICENSE = "Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)"
39
 
40
  _URL = "https://ota.bodleian.ox.ac.uk/repository/xmlui/bitstream/handle/20.500.12024/3193/3193.xml?sequence=9&isAllowed=y"
41
 
42
- _CLASS_MAP = {"L": "Law", "E": "Economy", "M": "Miscellaneous", "P": "Politics", "S": "Science", "R": "Religion"}
 
 
 
 
 
 
 
 
43
 
44
  class LampeterCorpus(datasets.GeneratorBasedBuilder):
45
  """ The Lampeter Corpus of Early Modern English Tracts is a collection of texts on
@@ -54,10 +63,10 @@ class LampeterCorpus(datasets.GeneratorBasedBuilder):
54
  {
55
  "id": datasets.Value("string"),
56
  "text": datasets.Value("string"),
57
- "date": datasets.Value("string"),
58
  "genre": datasets.Value("string"),
59
  "head": datasets.Value("string"),
60
- "title": datasets.Value("string")
61
  }
62
  )
63
  return datasets.DatasetInfo(
@@ -73,40 +82,38 @@ class LampeterCorpus(datasets.GeneratorBasedBuilder):
73
  return [
74
  datasets.SplitGenerator(
75
  name=datasets.Split.TRAIN,
76
- gen_kwargs={
77
- "filepath": data_file,
78
- "split": "train",
79
- },
80
- ),
81
  ]
82
 
83
  def _generate_examples(self, filepath, split):
 
84
  with open(filepath, encoding="utf-8") as f:
85
- soup=BeautifulSoup(f, features='xml')
86
  for entry in soup.find_all("TEI"):
87
  text_parts = []
88
  title_with_id = entry.teiHeader.fileDesc.titleStmt.title.text
89
  id, title = title_with_id.split(":", maxsplit=1)
90
  id = id.strip()
91
- title=title.strip()
92
- date=id[-4:]
93
  content = entry.find("text")
94
- head=content.find("body").find("head")
95
  if head:
96
- head=head.text
97
  else:
98
- head=""
99
- body_parts=content.find("body").find_all("p")
100
  for body_part in body_parts:
101
  text_parts.append(body_part.text)
102
  full_text = " ".join(text_parts)
103
- genre=_CLASS_MAP[id[0]]
104
  data_point = {
105
- "id": id,
106
- "text": full_text,
107
- "genre": genre,
108
- "date": date,
109
- "head": head,
110
- "title": title
111
- }
112
- yield id, data_point
 
19
 
20
  from bs4 import BeautifulSoup
21
  import datasets
22
+ from datetime import datetime
23
 
24
  _CITATION = """ @misc{20.500.12024/3193,
25
  title = {The Lampeter Corpus of Early Modern English Tracts},
 
40
 
41
  _URL = "https://ota.bodleian.ox.ac.uk/repository/xmlui/bitstream/handle/20.500.12024/3193/3193.xml?sequence=9&isAllowed=y"
42
 
43
+ _CLASS_MAP = {
44
+ "L": "Law",
45
+ "E": "Economy",
46
+ "M": "Miscellaneous",
47
+ "P": "Politics",
48
+ "S": "Science",
49
+ "R": "Religion",
50
+ }
51
+
52
 
53
  class LampeterCorpus(datasets.GeneratorBasedBuilder):
54
  """ The Lampeter Corpus of Early Modern English Tracts is a collection of texts on
 
63
  {
64
  "id": datasets.Value("string"),
65
  "text": datasets.Value("string"),
66
+ "date": datasets.Value("date64"),
67
  "genre": datasets.Value("string"),
68
  "head": datasets.Value("string"),
69
+ "title": datasets.Value("string"),
70
  }
71
  )
72
  return datasets.DatasetInfo(
 
82
  return [
83
  datasets.SplitGenerator(
84
  name=datasets.Split.TRAIN,
85
+ gen_kwargs={"filepath": data_file, "split": "train",},
86
+ ),
 
 
 
87
  ]
88
 
89
  def _generate_examples(self, filepath, split):
90
+ dt_format = "%Y"
91
  with open(filepath, encoding="utf-8") as f:
92
+ soup = BeautifulSoup(f, features="xml")
93
  for entry in soup.find_all("TEI"):
94
  text_parts = []
95
  title_with_id = entry.teiHeader.fileDesc.titleStmt.title.text
96
  id, title = title_with_id.split(":", maxsplit=1)
97
  id = id.strip()
98
+ title = title.strip()
99
+ date = datetime.strptime(id[-4:], dt_format)
100
  content = entry.find("text")
101
+ head = content.find("body").find("head")
102
  if head:
103
+ head = head.text
104
  else:
105
+ head = ""
106
+ body_parts = content.find("body").find_all("p")
107
  for body_part in body_parts:
108
  text_parts.append(body_part.text)
109
  full_text = " ".join(text_parts)
110
+ genre = _CLASS_MAP[id[0]]
111
  data_point = {
112
+ "id": id,
113
+ "text": full_text,
114
+ "genre": genre,
115
+ "date": date,
116
+ "head": head,
117
+ "title": title,
118
+ }
119
+ yield id, data_point