Skip to content

Commit

Permalink
Abjad convert/version/0.6.0 (#29)
Browse files Browse the repository at this point in the history
Support IPA
  • Loading branch information
amerharb authored Apr 21, 2024
1 parent 828632e commit 7e684bc
Show file tree
Hide file tree
Showing 34 changed files with 6,064 additions and 1,276 deletions.
672 changes: 336 additions & 336 deletions .yarn/releases/yarn-4.0.2.cjs → .yarn/releases/yarn-4.1.0.cjs

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
enableTransparentWorkspaces: false

nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.0.2.cjs
npmAuthToken: "${NODE_AUTH_TOKEN:-anyFallBackMockValue}"

enableTransparentWorkspaces: false
npmPublishRegistry: "https://registry.npmjs.org"

npmPublishRegistry: https://registry.npmjs.org
npmAuthToken: ${NODE_AUTH_TOKEN:-anyFallBackMockValue}
yarnPath: .yarn/releases/yarn-4.1.0.cjs
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
"node": ">=18.0.0",
"yarn": ">=4.0.0"
},
"packageManager": "yarn@4.0.2"
"packageManager": "yarn@4.1.0"
}
2 changes: 1 addition & 1 deletion packages/abjad-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"lint:fix": "npx eslint . --fix"
},
"dependencies": {
"abjad-convert": "0.5.0"
"abjad-convert": "0.6.0-next.3"
}
}
7 changes: 7 additions & 0 deletions packages/abjad-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ log(calmConvert(imperialAramaic, Abjad.ImperialAramaic, Abjad.Arabic))
log(`convert ImperialAramaic text ${imperialAramaic} to Phoenician`)
log(calmConvert(imperialAramaic, Abjad.ImperialAramaic, Abjad.Phoenician))

const ipa = 'a b c d e f g h i j k l m n o p q r s t u v w x y z'
log(`convert IPA text ${ipa} to Arabic`)
log(calmConvert(ipa, Abjad.IPA, Abjad.Arabic))
log(`convert IPA text ${ipa} to Phoenician`)
log(calmConvert(ipa, Abjad.IPA, Abjad.Phoenician))

const oldSouthArabian = '𐩱 𐩨 𐩴 𐩵'
log(`convert OldSouthArabian text ${oldSouthArabian} to Arabic`)
log(calmConvert(oldSouthArabian, Abjad.OldSouthArabian, Abjad.Arabic))
Expand All @@ -41,6 +47,7 @@ log(`convert Ugaritic text ${ugaritic} to Phoenician`)
log(calmConvert(ugaritic, Abjad.Ugaritic, Abjad.Phoenician))

log(calmConvert('مرحبا', Abjad.Arabic, Abjad.ImperialAramaic))
log(calmConvert('مرحبا', Abjad.Arabic, Abjad.IPA))
log(calmConvert('مرحبا', Abjad.Arabic, Abjad.Phoenician))
log(calmConvert('مرحبا', Abjad.Arabic, Abjad.Syriac))
log(calmConvert('مرحبا', Abjad.Arabic, Abjad.Tifinagh))
Expand Down
6 changes: 5 additions & 1 deletion packages/abjad-convert/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
# abjad-convert Changelog
<!-- https://keepachangelog.com/en/1.0.0/ -->

## [0.6.0] 2024-04-22
### Added
- Support IPA

