-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
drop nltk trie imp in lexicon and add case-insensitive search support
- Loading branch information
Showing
6 changed files
with
41,219 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import sys | ||
import logging | ||
from datetime import datetime | ||
from ..Lexicon import Lexicon | ||
from ..helper import setup_logging | ||
|
||
|
||
setup_logging() | ||
logger = logging.getLogger(__name__) | ||
|
||
cmd = sys.argv[1] | ||
if cmd == 'flat': | ||
l = Lexicon() | ||
l.flattenToFile(sys.argv[2]) | ||
elif cmd == 'loadflat': | ||
n = datetime.now() | ||
with open(sys.argv[2], encoding='utf8') as f: | ||
l = Lexicon() | ||
for line in f: | ||
if len(line) > 0: | ||
l.insertWord(line) | ||
|
||
d = datetime.now() - n | ||
logger.debug('timedelta to run: {}'.format(d)) | ||
elif cmd == "create_insensitive_xml": # create lexicon-insensitive.xml | ||
import os | ||
|
||
this_dir, this_filename = os.path.split(__file__) | ||
lexicon_src = os.path.join(this_dir, 'lexicon.txt') | ||
lexicon_xml = os.path.join(this_dir, 'lexicon-insensitive.xml') | ||
|
||
l = Lexicon(default=False, case_sensitive=False) | ||
f_lex = open(lexicon_src, mode='r', encoding='utf-8') | ||
|
||
logger.info('Building trie tree from lexicon.txt') | ||
lexes = [lex.strip() for lex in f_lex.readlines()] | ||
for lex in lexes: | ||
if len(lex) > 0: | ||
l.insertWord(lex) | ||
|
||
logger.info('Write to lexicon-insensitive.xml file') | ||
l.serialize_to_xml(lexicon_xml) |
Oops, something went wrong.