%include directive.

View: New views
3 Messages — Rating Filter:   Alert me  

%include directive.

by Guillaume Yziquel-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello.

I've made a swig freeling.i file that worked. As I was going to use more
and more std::lists, I tried to modularise it by adding %include
<std_list.i> and commenting out the code wrapping lists.

Now, I get std_list.ml and std_list.mli as well as std_lib_wrap.cxx, but
not anymore the files wrapping freeling.i...

What am I doing wrong?

All the best,

Guillaume Yziquel


> yziquel@seldon:~/svn/main/libmorfo-ocaml$ cat freeling.i
> %include <std_list.i>
>
> %module swig_Freeling
> %{
>
> #include "freeling.h"
>
> using namespace std;
>
> string string_of_chars (char * c)
> {
>   string s (c);
>   return s;
> }
>
> /*word last_word_of_word_list (list<word> & l)
> {
>   word head = l.front ();
>   return head;
> }
>
> void pop_last_word_list (list<word> & l)
> {
>   l.pop_front ();
> }
>
> bool is_empty_word_list (list<word> & l)
> {
>   bool b = l.empty ();
>   return b;
> }
>
> list<word> new_word_list ()
> {
>   list<word> l;
>   return l;
> }
>
> void push_last_word_list (list<word> & l, word& w)
> {
>   l.push_back (w);
> }*/
>
> %}
>
> // C++ functions used to glue code with OCaml.
>
> string string_of_chars (char *);
>
> /*word last_word_of_word_list (list<word> &);
> void pop_last_word_list (list<word> &);
> bool is_empty_word_list (list<word> &);
> list<word> new_word_list ();
> void push_last_word_list (list<word> &, word &);*/
>
> // Freeling declarations.
>
> class tokenizer {
>    public:
>        /// Constructor
>        tokenizer(const string &);
>
>        /// tokenize string with default options
>        list<word> tokenize(const string &);
>        /// tokenize string with default options, tracking offset in given int param.
>        list<word> tokenize(const string &, unsigned long &);
> };
>
> class splitter {
>    public:
>       /// Constructor
>       splitter(const std::string &);
>
>       /// split sentences with default options
>       std::list<sentence> split(const std::list<word> &, bool);
> };
>


------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: %include directive.

by wsfulton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I don't know the OCAML module and what files it generates, but in the
code below, you don't have any %template directive for wrapping
std::list. Please read the C++ chapter in the documentation on template
wrapping. %module should also be at the top of the interface file, but
it shouldn't matter given that you only have a %include of a templated
library above it. As you've commented out most of your code, you will
only get wrappers for tokenizer and spitter, it isn't clear if you were
expecting more.

William

Guillaume Yziquel wrote:

> Hello.
>
> I've made a swig freeling.i file that worked. As I was going to use more
> and more std::lists, I tried to modularise it by adding %include
> <std_list.i> and commenting out the code wrapping lists.
>
> Now, I get std_list.ml and std_list.mli as well as std_lib_wrap.cxx, but
> not anymore the files wrapping freeling.i...
>
> What am I doing wrong?
>
> All the best,
>
> Guillaume Yziquel
>
>
>> yziquel@seldon:~/svn/main/libmorfo-ocaml$ cat freeling.i
>> %include <std_list.i>
>>
>> %module swig_Freeling
>> %{
>>
>> #include "freeling.h"
>>
>> using namespace std;
>>
>> string string_of_chars (char * c)
>> {
>>   string s (c);
>>   return s;
>> }
>>
>> /*word last_word_of_word_list (list<word> & l)
>> {
>>   word head = l.front ();
>>   return head;
>> }
>>
>> void pop_last_word_list (list<word> & l)
>> {
>>   l.pop_front ();
>> }
>>
>> bool is_empty_word_list (list<word> & l)
>> {
>>   bool b = l.empty ();
>>   return b;
>> }
>>
>> list<word> new_word_list ()
>> {
>>   list<word> l;
>>   return l;
>> }
>>
>> void push_last_word_list (list<word> & l, word& w)
>> {
>>   l.push_back (w);
>> }*/
>>
>> %}
>>
>> // C++ functions used to glue code with OCaml.
>>
>> string string_of_chars (char *);
>>
>> /*word last_word_of_word_list (list<word> &);
>> void pop_last_word_list (list<word> &);
>> bool is_empty_word_list (list<word> &);
>> list<word> new_word_list ();
>> void push_last_word_list (list<word> &, word &);*/
>>
>> // Freeling declarations.
>>
>> class tokenizer {
>>    public:
>>        /// Constructor
>>        tokenizer(const string &);
>>
>>        /// tokenize string with default options
>>        list<word> tokenize(const string &);
>>        /// tokenize string with default options, tracking offset in given int param.
>>        list<word> tokenize(const string &, unsigned long &);
>> };
>>
>> class splitter {
>>    public:
>>       /// Constructor
>>       splitter(const std::string &);
>>
>>       /// split sentences with default options
>>       std::list<sentence> split(const std::list<word> &, bool);
>> };
>>
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Swig-user mailing list
> Swig-user@...
> https://lists.sourceforge.net/lists/listinfo/swig-user
>


------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Type mismatch...

by Guillaume Yziquel-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

William S Fulton a écrit :

> I don't know the OCAML module and what files it generates, but in the
> code below, you don't have any %template directive for wrapping
> std::list. Please read the C++ chapter in the documentation on template
> wrapping. %module should also be at the top of the interface file, but
> it shouldn't matter given that you only have a %include of a templated
> library above it. As you've commented out most of your code, you will
> only get wrappers for tokenizer and spitter, it isn't clear if you were
> expecting more.
>
> William

OK.

Got a %template working. freeling.i is at the bottom of this email.

I'm surprised about the following compiler error.

> gcc -fPIC -O2 -c -xc++ freeling_wrap.cxx.c
> freeling_wrap.cxx.c: In function ‘caml_value_t _wrap_word_select_analysisswig_Freeling(caml_value_t)’:
> freeling_wrap.cxx.c:5107: error: no matching function for call to ‘word::select_analysis(analysis&)’
> /usr/include/fries/language.h:214: note: candidates are: void word::select_analysis(std::_List_iterator<analysis>)

Seems to me that the wrapping code make a mistake concerning the
select_analysis function wrapper. Line 5107 expects an *arg2 of type
analysis...

> freeling_wrap.cxx.c:
>
>   5090  SWIGEXT CAML_VALUE _wrap_word_select_analysisswig_Freeling (CAML_VALUE args)
>   5091  {
>   5092    CAMLparam1(args);
>   5093    SWIG_CAMLlocal2(swig_result,rv);
>   5094    int _v = 0;
>   5095    word *arg1 = (word *) 0 ;
>   5096    analysis *arg2 = 0 ;
>   5097    
>   5098    swig_result = Val_unit;
>   5099    {
>   5100      /* %typemap(in) SWIGTYPE * */
>   5101      arg1 = (word *)caml_ptr_val(caml_list_nth(args,0),SWIGTYPE_p_word);
>   5102    }
>   5103    {
>   5104      /* %typemap(in) SWIGTYPE & */
>   5105      arg2 = (analysis *) caml_ptr_val(caml_list_nth(args,1),SWIGTYPE_p_analysis);
>   5106    }
>   5107    (arg1)->select_analysis(*arg2);
>   5108    rv = Val_unit;
>   5109    swig_result = caml_list_append(swig_result,rv);
>   5110    CAMLreturn(swig_result);
>   5111  }

But it is declared in language.h as void select_analysis(word::iterator);

So there's a typing mismatch in the wrapper code. Is it a bug of swig,
or a bug of my brain?

freeling.i file follows at the bottom of the mail.

