lsimul/tyop

解决大多数在捷克语短语中发现的拼写错误。

0.1.0 2024-08-06 20:04 UTC

This package is not auto-updated.

Last update: 2024-10-03 07:19:51 UTC


README

一组正则表达式,试图修复捷克语中常见的错误,例如

  • 多个空格
  • 空格放置不正确(在逗号/句号之前,逗号/句号之后缺少空格等)
  • 正确的日期格式
  • 货币格式化
  • 在必要时将'-'转换为'–'
  • 以及一些其他的小而整洁的修复

安装

composer require lsimul/tyop

使用

use LSimul\Tyop;

$corrector = new Tyop\Corrector;

$text = 'Ale,ovšem ,tato věc , ta je od 2.12. za 300 ,- Kč .  '

$text = $corrector->normalize($text);
// Ale, ovšem, tato věc, ta je od 2.12. za 300,- Kč.

$text = $corrector->fix($text);
// Ale, ovšem, tato věc, ta je od 2. 12. za 300 Kč.

Corrector有两种方法,想法是按以下顺序使用它们:normalize -> fix (-> fixDomain)

  • normalize(string $text): string 解决一些简单的空格问题,如括号前缺少空格等。
  • fix(string $text): string 挖得更深一些,并且愿意格式化日期、货币,通过移除/添加不同的字符而不是仅仅空格。

扩展

Corrector有两种方法,允许用户扩展其行为

  • addRule(string $regex, string $replacement): self
    • 添加新规则,基本上只是验证regex并将其存储起来。
  • fixDomain(string $text): string
    • 在文本上使用所有新规则。

fixDomain的存在是为了修复特定于给定文本的问题,这些问题不能放入主规则集(例如,将lt激进地转换为l,因为在这里它总是表示liter)。

修复HTML

除了Corrector之外,还有一个Bridge\Html,它包装Corrector并且可以处理HTML;修剪段落末尾的空白,删除换行符。

<p>
	<em><u>Interval 3.3. - 8.3. 2024   </u></em>
</p>
<p><br></p>

<!-- Will be turned into: -->
<p>
	<em><u>Interval 3. 3. – 8. 3. 2024</u></em>
</p>