Commit e4d7599753012a66a8e422af613d2e3e2f42fa19
1 parent
9da6d968
- praca nad wrapperem javowym
git-svn-id: svn://svn.nlp.ipipan.waw.pl/morfeusz/trunk@242 ff4e3ee1-f430-4e82-ade0-24591c43f1fd
Showing
2 changed files
with
93 additions
and
20 deletions
morfeusz/wrappers/morfeusz.i
... | ... | @@ -59,6 +59,10 @@ namespace morfeusz { |
59 | 59 | %ignore MorphInterpretation::createIgn(int startNode, int endNode, const std::string& orth, const Tagset<std::string>& tagset); |
60 | 60 | %ignore MorphInterpretation::createWhitespace(int startNode, int endNode, const std::string& orth, const Tagset<std::string>& tagset); |
61 | 61 | %ignore Morfeusz::analyze(const char*) const; |
62 | + %ignore Morfeusz::analyze(const string&) const; | |
63 | + %ignore Morfeusz::analyze(const string&, std::vector<MorphInterpretation>&) const; | |
64 | + %ignore Morfeusz::generate(const string&, std::vector<MorphInterpretation>&) const; | |
65 | + %ignore Morfeusz::generate(const string&, int, std::vector<MorphInterpretation>&) const; | |
62 | 66 | |
63 | 67 | %newobject Morfeusz::createInstance(); |
64 | 68 | %newobject Morfeusz::analyze(const std::string&) const; |
... | ... |
morfeusz/wrappers/morfeusz_java.i
1 | -%typemap(javaimports) Morfeusz %{ | |
1 | +%typemap(javaimports) morfeusz::Morfeusz %{ | |
2 | 2 | import java.io.IOException; |
3 | +import java.util.List; | |
3 | 4 | %} |
4 | 5 | |
5 | -%javaexception("java.io.IOException") Morfeusz::setAnalyzerDictionary { | |
6 | +%typemap(javaimports) std::vector %{ | |
7 | +import java.util.List; | |
8 | +import java.util.AbstractList; | |
9 | +%} | |
10 | + | |
11 | +%javaexception("IOException") morfeusz::Morfeusz::setAnalyzerDictionary { | |
6 | 12 | try { |
7 | 13 | $action |
8 | 14 | } |
... | ... | @@ -13,7 +19,7 @@ import java.io.IOException; |
13 | 19 | } |
14 | 20 | } |
15 | 21 | |
16 | -%javaexception("java.io.IOException") Morfeusz::setGeneratorDictionary { | |
22 | +%javaexception("IOException") morfeusz::Morfeusz::setGeneratorDictionary { | |
17 | 23 | try { |
18 | 24 | $action |
19 | 25 | } |
... | ... | @@ -24,30 +30,93 @@ import java.io.IOException; |
24 | 30 | } |
25 | 31 | } |
26 | 32 | |
27 | -%include "enums.swg" | |
28 | - | |
29 | -/* Force the generated Java code to use the C enum values rather than making a JNI call */ | |
30 | -%javaconst(1); | |
31 | - | |
32 | -%pragma(java) jniclasscode=%{ | |
33 | - static { | |
34 | - System.loadLibrary("jmorfeusz"); | |
35 | - } | |
36 | -%} | |
37 | - | |
38 | -%typemap(javabase) std::vector<morfeusz::MorphInterpretation> "java.util.AbstractList<MorphInterpretation>" | |
39 | -%typemap(javabase) std::vector<morfeusz::String> "java.util.AbstractList<String>" | |
33 | +%typemap(javabase) std::vector<morfeusz::MorphInterpretation> "AbstractList<MorphInterpretation>" | |
34 | +%typemap(javabase) std::vector<morfeusz::String> "AbstractList<String>" | |
40 | 35 | |
41 | -%typemap(javabody) morfeusz::Morfeusz %{ | |
36 | +%typemap(javacode) morfeusz::Morfeusz %{ | |
37 | + | |
42 | 38 | public List<MorphInterpretation> analyzeAsList(String text) { |
43 | 39 | InterpsList res = new InterpsList(); |
44 | 40 | analyze(text, res); |
45 | 41 | return res; |
46 | 42 | } |
43 | + | |
44 | +// public ResultsIterator analyzeAsIterator(String text) { | |
45 | +// ResultsIterator res = analyze(text); | |
46 | +// res.setTextReference(text); | |
47 | +// return res; | |
48 | +// } | |
49 | + | |
50 | + public List<MorphInterpretation> generate(String text) { | |
51 | + InterpsList res = new InterpsList(); | |
52 | + generate(text, res); | |
53 | + return res; | |
54 | + } | |
55 | + | |
56 | + public List<MorphInterpretation> generate(String text, int tagnum) { | |
57 | + InterpsList res = new InterpsList(); | |
58 | + generate(text, tagnum, res); | |
59 | + return res; | |
60 | + } | |
61 | +%} | |
62 | + | |
63 | +%typemap(javafinalize) SWIGTYPE %{ | |
64 | + protected void finalize() { | |
65 | + if (swigCMemOwn) { | |
66 | + $moduleJNI.delete_$javaclassname(getCPtr(this)); | |
67 | + } | |
68 | + } | |
69 | +%} | |
70 | + | |
71 | +%typemap(javadestruct, methodname="delete", methodmodifiers="private") SWIGTYPE ""; | |
72 | + | |
73 | +%javamethodmodifiers morfeusz::Morfeusz::analyze(const std::string&) const "private"; | |
74 | +%javamethodmodifiers morfeusz::Morfeusz::analyze(const std::string&, std::vector<MorphInterpretation>&) const "private"; | |
75 | +%javamethodmodifiers morfeusz::Morfeusz::generate(const std::string&, std::vector<MorphInterpretation>&) const "private"; | |
76 | +%javamethodmodifiers morfeusz::Morfeusz::generate(const std::string&, int, std::vector<MorphInterpretation>&) const "private"; | |
77 | + | |
78 | +// ignore size_t std::vector<T>::size() function as it gives "long" return type instead of "int" | |
79 | +%rename("$ignore", regextarget=1, fullname=1) "std::vector<.*>::size$"; | |
80 | + | |
81 | +%typemap(javaclassmodifiers) std::vector "class" | |
82 | + | |
83 | +%typemap(javacode) std::vector %{ | |
84 | + public int size() { | |
85 | + return getSizeAsInt(); | |
86 | + } | |
47 | 87 | %} |
48 | 88 | |
49 | 89 | %extend std::vector { |
50 | - T& std::vector::get(int idx) const { | |
51 | - return at(idx); | |
90 | +// T& std::vector::get(int idx) { | |
91 | +// return at(idx); | |
92 | +// } | |
93 | + | |
94 | +// void std::vector::set(int idx, const T& object) { | |
95 | +// (*this)[idx] = object; | |
96 | +// } | |
97 | + | |
98 | + void std::vector::add(int idx, const T& object) { | |
99 | + insert(begin() + idx, object); | |
100 | + } | |
101 | + | |
102 | + T std::vector::remove(int idx) { | |
103 | + T res = this->at(idx); | |
104 | + erase(begin() + idx); | |
105 | + return res; | |
52 | 106 | } |
53 | -} | |
54 | 107 | \ No newline at end of file |
108 | + | |
109 | + int getSizeAsInt() const { | |
110 | + return size(); | |
111 | + } | |
112 | +} | |
113 | + | |
114 | +%include "enums.swg" | |
115 | + | |
116 | +/* Force the generated Java code to use the C enum values rather than making a JNI call */ | |
117 | +%javaconst(1); | |
118 | + | |
119 | +%pragma(java) jniclasscode=%{ | |
120 | + static { | |
121 | + System.loadLibrary("jmorfeusz"); | |
122 | + } | |
123 | +%} | |
... | ... |