> language.h:
>
>    102  class word : public std::list<analysis> {
>    103     private:
>    104       /// lexical form
>    105       std::string form;                
>    106       /// first selected analysis (if any)
>    107       word::iterator selected;
>    108       /// empty list if not a multiword
>    109       std::list<word> multiword;
>    110       /// token span
>    111       unsigned long start, finish;
>    112       /// word form found in dictionary
>    113       bool in_dict;
>    114       /// word morphological shouldn't be further modified
>    115       bool locked;
>    116  
>    117     public:
>    118        /// user-managed data, we just store it.
>    119        std::vector<std::string> user;
>    120  
>    121        /// constructor
>    122        word();
>    123        /// constructor
>    124        word(const std::string &);
>    125        /// constructor
>    126        word(const std::string &, const std::list<word> &);
>    127        /// constructor
>    128        word(const std::string &, const std::list<analysis> &, const std::list<word> &);
>    129        /// Copy constructor
>    130        word(const word &);
>    131        /// assignment
>    132        word& operator=(const word&);
>    133  
>    134        /// Get the number of selected analysis
>    135        int get_n_selected(void) const;
>    136        /// get the number of unselected analysis
>    137        int get_n_unselected(void) const;
>    138        /// true iff the word is a multiword compound
>    139        bool is_multiword(void) const;
>    140        /// get number of words in compound
>    141        int get_n_words_mw(void) const;
>    142        /// get word objects that compound the multiword
>    143        std::list<word> get_words_mw(void) const;
>    144        /// get word form
>    145        std::string get_form(void) const;
>    146        /// Get an iterator to the first selected analysis
>    147        word::iterator selected_begin(void);
>    148        /// Get an iterator to the first selected analysis
>    149        word::const_iterator selected_begin(void) const;
>    150        /// Get an iterator to the end of selected analysis list
>    151        word::iterator selected_end(void);
>    152        /// Get an iterator to the end of selected analysis list
>    153        word::const_iterator selected_end(void) const;
>    154        /// Get an iterator to the first unselected analysis
>    155        word::iterator unselected_begin(void);
>    156        /// Get an iterator to the first unselected analysis
>    157        word::const_iterator unselected_begin(void) const;
>    158        /// Get an iterator to the end of unselected analysis list
>    159        word::iterator unselected_end(void);
>    160        /// Get an iterator to the end of unselected analysis list
>    161        word::const_iterator unselected_end(void) const;
>    162        /// get lemma for the selected analysis in list
>    163        std::string get_lemma(void) const;
>    164        /// get parole for the selected analysis  
>    165        std::string get_parole(void) const;
>    166        /// get parole (short version) for the selected analysis  
>    167        std::string get_short_parole(const std::string &) const;
>    168  
>    169        /// get sense list for the selected analysis  
>    170        std::list<std::string> get_senses(void) const;
>    171        // useful for java API
>    172        std::string get_senses_string(void) const;
>    173        /// set sense list for the selected analysis  
>    174        void set_senses(const std::list<std::string> &);
>    175    
>    176        /// get token span.
>    177        unsigned long get_span_start(void) const;
>    178        unsigned long get_span_finish(void) const;
>    179  
>    180        /// get in_dict
>    181        bool found_in_dict(void) const;
>    182        /// set in_dict
>    183        void set_found_in_dict(bool);
>    184        /// check if there is any retokenizable analysis
>    185        bool has_retokenizable(void) const;
>    186        /// mark word as having definitive analysis
>    187        void lock_analysis();
>    188        /// check if word is marked as having definitive analysis
>    189        bool is_locked(void) const;
>    190  
>    191        /// add one analysis to current analysis list  (no duplicate check!)
>    192        void add_analysis(const analysis &);
>    193        /// set analysis list to one single analysis, overwriting current values
>    194        void set_analysis(const analysis &);
>    195        /// set analysis list, overwriting current values
>    196        void set_analysis(const std::list<analysis> &);
>    197        /// set word form
>    198        void set_form(const std::string &);
>    199        /// set token span
>    200        void set_span(unsigned long, unsigned long);
>    201        
>    202        /// look for an analysis with a parole matching given regexp
>    203        bool find_tag_match(RegEx &);
>    204  
>    205        /// get number of analysis in current list
>    206        int get_n_analysis(void) const;
>    207        /// copy analysis list
>    208        void copy_analysis(const word &);
>    209        /// empty the list of selected analysis
>    210        void unselect_all_analysis();
>    211        /// mark all analysisi as selected
>    212        void select_all_analysis();
>    213        /// add the given analysis to selected list.
>    214        void select_analysis(word::iterator);
>    215        /// remove the given analysis from selected list.
>    216        void unselect_analysis(word::iterator);
>    217        /// get list of analysis (useful for perl API)
>    218        std::list<analysis> get_analysis(void) const;
>    219        /// get begin iterator to analysis list (useful for perl/java API)
>    220        word::iterator analysis_begin(void);
>    221        word::const_iterator analysis_begin(void) const;
>    222        /// get end iterator to analysis list (useful for perl/java API)
>    223        word::iterator analysis_end(void);
>    224        word::const_iterator analysis_end(void) const;
>    225  };

All the best,

Guillaume Yziquel.

freeling.i file:

