-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
All files needed to create Python module cstlempy
- Loading branch information
1 parent
7efb808
commit bff2860
Showing
7 changed files
with
646 additions
and
0 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,4 @@ | ||
del cstlempy.c* | ||
del /s /q build | ||
python setup.py build_ext --inplace | ||
python launch.py |
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,5 @@ | ||
#!/bin/bash | ||
rm cstlempy.c* | ||
rm -r build | ||
python setup.py build_ext --inplace | ||
python launch.py |
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,24 @@ | ||
# cstlempy.pyx - Python Module, this code will be translated to C by Cython. | ||
|
||
cdef extern from "tinylemmatizer.h": | ||
cdef extern void startProc(const char* flexrulesFileName, int* err) | ||
cdef extern void stringEval(const char * s,const char ** out,int * err) | ||
cdef extern void endProc() | ||
|
||
# Function to be called once, before the first call to lemmatize() | ||
def init(Str): | ||
cdef int Err | ||
startProc(bytes(Str,'iso8859-1'),&Err) | ||
|
||
# Function to lemmatize a full form | ||
def lemmatize(Str): | ||
cdef const char * Sout | ||
cdef int Err | ||
stringEval(bytes(Str,'iso8859-1'),&Sout,&Err) | ||
cdef bytes py_string = Sout | ||
return py_string.decode('UTF-8') | ||
|
||
# Function to be called after the last call to lemmatize() | ||
def final(): | ||
endProc() | ||
|
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,18 @@ | ||
# launch.py - Python 3 stub loader, loads the 'cstlempy' module that was made by Cython. | ||
|
||
# This code is always interpreted, like normal Python. | ||
# It is not compiled to C. | ||
|
||
import cstlempy | ||
|
||
filename = "flexrules" | ||
print("Initialise cstlempy with the call 'cstlempy.init("+filename+")'.\n") | ||
cstlempy.init(filename) | ||
|
||
cstlempyFullForm = "went" | ||
print("Going to call lemmatize(<full form>).\n\nThe full form is this one: "+cstlempyFullForm) | ||
answer = cstlempy.lemmatize(cstlempyFullForm) | ||
print('Answer from cstlempy: '+answer+'\n') | ||
cstlempy.final() | ||
print("We have called cstlempy.final(), so now cstlempy is not available until we call\n'cstlempy.init()' again.") | ||
|
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,13 @@ | ||
# setup.py | ||
# | ||
from setuptools import setup | ||
from Cython.Build import cythonize | ||
from setuptools.extension import Extension | ||
|
||
sourcefiles = ['tinylemmatizer.c', 'cstlempy.pyx'] | ||
|
||
extensions = [Extension("cstlempy", sourcefiles, extra_compile_args=["-I.", "-D_CRT_SECURE_NO_WARNINGS","-DPYTHONINTERFACE"])] | ||
|
||
setup( | ||
ext_modules = cythonize(extensions, emit_linenums=True, compiler_directives={'language_level': 3}) | ||
) |
Oops, something went wrong.