Skip to content

Commit d70799f

Browse files
author
Jack
committed
1、编写 WordCutHelper 实体逻辑
2、编写 WordCutHelperTest 实体逻辑 3、更新说明文档
1 parent d8f561e commit d70799f

File tree

6 files changed

+88
-31
lines changed

6 files changed

+88
-31
lines changed

README.MD

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,37 @@ Helper::dateTime()::now()->toDateTimeString();
2727
## 文档目录
2828

2929

30-
| 数据与文档处理 | 网络扩展与辅助工具 | 运行时、调试、框架、算法等 |
31-
| --------------------------------------------- | -------------------------------------------- | -------------------------------------------------- |
32-
| [字符串 Str](doc/Str.md) | [网络请求 Http](doc/Http.md) | [注解 Annotation](doc/Annotation.md) |
33-
| [字符串 Str(Advanced)](doc/StrAdvanced.md) | [网际协议 IP](doc/IP.md) | [协程 Coroutine](doc/Coroutine.md) |
34-
| [字符串 Str(UTF-8)](doc/StrUtf8.md) | [网络 Net](doc/Net.md) | [异常 Exceptions](doc/Exceptions.md) |
35-
| [字符串 Str(ASCII)](doc/StrAscii.md) | [域名 Domain](doc/Domain.md) | [日志 Log](doc/Log.md) |
36-
| [数组 Array](doc/Array.md) | [资源标识符 URI](doc/URI.md) | [配置 Config](doc/Config.md) |
37-
| [文档处理 Office](doc/Office.md) | [认证 Jwt](doc/Jwt.md) | [环境变量 Env](doc/Env.md) |
38-
| [文档处理 CSV](doc/CSV.md) | [认证 OAuth2](doc/OAuth2.md) | [调试器 Debugger](doc/Debugger.md) |
39-
| [文档处理 XML](doc/XML.md) | [上传 Upload](doc/Upload.md) | [运行时 Runtime](doc/Runtime.md) |
40-
| [文档处理 PDF](doc/Pdf.md) | [下载 Download](doc/Download.md) | [验证/断言 Validate/Assert](doc/ValidateAssert.md) |
41-
| [文档对象 Markdown](doc/Markdown.md) | [翻译 Translate](doc/Translate.md) | [终端 Terminal](doc/Terminal.md) |
42-
| [文档对象 Dom](doc/Dom.md) | [短信 SMS](doc/SMS.md) | [系统 System](doc/System.md) |
43-
| [随机字符串 RandStr](doc/RandomString.md) | [邮件 Email](doc/Email.md) | [服务器 Server](doc/Server.md) |
44-
| [编码加密 Encode/Crypto](doc/EncodeCrypto.md) | [阿里云 Aliyun](doc/Aliyun.md) | [数据库 ORM](doc/ORM.md) |
45-
| [编码 Json](doc/Json.md) | [腾讯云 Tencent](doc/TencentCloud.md) | [路由器 Router](doc/Router.md) |
46-
| [颜色 Color](doc/Color.md) | [百度AI BaiduAi](doc/BaiduAi.md) | [容器 Container](doc/Container.md) |
47-
| [拼音 Pinyin](doc/Pinyin.md) | [支付宝 Alipay](doc/Alipay.md) | [接口 Api](doc/Api.md) |
48-
| [语言 Language](doc/Language.md) | [微信 Wechat](doc/Wechat.md) | [模板 Template](doc/Template.md) |
49-
| [时间日期 Datetime](doc/Datetime.md) | [支付 Payment](doc/Payment.md) | [权限控制 Access](doc/Access.md) |
50-
| [图像处理 Image](doc/Image.md) | [条形码 Barcode](doc/Barcode.md) | [开放接口 Openapi](doc/OpenApi.md) |
51-
| [文件 File](doc/File.md) | [验证码 Captcha](doc/Captcha.md) | [数学 Math](doc/Math.md) |
52-
| [表单 Form](doc/Form.md) | [嵌入地图 EmbedMap](doc/EmbedMap.md) | [算法 Algorithm](doc/Algorithm.md) |
53-
| [压缩 Zip](doc/Zip.md) | [身份标识 Identity ID](doc/IdentityID.md) | |
54-
| [缓存 Cache](doc/Cache.md) | [版本号 Version](doc/Version.md) | |
55-
| [缓存 LruCache](doc/LRUCache.md) | [唯一标识符 UUID](doc/UUID.md) | |
56-
| [表情符号 Emoji](doc/Emoji.md) | [硬件唯一码 DeviceId](doc/DeviceId.md) | |
57-
| [用户代理 UserAgent](doc/UserAgent.md) | [双因素身份验证 Google2fa](doc/Google2fa.md) | |
58-
| [地理国家 Geo/Country](doc/GeoCountry.md) | [布隆过滤器 BloomFilter](doc/BloomFilter.md) | |
59-
| [跨站点脚本 Xss](doc/Xss.md) | [敏感词过滤器 Sensitive](doc/Sensitive.md) | |
30+
| 数据与文档处理 | 网络扩展与辅助工具 | 运行时、调试、框架、算法等 |
31+
| ----------------- |-----------------------------------------| -------------- |
32+
| [字符串 Str](doc/Str.md) | [网络请求 Http](doc/Http.md) | [注解 Annotation](doc/Annotation.md) |
33+
| [字符串 Str(Advanced)](doc/StrAdvanced.md) | [网际协议 IP](doc/IP.md) | [协程 Coroutine](doc/Coroutine.md) |
34+
| [字符串 Str(UTF-8)](doc/StrUtf8.md) | [网络 Net](doc/Net.md) | [异常 Exceptions](doc/Exceptions.md) |
35+
| [字符串 Str(ASCII)](doc/StrAscii.md) | [域名 Domain](doc/Domain.md) | [日志 Log](doc/Log.md) |
36+
| [数组 Array](doc/Array.md) | [资源标识符 URI](doc/URI.md) | [配置 Config](doc/Config.md) |
37+
| [文档处理 Office](doc/Office.md) | [认证 Jwt](doc/Jwt.md) | [环境变量 Env](doc/Env.md) |
38+
| [文档处理 CSV](doc/CSV.md) | [认证 OAuth2](doc/OAuth2.md) | [调试器 Debugger](doc/Debugger.md) |
39+
| [文档处理 XML](doc/XML.md) | [上传 Upload](doc/Upload.md) | [运行时 Runtime](doc/Runtime.md) |
40+
| [文档处理 PDF](doc/Pdf.md) | [下载 Download](doc/Download.md) | [验证/断言 Validate/Assert](doc/ValidateAssert.md) |
41+
| [文档对象 Markdown](doc/Markdown.md) | [翻译 Translate](doc/Translate.md) | [终端 Terminal](doc/Terminal.md) |
42+
| [文档对象 Dom](doc/Dom.md) | [短信 SMS](doc/SMS.md) | [系统 System](doc/System.md) |
43+
| [随机字符串 RandStr](doc/RandomString.md) | [邮件 Email](doc/Email.md) | [服务器 Server](doc/Server.md) |
44+
| [编码加密 Encode/Crypto](doc/EncodeCrypto.md) | [阿里云 Aliyun](doc/Aliyun.md) | [数据库 ORM](doc/ORM.md) |
45+
| [编码 Json](doc/Json.md) | [腾讯云 Tencent](doc/TencentCloud.md) | [路由器 Router](doc/Router.md) |
46+
| [颜色 Color](doc/Color.md) | [百度AI BaiduAi](doc/BaiduAi.md) | [容器 Container](doc/Container.md) |
47+
| [拼音 Pinyin](doc/Pinyin.md) | [支付宝 Alipay](doc/Alipay.md) | [接口 Api](doc/Api.md) |
48+
| [语言 Language](doc/Language.md) | [微信 Wechat](doc/Wechat.md) | [模板 Template](doc/Template.md) |
49+
| [时间日期 Datetime](doc/Datetime.md) | [支付 Payment](doc/Payment.md) | [权限控制 Access](doc/Access.md) |
50+
| [图像处理 Image](doc/Image.md) | [条形码 Barcode](doc/Barcode.md) | [开放接口 Openapi](doc/OpenApi.md) |
51+
| [文件 File](doc/File.md) | [验证码 Captcha](doc/Captcha.md) | [数学 Math](doc/Math.md) |
52+
| [表单 Form](doc/Form.md) | [嵌入地图 EmbedMap](doc/EmbedMap.md) | [算法 Algorithm](doc/Algorithm.md) |
53+
| [压缩 Zip](doc/Zip.md) | [身份标识 Identity ID](doc/IdentityID.md) | |
54+
| [缓存 Cache](doc/Cache.md) | [版本号 Version](doc/Version.md) | |
55+
| [缓存 LruCache](doc/LRUCache.md) | [唯一标识符 UUID](doc/UUID.md) | |
56+
| [表情符号 Emoji](doc/Emoji.md) | [硬件唯一码 DeviceId](doc/DeviceId.md) | |
57+
| [用户代理 UserAgent](doc/UserAgent.md) | [双因素身份验证 Google2fa](doc/Google2fa.md) | |
58+
| [地理国家 Geo/Country](doc/GeoCountry.md) | [布隆过滤器 BloomFilter](doc/BloomFilter.md) | |
59+
| [跨站点脚本 Xss](doc/Xss.md) | [敏感词过滤器 Sensitive](doc/Sensitive.md) | |
60+
|| [中文分词 Word Segmentation](doc/WordCut.md) |
6061