> %module swig_Freeling
> %{
>   #include "freeling.h"
>   #include "fries.h"
> %}
>
> %include std_list.i
>
> %template(ListAnalysis) std::list<analysis>;
>
> // Fries declarations.
>
> class analysis {
>    public:
>       /// user-managed data, we just store it.
>       std::vector<std::string> user;
>
>       /// constructor
>       analysis();
>       /// constructor
>       analysis(const std::string &, const std::string &);
>       /// assignment
>       analysis& operator=(const analysis&);
>
>       void set_lemma(const std::string &);
>       void set_parole(const std::string &);
>       void set_prob(double);
>       void set_retokenizable(const std::list<word> &);
>
>       bool has_prob(void) const;  
>       std::string get_lemma(void) const;
>       std::string get_parole(void) const;
>       std::string get_short_parole(const std::string &) const;
>       double get_prob(void) const;
>       bool is_retokenizable(void) const;
>       std::list<word> get_retokenizable(void) const;
>
>       std::list<std::string> get_senses(void) const;
>       std::string get_senses_string(void) const;
>       void set_senses(const std::list<std::string> &);
>
> };
>
> class word : public std::list<analysis> {
>    public:
>       /// user-managed data, we just store it.
>       std::vector<std::string> user;
>
>       /// constructor
>       word();
>       /// constructor
>       word(const std::string &);
>       /// constructor
>       word(const std::string &, const std::list<word> &);
>       /// constructor
>       word(const std::string &, const std::list<analysis> &, const std::list<word> &);
>       /// Copy constructor
>       word(const word &);
>       /// assignment
>       word& operator=(const word&);
>
>       /// Get the number of selected analysis
>       int get_n_selected(void) const;
>       /// get the number of unselected analysis
>       int get_n_unselected(void) const;
>       /// true iff the word is a multiword compound
>       bool is_multiword(void) const;
>       /// get number of words in compound
>       int get_n_words_mw(void) const;
>       /// get word objects that compound the multiword
>       std::list<word> get_words_mw(void) const;
>       /// get word form
>       std::string get_form(void) const;
>       /// Get an iterator to the first selected analysis
>       word::iterator selected_begin(void);
>       /// Get an iterator to the first selected analysis
>       word::const_iterator selected_begin(void) const;
>       /// Get an iterator to the end of selected analysis list
>       word::iterator selected_end(void);
>       /// Get an iterator to the end of selected analysis list
>       word::const_iterator selected_end(void) const;
>       /// Get an iterator to the first unselected analysis
>       word::iterator unselected_begin(void);
>       /// Get an iterator to the first unselected analysis
>       word::const_iterator unselected_begin(void) const;
>       /// Get an iterator to the end of unselected analysis list
>       word::iterator unselected_end(void);
>       /// Get an iterator to the end of unselected analysis list
>       word::const_iterator unselected_end(void) const;
>       /// get lemma for the selected analysis in list
>       std::string get_lemma(void) const;
>       /// get parole for the selected analysis  
>       std::string get_parole(void) const;
>       /// get parole (short version) for the selected analysis  
>       std::string get_short_parole(const std::string &) const;
>
>       /// get sense list for the selected analysis  
>       std::list<std::string> get_senses(void) const;
>       std::string get_senses_string(void) const;
>       /// set sense list for the selected analysis  
>       void set_senses(const std::list<std::string> &);
>    
>       /// get token span.
>       unsigned long get_span_start(void) const;
>       unsigned long get_span_finish(void) const;
>
>       /// get in_dict
>       bool found_in_dict(void) const;
>       /// set in_dict
>       void set_found_in_dict(bool);
>       /// check if there is any retokenizable analysis
>       bool has_retokenizable(void) const;
>
>       /// add one analysis to current analysis list  (no duplicate check!)
>       void add_analysis(const analysis &);
>       /// set analysis list to one single analysis, overwriting current values
>       void set_analysis(const analysis &);
>       /// set analysis list, overwriting current values
>       void set_analysis(const std::list<analysis> &);
>       /// set word form
>       void set_form(const std::string &);
>       /// set token span
>       void set_span(unsigned long, unsigned long);
>      
>       /// look for an analysis with a parole matching given regexp
>       bool find_tag_match(RegEx &);
>
>       /// get number of analysis in current list
>       int get_n_analysis(void) const;
>       /// copy analysis list
>       void copy_analysis(const word &);
>       /// empty the list of selected analysis
>       void unselect_all_analysis();
>       /// mark all analysisi as selected
>       void select_all_analysis();
>       /// add the given analysis to selected list.
>       void select_analysis(word::iterator);
>       /// remove the given analysis from selected list.
>       void unselect_analysis(word::iterator);
>       /// get list of analysis (useful for perl API)
>       std::list<analysis> get_analysis(void) const;
>       /// get begin iterator to analysis list (useful for perl/java API)
>       word::iterator analysis_begin(void);
>       word::const_iterator analysis_begin(void) const;
>       /// get end iterator to analysis list (useful for perl/java API)
>       word::iterator analysis_end(void);
>       word::const_iterator analysis_end(void) const;
> };
>
>
> // Freeling declarations.
>
> class tokenizer {
>    public:
>        /// Constructor
>        tokenizer(const std::string &);
>
>        /// tokenize string with default options
>        std::list<word> tokenize(const std::string &);
>        /// tokenize string with default options, tracking offset in given int param.
>        std::list<word> tokenize(const std::string &, unsigned long &);
> };

--
      Guillaume Yziquel
http://yziquel.homelinux.org/

------------------------------------------------------------------------------
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user