Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next version #10

Merged
merged 39 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
084c927
save work
tbrowder Jun 7, 2023
91f509a
chg to demo diff, if any, in order of sorts
tbrowder Jun 10, 2023
22b668d
test 2 looks good
tbrowder Jun 11, 2023
e30785c
good tests
tbrowder Jun 11, 2023
27ec016
tests look good
tbrowder Jun 12, 2023
809ba83
looking good
tbrowder Jun 12, 2023
7caf55d
remove the unneeded export trait
tbrowder Jun 12, 2023
3e700fd
Changes looking good
tbrowder Jun 12, 2023
b89b674
added Numerc type for sort-list
tbrowder Jun 14, 2023
6e60ae1
add test for Numeric sorting
tbrowder Jun 14, 2023
b1a59b5
test an input set type
tbrowder Jun 14, 2023
3708212
preview docs aftet a build
tbrowder Jun 14, 2023
f439c6f
rebuild after doc tweak
tbrowder Jun 14, 2023
a5e1f66
rebuild after doc tweak
tbrowder Jun 14, 2023
9bb7693
rebuild after doc tweak
tbrowder Jun 14, 2023
685baa4
rebuild after another doc tweak
tbrowder Jun 14, 2023
8e5c27b
2.1.0
tbrowder Jun 14, 2023
3194ba7
add the next change
tbrowder Jan 18, 2024
19805e1
add new capability
tbrowder Jan 18, 2024
2fa9913
reorder
tbrowder Jan 18, 2024
d75ef54
update windows.yml test to use zef
tbrowder Jan 19, 2024
84888d8
try to fix test
tbrowder Jan 19, 2024
2af5458
save work, need to fix README and tidy code
tbrowder Jan 19, 2024
b901dff
add info
tbrowder Jan 19, 2024
15378c0
add tests
tbrowder Jan 19, 2024
3aa6c01
save work
tbrowder Jan 19, 2024
b3a30dc
save work
tbrowder Jan 19, 2024
62c423d
making progress, rename tests for convenience
tbrowder Jan 19, 2024
ec7ae13
save work
tbrowder Jan 19, 2024
22c0ce7
save work
tbrowder Jan 19, 2024
f00bab5
save work
tbrowder Jan 19, 2024
f77acf2
save after rebuild
tbrowder Jan 19, 2024
0835b36
save work
tbrowder Jan 19, 2024
329dc4e
save work
tbrowder Jan 20, 2024
3630704
save work
tbrowder Jan 20, 2024
c84b54b
got test 9 working
tbrowder Jan 20, 2024
0df5b9a
rebuild prior to publishing
tbrowder Jan 20, 2024
af3be94
tweak docs and rebuild
tbrowder Jan 20, 2024
29c3a8b
Merge branch 'master' into next-ver
tbrowder Jan 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Linux

on:
push:
branches:
- '*'
tags-ignore:
- '*'
pull_request:

jobs:
raku:
strategy:
matrix:
os:
- ubuntu-latest
raku-version:
- 'latest'
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: Raku/setup-raku@v1
with:
raku-version: ${{ matrix.raku-version }}
- name: Install Dependencies
run: |
zef install --/test --deps-only .
zef install --/test App::Prove6
- name: Run Tests
run: prove6 -l t
30 changes: 30 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: MacOS

on:
push:
branches:
- '*'
tags-ignore:
- '*'
pull_request:

jobs:
raku:
strategy:
matrix:
os:
- macos-latest
raku-version:
- 'latest'
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: Raku/setup-raku@v1
with:
raku-version: ${{ matrix.raku-version }}
- name: Install Dependencies
run: |
zef install --/test --deps-only .
zef install --/test App::Prove6
- name: Run Tests
run: prove6 -l t
32 changes: 0 additions & 32 deletions .github/workflows/test.yml

This file was deleted.

28 changes: 28 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Win64

on:
push:
branches:
- '*'
tags-ignore:
- '*'
pull_request:

jobs:
raku:
strategy:
matrix:
os:
- windows-latest
raku-version:
- 'latest'
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: Raku/setup-raku@v1
with:
raku-version: ${{ matrix.raku-version }}
- name: Install Dependencies
run: zef install --/test --test-depends --deps-only .
- name: Run Tests
run: zef --debug --/prove --/tap-harness test .
27 changes: 27 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,4 +1,31 @@
{{$NEXT}}
- Make the default output for a single word be a
suitable word for an arg regex selection, e.g.,
abbrev "Args" => "A|Ar|Arg|Args"
+ Add info in the README
- Separate tests into one for each arg
- Add t/Utils/Subs.rakumod with a 'test-junction' routine

2.1.0 2023-06-14T16:05:14-05:00
- Removed the unneeded 'is export' trait from sub 'abbreviations'.
- Improved sorting routines for consistency and expected results
by using an updated 'sort-list' function to clarify the
type and order of the various sorting types
defined.
+ Added an enum Sort-type to define the sort types
+ Made the default sort type LS (length first,
then by string order).
+ Added an option to reverse the output
+ Added tests
- Updated the README for improved grammar and better
coverage of details.
- Added a :$min-length parameter for abbreviations.
- Created a new output format: HA (Hash Abbrev)
consisting of the word as key and its shortest
abbreviation as its value.
+ added tests for it
- Made the default output the HA type.
- Use the three-OS test workflow.