6162
## Composer 源管理工具(可选)
6263

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@
122122
"alipaysdk/easysdk": "^2.2",
123123
"alipaysdk/openapi": "^1.0",
124124
"tencentcloud/tencentcloud-sdk-php": "^3.0",
125-
"rinvex/countries": "^8.1"
125+
"rinvex/countries": "^8.1",
126+
"forever2077/jieba-php": "^0.1.1"
126127
},
127128
"minimum-stability": "stable",
128129
"config": {

doc/WordCut.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## 中文分词 chinese Word Segmentation
2+
3+
```php
4+
$this->assertEquals(['你好', '中国'], WordCutHelper::cut('你好中国'));
5+
$this->assertEquals(['你', '你好', '好', '中', '中国', '国'], WordCutHelper::cutAll('你好中国'));
6+
$this->assertEquals(['你好', '中国'], WordCutHelper::cutForSearch('你好中国'));
7+
8+
array cut(string $sentence, bool $hmm = true)
9+
array cutAll(string $sentence)
10+
array cutForSearch(string $sentence, bool $hmm = true)
11+
array TFIDFExtract(string $sentence, int $topK = 20, array $allowedPOS = [])
12+
array textRankExtract(string $sentence, int $topK = 20, array $allowedPOS = [])
13+
array tokenize(string $sentence, string $mode = 'default', bool $hmm = true)
14+
array tag(string $sentence, bool $hmm = true)
15+
int suggestFrequency(string $segment)
16+
self addWord(string $word, ?int $frequency = null, ?string $tag = null)
17+
self useDictionary(string $path)
18+
19+
安装 composer require forever2077/jieba-php
20+
```

src/Helper.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,4 +371,9 @@ public static function xss(): XssHelper
371371
{
372372
return new XssHelper();
373373
}
374+
375+
public static function word(): WordCutHelper
376+
{
377+
return new WordCutHelper();
378+
}
374379
}

src/WordCutHelper.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Helpful;
4+
5+
use Binaryoung\Jieba\Jieba;
6+
7+
class WordCutHelper extends Jieba
8+
{
9+
10+
}

tests/WordCutHelperTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
use PHPUnit\Framework\TestCase;
4+
use Helpful\Helper;
5+
use Helpful\WordCutHelper;
6+
7+
class WordCutHelperTest extends TestCase
8+
{
9+
public function testInstance()
10+
{
11+
$this->assertInstanceOf(WordCutHelper::class, Helper::word());
12+
}
13+
14+
public function testWordCut()
15+
{
16+
$this->assertEquals(['你好', '中国'], WordCutHelper::cut('你好中国'));
17+
$this->assertEquals(['', '你好', '', '', '中国', ''], WordCutHelper::cutAll('你好中国'));
18+
$this->assertEquals(['你好', '中国'], WordCutHelper::cutForSearch('你好中国'));
19+
}
20+
}

0 commit comments

Comments
 (0)