class_docstr: An ordered collection of :class:`spacy.tokens.Doc`, all of the same language
  and sharing the same :class:`spacy.language.Language` processing pipeline
  and vocabulary, with data held *in-memory*.
  
  Initialize from a ``Language`` name or instance and (optionally) one or a stream
  of texts or (text, metadata) pairs:
  
  .. code-block:: pycon
  
      >>> ds = textacy.datasets.CapitolWords()
      >>> records = ds.records(limit=50)
      >>> corpus = textacy.Corpus("en_core_web_sm", data=records)
      >>> print(corpus)
      Corpus(50 docs, 32175 tokens)
  
  Add or remove documents, with automatic updating of corpus statistics:
  
  .. code-block:: pycon
  
      >>> texts = ds.texts(congress=114, limit=25)
      >>> corpus.add(texts)
      >>> corpus.add("If Burton were a member of Congress, here's what he'd say.")
      >>> print(corpus)
      Corpus(76 docs, 55906 tokens)
      >>> corpus.remove(lambda doc: doc._.meta.get("speaker_name") == "Rick Santorum")
      >>> print(corpus)
      Corpus(61 docs, 48567 tokens)
  
  Get subsets of documents matching your particular use case:
  
  .. code-block:: pycon
  
      >>> match_func = lambda doc: doc._.meta.get("speaker_name") == "Bernie Sanders"
      >>> for doc in corpus.get(match_func, limit=3):
      ...     print(doc._.preview)
      Doc(159 tokens: "Mr. Speaker, 480,000 Federal employees are work...")
      Doc(336 tokens: "Mr. Speaker, I thank the gentleman for yielding...")
      Doc(177 tokens: "Mr. Speaker, if we want to understand why in th...")
  
  Get or remove documents by indexing, too:
  
  .. code-block:: pycon
  
      >>> corpus[0]._.preview
      'Doc(159 tokens: "Mr. Speaker, 480,000 Federal employees are work...")'
      >>> [doc._.preview for doc in corpus[:3]]
      ['Doc(159 tokens: "Mr. Speaker, 480,000 Federal employees are work...")',
       'Doc(219 tokens: "Mr. Speaker, a relationship, to work and surviv...")',
       'Doc(336 tokens: "Mr. Speaker, I thank the gentleman for yielding...")']
      >>> del corpus[:5]
      >>> print(corpus)
      Corpus(56 docs, 41573 tokens)
  
  Compute basic corpus statistics:
  
  .. code-block:: pycon
  
      >>> corpus.n_docs, corpus.n_sents, corpus.n_tokens
      (56, 1771, 41573)
      >>> word_counts = corpus.word_counts(by="lemma_")
      >>> sorted(word_counts.items(), key=lambda x: x[1], reverse=True)[:5]
      [('-PRON-', 2553), ('people', 215), ('year', 148), ('Mr.', 139), ('$', 137)]
      >>> word_doc_counts = corpus.word_doc_counts(by="lemma_", weighting="freq")
      >>> sorted(word_doc_counts.items(), key=lambda x: x[1], reverse=True)[:5]
      [('-PRON-', 0.9821428571428571),
       ('Mr.', 0.7678571428571429),
       ('President', 0.5),
       ('people', 0.48214285714285715),
       ('need', 0.44642857142857145)]
  
  Save corpus data to and load from disk:
  
  .. code-block:: pycon
  
      >>> corpus.save("./cw_sample.bin.gz")
      >>> corpus = textacy.Corpus.load("en_core_web_sm", "./cw_sample.bin.gz")
      >>> print(corpus)
      Corpus(56 docs, 41573 tokens)
  
  Args:
      lang:
          Language with which spaCy processes (or processed) all documents
          added to the corpus, whether as ``data`` now or later.
  
          Pass the name of a spacy language pipeline (e.g. "en_core_web_sm"),
          or an already-instantiated :class:`spacy.language.Language` object.
  
          A given / detected language string is then used to instantiate
          a corresponding ``Language`` with all default components enabled.
      data: One or a stream of texts, records, or :class:`spacy.tokens.Doc` s
          to be added to the corpus.
  
          .. seealso:: :meth:`Corpus.add()`
  
  Attributes:
      lang
      spacy_lang
      docs
      n_docs
      n_sents
      n_tokens
