You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?.
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.
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)
Dear Petrak,
Thanks for the information, I was able to test it and get similar results
for most gazetteers,
but in one of them I got the following error:
Cannot add gazetteer entry '', matches root node
It seems there is a blank space in the list, but I used the same procedure
for all of them, so I do not have idea how to solve this problem.
Best regards
Luis Ramos
El lun, 17 abr 2023 a las 12:15, Johann Petrak ***@***.***>)
escribió:
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?
Activity
johann-petrak commentedon Apr 17, 2023
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.johann-petrak commentedon Apr 17, 2023
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:
Load:
Does that work for you?
johann-petrak commentedon Apr 17, 2023
Alternately, you could try using the dill package in a similar way.
luisenriqueramos1977 commentedon May 30, 2023
johann-petrak commentedon May 30, 2023
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?