-
-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Load sudachidict dictionary #93
Load sudachidict dictionary #93
Conversation
Assume that "systemDict" key of default |
Can we do path resolution completely in Python? |
We can load python file using In that case python side code will be like this: |
python/src/dictionary.rs
Outdated
@@ -151,3 +153,21 @@ fn get_absolute_dict_path(py: Python, dict_type: DictionaryType) -> PyResult<Pat | |||
|
|||
Ok(dict_path) | |||
} | |||
|
|||
fn find_dict_path_py(py: Python, dict_type: &str) -> PyResult<PathBuf> { | |||
let source_file = PathBuf::from(env!("CARGO_MANIFEST_DIR")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The path won't be like this in the installed module (after doing pip install
).
I think it is OK to do this resolution inside __init__.py
, or even put the resolution function there (prefixed with underscore so it will be sort of private for the module).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like this?
let module = PyModule::import(py, "sudachi.dictionary_path")?;
In this case I think it's better to separate file, not to load other functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by load?
Resolving the path of the pip-installed dictionary is a core functionality of the Python binding, as long as it is shown as "do not call" for users, e.g. having _revolve_dic_internal
, it should not be a problem. Python does not have the concept of visibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PyModule.import
should work though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant the loading cost of PyModule::import
, which will loads entire module.
If we put functions in __init__.py
, maybe PyModule::from_code(py, "from sudachi import function")
, is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating a new dictionary is one off operation, it is OK for it to be more or less heavy.
return get_absolute_dict_path(dict_type) | ||
else: | ||
raise ModuleNotFoundError( | ||
'Package `sudachidict_{}` dose not exist. ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: does not exist
#73
WIP: default dictionary path settingSudachiPy:
dict_type
>config.systemDict
>sudachidict_core
.sudachi.rs: arg >
config.systemDict
> baked dict.