Skip to content

Reuse StringGazetteer Object #188

Open

Description

@luisenriqueramos1977

Is your feature request related to a problem? Please describe.

I currently can use a text file with a list of terms to create a StringGazetteer, which I can use without any problem.
However, as this is part of a repetitive process, I would like to have the possibility of storing the StringGazetteer object to reuse it,
and I wonder if such a feature is available?, or if there is any other approach to reach this goal?.

Luis Ramos

Activity

  1. johann-petrak commented on Apr 17, 2023

    @johann-petrak
    Collaborator

    Thank you for this feature request!

    I think it would be a good idea to be able to store and load a gazetteer instance, however currently this is not immediately possible and the code would need some work to make it possible to e.g. pickle the instance.

    The main issue I see at the moment is that in order to be able to pickle the object, any lambdas must be replaced with callables that can be pickled, or by plugging into the pickle process by implementing our own __getstate__ and __setstate__ methods.

  2. johann-petrak commented on Apr 17, 2023

    @johann-petrak
    Collaborator

    Actually, I think you could try doing this with the cloudpickle package:
    Install the package into your environment then do something like this to save and restore the gazetteer instance:

    Save:

    import cloudpickle
    with open("gaz1.pkl", "wb") as outf:
        cloudpickle.dump(gaz1, outf)
    

    Load:

    with open("gaz1.pkl", "rb") as inf:
        gaz1 = cloudpickle.load(inf)
    

    Does that work for you?

  3. johann-petrak commented on Apr 17, 2023

    @johann-petrak
    Collaborator

    Alternately, you could try using the dill package in a similar way.

  4. luisenriqueramos1977 commented on May 30, 2023

    @luisenriqueramos1977
    Author
  5. johann-petrak commented on May 30, 2023

    @johann-petrak
    Collaborator

    It seems there is a blank space in the list,

    What do you mean by that? Would you be able to cut the list down to the shortest list that produces that error and share it with me either heere, or by private email?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions