Version française
Home     About     Download     Resources     Contact us    
Browse thread
porter's stemmer implementation
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Yoann Padioleau <padator@w...>
Subject: Re: [Caml-list] porter's stemmer implementation

On Jan 17, 2010, at 4:49 PM, Guillaume Yziquel wrote:

> 
> Yoann Padioleau a écrit :
>> On Jan 16, 2010, at 11:01 PM, Grégoire Seux wrote:
>> There is one in nltk, a very complete python library for NLP and there is
>> ocamlpython to link ocaml and python code. As the stemmer interface is
>> very simpler (string -> string), it's very easy to use ocamlpython to do that.
>> open Pycaml
>> module Py = Python let modul = Py.cpr (Pycaml.pyimport_importmodule "nltk_ocaml")
>> let dict = Py.cpr (Pycaml.pymodule_getdict modul)
>> let stem s =   let py_str = Pycaml.pystring_fromstring s in
>>  let f = Py.cpr (Pycaml.pydict_getitemstring(dict, "stem")) in
>>  let args = Py.cpr (Pycaml.pytuple_fromsingle py_str) in
>>  let res = Py.cpr (Pycaml.pyeval_callobject (f,args)) in
>>  Pycaml.guarded_pystring_asstring res
> 
> I'm afraid I do not understand where you get your Python module from and you Py.cpr value from. I get from the Debian pycaml package:

Oops. I have an extra module called python.ml containing small
helper functions:

exception PythonError

(* henrik have written similar things *)
let check_python_return v =
  if v = Pycaml.pynull () 
  then begin
    Pycaml.pyerr_print ();
    raise PythonError
  end
  else v
      
(* alias *)
let cpr = check_python_return


> 
> # #require "pycaml";;
> /usr/lib/ocaml/unix.cma: loaded
> /usr/lib/ocaml/pycaml: added to search path
> /usr/lib/ocaml/pycaml/pycaml.cma: loaded
> # module X = Python;;
> Error: Unbound module Python
> # module X = Pycaml.Python;;
> Error: Unbound module Pycaml.Python
> # module X = Pycaml;;
> module X :
>  sig
>    type funcptr = Pycaml.funcptr
>    type pyobject = Pycaml.pyobject
>    type funcent = funcptr * int * int
>    type pymodule_func =
>      Pycaml.pymodule_func = {
>      pyml_name : string;
>      pyml_func : pyobject -> pyobject;
>      pyml_flags : int;
>      pyml_doc : string;
>    }
>    type pyobject_type =
>      Pycaml.pyobject_type =
>        TupleType
>      | StringType
>      | IntType
>      | FloatType
>      | ListType
>      | NoneType
>      | CallableType
> 
> Where did you get your pycaml from?

A mix of 
 * - Arty Yekes original pycaml 0.82,
 * - Henrik stuart port to python 2.5
 * - Thomas Fischbacher heavy extension.


> 
> All the best,
> 
> -- 
>     Guillaume Yziquel
> http://yziquel.homelinux.org/
>