NAME
Lingua::Conjunction - Convert lists into linguistic conjunctions and fill them into a template
SYNOPSIS
use Lingua::Conjunction;
say conjunction <chair>; # chair
say conjunction <chair spoon>; # chair and spoon
say conjunction <chair spoon window>; # chair, spoon, and window
# "Tom, a man; Tiffany, a woman; and GumbyBRAIN, a bot"
say conjunction 'Tom, a man', 'Tiffany, a woman', 'GumbyBRAIN, a bot';
# These are reports for May, June, and August
say conjunction <May June August>, :str('These [is|are] report[|s] for |list|');
# "Jacques, un garcon; Jeanne, une fille et Spot, un chien"
say conjunction 'Jacques, un garcon', 'Jeanne, une fille', 'Spot, un chien',
:lang<fr>;
DESCRIPTION
Provides a way to make it easy to prepare a string containing a list of items, where that string is meant to be read by a human.
EXPORTED SUBROUTINES
conjunction
say conjunction <chair spoon>;
say conjunction <May June August>, :str('Report[|s] for |list|'),
:lang<fr>, :!last, :sep<·>, :alt<°>, :con<aaand>, :dis<ooor>, :type<or>;
Returns a string with the given list of items joined based on the configuration specified by the named arguments, which are as follows:
alt
Specifies an alternative separator to use when at least one of the items contains sep
separator. Defaults to ;
(a semicolon).
head3 con
Short for conjunction. The term to use when joining the last item to the previous one, when type
argument is set to value and
. By default is set based on value of lang
argument.
dis
Short for disjunction. The term to use when joining the last item to the previous one, when type
argument is set to value or
. By default is set based on value of lang
argument.
lang
Takes a string representing the code of the language to use. This will pre-set con
, dis
, and last
arguments. Defaults to en
. Currently supported languages and the defaults they pre-set are as follows (language is the first two-letter key on the left; that's what you'd specify as lang
argument):
lang | last | con | dis | |
---|
af | True | en | of | |
da | True | og | eller | |
de | True | und | oder | |
en | True | and | or | |
es | True | y | o | |
fi | True | ja | tai | |
fr | False | et | ou | |
it | True | e | o | |
la | True | et | vel | |
nl | True | en | of | |
no | False | og | eller | |
pt | True | e | ou | |
sw | True | na | au | |
last
Specifies whether to use sep
when joining the penultimate and last elements of the list, when the number of elements is more than 2. In English, this is what's known as Oxford Comma. By default is set based on value of lang
argument.
sep
The primary item separator to use. Defaults to ,
(a comma).
str
say conjunction <May June August>, :str('Report[|s] for |list|');
say conjunction <Squishy Slushi Sushi>,
:str('Octop[us|i] [is|are] named |list|');
Specifies a template to use when generating the string. You can use special sequence [|]
(e.g. octop[us|i]
) where string to the left of the |
will be used when the list contains just one item and the string to the right will be used otherwise. The other special sequence is |list|
that will be replaced with the "conjuncted" items of the list. Defaults to |list|
.
type
Takes either value and
or value or
. Specifies whether words specified by con
or by dis
arguments should be used when joining the last two elements of the list.
AUTHOR
This module was inspired by Perl's Lingua::Conjunction and and List::ToHumanString. Some of the internal data was shamelessly stolen borrowed from Lingua::Conjunction's guts.
The rest is by Zoffix Znet (http://zoffix.com/)
COPYRIGHT AND LICENSE
Copyright 2015 - 2017 Zoffix Znet
Copyright 2020 - 2024 Raku Community
This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.