Skip to content

Commit

Permalink
use prepared ipa phonetic symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
dongyuwei committed May 9, 2019
1 parent 7a69011 commit 900cf0b
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 1,889 deletions.

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions dictionary/words_with_frequency_and_translation_and_ipa.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

# https://github.com/mphilli/English-to-IPA
# python3 setup.py install
# python3 words_with_frequency_and_translation_and_ipa.py

import json
import eng_to_ipa as ipa

with open('words_with_frequency_and_translation.json', 'r') as f:
data = json.load(f)

for key, val in data.items():
phonetic_symbol = ipa.convert(key,
keep_punct=False,
retrieve_all=False,
stress_marks="primary")
if phonetic_symbol:
val["ipa"] = phonetic_symbol

file = open("words_with_frequency_and_translation_and_ipa.json", "w")
file.write(json.dumps(data, ensure_ascii=False))
file.close()
9 changes: 5 additions & 4 deletions hallelujah.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
0DE74BFE1978EC6A00040F3C /* him.png in Resources */ = {isa = PBXBuildFile; fileRef = 0DE74BFD1978EC6A00040F3C /* him.png */; };
0DE74C001978F18E00040F3C /* him.icns in Resources */ = {isa = PBXBuildFile; fileRef = 0DE74BFF1978F18E00040F3C /* him.icns */; };
3804D23720F2FC2A00CF1BD9 /* NSScreen+PointConversion.m in Sources */ = {isa = PBXBuildFile; fileRef = 3804D23520F2FC2A00CF1BD9 /* NSScreen+PointConversion.m */; };
3843EC702283BE8E00F52003 /* words_with_frequency_and_translation_and_ipa.json in Resources */ = {isa = PBXBuildFile; fileRef = 3843EC6F2283BE8E00F52003 /* words_with_frequency_and_translation_and_ipa.json */; };
389468CB1F56A34A00EF1F5E /* web in Resources */ = {isa = PBXBuildFile; fileRef = 389468CA1F56A34A00EF1F5E /* web */; };
389468D61F57C8CE00EF1F5E /* InputApplicationDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 389468D51F57C8CE00EF1F5E /* InputApplicationDelegate.m */; };
38DD401A1F5800A400A276CB /* PreferencesMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 38DD40191F5800A400A276CB /* PreferencesMenu.xib */; };
Expand All @@ -22,7 +23,6 @@
E93074B70A5C264700470842 /* InputMethodKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E93074B60A5C264700470842 /* InputMethodKit.framework */; };
F102C5A41F487D5A0005B03F /* libmarisa.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F102C5A31F487D5A0005B03F /* libmarisa.a */; };
F102C5A61F487DE80005B03F /* google_227800_words.bin in Resources */ = {isa = PBXBuildFile; fileRef = F102C5A51F487DE80005B03F /* google_227800_words.bin */; };
F102C5A81F48818A0005B03F /* words_with_frequency_and_translation.json in Resources */ = {isa = PBXBuildFile; fileRef = F102C5A71F48818A0005B03F /* words_with_frequency_and_translation.json */; };
F102C5AA1F4882C80005B03F /* main.mm in Sources */ = {isa = PBXBuildFile; fileRef = F102C5A91F4882C80005B03F /* main.mm */; };
F102C5AC1F4882D30005B03F /* InputController.mm in Sources */ = {isa = PBXBuildFile; fileRef = F102C5AB1F4882D30005B03F /* InputController.mm */; };
F109B4911E1A83AF00AA7A41 /* AnnotationWinController.m in Sources */ = {isa = PBXBuildFile; fileRef = F109B48F1E1A83AF00AA7A41 /* AnnotationWinController.m */; };
Expand All @@ -42,6 +42,7 @@
29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
3804D23520F2FC2A00CF1BD9 /* NSScreen+PointConversion.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSScreen+PointConversion.m"; path = "src/NSScreen+PointConversion.m"; sourceTree = "<group>"; };
3804D23620F2FC2A00CF1BD9 /* NSScreen+PointConversion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSScreen+PointConversion.h"; path = "src/NSScreen+PointConversion.h"; sourceTree = "<group>"; };
3843EC6F2283BE8E00F52003 /* words_with_frequency_and_translation_and_ipa.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = words_with_frequency_and_translation_and_ipa.json; path = dictionary/words_with_frequency_and_translation_and_ipa.json; sourceTree = "<group>"; };
389468CA1F56A34A00EF1F5E /* web */ = {isa = PBXFileReference; lastKnownFileType = folder; path = web; sourceTree = "<group>"; };
389468D41F57C8CE00EF1F5E /* InputApplicationDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = InputApplicationDelegate.h; path = src/InputApplicationDelegate.h; sourceTree = "<group>"; };
389468D51F57C8CE00EF1F5E /* InputApplicationDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = InputApplicationDelegate.m; path = src/InputApplicationDelegate.m; sourceTree = "<group>"; };
Expand All @@ -53,7 +54,6 @@
E93074B60A5C264700470842 /* InputMethodKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = InputMethodKit.framework; path = /System/Library/Frameworks/InputMethodKit.framework; sourceTree = "<absolute>"; };
F102C5A31F487D5A0005B03F /* libmarisa.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libmarisa.a; path = lib/libmarisa.a; sourceTree = "<group>"; };
F102C5A51F487DE80005B03F /* google_227800_words.bin */ = {isa = PBXFileReference; lastKnownFileType = archive.macbinary; name = google_227800_words.bin; path = dictionary/google_227800_words.bin; sourceTree = "<group>"; };
F102C5A71F48818A0005B03F /* words_with_frequency_and_translation.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = words_with_frequency_and_translation.json; path = dictionary/words_with_frequency_and_translation.json; sourceTree = "<group>"; };
F102C5A91F4882C80005B03F /* main.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = main.mm; path = src/main.mm; sourceTree = "<group>"; };
F102C5AB1F4882D30005B03F /* InputController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = InputController.mm; path = src/InputController.mm; sourceTree = "<group>"; };
F109B48F1E1A83AF00AA7A41 /* AnnotationWinController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AnnotationWinController.m; path = src/AnnotationWinController.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -135,10 +135,10 @@
29B97317FDCFA39411CA2CEA /* Resources */ = {
isa = PBXGroup;
children = (
3843EC6F2283BE8E00F52003 /* words_with_frequency_and_translation_and_ipa.json */,
F174745E1FDC2C9400AD2B84 /* cedict.json */,
38DD40191F5800A400A276CB /* PreferencesMenu.xib */,
389468CA1F56A34A00EF1F5E /* web */,
F102C5A71F48818A0005B03F /* words_with_frequency_and_translation.json */,
F102C5A51F487DE80005B03F /* google_227800_words.bin */,
0D2BFD8E194588F400DE18D9 /* Images.xcassets */,
E93396E20A9A0AAD0073E6C4 /* images */,
Expand Down Expand Up @@ -216,6 +216,7 @@
developmentRegion = English;
hasScannedForEncodings = 1;
knownRegions = (
English,
en,
);
mainGroup = 29B97314FDCFA39411CA2CEA /* NumberInput */;
Expand All @@ -238,9 +239,9 @@
389468CB1F56A34A00EF1F5E /* web in Resources */,
8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */,
F102C5A61F487DE80005B03F /* google_227800_words.bin in Resources */,
F102C5A81F48818A0005B03F /* words_with_frequency_and_translation.json in Resources */,
0D2BFD8F194588F400DE18D9 /* Images.xcassets in Resources */,
38DD401A1F5800A400A276CB /* PreferencesMenu.xib in Resources */,
3843EC702283BE8E00F52003 /* words_with_frequency_and_translation_and_ipa.json in Resources */,
0DE74C001978F18E00040F3C /* him.icns in Resources */,
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */,
);
Expand Down
19 changes: 3 additions & 16 deletions src/InputController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -456,24 +456,11 @@ - (NSArray *)getTranslations:(NSAttributedString *)candidate {
}

- (NSString *)getPhoneticSymbolOfWord:(NSAttributedString *)candidateString {
NSString *phoneticSymbol = nil;
if (candidateString && candidateString.length > 3) {
@try {
NSString *definition = (__bridge NSString *)DCSCopyTextDefinition(NULL, (__bridge CFStringRef)[candidateString string],
CFRangeMake(0, [[candidateString string] length]));

if (definition && definition.length > 0) {
NSArray *arr = [definition componentsSeparatedByString:@"|"];
if ([arr count] > 0) {
phoneticSymbol = [NSString stringWithFormat:@"[ %@ ]", arr[1]];
}
}
} @catch (NSException *exception) {
NSLog(@"error when call showPhoneticSymbolOfWord %@", exception.reason);
}
NSString *word = [[candidateString string] lowercaseString];
return [[wordsWithFrequencyAndTranslation objectForKey:word] objectForKey:@"ipa"];
}

return phoneticSymbol;
return nil;
}

@end
2 changes: 1 addition & 1 deletion src/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
}

NSDictionary *getWordsWithFrequencyAndTranslation() {
NSString *path = [[NSBundle mainBundle] pathForResource:@"words_with_frequency_and_translation" ofType:@"json"];
NSString *path = [[NSBundle mainBundle] pathForResource:@"words_with_frequency_and_translation_and_ipa" ofType:@"json"];
return deserializeJSON(path);
}

Expand Down
Loading

0 comments on commit 900cf0b

Please sign in to comment.