phonetics 4.0.0-x86_64-darwin
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +32 -0
- data/.rspec +3 -0
- data/.rubocop.yml +50 -0
- data/CHANGELOG +4 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Dockerfile +15 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +50 -0
- data/Rakefile +73 -0
- data/VERSION +1 -0
- data/_site/orthographic_levenshtein_example.png +0 -0
- data/_site/phonetic_levenshtein_example.png +0 -0
- data/_site/vowel_chart_b_words.jpg +0 -0
- data/bin/console +13 -0
- data/bin/gempush-if-changed +19 -0
- data/bin/phonetics +89 -0
- data/ext/phonetics_ruby/vendor/phonetics/README.md +29 -0
- data/lib/common_ipa_transcriptions.json +905980 -0
- data/lib/phonetics/3.2/phonetics_ruby.bundle +0 -0
- data/lib/phonetics/3.3/phonetics_ruby.bundle +0 -0
- data/lib/phonetics/3.4/phonetics_ruby.bundle +0 -0
- data/lib/phonetics/transcriptions.rb +167 -0
- data/lib/phonetics/version.rb +5 -0
- data/lib/phonetics.rb +79 -0
- data/phonetics.gemspec +55 -0
- metadata +149 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: c663433a5586f7094351b94e1122dc8b6eb9c0f54865173da74b3807003d143b
|
|
4
|
+
data.tar.gz: 6492f4be7ac860c5e610ed1d6ba2bd5de01271545d620300b3b528f7727c836e
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ba6120dd761a21daad7c52535c9f3e1177182445723188decadb89fe429cd2c8d171569765649cc8281df8fdd65a05735aeefa4e0021be8951516bb118b0aa4d
|
|
7
|
+
data.tar.gz: 7c13fa4c9d5584a7043a60c076c33fdaae356d609df9dc2b3e36cad5c2d2c97b5694d2c1b0009287cd0aca8dcff6aa42ae461f2eb380f520bb549dd34f06a824
|
data/.gitignore
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/.bundle/
|
|
2
|
+
/.yardoc
|
|
3
|
+
/_yardoc/
|
|
4
|
+
/coverage/
|
|
5
|
+
/doc/
|
|
6
|
+
/pkg/
|
|
7
|
+
/spec/reports/
|
|
8
|
+
/tmp/
|
|
9
|
+
|
|
10
|
+
# rspec failure tracking
|
|
11
|
+
.rspec_status
|
|
12
|
+
.ruby-version
|
|
13
|
+
*.so
|
|
14
|
+
Gemfile.lock
|
|
15
|
+
*.bundle
|
|
16
|
+
*.bundle.dSYM
|
|
17
|
+
|
|
18
|
+
# Rust extension build artifacts (mkmf-generated)
|
|
19
|
+
ext/phonetics_ruby/Makefile
|
|
20
|
+
ext/phonetics_ruby/Cargo.lock
|
|
21
|
+
ext/phonetics_ruby/target/
|
|
22
|
+
ext/phonetics_ruby/mkmf.log
|
|
23
|
+
|
|
24
|
+
# Vendored Rust core. Populated by `rake vendor_rust`; shipped in
|
|
25
|
+
# the .gem tarball but not tracked in git (single source of truth
|
|
26
|
+
# lives at <repo>/rust/phonetics).
|
|
27
|
+
ext/phonetics_ruby/vendor/
|
|
28
|
+
|
|
29
|
+
# Cargo workspace build artifacts (the gem-local workspace at
|
|
30
|
+
# ruby/Cargo.toml puts its target/ at ruby/target).
|
|
31
|
+
target/
|
|
32
|
+
Cargo.lock
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
AllCops:
|
|
3
|
+
Exclude:
|
|
4
|
+
- Rakefile
|
|
5
|
+
- tmp/**/*
|
|
6
|
+
|
|
7
|
+
Layout/LineLength:
|
|
8
|
+
Enabled: false
|
|
9
|
+
|
|
10
|
+
Metrics/AbcSize:
|
|
11
|
+
Enabled: false
|
|
12
|
+
|
|
13
|
+
Metrics/ClassLength:
|
|
14
|
+
Enabled: false
|
|
15
|
+
|
|
16
|
+
Metrics/BlockLength:
|
|
17
|
+
Enabled: false
|
|
18
|
+
|
|
19
|
+
Metrics/MethodLength:
|
|
20
|
+
Enabled: false
|
|
21
|
+
|
|
22
|
+
Naming/ConstantName:
|
|
23
|
+
Enabled: false
|
|
24
|
+
|
|
25
|
+
Naming/MethodParameterName:
|
|
26
|
+
Enabled: false
|
|
27
|
+
|
|
28
|
+
Style/Documentation:
|
|
29
|
+
Enabled: false
|
|
30
|
+
|
|
31
|
+
Style/AsciiComments:
|
|
32
|
+
Enabled: false
|
|
33
|
+
|
|
34
|
+
Style/ModuleFunction:
|
|
35
|
+
EnforcedStyle: extend_self
|
|
36
|
+
|
|
37
|
+
Style/MultilineBlockChain:
|
|
38
|
+
Enabled: false
|
|
39
|
+
|
|
40
|
+
Style/NumericPredicate:
|
|
41
|
+
Enabled: false
|
|
42
|
+
|
|
43
|
+
Style/TrailingCommaInHashLiteral:
|
|
44
|
+
EnforcedStyleForMultiline: consistent_comma
|
|
45
|
+
|
|
46
|
+
Layout/HashAlignment:
|
|
47
|
+
EnforcedHashRocketStyle: separator
|
|
48
|
+
|
|
49
|
+
Gemspec/RequiredRubyVersion:
|
|
50
|
+
Enabled: false
|
data/CHANGELOG
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at github@jackcanty.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Dockerfile
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
FROM ruby:latest
|
|
2
|
+
|
|
3
|
+
RUN apt update
|
|
4
|
+
RUN apt install -y valgrind
|
|
5
|
+
|
|
6
|
+
RUN mkdir /app
|
|
7
|
+
WORKDIR /app
|
|
8
|
+
|
|
9
|
+
COPY Gemfile /app/Gemfile
|
|
10
|
+
COPY Gemfile.lock /app/Gemfile.lock
|
|
11
|
+
COPY phonetics.gemspec /app/phonetics.gemspec
|
|
12
|
+
COPY VERSION /app/VERSION
|
|
13
|
+
|
|
14
|
+
RUN bundle
|
|
15
|
+
RUN apt install -y vim
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Jack Danger
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Phonetics
|
|
2
|
+
|
|
3
|
+
This library currently provides three utilities for anyone working with the International Phonetic Alphabet:
|
|
4
|
+
* An index of vowels and consonants with their linguistic features
|
|
5
|
+
* A phonetic implementation of the Levenshtein distance calculation
|
|
6
|
+
* English transcriptions for ~140,000 words from a variety of sources
|
|
7
|
+
|
|
8
|
+
## Exploring vowels and consonants
|
|
9
|
+
|
|
10
|
+
Vowels are sounds with unimpeded airflow. We categorize them by the resonant frequencies they make in our vocal tract. When a person changes their tongue position or the rounding of their lips they change the way the sound reverberates in their skull.
|
|
11
|
+
|
|
12
|
+
The primary classification for vowels is the frequency of their lowest two resonant frequencies (called 'formants'). When we plot these on an x/y axis we get a vowel chart like this:
|
|
13
|
+
|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## Phonetic Levenshtein Distance
|
|
18
|
+
Using a typical 'edit distance' algorithm, we can calculate how many
|
|
19
|
+
orthographic changes are needed to transform one string into another.
|
|
20
|
+
```
|
|
21
|
+
require 'damerau-levenshtein'
|
|
22
|
+
Levenshtein.distance('coorslight', 'budlight')
|
|
23
|
+
=> 5
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The `phonetics` gem provides a (very fast) implementation of an edit distance
|
|
27
|
+
algorithm that uses phonetic feature sets (for consonants) and precise formant
|
|
28
|
+
measurements (for vowels) as weights. It's a modified version of [Using
|
|
29
|
+
Phonologically Weighted Levenshtein Distances for the Prediction of Microscopic
|
|
30
|
+
Intelligibility](https://hal.archives-ouvertes.fr/hal-01474904/document) by
|
|
31
|
+
Lionel Fontan, Isabelle Ferrané, Jérôme Farinas, Julien Pinquier, Xavier
|
|
32
|
+
Aumont, 2016
|
|
33
|
+
|
|
34
|
+
With this, the input strings must be valid IPA notation and the output is a phonetic-weighted distance:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
require 'phonetics'
|
|
38
|
+
Phonetics::Levenshtein.distance('kuɹzlɑɪt', 'bədlɑɪt')
|
|
39
|
+
=> 1.388384
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Contributing
|
|
43
|
+
|
|
44
|
+
Patches welcome, forks celebrated.
|
|
45
|
+
|
|
46
|
+
Everyone interacting in the Phonetics project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/JackDanger/phonetics/blob/master/CODE_OF_CONDUCT.md).
|
|
47
|
+
|
|
48
|
+
## License
|
|
49
|
+
|
|
50
|
+
The gem is available as open source under the wide-open terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Rake tasks for the Rust-backed Ruby gem.
|
|
4
|
+
#
|
|
5
|
+
# rake compile build the native extension via cargo
|
|
6
|
+
# rake spec run rspec
|
|
7
|
+
# rake build assemble the source gem (vendor + package)
|
|
8
|
+
#
|
|
9
|
+
# Cross-platform native gem builds use rb-sys-dock; see
|
|
10
|
+
# .github/workflows/release.yml for the published recipe.
|
|
11
|
+
|
|
12
|
+
require 'fileutils'
|
|
13
|
+
require 'bundler/gem_tasks'
|
|
14
|
+
|
|
15
|
+
# ---------------------------------------------------------------
|
|
16
|
+
# Vendoring of the Rust core into the gem directory.
|
|
17
|
+
#
|
|
18
|
+
# A gem can't ship files from outside its own directory (rubygems
|
|
19
|
+
# policy), and `cargo` can't follow a path dependency that points
|
|
20
|
+
# up into the parent of a `gem install`-extracted source tree. So
|
|
21
|
+
# we keep the canonical Rust core at <repo>/rust/phonetics and
|
|
22
|
+
# copy it into <repo>/ruby/ext/phonetics_ruby/vendor/ for builds
|
|
23
|
+
# that need to ship it (gem-build, gem-install, CI).
|
|
24
|
+
#
|
|
25
|
+
# The vendor copy is git-ignored — single source of truth is the
|
|
26
|
+
# /rust/ tree. It IS bundled into the .gem tarball at build time.
|
|
27
|
+
# ---------------------------------------------------------------
|
|
28
|
+
|
|
29
|
+
RUST_CORE_SRC = File.expand_path('../rust/phonetics', __dir__)
|
|
30
|
+
RUST_CORE_VENDOR = File.expand_path('ext/phonetics_ruby/vendor/phonetics', __dir__)
|
|
31
|
+
|
|
32
|
+
def vendor_rust_core
|
|
33
|
+
return if File.directory?(RUST_CORE_SRC).nil?
|
|
34
|
+
|
|
35
|
+
unless File.directory?(RUST_CORE_SRC)
|
|
36
|
+
warn "(skipping vendor: #{RUST_CORE_SRC} not present)" if ENV['VERBOSE']
|
|
37
|
+
return
|
|
38
|
+
end
|
|
39
|
+
FileUtils.rm_rf(RUST_CORE_VENDOR)
|
|
40
|
+
FileUtils.mkdir_p(File.dirname(RUST_CORE_VENDOR))
|
|
41
|
+
FileUtils.cp_r(RUST_CORE_SRC, RUST_CORE_VENDOR)
|
|
42
|
+
# Strip the CLI bin and any stale build artifacts.
|
|
43
|
+
FileUtils.rm_rf(File.join(RUST_CORE_VENDOR, 'src', 'bin'))
|
|
44
|
+
FileUtils.rm_rf(File.join(RUST_CORE_VENDOR, 'target'))
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# The downstream Cargo workspace at ruby/Cargo.toml lists the ext
|
|
48
|
+
# crate as a member, and that crate's Cargo.toml has a path
|
|
49
|
+
# dependency on vendor/phonetics. `cargo metadata` (which
|
|
50
|
+
# `rb_sys/extensiontask` runs at load time) would fail before our
|
|
51
|
+
# tasks even register. Vendor synchronously here, before any
|
|
52
|
+
# require touches cargo.
|
|
53
|
+
vendor_rust_core
|
|
54
|
+
|
|
55
|
+
require 'rb_sys/extensiontask'
|
|
56
|
+
require 'rspec/core/rake_task'
|
|
57
|
+
|
|
58
|
+
desc 'Re-copy the Rust core into ext/phonetics_ruby/vendor/'
|
|
59
|
+
task(:vendor_rust) { vendor_rust_core }
|
|
60
|
+
|
|
61
|
+
GEMSPEC = Gem::Specification.load(File.expand_path('phonetics.gemspec', __dir__))
|
|
62
|
+
|
|
63
|
+
RbSys::ExtensionTask.new('phonetics_ruby', GEMSPEC) do |ext|
|
|
64
|
+
ext.lib_dir = 'lib/phonetics'
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# build / compile both depend on a fresh vendor copy.
|
|
68
|
+
task compile: :vendor_rust
|
|
69
|
+
task build: :vendor_rust
|
|
70
|
+
|
|
71
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
72
|
+
|
|
73
|
+
task default: %i[compile spec]
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
4.0.0
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/bin/console
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
$LOAD_PATH << '../lib'
|
|
5
|
+
|
|
6
|
+
require 'bundler/setup'
|
|
7
|
+
require 'pry-byebug'
|
|
8
|
+
require 'phonetics'
|
|
9
|
+
require 'phonetics/levenshtein'
|
|
10
|
+
require 'phonetics/ruby_levenshtein'
|
|
11
|
+
require 'phonetics/code_generator'
|
|
12
|
+
|
|
13
|
+
Phonetics.pry
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
set -x
|
|
4
|
+
|
|
5
|
+
# 'latest' is a git tag that we recreate every time we release a new
|
|
6
|
+
# version. If the VERSION file has changed since `latest` then we release a
|
|
7
|
+
# new version.
|
|
8
|
+
git pull --tags
|
|
9
|
+
if git diff --name-only HEAD latest -- VERSION | egrep -q .; then
|
|
10
|
+
# The VERSION file changed since 'latest', build the gem and push
|
|
11
|
+
gem build *.gemspec
|
|
12
|
+
gem push *.gem
|
|
13
|
+
|
|
14
|
+
git tag -f latest HEAD
|
|
15
|
+
git tag -f "v$(cat VERSION)"
|
|
16
|
+
|
|
17
|
+
git push -f origin latest
|
|
18
|
+
git push --tags
|
|
19
|
+
fi
|
data/bin/phonetics
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
# Phonetics CLI — implementation-agnostic contract.
|
|
5
|
+
#
|
|
6
|
+
# The integration tests in spec/phonetics/cli_spec.rb shell out to this
|
|
7
|
+
# binary (or any other one — set PHONETICS_BIN). What matters is
|
|
8
|
+
# stdin/stdout/exit-code behaviour, not which language fields the
|
|
9
|
+
# Phonetics module. With the Rust port live, this script is a thin
|
|
10
|
+
# layer over the Magnus binding.
|
|
11
|
+
|
|
12
|
+
$stdout.set_encoding('UTF-8')
|
|
13
|
+
$stderr.set_encoding('UTF-8')
|
|
14
|
+
|
|
15
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
|
|
16
|
+
require 'phonetics'
|
|
17
|
+
|
|
18
|
+
USAGE = <<~USAGE
|
|
19
|
+
Usage: phonetics <command> [args...]
|
|
20
|
+
|
|
21
|
+
Phrase-level distances (input: IPA strings, possibly with spaces):
|
|
22
|
+
distance <ipa1> <ipa2> Strict phonetic Levenshtein.
|
|
23
|
+
confusion <ipa1> <ipa2> Listener-confusion distance.
|
|
24
|
+
similarity <ipa1> <ipa2> 0..1 normalised similarity.
|
|
25
|
+
|
|
26
|
+
Phoneme-level distances (input: single phonemes):
|
|
27
|
+
phoneme <a> <b> Acoustic distance.
|
|
28
|
+
phoneme-conf <a> <b> Perceptual distance (with overlay).
|
|
29
|
+
|
|
30
|
+
Tokenisation:
|
|
31
|
+
tokenize [--boundaries] <ipa> Phoneme stream, one per line.
|
|
32
|
+
|
|
33
|
+
Numeric output is a single line. With --json, output is a JSON object.
|
|
34
|
+
USAGE
|
|
35
|
+
|
|
36
|
+
def die(message, code = 2)
|
|
37
|
+
warn message
|
|
38
|
+
exit code
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def format_number(value, json:)
|
|
42
|
+
return JSON.dump(value: value) if json
|
|
43
|
+
|
|
44
|
+
value.to_s
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
json = !ARGV.delete('--json').nil?
|
|
48
|
+
bounds = !ARGV.delete('--boundaries').nil?
|
|
49
|
+
|
|
50
|
+
command, *args = ARGV
|
|
51
|
+
require 'json' if json
|
|
52
|
+
|
|
53
|
+
case command
|
|
54
|
+
when 'distance'
|
|
55
|
+
die USAGE unless args.size == 2
|
|
56
|
+
puts format_number(Phonetics.levenshtein(args[0], args[1]), json: json)
|
|
57
|
+
|
|
58
|
+
when 'confusion'
|
|
59
|
+
die USAGE unless args.size == 2
|
|
60
|
+
puts format_number(Phonetics.confusion(args[0], args[1]), json: json)
|
|
61
|
+
|
|
62
|
+
when 'similarity'
|
|
63
|
+
die USAGE unless args.size == 2
|
|
64
|
+
puts format_number(Phonetics.similarity(args[0], args[1]), json: json)
|
|
65
|
+
|
|
66
|
+
when 'phoneme'
|
|
67
|
+
die USAGE unless args.size == 2
|
|
68
|
+
puts format_number(Phonetics.distance(args[0], args[1]), json: json)
|
|
69
|
+
|
|
70
|
+
when 'phoneme-conf'
|
|
71
|
+
die USAGE unless args.size == 2
|
|
72
|
+
puts format_number(Phonetics.sub_cost(args[0], args[1]), json: json)
|
|
73
|
+
|
|
74
|
+
when 'tokenize'
|
|
75
|
+
die USAGE unless args.size == 1
|
|
76
|
+
|
|
77
|
+
tokens = Phonetics.tokenize(args[0], boundaries: bounds)
|
|
78
|
+
if json
|
|
79
|
+
puts JSON.dump(tokens: tokens)
|
|
80
|
+
else
|
|
81
|
+
puts tokens
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
when '--help', '-h', nil
|
|
85
|
+
puts USAGE
|
|
86
|
+
|
|
87
|
+
else
|
|
88
|
+
die "phonetics: unknown command #{command.inspect}\n\n#{USAGE}"
|
|
89
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# phonetics
|
|
2
|
+
|
|
3
|
+
IPA-based phonetic distance metrics for Rust.
|
|
4
|
+
|
|
5
|
+
Two scores live in this crate:
|
|
6
|
+
|
|
7
|
+
* **`distance(a, b)`** — strict per-phoneme acoustic distance over IPA
|
|
8
|
+
phonemes (Bark-space vowel distance, 2D consonant place embedding,
|
|
9
|
+
approximant–vowel bridge, diphthong/affricate handling).
|
|
10
|
+
* **`Confusion::distance(s1, s2)`** — listener-confusion distance over
|
|
11
|
+
whole phonemic strings, calibrated against Mad Gab puzzle data and
|
|
12
|
+
English speech-perception literature.
|
|
13
|
+
|
|
14
|
+
The split is the point. The first is a claim about the waveform; the
|
|
15
|
+
second is a claim about how a listener parses it. They give different
|
|
16
|
+
answers to different questions.
|
|
17
|
+
|
|
18
|
+
This is a port of the Ruby gem of the same name; see the parent
|
|
19
|
+
repository for an extended write-up of the metric design.
|
|
20
|
+
|
|
21
|
+
## Status
|
|
22
|
+
|
|
23
|
+
Pre-1.0. Core data tables and the per-phoneme acoustic distance are
|
|
24
|
+
parity-tested against the Ruby reference. Levenshtein and Confusion DPs
|
|
25
|
+
are landing module-by-module.
|
|
26
|
+
|
|
27
|
+
## License
|
|
28
|
+
|
|
29
|
+
MIT.
|