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

How do I "run" my python dictionary to get it to output a json? #4

Open
winstond opened this issue Sep 26, 2023 · 9 comments
Open

How do I "run" my python dictionary to get it to output a json? #4

winstond opened this issue Sep 26, 2023 · 9 comments

Comments

@winstond
Copy link

I tried:
python dictionary.py

But I get an error: ModuleNotFoundError: No module named 'plover'. I tried a few things, but I'm not super familiar with python so not sure what I'm missing.

Thank you.

@winstond winstond changed the title How to I "run" my python dictionary to get it to output a json? How do I "run" my python dictionary to get it to output a json? Sep 26, 2023
@user202729
Copy link
Owner

Not sure what I can support about this. I think you have a few options

  • hard code the system instead of importing from Plover
  • run it with a Python executable with access to Plover (depends on the operating system the instruction might be different... are you on Windows/Linux/Mac?)

@winstond
Copy link
Author

Yes, I do apologize. More of a Python question really. I'm on Win 11. Plover is in the usual place, C:\Program Files\Open Steno Project\Plover.

Perhaps once I can confirm the way to do this it could be added to the readme page?

I have a dictionary for Hindi I'd like to share, but right now I'd have to provide command line instructions for people to use it. Hoping to just have a JSON.

@winstond
Copy link
Author

Update: I managed to get it to work. Here are the steps in case anyone else stumbles on this:

Windows 11. Python install on system, but Plover uses it's own...

  1. Open a powershell (might need to open as admin depending on where your files are)
  2. Navigate to your plover directory (ex: c:\program files\open steno project\plover)
  3. Install plover-python-dictionary-lib in this instance of python with:
    .\data\python.exe -m pip install plover_python_dictionary_lib
  4. Run your python dictionary (which should include the line to print the dictionary to the terminal as per readme)
    .\data\python.exe .\hindirun.py
    Your dictionary should dump out to the terminal
  5. Highlight and copy your dictionary from the command prompt and make your json file.

(I tried piping to a file, but my JSON output had unicode characters so I got an encoding error. However copying the output in the terminal and pasting it still worked even though the terminal wouldn't display the the unicode characters properly.)

@user202729
Copy link
Owner

Some day it would be easier.

openstenoproject/plover_python_dictionary#9

@winstond
Copy link
Author

Having an issue with the above steps. Did something change in this library? I tried the steps above and I'm now getting a "Duplicate Keys" error.

More detail:
I have a .py file. When loaded into Plover as a python dictionary it works fine. However when I attempt to print out the output to json following the steps I previously documented in this issue, I now am getting an error "duplicate keys".

What I'm confused about is if there was a problem with the .py dictionary file I would expect to get an error when the dictionary is loaded in plover. I'm not getting any error there. I'm only getting this error when I attempt to output to a json file in a command window.

Here's the code error from my command prompt:
Traceback (most recent call last):
File ".\hindirun.py", line 1123, in
dictionary.print_items()
File "C:\Program Files\Open Steno Project\Plover_continuous\data\lib\site-packages\plover_python_dictionary_lib_init_.py", line 112, in print_items
json.dump(self.items_str_dict(), sys.stdout, ensure_ascii=False, indent=0)
File "C:\Program Files\Open Steno Project\Plover_continuous\data\lib\site-packages\plover_python_dictionary_lib_init_.py", line 104, in items_str_dict
assert len(result_items)==len(result), "Duplicate keys"
AssertionError: Duplicate keys

@user202729
Copy link
Owner

The problem is it's nontrivial to detect duplicate keys quickly. In order to detect it the program can list all the key-value pairs, but if it does every time Plover starts it would be slow. On the other hand when printing out the JSON dictionary, it needs to list all the key/values anyway, so it might as well do.

@winstond
Copy link
Author

I guess I don't understand why that control about duplicates is needed given that Plover doesn't fail with the same .py file.

That said, if the error could tell me what the duplicate was I could attempt to modify the .py file to ensure my python logic doesn't produce any duplicate stroke definitions.

As it is, I don't get the list, just the error. And no feedback on what I would need to modify to avoid the error and get a print out.

@user202729
Copy link
Owner

I modified it to just print a warning of some example duplicating entries instead of an error.

@winstond
Copy link
Author

Oh awesome! Thank you.

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