Text::Affixes(3pm)

πŸ“¦
version 0.09 Β· 5 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Text::Affixes β€” like, the manual, but make it make sense πŸ’–

okay bestie, sit down, hydrate, because today we're learning Text::Affixes, a Perl module from the User Contributed Perl Documentation corner of the universe that does prefixes and suffixes analysis of text. yes. literally that. and it slays, actually.


✨ NAME ✨

Text::Affixes β€” Prefixes and suffixes analysis of text πŸ¦‹


🌸 SYNOPSIS 🌸

look at the whole vibe first, then we'll break it down:

  use Text::Affixes;
  my $text = "Hello, world. Hello, big world.";
  my $prefixes = get_prefixes($text);

  # $prefixes now holds
  # {
  #     3 => {
  #             'Hel' => 2,
  #             'wor' => 2,
  #     }
  # }

  # or

  $prefixes = get_prefixes({min => 1, max => 2},$text);

  # $prefixes now holds
  # {
  #     1 => {
  #             'H' => 2,
  #             'w' => 2,
  #             'b' => 1,
  #     },
  #     2 => {
  #             'He' => 2,
  #             'wo' => 2,
  #             'bi' => 1,
  #     }
  # }

  # the use for get_suffixes is similar

see how get_prefixes($text) on its own just gets it? no options, no drama, just vibes and a hash. and then when you pass {min => 1, max => 2} it gives you two whole layers of counting. iconic. and the get_suffixes situation? same energy, just flipped, iykyk. πŸ™ˆ


🌈 DESCRIPTION 🌈

Provides methods for prefix and suffix analysis of text. that's it, that's the whole thesis. it looks at your text and counts what words start with and what words end with. very demure, very mindful. ✨


πŸ‘‘ METHODS πŸ‘‘

πŸ’… get_prefixes

Extracts prefixes from text! and you get to pick the minimum and maximum number of characters of prefixes you want, because you're the main character and you have preferences. πŸ’…

It returns a reference to a hash, where the specified limits are mapped in hashes; and then each of those hashes maps every prefix in the text into the number of times it was found. so it's a hash of hashes and it's kind of giving nested-gift-boxes energy. πŸŽ€

By default, both the minimum and the maximum limits are 3. and β€” okay β€” if the minimum limit is greater than the lower one, an empty hash is returned. that's what the docs say, fr fr, and we respect it.

Now, a prefix is considered to be a sequence of word characters (\w) in the beginning of a word (that is, after a word boundary) that does not reach the end of the word. "regular expressionly" speaking, a prefix is the $1 of /\b(\w+)\w/. so basically the word minus its last character. it's not the whole word, bestie, it's the getting ready part of the word. πŸ’–

  # extracting prefixes of size 3
  $prefixes = get_prefixes( $text );

  # extracting prefixes of sizes 2 and 3
  $prefixes = get_prefixes( {min => 2}, $text );

  # extracting prefixes of sizes 3 and 4
  $prefixes = get_prefixes( {max => 4}, $text );

  # extracting prefixes of sizes 2, 3 and 4
  $prefixes = get_prefixes( {min => 2, max=> 4}, $text);

πŸ¦‹ get_suffixes

The get_suffixes function is similar to the get_prefixes one. so like. read the documentation for that one and then come back to this point. (yes it literally tells you to scroll back up, and honestly? same.) 🫢

A suffix is considered to be a sequence of word characters (\w) in the end of a word (that is, before a word boundary) that does not start at the beginning of the word. "regular expressionly" speaking, a suffix is the $1 of /\w(\w+)\b/. so it's the word minus its first character. the outro. the last lyric. the dramatic exit. 😭

  # extracting suffixes of size 3
  $suffixes = get_suffixes( $text );

  # extracting suffixes of sizes 2 and 3
  $suffixes = get_suffixes( {min => 2}, $text );

  # extracting suffixes of sizes 3 and 4
  $suffixes = get_suffixes( {max => 4}, $text );

  # extracting suffixes of sizes 2, 3 and 4
  $suffixes = get_suffixes( {min => 2, max=> 4}, $text);

⭐ OPTIONS ⭐

Apart from deciding on a minimum and maximum size for prefixes or suffixes, you can also decide on some configuration options. because choice is a love language. πŸ’–

πŸ”’ exclude_numbers

Set to 0 if you consider numbers as part of words. Default value is 1.

  # this
  get_suffixes( {min => 1, max => 1, exclude_numbers => 0}, "Hello, but w8" );

  # returns this:
    {
      1 => {
             'o' => 1,
             't' => 1,
             '8' => 1
           }
    }

notice how the 8 showed up to the party once you set it to 0?? it was always invited, you just had the door closed. 🌸

πŸ”‘ lowercase

Set to 1 to extract all prefixes in lowercase mode. Default value is 0.

ATTENTION: This does not mean that prefixes with uppercased characters won't be extracted. It means they will be extracted after being lowercased. so nothing gets ghosted β€” it just gets a glow-down into lowercase before it's counted. πŸ’€
  # this...
  get_prefixes( {min => 2, max => 2, lowercase => 1}, "Hello, hello");

  # returns this:
    {
      2 => {
             'he' => 2
           }
    }

"Hello, hello" β€” two different capitalisations, one single 'he' => 2. that's normalising and it ate. πŸ“


πŸ’€ TO DO πŸ’€

the devs left us a little note and it is deeply relatable:

  • Make it more efficient (use C for that)

the way that "use C for that" is doing so much emotional labour in nine characters. 😭


🫢 AUTHOR 🫢

Jose Castro, "<cog@cpan.org>"


Copyright 2004 Jose Castro, All Rights Reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


and that's the whole thing, bestie! no cap, you now understand prefixes, suffixes, exclude_numbers, lowercase, and the entire emotional journey of this module. go forth and count some word chunks. πŸ’œ

perl v5.36.0 ✦ 2022-10-13 ✦ Text::Affixes(3pm) β€” mwah, go slay πŸ¦‹βœ¨

πŸ“¦ where this page comes from