2.0.0 2022-07-23T17:49:28-05:00
- Remove the auto-abbreviate sub and rewrite the get-abbrevs sub
Expand Down
2 changes: 1 addition & 1 deletion META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
],
"test-depends": [
],
"version": "2.0.0"
"version": "2.1.0"
}
116 changes: 89 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,73 @@
[![Actions Status](https://github.com/tbrowder/Abbreviations/actions/workflows/linux.yml/badge.svg)](https://github.com/tbrowder/Abbreviations/actions) [![Actions Status](https://github.com/tbrowder/Abbreviations/actions/workflows/macos.yml/badge.svg)](https://github.com/tbrowder/Abbreviations/actions) [![Actions Status](https://github.com/tbrowder/Abbreviations/actions/workflows/windows.yml/badge.svg)](https://github.com/tbrowder/Abbreviations/actions)

NAME
====

**Abbreviations** - Provides abbreviations for an input set of one or more words
Abbreviations - Provides abbreviations for an input set of one or more words

SYNOPSIS
========

```raku
use Abbreviations;
my $words = 'A ab Abcde';
# The exported routine:
# The main exported routine:
my %abbrevs = abbreviations $words;
say %abbrevs.gist;
# OUTPUT: «{A => A, Abcde => Ab, ab => a}␤»
```

There are two shorter routine name abbreviations one can use that are always exported:
DESCRIPTION
===========

**Abbreviations** is a module with one automatically exported subroutine, `abbreviations`, which takes as input a set of words and returns the original set with added unique abbreviations for the set. (Note the input words are also abbreviations in the context of this module.)

Its signature:

sub abbreviations($word-set, #= Str, List, or Hash (Set)
:$out-type = HA, #= the default, HashAbbrev
:$lower-case, #= convert the word st to lowercase
:$min-length, #= minimum abbreviation length
) is export {...}

A *word* satisfies the Raku regex `$word ~~ /\S+/` which is quite loose. Using programs can of course further restrict that if need be. For example, for use with module **Opt::Handler** words must satisfy this regex: `$word ~~ /<ident>/`.

A natural consequence of generating all the abbreviations for a set of one word is this: the output provides a regex alternation which matches any partial length of the target word. For example, given a target word 'Args':

use Abbreviations;
use Test;
my $target = "Args";
my $regex = abbrev $target; # OUTPUT: «"A|Ar|Arg|Args"␤»;
my $res = False;
my @w = $regex.split('|');
for @w {
when /<$regex>/ {
$res = True
}
default {
$res = False
}
}
is $res, True; # OUTPUT: «ok 1␤»

As shown in the example above, limiting the input set to one word results in the output of a regex alternation string. The rest of this description applies to sets of two or more words. The input word set can be in one of three forms: (1) a list (recommended), (2) a string containing the words separated by spaces, or (3) as a hash (or set) with the words being keys of the hash (set members). Duplicate words will be automatically and quietly eliminated.

Note the input word set will not be modified unless the `:lower-case` option is used. In that case, all characters will be transformed to lower-case and any new duplicate words deleted.

If the user wishes, he or she can restrict the minimum length of the generated abbreviations by using the `:$min-length` parameter.

One will normally get the result as a hash with the input words as keys with their shortest abbreviation as values (return type HA), but the return type can be specified via `enum Out-type` if desired by selecting one of the `:$output-type` options. For example:

my %abbrevs = abbrevs @words, :output-type(AH);

There are two shorter alias names for `sub abbreviations` one can use that are always exported:

```raku
abbrevs
abbrev
```

In the sprit of the module, one can `use Abbreviations :ALL;` and have these additional short forms available:
In the sprit of the module, one can `use Abbreviations :ALL;` and have these additional shorter alias names available:

```raku
abbre
Expand All @@ -30,33 +77,26 @@ In the sprit of the module, one can `use Abbreviations :ALL;` and have these add
a
```

Each of those is individually available by adding its name as an adverb, e.g.:
Each of those is individually available by adding its name as an adverb, for example:

```raku
use Abbreviations :abb;
my %abb = abb $words;
```

DESCRIPTION
===========

**Abbreviations** is a module with one automatically exported subroutine, `abbreviations`, which takes as input a set of words and returns the original set with added unique abbreviations for the set. (Note the input words are also abbreviations in the context of this module.)

A *word* satisfies the Raku regex `$word ~~ /\S+/` which is quite loose. Using programs can of course further restrict that if need be. For example, for use with module **Opt::Handler** words must satisfy this regex: `$word ~~ /<ident>/`. (**CAUTION**: Words containing other than letters have not been tested and results are unknown. The author is willing to investigate those words if any user is so interested and files an issue indicating such.)

The input word set can be in one of two forms: a list or a string containing the words separated by spaces. Duplicate words will be automatically and quietly eliminated. An empty word set will cause an exception.
### `enum Out-type`

Note the input word set will not be modified unless the `:lower-case` option is used. In that case, all characters will be transformed to lower-case.
enum Out-type is export <HA H AH AL L S >;

One will normally get the result as a hash, but the return type can be specified via an `enum` if desired by selecting one of the `:out-type` options: `AH` (AbbrevHash), `AL` (AbbrevList), `H` (Hash), `L` (List), or `S` (String). For example,
The *enum* `Out-type` is exported automatically as it is required for using `sub abbreviations`. It has the following types:

my %abbrevs = abbrevs @words, :out-type(AH);
* `HA` (HashAbbrev)

### Output types by `enum Out-type`
The default *HashAbbrev* (`HA`) returned will have input words as keys whose value will be the shortest valid abbreviation.

* `H` (Hash)

The default *Hash* (`H`) returned will have input words as keys whose value will be a sorted list of one or more valid abbreviations (sorted by length, shortest first).
A variant of `HA`, the *Hash* (`H`) returned will have input words as keys whose value will be a sorted list of its valid abbreviations (sorted by length, shortest first, then by `Str` order).

* `AH` (AbbrevHash)

Expand All @@ -67,20 +107,25 @@ An *AbbrevHash* (`AH`) is keyed by all of the valid abbreviations for the input
An *AbbrevList* (`AL`) is special in that the returned list is the one, shortest abbreviation for each of the input words in input order. For example,

my @w = <Monday Tuesday Wednesday Thursday Friday Saturday Sunday>;
my @abb = abbrevs @w, :lower-case, :out-type(AL);
say @abb; # OUTPUT: «[m tu w th f sa su]␤»
my @abb = abbrevs @w, :output-type(AL);
say @abb; # OUTPUT: «M Tu W Th F Sa Su␤»

Note that a hash (or set) input type will not reliably provide this output as expected since the keys are not stored in order. Instead, the ouput will be based on a list of the hash's keys. In effect, entering `%out = abbreviations %in` is the same as:

my @inputlist = %in.keys.sort({.chars, .Str}';
my %out = abbreviations @inputlist;

* `L` (List)

A *List* (`L`) contains all of the valid abbreviations for the input word list, including the words themselves, sorted first by the default Raku sort and then by length (shortest first).
A *List* (`L`) contains all of the valid abbreviations for the input word list, including the words themselves, sorted by length, then character order.

* `S` (String)

A *String* (`S`) is the string formed by joining the *List* by a single space between words.

### Improved abbreviation search

The abbreviation algorithm has been improved in the following way: The input word set is formed into subgroups comprised of each input word. Abbreviations are created for each word, abbreviations shared by two or words are eliminated, then all those abbreviations are combined into one set. The result will be the largest possible set of unique abbreviations for a given input word set.
The abbreviation algorithm has been improved from the original (as found on [https://rosettacode.org](https://rosettacode.org)) in the following way: The input word set is formed into subgroups comprised of each input word. Abbreviations are created for each word, abbreviations shared by two or words are eliminated, then all those abbreviations are combined into one set. The result will be the largest possible set of unique abbreviations for a given input word set.

For example, given an input set consisting of the words `A ab Abcde`, the default output hash of abbreviations (with the original words as keys) contains a total of seven abbreviations:

Expand All @@ -99,18 +144,35 @@ The result is
ab => ['ab],
abcde => ['abc', 'abcd', 'abcde'],

Notice the input word **ab** now has only one abbreviation and **abcde** has only three.

Other exported symbols
----------------------

### `sub sort-list`

sub sort-list(@list, :longest-first --> List) is export(:sort) {...}
sub sort-list(@list, :$type = SL, :$reverse --> List) is export(:sort)
{...}

This routine sorts the input list first by the default Raku sort and then by word length. The order by length is by shortest abbreviation first unless the `:longest-first` option is used. This is the routine used for all the lists produced as output in this module *except* for the *AbbrevList* (`AL`) which keeps the original word set order.
By default, this routine sorts all lists by word length, then by Str order. The order by length is by the shortest abbreviation first unless the `:$reverse` option is used. This is the routine used for all the output types produced by this module *except* the *AbbrevList* (`AL`) which keeps the original word set order.

### `enum Out-type`
The routine's output can be modified for other uses by entering the `:$type` parameter to choose another of the <enum Sort-type>s.

### `enum Sort-type`

enum Sort-type is export(:sort) < SL LS SS LL N>;

The `Sort-type`s are:

* SL - order by Str, then order by Length

* LS - order by Length, then order by Str

* SS - Str order only

* LL - Length order only

The *enum* `Out-type` is exported automatically as it is required for use of `sub abbreviations`.
* N - Numerical order only (falls back to SS if any words are not numbers)

AUTHOR
======
Expand All @@ -129,7 +191,7 @@ CREDITS
COPYRIGHT and LICENSE
=====================

Copyright © 2020-2022 Tom Browder
Copyright © 2020-2023 Tom Browder

This library is free software; you may redistribute or modify it under the Artistic License 2.0.

File renamed without changes.
Loading