## [0.5.0] 2024-02-17
### Added
- Support Old South Arabian
Expand Down
14 changes: 8 additions & 6 deletions packages/abjad-convert/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ export const ugaritic = new Script(
- Step #6: Add the script to the enum `Abjad` in `src/types.ts` file.
at this point we have finished adding the script, but it is an island script. Meaning that it can't be converted to or from any other script.

- Step #7: To make it convertable we need at least to have one from and one to converter to another script.
- Step #7: To make it convertable, we need at least to have one "from" and one "to" converter to another script.
the preferred way is to add a converter to and from Arabic script, as it is currently act as a de facto hub script for all abjad scripts.
The algorithm for converting will look first for 1-step converter (direct converter) the one that convert from the source to the target, in case there isn't any it will look for 2-steps approach where it can find a middle script,
after that it won't look for 3 or more steps, it will basically throw an error.
That is why Arabic is used as preferred hub, so if all script add converter to Arabic and Arabic add converter to all other scripts then all conversion is possible.
However, there is a plan in the future to add IPA to be a canonical hub script.

Since version 0.6.0 IPA (International Phonetic Alphabet) is added, it is intended to be as a canonical hub script since IPA can cover all sounds.
however, the converter can be added to and from any script.
The algorithm for converting will look first for 1-step converter (direct converter) the one that converts from the source to the target,
in case there isn't any it will look for 2-steps approach where it can find a middle script,
after that it will try 3-steps approach, after that it won't look for 4 or more steps, it will basically throw an error.
As of version 0.6.0 scripts are connected as follows:
![converters.png](doc/converters.png)
- - Adding to Arabic: Add file to `foo` folder with name `toArabic.ts` that include a class called FooToArabicConverter that implements `IConverter` interface.
it should look like this:
```ts
Expand Down
12 changes: 9 additions & 3 deletions packages/abjad-convert/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# Abjad Convert

[![Version](https://img.shields.io/badge/version-0.5.0-blue.svg)](https://github.com/amerharb/abjad/tree/abjad-convert/version/0.5.0)
[![Version](https://img.shields.io/badge/version-0.6.0-blue.svg)](https://github.com/amerharb/abjad/tree/abjad-convert/version/0.6.0)
[![License: GPLv3](https://img.shields.io/badge/License-ISC-blue.svg)](https://opensource.org/licenses/ISC)
![Coverage](https://raw.githubusercontent.com/amerharb/abjad/abjad-convert/version/0.5.0/packages/abjad-convert/badges/coverage.svg)
![Github workflow](https://github.com/amerharb/abjad/actions/workflows/lint-test.yaml/badge.svg?branch=abjad-convert/version/0.5.0)
![Coverage](https://raw.githubusercontent.com/amerharb/abjad/abjad-convert/version/0.6.0/packages/abjad-convert/badges/coverage.svg)
![Github workflow](https://github.com/amerharb/abjad/actions/workflows/lint-test.yaml/badge.svg?branch=abjad-convert/version/0.6.0)

**abjad-convert** is a package for converting Abjad alphabets phonetically.

Current supported alphabets:
- Arabic
- Imperial Aramaic
- IPA (International Phonetic Alphabet)
- Old South Arabian
- Phoenician
- Syriac
Expand All @@ -36,6 +37,9 @@ const arabicWord = 'مرحبا';
const imperialAramaicWord = convert(arabicWord, Abjad.Arabic, Abjad.ImperialAramaic);
console.log(imperialAramaicWord); // 𐡌𐡓𐡇𐡁𐡀

const ipaWord = convert(arabicWord, Abjad.Arabic, Abjad.IPA);
console.log(ipaWord); // mrħbaː

const oldSouthArabianWord = convert(arabicWord, Abjad.Arabic, Abjad.OldSouthArabian);
console.log(oldSouthArabianWord); // 𐩣𐩧𐩢𐩨𐩡

Expand All @@ -51,3 +55,5 @@ console.log(tifinaghWord); // ⵎⵔⵃⴱⴰ
const ugariticWord = convert(arabicWord, Abjad.Arabic, Abjad.Ugaritic);
console.log(ugariticWord); // 𐎎𐎗𐎈𐎁𐎀
```
## How to contribute
Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct.
2 changes: 1 addition & 1 deletion packages/abjad-convert/badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packages/abjad-convert/doc/converters.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions packages/abjad-convert/doc/converters.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@startuml
'https://plantuml.com/use-case-diagram

(Arabic) -up-> (Imperial Aramaic)
(Arabic) <-up- (Imperial Aramaic)
(Arabic) -up-> (IPA)
(Arabic) <-up- (IPA)
(Arabic) -> (Old South Arabian)
(Arabic) <- (Old South Arabian)
(Arabic) -left-> (Phoenician)
(Arabic) <-left- (Phoenician)
(Arabic) --> (Syriac)
(Arabic) <-- (Syriac)
(Arabic) --> (Tifinagh)
(Arabic) <-- (Tifinagh)
(Arabic) --> (Uguritic)
(Arabic) <-- (Uguritic)

@enduml
9 changes: 6 additions & 3 deletions packages/abjad-convert/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "abjad-convert",
"version": "0.5.0",
"version": "0.6.0",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"files": [
Expand All @@ -23,15 +23,18 @@
"phonetic",
"arabic",
"imperial-aramaic",
"IPA",
"old-south-arabian",
"phoenician",
"syriac",
"tifinagh",
"ugaritic"
],
"license": "ISC",
"scripts": {
"build": "rm -rf dist && tsc",
"start": "node dist/index.js",
"test": "jest && yarn run make-coverage-badge",
"start": "node dist/src/index.js",
"test": "jest",
"make-coverage-badge": "npx make-coverage-badge --report-path coverage/coverage-summary.json --output-path badges/coverage.svg",
"dev": "ts-node src/index.ts",
"lint": "npx eslint . --max-warnings 0",
Expand Down
21 changes: 21 additions & 0 deletions packages/abjad-convert/src/converterFactory.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Abjad } from './types'
import { IConverter } from './IConverter'
import { ArabicToImperialAramaicConverter } from './scripts/arabic/toImperialAramaic'
import { ArabicToIpaConverter } from './scripts/arabic/toIpa'
import { ArabicToOldSouthArabianConverter } from './scripts/arabic/toOldSouthArabian'
import { ArabicToPhoenicianConverter } from './scripts/arabic/toPhoenician'
import { ArabicToSyriacConverter } from './scripts/arabic/toSyriac'
import { ArabicToTifinaghConverter } from './scripts/arabic/toTifinagh'
import { ArabicToUgariticConverter } from './scripts/arabic/toUgaritic'
import { ImperialAramaicToArabicConverter } from './scripts/imperialAramaic/toArabic'
import { IpaToArabicConverter } from './scripts/ipa/toArabic'
import { OldSouthArabicToArabicConverter } from './scripts/oldSouthArabian/toArabic'
import { PhoenicianToArabicConverter } from './scripts/phoenician/toArabic'
import { SyriacToArabicConverter } from './scripts/syriac/toArabic'
Expand All @@ -15,12 +17,14 @@ import { UgariticToArabicConverter } from './scripts/ugaritic/toArabic'

const converters: IConverter[] = [
new ArabicToImperialAramaicConverter(),
new ArabicToIpaConverter(),
new ArabicToOldSouthArabianConverter(),
new ArabicToPhoenicianConverter(),
new ArabicToSyriacConverter(),
new ArabicToTifinaghConverter(),
new ArabicToUgariticConverter(),
new ImperialAramaicToArabicConverter(),
new IpaToArabicConverter(),
new OldSouthArabicToArabicConverter(),
new PhoenicianToArabicConverter(),
new SyriacToArabicConverter(),
Expand Down Expand Up @@ -52,5 +56,22 @@ export function getConverter(from: Abjad, to: Abjad): IConverter {
}
}

// try to find 3 converters and create a composite converter from them
for (const fromConverter of fromConverters) {
for (const toConverter of toConverters) {
for (const middleConverter of converters) {
if (fromConverter.to === middleConverter.from && middleConverter.to === toConverter.from) {
return {
from,
to,
convert(text: string): string {
return toConverter.convert(middleConverter.convert(fromConverter.convert(text)))
},
}
}
}
}
}

throw new Error(`No converter exists from ${from} to ${to}`)
}
3 changes: 3 additions & 0 deletions packages/abjad-convert/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getConverter } from './converterFactory'
import { Abjad } from './types'
import { arabic } from './scripts/arabic/letters'
import { imperialAramaic } from './scripts/imperialAramaic/letters'
import { ipa } from './scripts/ipa/letters'
import { oldSouthArabian } from './scripts/oldSouthArabian/letters'
import { phoenician } from './scripts/phoenician/letters'
import { syriac } from './scripts/syriac/letters'
Expand All @@ -24,6 +25,8 @@ export function getLetters(script: Abjad): readonly string[] {
return arabic.letters
case Abjad.ImperialAramaic:
return imperialAramaic.letters
case Abjad.IPA:
return ipa.letters
case Abjad.OldSouthArabian:
return oldSouthArabian.letters
case Abjad.Phoenician:
Expand Down
Loading

0 comments on commit 7e684bc

Please sign in to comment.