class_docstr_tok: ["An","ordered","collection","of",":","class",":","`","spacy.tokens.Doc","`",",","all","of","the","same","language","and","sharing","the","same",":","class",":","`","spacy.language.Language","`","processing","pipeline","and","vocabulary",",","with","data","held","*","in-memory","*",".","Initialize","from","a","``","Language","``","name","or","instance","and","(","optionally",")","one","or","a","stream","of","texts","or","(","text",",","metadata",")","pairs",":","..","code-block",":",":","pycon",">",">",">","ds","=","textacy.datasets.CapitolWords","(",")",">",">",">","records","=","ds.records","(","limit=50",")",">",">",">","corpus","=","textacy.Corpus","(","``","en_core_web_sm","''",",","data=records",")",">",">",">","print","(","corpus",")","Corpus","(","50","docs",",","32175","tokens",")","Add","or","remove","documents",",","with","automatic","updating","of","corpus","statistics",":","..","code-block",":",":","pycon",">",">",">","texts","=","ds.texts","(","congress=114",",","limit=25",")",">",">",">","corpus.add","(","texts",")",">",">",">","corpus.add","(","``","If","Burton","were","a","member","of","Congress",",","here","'s","what","he","'d","say",".","''",")",">",">",">","print","(","corpus",")","Corpus","(","76","docs",",","55906","tokens",")",">",">",">","corpus.remove","(","lambda","doc",":","doc._.meta.get","(","``","speaker_name","''",")","==","``","Rick","Santorum","''",")",">",">",">","print","(","corpus",")","Corpus","(","61","docs",",","48567","tokens",")","Get","subsets","of","documents","matching","your","particular","use","case",":","..","code-block",":",":","pycon",">",">",">","match_func","=","lambda","doc",":","doc._.meta.get","(","``","speaker_name","''",")","==","``","Bernie","Sanders","''",">",">",">","for","doc","in","corpus.get","(","match_func",",","limit=3",")",":","...","print","(","doc._.preview",")","Doc","(","159","tokens",":","``","Mr.","Speaker",",","480,000","Federal","employees","are","work","...","''",")","Doc","(","336","tokens",":","``","Mr.","Speaker",",","I","thank","the","gentleman","for","yielding","...","''",")","Doc","(","177","tokens",":","``","Mr.","Speaker",",","if","we","want","to","understand","why","in","th","...","''",")","Get","or","remove","documents","by","indexing",",","too",":","..","code-block",":",":","pycon",">",">",">","corpus","[","0","]","._.preview","'Doc","(","159","tokens",":","``","Mr.","Speaker",",","480,000","Federal","employees","are","work","...","''",")","'",">",">",">","[","doc._.preview","for","doc","in","corpus","[",":3","]","]","[","'Doc","(","159","tokens",":","``","Mr.","Speaker",",","480,000","Federal","employees","are","work","...","''",")","'",",","'Doc","(","219","tokens",":","``","Mr.","Speaker",",","a","relationship",",","to","work","and","surviv","...","''",")","'",",","'Doc","(","336","tokens",":","``","Mr.","Speaker",",","I","thank","the","gentleman","for","yielding","...","''",")","'","]",">",">",">","del","corpus","[",":5","]",">",">",">","print","(","corpus",")","Corpus","(","56","docs",",","41573","tokens",")","Compute","basic","corpus","statistics",":","..","code-block",":",":","pycon",">",">",">","corpus.n_docs",",","corpus.n_sents",",","corpus.n_tokens","(","56",",","1771",",","41573",")",">",">",">","word_counts","=","corpus.word_counts","(","by=","''","lemma_","''",")",">",">",">","sorted","(","word_counts.items","(",")",",","key=lambda","x",":","x","[","1","]",",","reverse=True",")","[",":5","]","[","(","'-PRON-","'",",","2553",")",",","(","'people","'",",","215",")",",","(","'year","'",",","148",")",",","(","'Mr",".","'",",","139",")",",","(","'","$","'",",","137",")","]",">",">",">","word_doc_counts","=","corpus.word_doc_counts","(","by=","''","lemma_","''",",","weighting=","''","freq","''",")",">",">",">","sorted","(","word_doc_counts.items","(",")",",","key=lambda","x",":","x","[","1","]",",","reverse=True",")","[",":5","]","[","(","'-PRON-","'",",","0.9821428571428571",")",",","(","'Mr",".","'",",","0.7678571428571429",")",",","(","'President","'",",","0.5",")",",","(","'people","'",",","0.48214285714285715",")",",","(","'need","'",",","0.44642857142857145",")","]","Save","corpus","data","to","and","load","from","disk",":","..","code-block",":",":","pycon",">",">",">","corpus.save","(","``",".\/cw_sample.bin.gz","''",")",">",">",">","corpus","=","textacy.Corpus.load","(","``","en_core_web_sm","''",",","``",".\/cw_sample.bin.gz","''",")",">",">",">","print","(","corpus",")","Corpus","(","56","docs",",","41573","tokens",")","Args",":","lang",":","Language","with","which","spaCy","processes","(","or","processed",")","all","documents","added","to","the","corpus",",","whether","as","``","data","``","now","or","later",".","Pass","the","name","of","a","spacy","language","pipeline","(","e.g",".","``","en_core_web_sm","''",")",",","or","an","already-instantiated",":","class",":","`","spacy.language.Language","`","object",".","A","given","\/","detected","language","string","is","then","used","to","instantiate","a","corresponding","``","Language","``","with","all","default","components","enabled",".","data",":","One","or","a","stream","of","texts",",","records",",","or",":","class",":","`","spacy.tokens.Doc","`","s","to","be","added","to","the","corpus",".","..","seealso",":",":",":","meth",":","`","Corpus.add","(",")","`","Attributes",":","lang","spacy_lang","docs","n_docs","n_sents","n_tokens"]
docstr: Aggregate values for a particular metadata field over all documents
  in :class:`Corpus`.
  
  Args:
      name: Name of metadata field (key) in :class:`Doc._.meta`.
      agg_func: Callable that accepts an iterable of field values
          and outputs a single, aggregated result.
      default: Default field value to use if ``name`` is not found
          in a given document's metadata.
  
  Returns:
      Aggregated value for metadata field.
code: def agg_metadata(
      self,
      name: str,
      agg_func: Callable[[Iterable[Any]], Any],
      default: Optional[Any] = None,
  ) -> Any:
      """
      Aggregate values for a particular metadata field over all documents
      in :class:`Corpus`.
  
      Args:
          name: Name of metadata field (key) in :class:`Doc._.meta`.
          agg_func: Callable that accepts an iterable of field values
              and outputs a single, aggregated result.
          default: Default field value to use if ``name`` is not found
              in a given document's metadata.
  
      Returns:
          Aggregated value for metadata field.
      """
      return agg_func(
          doc._.meta.get(name, default) for doc in self.docs
      )
  
imports: from __future__ import annotations
  import collections
  import collections.abc
  import itertools
  import logging
  import math
  from typing import Any, Callable, Counter, Iterable, Literal, Optional, Union
  import numpy
  import spacy
  import spacy.attrs
  from cytoolz import itertoolz
  from spacy.language import Language
  from spacy.tokens import Doc
  from .None import errors, extract
  from .None import io
  from .None import spacier, types, utils
label_desc: Use image node_id 24 for calling the Corpus obj's underlying member method code with example usage: obj.agg_metadata(name, agg_func, default) and returns: agg_func