Datasets:

Modalities:
Text
Languages:
English
Size:
< 1K
Libraries:
Datasets
License:
shamikbose89 commited on
Commit
00e18ca
1 Parent(s): 0bd8269

Upload lampeter_corpus.py

Browse files

Dataloader for the lampeter corpus

Files changed (1) hide show
  1. lampeter_corpus.py +112 -0
lampeter_corpus.py ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """The Lampeter Corpus of Early Modern English Tracts is a collection of texts
16
+ on various subject matter published between 1640 and 1740 – a time that is marked
17
+ by the rise of mass publication, the development of a public discourse in many
18
+ areas of everyday life and, last but not least, the standardisation of British English."""
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},
25
+ url = {http://hdl.handle.net/20.500.12024/3193},
26
+ note = {Oxford Text Archive},
27
+ copyright = {Distributed by the University of Oxford under a Creative Commons Attribution-{ShareAlike} 3.0 Unported License},
28
+ """
29
+
30
+ _DESCRIPTION = """The Lampeter Corpus of Early Modern English Tracts is a collection of texts on
31
+ various subject matter published between 1640 and 1740 – a time that is marked by the rise of mass
32
+ publication, the development of a public discourse in many areas of everyday life
33
+ and, last but not least, the standardisation of British English.
34
+ """
35
+
36
+ _HOMEPAGE = "https://ota.bodleian.ox.ac.uk/repository/xmlui/handle/20.500.12024/3193"
37
+
38
+ _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
46
+ various subject matter published between 1640 and 1740. Each text is associated with a year
47
+ and one of the following topics: Law, Economy, Religion, Poitics, Science, Miscellaneous
48
+ """
49
+
50
+ VERSION = datasets.Version("1.0.0")
51
+
52
+ def _info(self):
53
+ features = datasets.Features(
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(
64
+ description=_DESCRIPTION,
65
+ features=features,
66
+ homepage=_HOMEPAGE,
67
+ license=_LICENSE,
68
+ citation=_CITATION,
69
+ )
70
+
71
+ def _split_generators(self, dl_manager):
72
+ data_file = dl_manager.download(_URL)
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