<commit_before>\section{\module{difflib} ---
         Helpers for computing deltas}

\declaremodule{standard}{difflib}
\modulesynopsis{Helpers for computing differences between objects.}
\moduleauthor{<NAME>}{<EMAIL>}
\sectionauthor{<NAME>}{<EMAIL>}
% LaTeXification by <NAME>, Jr. <<EMAIL>>.

\versionadded{2.1}


\begin{classdesc*}{SequenceMatcher}
  This is a flexible class for comparing pairs of sequences of any
  type, so long as the sequence elements are hashable.  The basic
  algorithm predates, and is a little fancier than, an algorithm
  published in the late 1980's by Ratcliff and Obershelp under the
  hyperbolic name ``gestalt pattern matching.''  The idea is to find
  the longest contiguous matching subsequence that contains no
  ``junk'' elements (the Ratcliff and Obershelp algorithm doesn't
  address junk).  The same idea is then applied recursively to the
  pieces of the sequences to the left and to the right of the matching
  subsequence.  This does not yield minimal edit sequences, but does
  tend to yield matches that ``look right'' to people.

  \strong{Timing:} The basic Ratcliff-Obershelp algorithm is cubic
  time in the worst case and quadratic time in the expected case.
  \class{SequenceMatcher} is quadratic time for the worst case and has
  expected-case behavior dependent in a complicated way on how many
  elements the sequences have in common; best case time is linear.
\end{classdesc*}

\begin{classdesc*}{Differ}
  This is a class for comparing sequences of lines of text, and
  producing human-readable differences or deltas.  Differ uses
  \class{SequenceMatcher} both to compare sequences of lines, and to
  compare sequences of characters within similar (near-matching)
  lines.

  Each line of a \class{Differ} delta begins with a two-letter code:

\begin{tableii}{l|l}{code}{Code}{Meaning}
  \lineii{'- '}{line unique to sequence 1}
  \lineii{'+ '}{line unique to sequence 2}
  \lineii{'  '}{line common to both sequences}
  \lineii{'? '}{line not present in either input sequence}
\end{tableii}

  Lines beginning with `\code{?~}' attempt to guide the eye to
  intraline differences, and were not present in either input
  sequence. These lines can be confusing if the sequences contain tab
  characters.
\end{classdesc*}

\begin{funcdesc}{get_close_matches}{word, possibilities\optional{,
                 n\optional{, cutoff}}}
  Return a list of the best ``good enough'' matches.  \var{word} is a
  sequence for which close matches are desired (typically a string),
  and \var{possibilities} is a list of sequences against which to
  match \var{word} (typically a list of strings).

  Optional argument \var{n} (default \code{3}) is the maximum number
  of close matches to return; \var{n} must be greater than \code{0}.

  Optional argument \var{cutoff} (default \code{0.6}) is a float in
  the range [0, 1].  Possibilities that don't score at least that
  similar to \var{word} are ignored.

  The best (no more than \var{n}) matches among the possibilities are
  returned in a list, sorted by similarity score, most similar first.

\begin{verbatim}
>>> get_close_matches('appel', ['ape', 'apple', 'peach', 'puppy'])
['apple', 'ape']
>>> import keyword
>>> get_close_matches('wheel', keyword.kwlist)
['while']
>>> get_close_matches('apple', keyword.kwlist)
[]
>>> get_close_matches('accept', keyword.kwlist)
['except']
\end{verbatim}
\end{funcdesc}

\begin{funcdesc}{ndiff}{a, b\optional{, linejunk\optional{,
                 charjunk}}}
  Compare \var{a} and \var{b} (lists of strings); return a
  \class{Differ}-style delta (a generator generating the delta lines).

  Optional keyword parameters \var{linejunk} and \var{charjunk} are
  for filter functions (or \code{None}):

  \var{linejunk}: A function that accepts a single string
  argument, and returns true if the string is junk, or false if not.
  The default is (\code{None}), starting with Python 2.3.  Before then,
  the default was the module-level function
  \function{IS_LINE_JUNK()}, which filters out lines without visible
  characters, except for at most one pound character (\character{\#}).
  As of Python 2.3, the underlying \class{SequenceMatcher} class
  does a dynamic analysis of which lines are so frequent as to
  constitute noise, and this usually works better than the pre-2.3
  default.

  \var{charjunk}: A function that accepts a character (a string of
  length 1), and returns if the character is junk, or false if not.
  The default is module-level function \function{IS_CHARACTER_JUNK()},
  which filters out whitespace characters (a blank or tab; note: bad
  idea to include newline in this!).

  \file{Tools/scripts/ndiff.py} is a command-line front-end to this
  function.

\begin{verbatim}
>>> diff = ndiff('one\ntwo\nthree\n'.splitlines(1),
...              'ore\ntree\nemu\n'.splitlines(1)))
>>> print ''.join(diff),
- one
?  ^
+ ore
?  ^
- two
- three
?  -
+ tree
+ emu
\end{verbatim}
\end{funcdesc}

\begin{funcdesc}{restore}{sequence, which}
  Return one of the two sequences that generated a delta.

  Given a \var{sequence} produced by \method{Differ.compare()} or
  \function{ndiff()}, extract lines originating from file 1 or 2
  (parameter \var{which}), stripping off line prefixes.
<commit_msg>Remove extra ")" in example.<commit_after>\section{\module{difflib} ---
         Helpers for computing deltas}

\declaremodule{standard}{difflib}
\modulesynopsis{Helpers for computing differences between objects.}
\moduleauthor{<NAME>}{<EMAIL>}
\sectionauthor{<NAME>ers}{<EMAIL>}
% LaTeXification by <NAME>, Jr. <<EMAIL>>.

\versionadded{2.1}


\begin{classdesc*}{SequenceMatcher}
  This is a flexible class for comparing pairs of sequences of any
  type, so long as the sequence elements are hashable.  The basic
  algorithm predates, and is a little fancier than, an algorithm
  published in the late 1980's by Ratcliff and Obershelp under the
  hyperbolic name ``gestalt pattern matching.''  The idea is to find
  the longest contiguous matching subsequence that contains no
  ``junk'' elements (the Ratcliff and Obershelp algorithm doesn't
  address junk).  The same idea is then applied recursively to the
  pieces of the sequences to the left and to the right of the matching
  subsequence.  This does not yield minimal edit sequences, but does
  tend to yield matches that ``look right'' to people.

  \strong{Timing:} The basic Ratcliff-Obershelp algorithm is cubic
  time in the worst case and quadratic time in the expected case.
  \class{SequenceMatcher} is quadratic time for the worst case and has
  expected-case behavior dependent in a complicated way on how many
  elements the sequences have in common; best case time is linear.
\end{classdesc*}

\begin{classdesc*}{Differ}
  This is a class for comparing sequences of lines of text, and
  producing human-readable differences or deltas.  Differ uses
  \class{SequenceMatcher} both to compare sequences of lines, and to
  compare sequences of characters within similar (near-matching)
  lines.

  Each line of a \class{Differ} delta begins with a two-letter code:

\begin{tableii}{l|l}{code}{Code}{Meaning}
  \lineii{'- '}{line unique to sequence 1}
  \lineii{'+ '}{line unique to sequence 2}
  \lineii{'  '}{line common to both sequences}
  \lineii{'? '}{line not present in either input sequence}
\end{tableii}

  Lines beginning with `\code{?~}' attempt to guide the eye to
  intraline differences, and were not present in either input
  sequence. These lines can be confusing if the sequences contain tab
  characters.
