-
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
ea2727d
commit a9252d0
Showing
5 changed files
with
146 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
|
||
xmlrpc: | ||
|
||
interface: 0.0.0.0 | ||
|
||
# 5566 is so cool! just kidding | ||
port: 5566 | ||
|
||
... |
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,14 @@ | ||
import logging | ||
|
||
import server | ||
|
||
def main(): | ||
logging.basicConfig(level=logging.DEBUG) | ||
service = server.SegumentService() | ||
while True: | ||
text = unicode(raw_input('Text:')) | ||
terms = service.splitTerms(text) | ||
print ' '.join(terms) | ||
|
||
if __name__ == '__main__': | ||
main() |
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,68 @@ | ||
# -*- coding: utf8 -*- | ||
import logging | ||
from SimpleXMLRPCServer import SimpleXMLRPCServer | ||
from SimpleXMLRPCServer import SimpleXMLRPCRequestHandler | ||
|
||
import yaml | ||
|
||
from loso import lexicon | ||
|
||
class SegumentService(object): | ||
|
||
def __init__(self, ngram=4, logger=None): | ||
self.logger = logger | ||
if self.logger is None: | ||
self.logger = logging.getLogger('segment.service') | ||
self.ngram = ngram | ||
self.db = lexicon.LexiconDatabase() | ||
self.builder = lexicon.LexiconBuilder(self.db, self.ngram) | ||
|
||
def getStats(self): | ||
"""Get statistics information | ||
""" | ||
return self.db.getStats() | ||
|
||
def feed(self, text): | ||
"""Feed text data to lexicon database | ||
""" | ||
self.logger.info('Feed %d bytes data', len(text)) | ||
return self.builder.feed(text) | ||
|
||
def splitTerms(self, text): | ||
"""Split text into terms | ||
""" | ||
terms = [] | ||
for sentence in lexicon.splitSentence(text): | ||
if sentence: | ||
terms.extend(self.db.splitTerms(sentence, self.ngram)) | ||
return terms | ||
|
||
def splitSentence(self, text): | ||
"""Split text into sentence | ||
""" | ||
return lexicon.splitSentence(text) | ||
|
||
def main(): | ||
logging.basicConfig(level=logging.INFO) | ||
logger = logging.getLogger('segment.main') | ||
|
||
config = yaml.load(open('config.yaml', 'rt')) | ||
|
||
service = SegumentService() | ||
|
||
xmlrpc_config = config['xmlrpc'] | ||
interface = xmlrpc_config.get('interface', '0.0.0.0') | ||
port = xmlrpc_config.get('port', 5566) | ||
logger.info('Start segmentation service at %s:%d', interface, port) | ||
|
||
server = SimpleXMLRPCServer((interface, port), allow_none=True) | ||
server.register_introspection_functions() | ||
server.register_instance(service) | ||
server.serve_forever() | ||
|
||
if __name__ == '__main__': | ||
main() |
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
long_description=__doc__, | ||
packages=['loso'], | ||
install_requires=[ | ||
'redis' | ||
'redis', | ||
'pyyaml' | ||
] | ||
) |