Skip to content

Commit

Permalink
use orjson to replace json module
Browse files Browse the repository at this point in the history
  • Loading branch information
dongyuwei committed Oct 20, 2024
1 parent 6f44e17 commit 04755dd
Show file tree
Hide file tree
Showing 378 changed files with 1,587 additions and 9 deletions.
18 changes: 9 additions & 9 deletions python/input_methods/hallelujah/ime_hallelujah.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from keycodes import *
from textService import *
import os.path
import json
import orjson
from collections import OrderedDict
from heapq import nlargest
import marisa_trie
Expand Down Expand Up @@ -40,18 +40,18 @@ def loadTrie(self):
self.trie = trie

def loadWordsWithFrequency(self):
with open(os.path.join(self.dictPath, "words_with_frequency_and_translation_and_ipa.json"), encoding='utf-8') as f:
self.wordsWithFrequencyDict = json.load(f)
with open(os.path.join(self.dictPath, "words_with_frequency_and_translation_and_ipa.json"), 'rb') as f:
self.wordsWithFrequencyDict = orjson.loads(f.read())

def loadPinyinData(self):
with open(os.path.join(self.dictPath, "cedict.json"), encoding='utf-8') as f:
self.pinyinDict = json.load(f)
with open(os.path.join(self.dictPath, "cedict.json"), 'rb') as f:
self.pinyinDict = orjson.loads(f.read())

def get_user_defined_substitutions(self):
json_file_path = os.path.join(os.environ['USERPROFILE'], 'hallelujah.json')
try:
with open(json_file_path, 'r') as file:
self.substitutions = json.load(file)
with open(json_file_path, 'rb') as f:
self.substitutions = orjson.loads(f.read())
except FileNotFoundError:
print(f"File {json_file_path} not found.")
self.substitutions = {}
Expand All @@ -61,8 +61,8 @@ def get_user_defined_substitutions(self):

# get phonetics match
def loadFuzzySoundexEncodedData(self):
with open(os.path.join(self.dictPath, "fuzzy_soundex_encoded_words.json"), encoding='utf-8') as f:
self.fuzzySoundexEncodedDict = json.load(f)
with open(os.path.join(self.dictPath, "fuzzy_soundex_encoded_words.json"), 'rb') as f:
self.fuzzySoundexEncodedDict = orjson.loads(f.read())

imeService = PersistentImeService()

Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pip
Loading

0 comments on commit 04755dd

Please sign in to comment.