(self)
return metadata
Read in ``metadata.tsv`` file from :attr:`OxfordTextArchive._metadata_filepath``
        zip archive; convert into a dictionary keyed by record ID; clean up some
        of the fields, and remove a couple fields that are identical throughout.
Read in ``metadata.tsv`` file from :attr:`OxfordTextArchive._metadata_filepath``
        zip archive; convert into a dictionary keyed by record ID; clean up some
        of the fields, and remove a couple fields that are identical throughout.
Read in metadata . tsv file from : attr : OxfordTextArchive . _metadata_filepath zip archive ; convert into a dictionary keyed by record ID ; clean up some of the fields and remove a couple fields that are identical throughout .
def _load_and_parse_metadata(self) -> Dict[str, Dict[str, Any]]:
        """
        Read in ``metadata.tsv`` file from :attr:`OxfordTextArchive._metadata_filepath``
        zip archive; convert into a dictionary keyed by record ID; clean up some
        of the fields, and remove a couple fields that are identical throughout.
        """
        if not self._metadata_filepath.is_file():
            raise OSError(
                f"metadata file {self._metadata_filepath} not found;\n"
                "has the dataset been downloaded yet?"
            )

        re_extract_year = re.compile(r"(\d{4})")
        re_extract_authors = re.compile(
            r"(\D+)"
            r"(?:, "
            r"(?:[bdf]l?\. )?(?:ca. )?\d{4}(?:\?| or \d{1,2})?(?:-(?:[bdf]l?\. )?(?:ca. )?\d{4}(?:\?| or \d{1,2})?)?|"
            r"(?:\d{2}th(?:/\d{2}th)? cent\.)"
            r"\.?)"
        )
        re_clean_authors = re.compile(r"^[,;. ]+|[,.]+\s*?$")
        metadata = {}
        with self._metadata_filepath.open(mode="rb") as f:
            subf = io.StringIO(f.read().decode("utf-8"))
            for row in csv.DictReader(subf, delimiter="\t"):
                # only include English-language works (99.9% of all works)
                if not row["Language"].startswith("English"):
                    continue
                # clean up years
                year_match = re_extract_year.search(row["Year"])
                if year_match:
                    row["Year"] = year_match.group()
                else:
                    row["Year"] = None
                # extract and clean up authors
                authors = re_extract_authors.findall(row["Author"]) or [row["Author"]]
                row["Author"] = tuple(
                    re_clean_authors.sub("", author) for author in authors
                )
                row["Title"] = row["Title"].strip()
                # get rid of uniform "Language" and "License" fields
                del row["Language"]
                del row["License"]
                metadata[row["ID"]] = {key.lower(): val for key, val in row.items()}
        # set authors attribute for user convenience / to validate author filtering
        self.authors = {
            author
            for value in metadata.values()
            for author in value["author"]
            if value.get("author")
        }
        return metadata
def _load_and_parse_metadata ( self ) -> Dict [ str , Dict [ str , Any ] ] : if not self . _metadata_filepath . is_file ( ) : raise OSError ( f"metadata file {self._metadata_filepath} not found;\n" "has the dataset been downloaded yet?" ) re_extract_year = re . compile ( r"(\d{4})" ) re_extract_authors = re . compile ( r"(\D+)" r"(?:, " r"(?:[bdf]l?\. )?(?:ca. )?\d{4}(?:\?| or \d{1,2})?(?:-(?:[bdf]l?\. )?(?:ca. )?\d{4}(?:\?| or \d{1,2})?)?|" r"(?:\d{2}th(?:/\d{2}th)? cent\.)" r"\.?)" ) re_clean_authors = re . compile ( r"^[,;. ]+|[,.]+\s*?$" ) metadata = { } with self . _metadata_filepath . open ( mode = "rb" ) as f : subf = io . StringIO ( f . read ( ) . decode ( "utf-8" ) ) for row in csv . DictReader ( subf , delimiter = "\t" ) : # only include English-language works (99.9% of all works) if not row [ "Language" ] . startswith ( "English" ) : continue # clean up years year_match = re_extract_year . search ( row [ "Year" ] ) if year_match : row [ "Year" ] = year_match . group ( ) else : row [ "Year" ] = None # extract and clean up authors authors = re_extract_authors . findall ( row [ "Author" ] ) or [ row [ "Author" ] ] row [ "Author" ] = tuple ( re_clean_authors . sub ( "" , author ) for author in authors ) row [ "Title" ] = row [ "Title" ] . strip ( ) # get rid of uniform "Language" and "License" fields del row [ "Language" ] del row [ "License" ] metadata [ row [ "ID" ] ] = { key . lower ( ) : val for key , val in row . items ( ) } # set authors attribute for user convenience / to validate author filtering self . authors = { author for value in metadata . values ( ) for author in value [ "author" ] if value . get ( "author" ) } return metadata