# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import csv import json import os import datasets _CITATION = """\ @misc{11356/1467, title = {Slovene Web genre identification corpus {GINCO} 1.0}, author = {Kuzman, Taja and Brglez, Mojca and Rupnik, Peter and Ljube{\v s}i{\'c}, Nikola}, url = {http://hdl.handle.net/11356/1467}, note = {Slovenian language resource repository {CLARIN}.{SI}}, copyright = {Creative Commons - Attribution-{ShareAlike} 4.0 International ({CC} {BY}-{SA} 4.0)}, issn = {2820-4042}, year = {2021} } """ _DESCRIPTION = """\ The Slovene Web genre identification corpus GINCO 1.0 contains web texts, manually annotated with genre, from two Slovene web corpora, the slWaC 2.0 corpus, crawled in 2014, and a web corpus, crawled in 2021 in the scope of the MaCoCu project. The corpus allows for automated genre identification and genre analyses as well as other web corpora research. This is a subcorpus of suitable texts, containing 1002 texts (478,969 words), manually annotated with 24 genre categories (News/Reporting, Announcement, Research Article, Instruction, Recipe, Call (such as a Call for Papers), Legal/Regulation, Information/Explanation, Opinionated News, Review, Opinion/Argumentation, Promotion of a Product, Promotion of Services, Invitation, Promotion, Interview, Forum, Correspondence, Script/Drama, Prose, Lyrical, FAQ (Frequently Asked Questions), List of Summaries/Excerpts, and Other). The texts in the suitable subset are annotated with up to three genre categories, where the primary label is the most prevalent, and secondary and tertiary labels denote presence of additional genre(s). They are encoded in three levels of detail, allowing experiments with the full set (24 labels), set of 21 labels (labels with less than 5 instances are merged with label Other) and set of 12 labels (similar labels are merged). Additionally, the corpus contains some metadata about the text (e.g. url, domain, year) and its paragraphs (e.g. near-duplicates and their usefulness for the genre identification). """ _HOMEPAGE = "http://hdl.handle.net/11356/1467" _LICENSE = "Creative Commons - Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)" _URLS = { "ginco": "https://www.clarin.si/repository/xmlui/bitstream/handle/11356/1467/GINCO-1.0-suitable.json.zip?sequence=5&isAllowed=y", } class Ginco(datasets.GeneratorBasedBuilder): """Genre identification and genre analyses for Slovenian texts.""" VERSION = datasets.Version("1.1.0") def _info(self): features = datasets.Features( { "id": datasets.Value("string"), "url": datasets.Value("string"), "crawled": datasets.Value("string"), "hard": datasets.Value("bool"), "paragraphs": [ { "text": datasets.Value("string"), "duplicate": datasets.Value("bool"), "keep": datasets.Value("bool"), } ], "primary_level_1": datasets.Value("string"), "primary_level_2": datasets.Value("string"), "primary_level_3": datasets.Value("string"), "secondary_level_1": datasets.Value("string"), "secondary_level_2": datasets.Value("string"), "secondary_level_3": datasets.Value("string"), "tertiary_level_1": datasets.Value("string"), "tertiary_level_2": datasets.Value("string"), "tertiary_level_3": datasets.Value("string"), "split": datasets.Value("string"), "domain": datasets.Value("string"), } ) return datasets.DatasetInfo( description=_DESCRIPTION, features=features, homepage=_HOMEPAGE, license=_LICENSE, citation=_CITATION, ) def _split_generators(self, dl_manager): urls = _URLS["ginco"] download_path = dl_manager.download_and_extract(urls) download_path = os.path.join(download_path, "GINCO-1.0-suitable.json", "GINCO-1.0-suitable.json") return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={ "filepath": download_path, "split": "train", }, ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, gen_kwargs={ "filepath": download_path, "split": "dev", }, ), datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={ "filepath": download_path, "split": "test", }, ), ] def _generate_examples(self, filepath, split): with open(filepath, "r", encoding='utf-8') as file_obj: data = json.load(file_obj) if split == "train": examples = [example for example in data if example["split"] == "train"] elif split == "dev": examples = [example for example in data if example["split"] == "dev"] elif split == "test": examples = [example for example in data if example["split"] == "test"] for i, example in enumerate(examples): yield i, { "id": example["id"], "url": example["url"], "crawled": example["crawled"], "hard": example["hard"], "paragraphs": example["paragraphs"], "primary_level_1": example["primary_level_1"], "primary_level_2": example["primary_level_2"], "primary_level_3": example["primary_level_3"], "secondary_level_1": example["secondary_level_1"], "secondary_level_2": example["secondary_level_2"], "secondary_level_3": example["secondary_level_3"], "tertiary_level_1": example["tertiary_level_1"], "tertiary_level_2": example["tertiary_level_2"], "tertiary_level_3": example["tertiary_level_3"], "split": example["split"], "domain": example["domain"], }