Skip to content
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

dictionary as an argument instead of attribute #12

Closed
drdhaval2785 opened this issue Feb 6, 2022 · 9 comments
Closed

dictionary as an argument instead of attribute #12

drdhaval2785 opened this issue Feb 6, 2022 · 9 comments

Comments

@drdhaval2785
Copy link

drdhaval2785 commented Feb 6, 2022

  • Python Interface to Cologne Digital Sanskrit Lexicon (CDSL) version: 0.2.1
  • Python version: 3.9.1
  • Operating System: Bodhi linux 6

Description

Instead of results = CDSL.MW.search("राम")
Kindly provide a functionality like results = CDSL.search(query="राम", dictionary="MW")

This would be required because I can easily pass 'MW' string I got from CLI, without much hassle.
Otherwise it gives me CDSL."MW" instead of CDSL.MW required in present state of affairs.

What I Did

Feature request.
@drdhaval2785
Copy link
Author

Similarly require the same functionality for entry.
entry = CDSL.entry('12352', dictionary="MW")

@drdhaval2785
Copy link
Author

Also see #13 for transliteration preferences to be added in the search and entry functionalities.

@hrishikeshrt
Copy link
Owner

Current CDSL.MW etc usage is a QoL feature.
The dictionary access actually happens through CDSL.dicts['MW'] etc.
Under the hood, when CDSL.MW is called, it calls CDSL.dicts['MW'] if the dictionary is installed.

@hrishikeshrt
Copy link
Owner

We can discuss the addition of search and entry commands to CDSLCorpus as well.
Currently, they are part of CDSLDict class.

I am in favour of search functionality, but not of entry functionality. Tracking this in #15

@drdhaval2785
Copy link
Author

You mean to say that I can use CDSL.dicts["MW"].search("राम") to achieve results similar to CDSL.MW.search("राम") ?

@drdhaval2785
Copy link
Author

If so, Kind request to document it in the docs, please.

@hrishikeshrt
Copy link
Owner

hrishikeshrt commented Feb 6, 2022

You mean to say that I can use CDSL.dicts["MW"].search("राम") to achieve results similar to CDSL.MW.search("राम") ?

That is correct.
Doing CDSL.dicts["MW"] would in fact be faster, as CDSL.MW first has to pass through a __getattr__ call.

If so, Kind request to document it in the docs, please.

Documentation added in fec3de7

@drdhaval2785
Copy link
Author

thanks

@hrishikeshrt
Copy link
Owner

I would like to add that since version 0.6.0+, use of [] operator is supported on CDSLCorpus and CDSLDict objects (introduced in commits 554fa7c and 4efce8f)

What this means is, we can now do CDSL["MW"] (in addition to the other two methods, CDSL.dicts["MW"] and CDSL.MW for CDSLCorpus instance.
Similarly, we can also use it on CDSLDict isntance to get entry by ID, i.e. CDSL["MW"]["263938"] (which is (mostly) equivalent with CDSL.entry("263938")

The documentation mentions these features as well. Also, it should be noted that while [] on CDSLCorpus is completely equivalent with . access and .dicts[] access, there is a minor difference between CDSLDict[] and CDSLDict.entry().
The difference being, in case an entry_id is absent, call based on [] will raise a KeyError while a call to CDSLDict.entry will return None and log a logging.ERROR level message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants