hor2vec

Change your horizontal pure text to vertical with some options.


Keywords
chinese, cli, python, python3, string, text
Licenses
GPL-3.0/GPL-3.0+
Install
pip install hor2vec==2.2.1

Documentation

hor2vec

Coverage Status

 _               ____
| |__   ___  _ _|___ \__   _____  ___
| '_ \ / _ \| '__|__) \ \ / / _ \/ __|
| | | | (_) | |  / __/ \ V /  __/ (__
|_| |_|\___/|_| |_____| \_/ \___|\___|

Change your horizontal pure text to vertical with some options.


Installation

  • hor2vec doesn't use any third party Python package.
  • You can just git clone from GitHub, cd into cloned hor2vec dir, and use python3 hor2vec ....
  • You can also install from PyPI with pip install hor2vec, after that, you can just use hor2vec ....

GitHub

$ git clone https://github.com/M157q/hor2vec

PyPI

$ pip install hor2vec

Docker

$ docker pull M157q/hor2vec


Usage

usage: hor2vec [-h] [-s SEP] [-ld {l2r,r2l}] [-wd {t2b,b2t}] [-nr] [-fw] [input]

positional arguments:
  input                 The file has horizontal pure text to be changed to vertical. If not
                        been given in the command, will use the stdin as input.

optional arguments:
  -h, --help            show this help message and exit
  -s SEP, --sep SEP, --separator SEP
                        The separator between lines. Default is '', you can use ' ', '|' or any
                        other strings.
  -ld {l2r,r2l}, --line-direction {l2r,r2l}
                        The reading direction of each line. Default is 'l2r' (left to right),
                        you can choose 'r2l' (right to left).
  -wd {t2b,b2t}, --word-direction {t2b,b2t}
                        The reading direction of each word/character. Default is 't2b' (top to
                        bottom), you can choose 'b2t' (bottom to top).
  -nr, --no-rotate      If this option has been given, hor2vec won't rotate the input.
  -fw, --full-width     If this option has been given, hor2vec will use fullwidth characters
                        instead of halfwidth characters. Some half-width punctuation marks
                        don't have vertical way. You can enable this option to make it show
                        full-width in vertical way.
  • Some half-width punctuation marks don't have vertical way.
    • You can enable option --full-width to make it show full-width in vertical way.

Usage - Docker

  • There are 2 ways to use the docker image
    • Use stdin as input
      • docker run -it --rm M157q/hor2vec
      • type in the input string
      • Press Ctrl-D
      • Get the output
    • Use local file as input
      • docker run -it --rm -v $PWD:/srv/work m157q/hor2vec ${FILENAME}
      • e.g., If you have a file a in your current directory:
        • docker run -it --rm -v $PWD:/srv/work m157q/hor2vec a
      • Get the output

Examples

Chinese

$ cat tests/data/chinese_test_data.txt
ๆˆ‘่ฆ่ธไธŠไธ€ๅ€‹้™Œ็”Ÿ็š„ๆ—…้€”
ๆˆ‘ๆœƒๅฟ˜่จ˜ๆœ‰ไฝ ้™ชไผด็š„ๆบซๅบฆ
่ฉฆ่‘—ๆ”พไธ‹ๅฟƒไธญๆœ€้บๆ†พๅญค็จ
ๅญธ่‘—็ฅ็ฆ
ๆˆ‘่ฆ่ฎŠๆˆๅ…จไธ–็•Œๆœ€ๅ‹‡ๆ•ข็š„ไบบ
็›ธไฟกไธ€ๅˆ‡ๅฎ‰ๆŽ’้ƒฝๆ˜ฏๆœ€ๅฅฝ็š„่ทฏ
ๅ†่ฆ‹
$ python3 hor2vec tests/data/chinese_test_data.txt
ๆˆ‘ๆˆ‘่ฉฆๅญธๆˆ‘็›ธๅ†
่ฆๆœƒ่‘—่‘—่ฆไฟก่ฆ‹
่ธๅฟ˜ๆ”พ็ฅ่ฎŠไธ€
ไธŠ่จ˜ไธ‹็ฆๆˆๅˆ‡
ไธ€ๆœ‰ๅฟƒใ€€ๅ…จๅฎ‰
ๅ€‹ไฝ ไธญใ€€ไธ–ๆŽ’
้™Œ้™ชๆœ€ใ€€็•Œ้ƒฝ
็”Ÿไผด้บใ€€ๆœ€ๆ˜ฏ
็š„็š„ๆ†พใ€€ๅ‹‡ๆœ€
ๆ—…ๆบซๅญคใ€€ๆ•ขๅฅฝ
้€”ๅบฆ็จใ€€็š„็š„
ใ€€ใ€€ใ€€ใ€€ไบบ่ทฏ
$ python3 hor2vec -s '|' tests/data/chinese_test_data.txt
ๆˆ‘|ๆˆ‘|่ฉฆ|ๅญธ|ๆˆ‘|็›ธ|ๅ†
่ฆ|ๆœƒ|่‘—|่‘—|่ฆ|ไฟก|่ฆ‹
่ธ|ๅฟ˜|ๆ”พ|็ฅ|่ฎŠ|ไธ€|
ไธŠ|่จ˜|ไธ‹|็ฆ|ๆˆ|ๅˆ‡|
ไธ€|ๆœ‰|ๅฟƒ|ใ€€|ๅ…จ|ๅฎ‰|
ๅ€‹|ไฝ |ไธญ|ใ€€|ไธ–|ๆŽ’|
้™Œ|้™ช|ๆœ€|ใ€€|็•Œ|้ƒฝ|
็”Ÿ|ไผด|้บ|ใ€€|ๆœ€|ๆ˜ฏ|
็š„|็š„|ๆ†พ|ใ€€|ๅ‹‡|ๆœ€|
ๆ—…|ๆบซ|ๅญค|ใ€€|ๆ•ข|ๅฅฝ|
้€”|ๅบฆ|็จ|ใ€€|็š„|็š„|
ใ€€|ใ€€|ใ€€|ใ€€|ไบบ|่ทฏ|
$ python3 hor2vec -s '|' -ld r2l tests/data/chinese_test_data.txt
ๅ†|็›ธ|ๆˆ‘|ๅญธ|่ฉฆ|ๆˆ‘|ๆˆ‘
่ฆ‹|ไฟก|่ฆ|่‘—|่‘—|ๆœƒ|่ฆ
ใ€€|ไธ€|่ฎŠ|็ฅ|ๆ”พ|ๅฟ˜|่ธ
ใ€€|ๅˆ‡|ๆˆ|็ฆ|ไธ‹|่จ˜|ไธŠ
ใ€€|ๅฎ‰|ๅ…จ|ใ€€|ๅฟƒ|ๆœ‰|ไธ€
ใ€€|ๆŽ’|ไธ–|ใ€€|ไธญ|ไฝ |ๅ€‹
ใ€€|้ƒฝ|็•Œ|ใ€€|ๆœ€|้™ช|้™Œ
ใ€€|ๆ˜ฏ|ๆœ€|ใ€€|้บ|ไผด|็”Ÿ
ใ€€|ๆœ€|ๅ‹‡|ใ€€|ๆ†พ|็š„|็š„
ใ€€|ๅฅฝ|ๆ•ข|ใ€€|ๅญค|ๆบซ|ๆ—…
ใ€€|็š„|็š„|ใ€€|็จ|ๅบฆ|้€”
ใ€€|่ทฏ|ไบบ|ใ€€|ใ€€|ใ€€|
$ python3 hor2vec -s '|' -ld r2l -wd b2t tests/data/chinese_test_data.txt
ใ€€|่ทฏ|ไบบ|ใ€€|ใ€€|ใ€€|
ใ€€|็š„|็š„|ใ€€|็จ|ๅบฆ|้€”
ใ€€|ๅฅฝ|ๆ•ข|ใ€€|ๅญค|ๆบซ|ๆ—…
ใ€€|ๆœ€|ๅ‹‡|ใ€€|ๆ†พ|็š„|็š„
ใ€€|ๆ˜ฏ|ๆœ€|ใ€€|้บ|ไผด|็”Ÿ
ใ€€|้ƒฝ|็•Œ|ใ€€|ๆœ€|้™ช|้™Œ
ใ€€|ๆŽ’|ไธ–|ใ€€|ไธญ|ไฝ |ๅ€‹
ใ€€|ๅฎ‰|ๅ…จ|ใ€€|ๅฟƒ|ๆœ‰|ไธ€
ใ€€|ๅˆ‡|ๆˆ|็ฆ|ไธ‹|่จ˜|ไธŠ
ใ€€|ไธ€|่ฎŠ|็ฅ|ๆ”พ|ๅฟ˜|่ธ
่ฆ‹|ไฟก|่ฆ|่‘—|่‘—|ๆœƒ|่ฆ
ๅ†|็›ธ|ๆˆ‘|ๅญธ|่ฉฆ|ๆˆ‘|ๆˆ‘
$ python3 hor2vec -nr -ld r2l tests/data/chinese_test_data.txt
ใ€€้€”ๆ—…็š„็”Ÿ้™Œๅ€‹ไธ€ไธŠ่ธ่ฆๆˆ‘
ใ€€ๅบฆๆบซ็š„ไผด้™ชไฝ ๆœ‰่จ˜ๅฟ˜ๆœƒๆˆ‘
ใ€€็จๅญคๆ†พ้บๆœ€ไธญๅฟƒไธ‹ๆ”พ่‘—่ฉฆ
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€็ฆ็ฅ่‘—ๅญธ
ไบบ็š„ๆ•ขๅ‹‡ๆœ€็•Œไธ–ๅ…จๆˆ่ฎŠ่ฆๆˆ‘
่ทฏ็š„ๅฅฝๆœ€ๆ˜ฏ้ƒฝๆŽ’ๅฎ‰ๅˆ‡ไธ€ไฟก็›ธ
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€่ฆ‹ๅ†
$ python3 hor2vec -nr -ld r2l -wd b2t tests/data/chinese_test_data.txt
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€่ฆ‹ๅ†
่ทฏ็š„ๅฅฝๆœ€ๆ˜ฏ้ƒฝๆŽ’ๅฎ‰ๅˆ‡ไธ€ไฟก็›ธ
ไบบ็š„ๆ•ขๅ‹‡ๆœ€็•Œไธ–ๅ…จๆˆ่ฎŠ่ฆๆˆ‘
ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€็ฆ็ฅ่‘—ๅญธ
ใ€€็จๅญคๆ†พ้บๆœ€ไธญๅฟƒไธ‹ๆ”พ่‘—่ฉฆ
ใ€€ๅบฆๆบซ็š„ไผด้™ชไฝ ๆœ‰่จ˜ๅฟ˜ๆœƒๆˆ‘
ใ€€้€”ๆ—…็š„็”Ÿ้™Œๅ€‹ไธ€ไธŠ่ธ่ฆๆˆ‘

English

$ cat tests/data/english_test_data.txt
I
want
to
be
your
friend.

Can
we
?
$ python3 hor2vec tests/data/english_test_data.txt
Iwtbyf Cw?
 aoeor ae
 n  ui n
 t  re
     n
     d
     .
$ python3 hor2vec -fw tests/data/english_test_data.txt
๏ผฉ๏ฝ—๏ฝ”๏ฝ‚๏ฝ™๏ฝ† ๏ผฃ๏ฝ—๏ผŸ
ใ€€๏ฝ๏ฝ๏ฝ…๏ฝ๏ฝ’ ๏ฝ๏ฝ…
ใ€€๏ฝŽใ€€ใ€€๏ฝ•๏ฝ‰ ๏ฝŽ
ใ€€๏ฝ”ใ€€ใ€€๏ฝ’๏ฝ…
ใ€€ใ€€ใ€€ใ€€ใ€€๏ฝŽ
ใ€€ใ€€ใ€€ใ€€ใ€€๏ฝ„
ใ€€ใ€€ใ€€ใ€€ใ€€๏ผŽ
$ python3 hor2vec -s ' ' tests/data/english_test_data.txt
I w t b y f   C w ?
  a o e o r   a e
  n     u i   n
  t     r e
          n
          d
          .
$ python3 hor2vec -s ' ' -ld r2l tests/data/english_test_data.txt
? w C   f y b t w I
  e a   r o e o a
    n   i u     n
        e r     t
        n
        d
        .
$ python3 hor2vec -s ' ' -ld r2l -wd b2t tests/data/english_test_data.txt
        .
        d
        n
        e r     t
    n   i u     n
  e a   r o e o a
? w C   f y b t w I
$ python3 hor2vec -nr -ld r2l tests/data/english_test_data.txt
      I
   tnaw
     ot
     eb
   ruoy
.dneirf

    naC
     ew
      ?
$ python3 hor2vec -nr -ld r2l -wd b2t tests/data/english_test_data.txt
      ?
     ew
    naC

.dneirf
   ruoy
     eb
     ot
   tnaw
      I

Development

Install test dependencies

pip install -r requirements-test.txt

Testings

python -m pytest --cov hor2vec/ --cov-report html --cov-report term

or just

make test