-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6d3b77
commit 73363b6
Showing
4 changed files
with
84 additions
and
18 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
This file was deleted.
Oops, something went wrong.
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,64 @@ | ||
import sys | ||
import logging | ||
from distutils.cmd import Command | ||
from distutils.errors import DistutilsOptionError | ||
|
||
import server | ||
|
||
class InteractCommand(Command): | ||
description = 'provide interact interface for testing splitting terms' | ||
user_options = [] | ||
|
||
def initialize_options(self): | ||
pass | ||
|
||
def finalize_options(self): | ||
pass | ||
|
||
def run(self): | ||
logging.basicConfig(level=logging.DEBUG) | ||
service = server.SegumentService() | ||
while True: | ||
text = raw_input('Text:').decode(sys.stdin.encoding) | ||
terms = service.splitTerms(text) | ||
print ' '.join(terms) | ||
|
||
class FeedCommand(Command): | ||
description = 'feed text data file' | ||
user_options = [ | ||
('file=', 'f', 'text file to feed'), | ||
('encoding=', 'e', 'encoding of text file'), | ||
] | ||
|
||
def initialize_options(self): | ||
self.encoding = 'utf8' | ||
self.file = None | ||
|
||
def finalize_options(self): | ||
import codecs | ||
if not self.file: | ||
raise DistutilsOptionError('Must set text file path to feed') | ||
self.text_file = codecs.open(self.file, 'rt', encoding=self.encoding) | ||
self.text = self.text_file.read() | ||
|
||
def run(self): | ||
logging.basicConfig(level=logging.DEBUG) | ||
service = server.SegumentService() | ||
service.feed(self.text) | ||
|
||
|
||
class ResetCommand(Command): | ||
description = 'reset lexicon database' | ||
user_options = [] | ||
|
||
def initialize_options(self): | ||
pass | ||
|
||
def finalize_options(self): | ||
pass | ||
|
||
def run(self): | ||
logging.basicConfig(level=logging.DEBUG) | ||
service = server.SegumentService() | ||
service.db.reset() | ||
print 'Done.' |
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