From fc2123a45b3ceacc2ec887d24e5e752dca59bb4f Mon Sep 17 00:00:00 2001 From: StefanVukovic99 Date: Thu, 28 Dec 2023 06:39:19 +0100 Subject: add phonetic transcriptions term meta type (#434) * move dictionary files to dictionary folder * wip * move dictionary files to dictionary folder * add ipa term meta * wip * fixing comments wip * fixing comments wip * fixing comments wip * fixing comments wip * fixing comments wip * fixing comments wip * fix comments * fix comments * update test data * fix gitignore * engines * add tests * update database test * fix test --- types/ext/anki-templates.d.ts | 44 ++++++++++++++++++++++++++++++++----- types/ext/dictionary-data-util.d.ts | 10 ++------- types/ext/dictionary-data.d.ts | 16 +++++++++++++- types/ext/dictionary-database.d.ts | 21 +++++++++++++++--- types/ext/dictionary.d.ts | 31 +++++++++++++++++++++++--- 5 files changed, 102 insertions(+), 20 deletions(-) (limited to 'types/ext') diff --git a/types/ext/anki-templates.d.ts b/types/ext/anki-templates.d.ts index 5c40f406..098873e6 100644 --- a/types/ext/anki-templates.d.ts +++ b/types/ext/anki-templates.d.ts @@ -76,6 +76,7 @@ export type NoteData = { readonly uniqueReadings: string[]; readonly pitches: PitchGroup[]; readonly pitchCount: number; + readonly phoneticTranscriptions: TranscriptionGroup[]; readonly context: Context; media: Media; readonly dictionaryEntry: Dictionary.DictionaryEntry; @@ -97,6 +98,20 @@ export type Pitch = { exclusiveReadings: string[]; }; +export type TranscriptionGroup = { + dictionary: string; + phoneticTranscriptions: Transcription[]; +}; + +export type Transcription = { + expressions: string[]; + reading: string; + ipa: string; + tags: Dictionary.Tag[]; + exclusiveExpressions: string[]; + exclusiveReadings: string[]; +}; + /** * For legacy reasons, {@link Pitch} has a custom tag type that resembles {@link Dictionary.Tag}. */ @@ -175,7 +190,8 @@ export type TermDictionaryEntry = { readonly termTags?: Tag[]; readonly definitions?: TermDefinition[]; readonly frequencies: TermFrequency[]; - readonly pitches: TermPronunciation[]; + readonly pitches: TermPitchAccent[]; + readonly phoneticTranscriptions: TermPhoneticTranscription[]; sourceTermExactMatchCount: number; url: string; readonly cloze: Cloze; @@ -225,7 +241,7 @@ export type TermFrequency = { frequency: number | string; }; -export type TermPronunciation = { +export type TermPitchAccent = { index: number; expressionIndex: number; dictionary: string; @@ -235,14 +251,32 @@ export type TermPronunciation = { }; expression: string; reading: string; - readonly pitches: TermPitch[]; + readonly pitches: PitchAccent[]; }; -export type TermPitch = { +export type PitchAccent = { position: number; tags: Tag[]; }; +export type TermPhoneticTranscription = { + index: number; + expressionIndex: number; + dictionary: string; + dictionaryOrder: { + index: number; + priority: number; + }; + expression: string; + reading: string; + readonly phoneticTranscriptions: PhoneticTranscription[]; +}; + +export type PhoneticTranscription = { + ipa: string; + tags: Tag[]; +}; + export type TermFrequencyType = DictionaryDataUtil.TermFrequencyType; export type TermHeadword = { @@ -251,7 +285,7 @@ export type TermHeadword = { reading: string; readonly termTags: Tag[]; readonly frequencies: TermFrequency[]; - readonly pitches: TermPronunciation[]; + readonly pitches: TermPitchAccent[]; readonly furiganaSegments: FuriganaSegment[]; readonly termFrequency: TermFrequencyType; wordClasses: string[]; diff --git a/types/ext/dictionary-data-util.d.ts b/types/ext/dictionary-data-util.d.ts index b78e6439..4ab06f11 100644 --- a/types/ext/dictionary-data-util.d.ts +++ b/types/ext/dictionary-data-util.d.ts @@ -64,21 +64,15 @@ export type KanjiFrequency = { export type TermFrequencyType = 'popular' | 'rare' | 'normal'; export type GroupedPronunciationInternal = { + pronunciation: Dictionary.Pronunciation; terms: Set; reading: string; - position: number; - nasalPositions: number[]; - devoicePositions: number[]; - tags: Dictionary.Tag[]; }; export type GroupedPronunciation = { + pronunciation: Dictionary.Pronunciation; terms: string[]; reading: string; - position: number; - nasalPositions: number[]; - devoicePositions: number[]; - tags: Dictionary.Tag[]; exclusiveTerms: string[]; exclusiveReadings: string[]; }; diff --git a/types/ext/dictionary-data.d.ts b/types/ext/dictionary-data.d.ts index b194c190..0e0edd5c 100644 --- a/types/ext/dictionary-data.d.ts +++ b/types/ext/dictionary-data.d.ts @@ -125,7 +125,7 @@ export type GenericFrequencyData = string | number | { export type TermMetaArray = TermMeta[]; -export type TermMeta = TermMetaFrequency | TermMetaPitch; +export type TermMeta = TermMetaFrequency | TermMetaPitch | TermMetaPhonetic; export type TermMetaFrequencyDataWithReading = { reading: string; @@ -154,6 +154,20 @@ export type TermMetaPitch = [ data: TermMetaPitchData, ]; +export type TermMetaPhonetic = [ + expression: string, + mode: 'ipa', + data: TermMetaPhoneticData, +]; + +export type TermMetaPhoneticData = { + reading: string; + transcriptions: { + ipa: string; + tags?: string[]; + }[]; +}; + export type KanjiMetaArray = KanjiMeta[]; export type KanjiMeta = KanjiMetaFrequency; diff --git a/types/ext/dictionary-database.d.ts b/types/ext/dictionary-database.d.ts index 3202ef60..3cf68543 100644 --- a/types/ext/dictionary-database.d.ts +++ b/types/ext/dictionary-database.d.ts @@ -102,7 +102,7 @@ export type Tag = { dictionary: string; }; -export type DatabaseTermMeta = DatabaseTermMetaFrequency | DatabaseTermMetaPitch; +export type DatabaseTermMeta = DatabaseTermMetaFrequency | DatabaseTermMetaPitch | DatabaseTermMetaPhoneticData; export type DatabaseTermMetaFrequency = { expression: string; @@ -118,12 +118,19 @@ export type DatabaseTermMetaPitch = { dictionary: string; }; +export type DatabaseTermMetaPhoneticData = { + expression: string; + mode: 'ipa'; + data: DictionaryData.TermMetaPhoneticData; + dictionary: string; +}; + export type TermMetaFrequencyDataWithReading = { reading: string; frequency: DictionaryData.GenericFrequencyData; }; -export type TermMeta = TermMetaFrequency | TermMetaPitch; +export type TermMeta = TermMetaFrequency | TermMetaPitch | TermMetaPhoneticData; export type TermMetaType = TermMeta['mode']; @@ -136,13 +143,21 @@ export type TermMetaFrequency = { }; export type TermMetaPitch = { + mode: 'pitch'; index: number; term: string; - mode: 'pitch'; data: DictionaryData.TermMetaPitchData; dictionary: string; }; +export type TermMetaPhoneticData = { + mode: 'ipa'; + index: number; + term: string; + data: DictionaryData.TermMetaPhoneticData; + dictionary: string; +}; + export type DatabaseKanjiMeta = DatabaseKanjiMetaFrequency; export type DatabaseKanjiMetaFrequency = { diff --git a/types/ext/dictionary.d.ts b/types/ext/dictionary.d.ts index 3e90dec0..7c348e7f 100644 --- a/types/ext/dictionary.d.ts +++ b/types/ext/dictionary.d.ts @@ -365,15 +365,21 @@ export type TermPronunciation = { */ dictionaryPriority: number; /** - * The pitch accent representations for the term. + * The pronunciations for the term. */ - pitches: TermPitch[]; + pronunciations: Pronunciation[]; }; +export type Pronunciation = PitchAccent | PhoneticTranscription; + /** * Pitch accent information for a term, represented as the position of the downstep. */ -export type TermPitch = { +export type PitchAccent = { + /** + * Type of the pronunciation, for disambiguation between union type members. + */ + type: 'pitch-accent'; /** * Position of the downstep, as a number of mora. */ @@ -392,6 +398,25 @@ export type TermPitch = { tags: Tag[]; }; +export type PhoneticTranscription = { + /** + * Type of the pronunciation, for disambiguation between union type members. + */ + type: 'phonetic-transcription'; + /** + * An IPA transcription. + */ + ipa: string; + /** + * Tags for the IPA transcription. + */ + tags: Tag[]; +}; + +export type PronunciationType = Pronunciation['type']; + +export type PronunciationGeneric = Extract; + /** * Frequency information corresponds to how frequently a term appears in a corpus, * which can be a number of occurrences or an overall rank. -- cgit v1.2.3