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

Added python3 support, added lookup utility #418

Merged
merged 3 commits into from
Mar 11, 2023

Conversation

sebimoe
Copy link
Contributor

@sebimoe sebimoe commented Mar 11, 2023

Python 3 support

I have updated kvg.py and kanjivg.py files to work with both Python 2 and Python 3 (tested 2.7 and 3.9).

XML Handler Fixes

I have updated KanjisHandler and SVGHandler XML-parsing classes in kanjivg.py to work on the current SVG/XML structure. I may have been confused by them, but I could not get them to work, so I rewrote some functionality.

  • In case of SVGHandler the changes were limited to accounting for the parent StrokePaths group and ignoring it.
  • In case of KanjisHandler the changes involved re-writing how it processes each kanji in turn, as I could not figure out how it was meant to be used.

New command-line utility

I added a utility for displaying a summary of a character based on SVG or XML files. It is useful for checking that the SVGHandler and KanjisHandler classes work correctly at first glance. It is also an example of how to use XML parsing.

$ python .\kvg-lookup.py            
Usage: .\kvg-lookup.py <find-svg|find-xml> <element1> [...elementN]

Recognized commands:
  find-svg      Find and view summary of an SVG file for the given
                element in ./kanji/ directory.
  find-xml      Find and view summary of a <kanji> entry for
                the given element from ./kanjivg.xml file.

Parameters:
  element           May either be the singular character, e.g. 並 or its
                unicode code-point e.g. 4e26.

Examples:
  .\kvg-lookup.py find-svg 並      Will list SVG files describing given character.
  .\kvg-lookup.py find-xml 4e26    Will list <kanji> entry for the same character.
$ python .\kvg-lookup.py find-svg 香  
Found 2 files matching ID 09999

File ./kanji/09999-Kaisho.svg (1/2):
Character summary: 09999 (香) - variant: Kaisho
- group 香
    - group 禾 (top)
        - group 丿 (top)
            - strokes: ㇒
        - group 木 (bottom)
            - strokes: ㇐ ㇑ ㇒ ㇏
    - group 日 (bottom)
        - strokes: ㇑ ㇕a ㇐a ㇐a


File ./kanji/09999.svg (2/2):
Character summary: 09999 (香)
- group 香
    - group 禾 (top)
        - group 丿 (top)
            - strokes: ㇒
        - group 木 (bottom)
            - strokes: ㇐ ㇑ ㇒ ㇏
    - group 日 (bottom)
        - strokes: ㇑ ㇕a ㇐a ㇐a

sebimoe added 2 commits March 4, 2023 23:20
The tool displays a summary of loaded character, can be used for validating xml parser functions.
@sebimoe sebimoe marked this pull request as ready for review March 11, 2023 23:45
@benkasminbullock benkasminbullock merged commit 1344798 into KanjiVG:master Mar 11, 2023
@benkasminbullock
Copy link
Member

Thanks @sebimoe, it's great to have support for both Pythons, and the utility looks handy.

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

Successfully merging this pull request may close these issues.

2 participants