min_word_edit_distance
描述
计算将一个句子转换为另一个句子所需的最少单词操作次数(添加/删除)。
参数
str1
- 源句子str2
- 目标句子
示例
```python from rust_pyfunc import min_word_edit_distance
示例1:添加一个单词
da = "We expect demand to increase" db = "We expect worldwide demand to increase" print(min_word_edit_distance(da, db)) # 输出: 1 (添加 "worldwide")
示例2:多次修改
dc = "We expect weakness in sales" print(min_word_edit_distance(da, dc)) # 输出: 6 (删除3个单词,添加3个单词) ```
函数签名
min_word_edit_distance(str1, str2) -> None
参数
此函数没有参数
返回值
示例
输入:
min_word_edit_distance(
"这是一个测试句子",
"这是另一个测试句子"
)
输出:
2
输入:
min_word_edit_distance(
"深度学习算法",
"机器学习算法"
)
输出:
2
Python使用示例
import numpy as np
from rust_pyfunc import min_word_edit_distance
# 使用示例
result = min_word_edit_distance("这是一个测试句子", "这是另一个测试句子")
print(f"结果: {result}")