class_docstr: Stream a collection of Congressional speeches from a compressed json file on disk,
  either as texts or text + metadata pairs.
  
  Download the data (one time only!) from the textacy-data repo
  (https://github.com/bdewilde/textacy-data), and save its contents to disk::
  
      >>> import textacy.datasets
      >>> ds = textacy.datasets.CapitolWords()
      >>> ds.download()
      >>> ds.info
      {'name': 'capitol_words',
       'site_url': 'http://sunlightlabs.github.io/Capitol-Words/',
       'description': 'Collection of ~11k speeches in the Congressional Record given by notable U.S. politicians between Jan 1996 and Jun 2016.'}
  
  Iterate over speeches as texts or records with both text and metadata::
  
      >>> for text in ds.texts(limit=3):
      ...     print(text, end="\n\n")
      >>> for text, meta in ds.records(limit=3):
      ...     print("\n{} ({})\n{}".format(meta["title"], meta["speaker_name"], text))
  
  Filter speeches by a variety of metadata fields and text length::
  
      >>> for text, meta in ds.records(speaker_name="Bernie Sanders", limit=3):
      ...     print("\n{}, {}\n{}".format(meta["title"], meta["date"], text))
      >>> for text, meta in ds.records(speaker_party="D", congress={110, 111, 112},
      ...                          chamber="Senate", limit=3):
      ...     print(meta["title"], meta["speaker_name"], meta["date"])
      >>> for text, meta in ds.records(speaker_name={"Barack Obama", "Hillary Clinton"},
      ...                              date_range=("2005-01-01", "2005-12-31")):
      ...     print(meta["title"], meta["speaker_name"], meta["date"])
      >>> for text in ds.texts(min_len=50000):
      ...     print(len(text))
  
  Stream speeches into a :class:`textacy.Corpus <textacy.corpus.Corpus>`::
  
      >>> textacy.Corpus("en", data=ota.records(limit=100))
      Corpus(100 docs; 70496 tokens)
  
  Args:
      data_dir: Path to directory on disk under which dataset is stored,
          i.e. ``/path/to/data_dir/capitol_words``.
  
  Attributes:
      full_date_range: First and last dates for which speeches are available,
          each as an ISO-formatted string (YYYY-MM-DD).
      speaker_names: Full names of all speakers included in corpus, e.g. "Bernie Sanders".
      speaker_parties: All distinct political parties of speakers, e.g. "R".
      chambers: All distinct chambers in which speeches were given, e.g. "House".
      congresses: All distinct numbers of the congresses in which speeches were given, e.g. 114.
class_docstr_tok: ["Stream","a","collection","of","Congressional","speeches","from","a","compressed","json","file","on","disk",",","either","as","texts","or","text","+","metadata","pairs",".","Download","the","data","(","one","time","only","!",")","from","the","textacy-data","repo","(","https",":","\/\/github.com\/bdewilde\/textacy-data",")",",","and","save","its","contents","to","disk",":",":",">",">",">","import","textacy.datasets",">",">",">","ds","=","textacy.datasets.CapitolWords","(",")",">",">",">","ds.download","(",")",">",">",">","ds.info","{","'name","'",":","'capitol_words","'",",","'site_url","'",":","'http",":","\/\/sunlightlabs.github.io\/Capitol-Words\/","'",",","'description","'",":","'Collection","of","~11k","speeches","in","the","Congressional","Record","given","by","notable","U.S.","politicians","between","Jan","1996","and","Jun","2016",".","'","}","Iterate","over","speeches","as","texts","or","records","with","both","text","and","metadata",":",":",">",">",">","for","text","in","ds.texts","(","limit=3",")",":","...","print","(","text",",","end=","''","\\n\\n","''",")",">",">",">","for","text",",","meta","in","ds.records","(","limit=3",")",":","...","print","(","``","\\n","{","}","(","{","}",")","\\n","{","}","''",".format","(","meta","[","``","title","''","]",",","meta","[","``","speaker_name","''","]",",","text",")",")","Filter","speeches","by","a","variety","of","metadata","fields","and","text","length",":",":",">",">",">","for","text",",","meta","in","ds.records","(","speaker_name=","''","Bernie","Sanders","''",",","limit=3",")",":","...","print","(","``","\\n","{","}",",","{","}","\\n","{","}","''",".format","(","meta","[","``","title","''","]",",","meta","[","``","date","''","]",",","text",")",")",">",">",">","for","text",",","meta","in","ds.records","(","speaker_party=","''","D","''",",","congress=","{","110",",","111",",","112","}",",","...","chamber=","''","Senate","''",",","limit=3",")",":","...","print","(","meta","[","``","title","''","]",",","meta","[","``","speaker_name","''","]",",","meta","[","``","date","''","]",")",">",">",">","for","text",",","meta","in","ds.records","(","speaker_name=","{","``","Barack","Obama","''",",","``","Hillary","Clinton","''","}",",","...","date_range=","(","``","2005-01-01","''",",","``","2005-12-31","''",")",")",":","...","print","(","meta","[","``","title","''","]",",","meta","[","``","speaker_name","''","]",",","meta","[","``","date","''","]",")",">",">",">","for","text","in","ds.texts","(","min_len=50000",")",":","...","print","(","len","(","text",")",")","Stream","speeches","into","a",":","class",":","`","textacy.Corpus","<","textacy.corpus.Corpus",">","`",":",":",">",">",">","textacy.Corpus","(","``","en","''",",","data=ota.records","(","limit=100",")",")","Corpus","(","100","docs",";","70496","tokens",")","Args",":","data_dir",":","Path","to","directory","on","disk","under","which","dataset","is","stored",",","i.e",".","``","\/path\/to\/data_dir\/capitol_words","``",".","Attributes",":","full_date_range",":","First","and","last","dates","for","which","speeches","are","available",",","each","as","an","ISO-formatted","string","(","YYYY-MM-DD",")",".","speaker_names",":","Full","names","of","all","speakers","included","in","corpus",",","e.g",".","``","Bernie","Sanders","''",".","speaker_parties",":","All","distinct","political","parties","of","speakers",",","e.g",".","``","R","''",".","chambers",":","All","distinct","chambers","in","which","speeches","were","given",",","e.g",".","``","House","''",".","congresses",":","All","distinct","numbers","of","the","congresses","in","which","speeches","were","given",",","e.g",".","114","."]
docstr: Iterate over speeches in this dataset, optionally filtering by a variety
  of metadata and/or text length, and yield texts only,
  in chronological order.
  
  Args:
      speaker_name: Filter speeches by the speakers' name;
          see :attr:`CapitolWords.speaker_names`.
      speaker_party: Filter speeches by the speakers' party;
          see :attr:`CapitolWords.speaker_parties`.
      chamber: Filter speeches by the chamber in which they were given;
          see :attr:`CapitolWords.chambers`.
      congress: Filter speeches by the congress in which they were given;
          see :attr:`CapitolWords.congresses`.
      date_range: Filter speeches by the date on which they were given.
          Both start and end date must be specified, but a null value for either
          will be replaced by the min/max date available for the dataset.
      min_len: Filter texts by the length (# characters) of their text content.
      limit: Yield no more than ``limit`` texts that match all specified filters.
  
  Yields:
      Full text of next (by chronological order) speech in dataset
      passing all filter params.
  
  Raises:
      ValueError: If any filtering options are invalid.
docstr_tok: ["Iterate","over","speeches","in","this","dataset",",","optionally","filtering","by","a","variety","of","metadata","and\/or","text","length",",","and","yield","texts","only",",","in","chronological","order",".","Args",":","speaker_name",":","Filter","speeches","by","the","speakers","'","name",";","see",":","attr",":","`","CapitolWords.speaker_names","`",".","speaker_party",":","Filter","speeches","by","the","speakers","'","party",";","see",":","attr",":","`","CapitolWords.speaker_parties","`",".","chamber",":","Filter","speeches","by","the","chamber","in","which","they","were","given",";","see",":","attr",":","`","CapitolWords.chambers","`",".","congress",":","Filter","speeches","by","the","congress","in","which","they","were","given",";","see",":","attr",":","`","CapitolWords.congresses","`",".","date_range",":","Filter","speeches","by","the","date","on","which","they","were","given",".","Both","start","and","end","date","must","be","specified",",","but","a","null","value","for","either","will","be","replaced","by","the","min\/max","date","available","for","the","dataset",".","min_len",":","Filter","texts","by","the","length","(","#","characters",")","of","their","text","content",".","limit",":","Yield","no","more","than","``","limit","``","texts","that","match","all","specified","filters",".","Yields",":","Full","text","of","next","(","by","chronological","order",")","speech","in","dataset","passing","all","filter","params",".","Raises",":","ValueError",":","If","any","filtering","options","are","invalid","."]
code: def texts(
      self,
      *,
      speaker_name: Optional[str | set[str]] = None,
      speaker_party: Optional[str | set[str]] = None,
      chamber: Optional[str | set[str]] = None,
      congress: Optional[int | set[int]] = None,
      date_range: Optional[tuple[Optional[str], Optional[str]]] = None,
      min_len: Optional[int] = None,
      limit: Optional[int] = None,
  ) -> Iterable[str]:
      """
      Iterate over speeches in this dataset, optionally filtering by a variety
      of metadata and/or text length, and yield texts only,
      in chronological order.
  
      Args:
          speaker_name: Filter speeches by the speakers' name;
              see :attr:`CapitolWords.speaker_names`.
          speaker_party: Filter speeches by the speakers' party;
              see :attr:`CapitolWords.speaker_parties`.
          chamber: Filter speeches by the chamber in which they were given;
              see :attr:`CapitolWords.chambers`.
          congress: Filter speeches by the congress in which they were given;
              see :attr:`CapitolWords.congresses`.
          date_range: Filter speeches by the date on which they were given.
              Both start and end date must be specified, but a null value for either
              will be replaced by the min/max date available for the dataset.
          min_len: Filter texts by the length (# characters) of their text content.
          limit: Yield no more than ``limit`` texts that match all specified filters.
  
      Yields:
          Full text of next (by chronological order) speech in dataset
          passing all filter params.
  
      Raises:
          ValueError: If any filtering options are invalid.
      """
      filters = self._get_filters(
          speaker_name,
          speaker_party,
          chamber,
          congress,
          date_range,
          min_len,
      )
      for record in itertools.islice(
          self._filtered_iter(filters), limit
      ):
          yield record["text"]
  
file_path: textacy/src/textacy/datasets/capitol_words.py
imports: from __future__ import annotations
  import itertools
  import logging
  import urllib.parse
  from typing import Any, Callable, ClassVar, Iterable, Optional
  from ..None import constants
  from ..None import io
  from ..None import types, utils
  from .base import Dataset
label_desc: Use image node_id 7 for calling the CapitolWords obj's underlying member method code with example usage: obj.texts() without return types