\end{classdesc*}

\begin{funcdesc}{get_close_matches}{word, possibilities\optional{,
                 n\optional{, cutoff}}}
  Return a list of the best ``good enough'' matches.  \var{word} is a
  sequence for which close matches are desired (typically a string),
  and \var{possibilities} is a list of sequences against which to
  match \var{word} (typically a list of strings).

  Optional argument \var{n} (default \code{3}) is the maximum number
  of close matches to return; \var{n} must be greater than \code{0}.

  Optional argument \var{cutoff} (default \code{0.6}) is a float in
  the range [0, 1].  Possibilities that don't score at least that
  similar to \var{word} are ignored.

  The best (no more than \var{n}) matches among the possibilities are
  returned in a list, sorted by similarity score, most similar first.

\begin{verbatim}
>>> get_close_matches('appel', ['ape', 'apple', 'peach', 'puppy'])
['apple', 'ape']
>>> import keyword
>>> get_close_matches('wheel', keyword.kwlist)
['while']
>>> get_close_matches('apple', keyword.kwlist)
[]
>>> get_close_matches('accept', keyword.kwlist)
['except']
\end{verbatim}
\end{funcdesc}

\begin{funcdesc}{ndiff}{a, b\optional{, linejunk\optional{,
                 charjunk}}}
  Compare \var{a} and \var{b} (lists of strings); return a
  \class{Differ}-style delta (a generator generating the delta lines).

  Optional keyword parameters \var{linejunk} and \var{charjunk} are
  for filter functions (or \code{None}):

  \var{linejunk}: A function that accepts a single string
  argument, and returns true if the string is junk, or false if not.
  The default is (\code{None}), starting with Python 2.3.  Before then,
  the default was the module-level function
  \function{IS_LINE_JUNK()}, which filters out lines without visible
  characters, except for at most one pound character (\character{\#}).
  As of Python 2.3, the underlying \class{SequenceMatcher} class
  does a dynamic analysis of which lines are so frequent as to
  constitute noise, and this usually works better than the pre-2.3
  default.

  \var{charjunk}: A function that accepts a character (a string of
  length 1), and returns if the character is junk, or false if not.
  The default is module-level function \function{IS_CHARACTER_JUNK()},
  which filters out whitespace characters (a blank or tab; note: bad
  idea to include newline in this!).

  \file{Tools/scripts/ndiff.py} is a command-line front-end to this
  function.

\begin{verbatim}
>>> diff = ndiff('one\ntwo\nthree\n'.splitlines(1),
...              'ore\ntree\nemu\n'.splitlines(1))
>>> print ''.join(diff),
- one
?  ^
+ ore
?  ^
- two
- three
?  -
+ tree
+ emu
\end{verbatim}
\end{funcdesc}

\begin{funcdesc}{restore}{sequence, which}
  Return one of the two sequences that generated a delta.

  Given a \var{sequence} produced by \method{Differ.compare()} or
  \function{ndiff()}, extract lines originating from file 1 or 2
  (parameter \var{which}), stripping off line prefixes.

{'fraction_non_alphanumeric': 0.10304872257574318, 'fraction_numerical': 0.004748789058790008, 'mean_word_length': 4.111650485436893, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3268880', 'n_tokens_mistral': 3157, 'n_tokens_neox': 3080, 'n_words': 1289}