Skip to content

Commit

Permalink
freezing version 0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael R. Hines committed Apr 28, 2014
1 parent f6d171e commit 61b4682
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 20 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ There are several steps to perform before MICA can run:

1. Install basic package dependencies

$ apt-get install python-dev python-openssl python-setuptools python-sqlalchemy python-twisted* python-beaker python-webob libstdc++5 python-simplejson python-daemon python-pip

# (yes, they are all required as of now)
$ apt-get install python-dev python-openssl python-setuptools python-sqlalchemy python-twisted* python-beaker python-webob libstdc++5 python-simplejson python-daemon python-pip python-crypto

2. Create a developer account / Translator Application key/ID requests from Microsoft

Expand Down Expand Up @@ -71,8 +69,8 @@ $ sudo ldconfig
$ cd mica

$ python setup.py build

$ cp build/*/mica.so .
$ python setup.py install
$ cp build/*/mica_ictclas.so .


RUNNING:
Expand Down
16 changes: 11 additions & 5 deletions mica.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import shelve
import uuid as uuid4
import cjklib
import mica
import mica_ictclas
import hashlib
import errno
import simplejson as json
Expand Down Expand Up @@ -1104,7 +1104,7 @@ def parse_actual(self, uuid, name, story, storydb, groups, temp_units = False) :

def parse(self, uuid, name, story, username, storydb) :
mdebug("Ready to translate: " + name)
parsed = mica.trans(story["original"].encode("UTF-8"))
parsed = mica_ictclas.trans(story["original"].encode("UTF-8"))
mdebug("Parsed result: " + parsed)
lines = parsed.split("\n")
groups = []
Expand Down Expand Up @@ -2293,7 +2293,7 @@ def add_record(db, unit, mindex, which, key) :

except exc.HTTPTemporaryRedirect, e :
raise e
except mica.error, e :
except mica_ictclas.error, e :
return self.bootstrap(req, self.heromsg + "\n<h4 id='gerror'>Error: mica C-extension failed: " + str(e) + "</h4>")
except Exception, msg:
mdebug("Exception: " + str(msg))
Expand All @@ -2314,7 +2314,8 @@ def add_record(db, unit, mindex, which, key) :
return out

session_opts = {
'session.data_dir' : '/tmp/mica_sessions_' + getpwuid(os.getuid())[0] + 'data',
'session.data_dir' : '/tmp/mica_sessions_' + getpwuid(os.getuid())[0] + '_data',
'session.lock_dir' : '/tmp/mica_sessions_' + getpwuid(os.getuid())[0] + '_lock',
'session.type' : 'file',
}

Expand Down Expand Up @@ -2406,23 +2407,28 @@ def getChild(self, name, request) :
print "Microsoft Client ID and Secret are for their translation service is required (options -I and -S). Why? Because it's free and google is not =)"
exit(1)

if not options.keepsession :
if not options.keepsession and 'session.data_dir' in session_opts and 'session.lock_dir' in session_opts :
try :
shutil.rmtree(session_opts['session.data_dir'])
shutil.rmtree(session_opts['session.lock_dir'])
except OSError :
pass

def main() :
blog = logging.getLogger('beaker.container')
blog.setLevel(logging.DEBUG)
global micalogger
micalogger = logging.getLogger("")
micalogger.setLevel(logging.DEBUG)
handler = logging.handlers.RotatingFileHandler(options.logfile, maxBytes=(1048576*5), backupCount=7)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
handler.setFormatter(formatter)
micalogger.addHandler(handler)
blog.addHandler(handler)
streamhandler = logging.StreamHandler()
streamhandler.setFormatter(formatter)
micalogger.addHandler(streamhandler)
blog.addHandler(streamhandler)

log.startLogging(DailyLogFile.fromFullPath(options.tlogfile), setStdout=True)

Expand Down
12 changes: 6 additions & 6 deletions mica.cpp → mica_ictclas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

using namespace std;

static PyObject * mica_translate(PyObject *self, PyObject *args)
static PyObject * mica_ictclas_translate(PyObject *self, PyObject *args)
{
PyObject * ret;
unsigned int nPaLen;
Expand All @@ -29,17 +29,17 @@ static PyObject * mica_translate(PyObject *self, PyObject *args)
}

static PyMethodDef MicaMethods[] = {
{"trans", mica_translate, METH_VARARGS,
{"trans", mica_ictclas_translate, METH_VARARGS,
"Identify chinese character groups."},
{NULL, NULL, 0, NULL}
};

static PyObject *MicaError;
static string errorname1("mica.error"), errorname2("error");
static string errorname1("mica_ictclas.error"), errorname2("error");
static char name[100];

PyMODINIT_FUNC
initmica(void)
initmica_ictclas(void)
{
PyObject *m;

Expand All @@ -51,7 +51,7 @@ initmica(void)

ICTCLAS_SetPOSmap(2);

m = Py_InitModule("mica", MicaMethods);
m = Py_InitModule("mica_ictclas", MicaMethods);

if (m == NULL)
return;
Expand All @@ -70,6 +70,6 @@ main(int argc, char *argv[])
{
Py_SetProgramName(argv[0]);
Py_Initialize();
initmica();
initmica_ictclas();
return 1;
}
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
from distutils.core import setup, Extension

module1 = Extension('mica',
module1 = Extension('mica_ictclas',
define_macros = [('MAJOR_VERSION', '1'),
('MINOR_VERSION', '0')],
libraries = ['ICTCLAS50'],
library_dirs = ['.'],
sources = ['mica.cpp'])
sources = ['mica_ictclas.cpp'])

setup (name = 'PackageName',
version = '1.0',
description = 'This is a demo package',
description = 'This is a python-extention for the ICTCLAS package',
author = 'Michael R. Hines',
author_email = '[email protected]',
url = 'http://michael.hinespot.com/',
long_description = '''
Exposing the C++ Beijing University language word-grouping API program in Python.
Exposing the C++ ICTCLAS lexical chinese word parser API in Python.
''',
ext_modules = [module1])

0 comments on commit 61b4682

Please sign in to comment.