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
510acea
commit 3987d79
Showing
4 changed files
with
110 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,29 @@ | ||
cc_sources = alphabet.cc att_compiler.cc compiler.cc compression.cc entry_token.cc \ | ||
expander.cc fst_processor.cc lt_locale.cc match_exe.cc \ | ||
match_node.cc match_state.cc node.cc pattern_list.cc \ | ||
regexp_compiler.cc sorted_vector.cc state.cc transducer.cc \ | ||
trans_exe.cc xml_parse_util.cc tmx_compiler.cc | ||
|
||
# SWIG_INTERFACE = analysis.i | ||
|
||
EXTRA_DIST = analysis.i | ||
|
||
pkgdata_DATA = analysis.py | ||
|
||
lib_LTLIBRARIES = libAnalysisPython.la | ||
libAnalysisPython_la_SOURCES = analysis_wrap_python.cpp | ||
libAnalysisPython_la_SOURCES = analysis_wrap_python.cpp | ||
foo_wrap_python.cpp: analysis.i | ||
$(SWIG) -python $(SWIG_ARGS) -o $@ $< | ||
|
||
|
||
BUILT_SOURCES = analysis_wrap.cpp analysis.py | ||
CLEANFILES = $(BUILT_SOURCES) | ||
|
||
library_includedir = $(includedir)/$(GENERIC_LIBRARY_NAME)-$(GENERIC_API_VERSION)/$(GENERIC_LIBRARY_NAME) | ||
library_include_HEADERS = $(h_sources) | ||
|
||
%_wrap.cpp %.py: %.i ../src/libdivvun.la | ||
$(SWIG) -c++ -python -I$(top_srcdir)/src/lib -o $*_wrap.cpp -outdir . $(srcdir)/$*.i | ||
CPPFLAGS="$(CPPFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="-Wl,-rpath,${prefix}/lib $(LDFLAGS)" | ||
|
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,58 @@ | ||
%module analysis | ||
|
||
%{ | ||
#define SWIG_FILE_WITH_INIT | ||
#include <lttoolbox/fst_processor.h> | ||
#include <lttoolbox/lttoolbox_config.h> | ||
#include <lttoolbox/my_stdio.h> | ||
#include <lttoolbox/lt_locale.h> | ||
|
||
class FST: private FSTProcessor | ||
{ | ||
public: | ||
/** | ||
* Reads from input_path and stores result at output_path | ||
*/ | ||
void init_analysis(char *automorf_path, char *input_path, char *output_path); | ||
bool validity() const; | ||
|
||
}; | ||
|
||
bool | ||
FST::validity() const | ||
{ | ||
return valid(); | ||
} | ||
|
||
void | ||
FST::init_analysis(char *automorf_path, char *input_path, char *output_path) | ||
{ | ||
setDictionaryCaseMode(true); | ||
LtLocale::tryToSetLocale(); | ||
FILE *in = fopen(automorf_path, "rb"); | ||
load(in); | ||
initAnalysis(); | ||
FILE *input = fopen(input_path, "r"), *output = fopen(output_path, "w"); | ||
analysis(input, output); | ||
fclose(in); | ||
fclose(input); | ||
fclose(output); | ||
} | ||
|
||
%} | ||
|
||
|
||
#include <lttoolbox/fst_processor.h> | ||
#include <lttoolbox/lttoolbox_config.h> | ||
#include <lttoolbox/my_stdio.h> | ||
#include <lttoolbox/lt_locale.h> | ||
|
||
class FST: private FSTProcessor | ||
{ | ||
public: | ||
/** | ||
* Reads from input_path and stores result at output_path | ||
*/ | ||
void init_analysis(char *automorf_path, char *input_path, char *output_path); | ||
bool validity() const; | ||
}; |
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,2 @@ | ||
- add python & swig checkers in config.ac from libdivun | ||
- |
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,21 @@ | ||
import os | ||
import sys | ||
import tempfile | ||
import unittest | ||
|
||
base_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..') | ||
sys.path.append(base_path) | ||
|
||
import analysis | ||
|
||
class TestAnalysisunittest.TestCase): | ||
def test_FST(self): | ||
with tempfile.NamedTemporaryFile('w') as input_file, tempfile.NamedTemporaryFile('r') as output_file: | ||
input_text = 'cats\n' | ||
automorf_path = "/usr/share/apertium/apertium-eng/eng.automorf.bin" | ||
input_file.write(input_text) | ||
input_file.flush() | ||
x = analysis.FST() | ||
x.init_analysis(automorf_path, input_file.name, output_file.name) | ||
output = output_file.read() | ||
self.assertEqual(output, "cats<n><pl>") |