semvec/pypi-packages huggingface dataset:
baltech-sdk 3.19.4
SDK to communicate with Baltech RFID readers.
License: MIT
Requires Python: <4.0,>=3.9

# Baltech SDK

***Warning: While the underlying SDK is stable, the Python API is not stable yet, and future releases are not guaranteed to be backwards compatible. Pinning this project to a specific version in your dependency management is recommended.***

## Installation
```bash
pip install baltech-sdk
```

## Usage

```python
from baltech_sdk import Brp, UsbHid

# Sample code for GetInfo
with Brp(UsbHid()) as brp:
    print(brp.Sys_GetInfo())

# This is a shortcut for:
io = UsbHid()
brp = Brp(io, open=False)
brp.open()
print(brp.Sys_GetInfo())
brp.close()
```
A complete reference of the supported commands can be found [here](https://docs.baltech.de/refman/cmds/index.html).

### Supported IO protocols
```python
from baltech_sdk import Brp, UsbHid, RS232, Tcp

# USB HID autodetect connected reader
brp = Brp(UsbHid())

# USB HID by serialnumber
brp = Brp(UsbHid(serialnumber=99999999))

# Serial with (optional) custom settings
brp = Brp(RS232("COM1", baudrate=115200, parity=b"N"))

# TCP by ip address
brp = Brp(Tcp(ipaddr="192.168.0.1"))
```

### Access Reader Configuration
```python
from baltech_sdk import Config

cfg_src = {(0x0201, 0x02): b'\x01'}   # instead of a confDict also a brp object 
                                     # can be passed to modify reader's 
                                     # configuration directly
cfg = Config(cfg_src)

# set value
cfg.Device_Boot_StartAutoreadAtPowerup("EnableOnce")

# get value
print(cfg.Device_Boot_StartAutoreadAtPowerup.get())

# delete value
cfg.Device_Boot_StartAutoreadAtPowerup.delete()
```

### Templates and BaltechScripts
```python
from baltech_sdk import Config, Template, BaltechScript, TemplateFilter

confdict = {}
cfg = Config(confdict)

cfg.Scripts_Events_OnAccepted(
    BaltechScript()
        .ToggleInverted("RedLed", RepeatCount=3, Delay=20)
        .Toggle("GreenLed", RepeatCount=1, Delay=20)
        .DefaultAction()
)
cfg.Autoread_Rule_Template(
    0, 
    Template()
        .Static(b"SNR:")
        .Serialnr(TemplateFilter(BinToAscii=True, Unpack=True, BinToBcd=True))
)
print(confdict)
```

### Linux or macOS
To use ``baltech-sdk`` under Linux or macOS you need to build your own binary of the [BaltechSDK](https://docs.baltech.de/developers/sdk.html) and manually set the path to your binary.
```python
from pathlib import Path
from baltech_sdk import set_brp_lib_path

set_brp_lib_path(Path("path/to/brp_lib"))
```


### Further parameters on connections fors sensible data 

Additional Options: 
 * [AES based Encryption](https://docs.baltech.de/developers/add-aes-auth-and-encryption.html) can be activated
 * [Enabled monitoring](https://docs.baltech.de/developers/analyze-communication.html#enable-monitoring) can be suppressed or extended to plaintext

```python
from baltech_sdk import Brp, UsbHid, SecureChannel

KEY = b'abcdefghijklmnuk'
brp = Brp(UsbHid(), 
          crypto=SecureChannel(security_level=1, key=KEY),  # encrypt communication
          monitor="plaintext"                               # log unencrypted data (if activated by user)
)
```
char-similar 0.0.2
char-similar: Tookit of Chinese Character Similarity, Especially the Shape of the Characters.
License: MIT

# char-similar


>>> 汉字字形/拼音/语义相似度(单字, 可用于数据增强, CSC错别字检测识别任务(构建混淆集))





# 一、安装


```


0. 注意事项


   默认不指定numpy版本(标准版numpy==1.22.4), 过高或者过低的版本可能不支持


   标准版本的依赖包详见 requirements-all.txt


   


1. 通过PyPI安装


   pip install char-similar


   使用镜像源, 如：


   pip install -i https://pypi.tuna.tsinghua.edu.cn/simple char-similar


```





# 二、使用方式





## 2.1 快速使用


```python3


from char_similar import std_cal_sim


char1 = "我"


char2 = "他"


res = std_cal_sim(char1, char2)


print(res)


# output:


# 0.5821


```





## 2.2 详细使用


```python3


from char_similar import std_cal_sim


# "all"(字形:拼音:字义=1:1:1)  # "w2v"(字形:字义=1:1)  # "pinyin"(字形:拼音=1:1)  # "shape"(字形=1)


kind = "shape"


rounded = 4  # 保留x位小数


char1 = "我"


char2 = "他"


res = std_cal_sim(char1, char2, rounded=rounded, kind=kind)


print(res)


# output:


# 0.5821


```








## 2.3 多线程使用


```python3


from char_similar import pool_cal_sim


# "all"(字形:拼音:字义=1:1:1)  # "w2v"(字形:字义=1:1)  # "pinyin"(字形:拼音=1:1)  # "shape"(字形=1)


kind = "shape"


rounded = 4  # 保留x位小数


char1 = "我"


char2 = "他"


res = pool_cal_sim(char1, char2, rounded=rounded, kind=kind)


print(res)


# output:


# 0.5821


```








## 2.4 多进程使用(不建议, 实现得较慢)


```python3


if __name__ == '__main__':


    from char_similar import multi_cal_sim


    # "all"(字形:拼音:字义=1:1:1)  # "w2v"(字形:字义=1:1)  # "pinyin"(字形:拼音=1:1)  # "shape"(字形=1)


    kind = "shape"


    rounded = 4  # 保留x位小数


    char1 = "我"


    char2 = "他"


    res = multi_cal_sim(char1, char2, rounded=rounded, kind=kind)


    print(res)


    # output:


    # 0.5821


```





# 三、技术原理


```


char-similar最初的使用场景是计算两个汉字的字形相似度(构建csc混淆集), 后加入拼音相似度,字义相似度,字频相似度...详见源码.





# 四角码(code=4, 共5位), 统计四个数字中的相同数/4


# 偏旁部首, 相同为1


# 词频log10, 统计大规模语料macropodus中词频log10的 1-(差的绝对值/两数中的最大值)


# 笔画数, 1-(差的绝对值/两数中的最大值)


# 拆字, 集合的与 / 集合的并


# 构造结构, 相同为1


# 笔顺(实际为最小的集合), 集合的与 / 集合的并


# 拼音(code=4, 共4位), 统计四个数字中的相同数(拼音/声母/韵母/声调)/4


# 词向量, char-word2vec, cosine


```








# 四、参考(部分字典来源以下项目)


 - [https://github.com/contr4l/SimilarCharacter](https://github.com/contr4l/SimilarCharacter)


 - [https://github.com/houbb/nlp-hanzi-similar](https://github.com/houbb/nlp-hanzi-similar)


 - [https://github.com/mozillazg/python-pinyin](https://github.com/mozillazg/python-pinyin)


 - [https://github.com/CNMan/UnicodeCJK-WuBi](https://github.com/CNMan/UnicodeCJK-WuBi)


 - [https://github.com/yongzhuo/Macropodus](https://github.com/yongzhuo/Macropodus)


 - [https://github.com/kfcd/chaizi](https://github.com/kfcd/chaizi)


 








# Reference


For citing this work, you can refer to the present GitHub project. For example, with BibTeX:


```


@misc{Macropodus,


    howpublished = {https://github.com/yongzhuo/char-similar},


    title = {char-similar},


    author = {Yongzhuo Mo},


    publisher = {GitHub},


    year = {2024}


}


```