Skip to content

Commit da195be

Browse files
author
Jiawen
committed
feat: update readme file
1 parent dfb8281 commit da195be

File tree

6 files changed

+58
-46
lines changed

6 files changed

+58
-46
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,12 @@ import "github.com/duke-git/lancet/v2/formatter"
962962
- **<big>ParseBinaryBytes</big>** : return the human readable bytes size string into the amount it represents(base 1024).
963963
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/formatter.md#ParseBinaryBytes)]
964964
[[play](https://go.dev/play/p/69v1tTT62x8)]
965+
- **<big>ParseCNAddress</big>** : parses a Chinese address string intelligently and extracts structured information (province, city, district, street, name, phone, etc.). Supports various address formats including county-level cities.
966+
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/formatter.md#ParseCNAddress)]
967+
[[play](https://go.dev/play/p/o5l09hQopEV)]
968+
- **<big>ParsePersonInfo</big>** : extracts user information (name, phone, ID card, postal code) from an address string and separates it from the location address.
969+
[[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/formatter.md#ParsePersonInfo)]
970+
[[play](https://go.dev/play/p/JO-uTlJlTy7)]
965971

966972
<h3 id="function"> 13. Function package can control the flow of function execution and support part of functional programming.&nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">index</a></h3>
967973

README_zh-CN.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,12 @@ import "github.com/duke-git/lancet/v2/formatter"
972972
- **<big>ParseBinaryBytes</big>** : 将字节单位字符串转换成其所表示的字节数(以 1024 为基数)。
973973
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/formatter.md#ParseBinaryBytes)]
974974
[[play](https://go.dev/play/p/69v1tTT62x8)]
975+
- **<big>ParseCNAddress</big>** : 智能解析中国地址字符串并提取结构化信息(省、市、区、街道、姓名、电话等)。支持多种地址格式,包括县级市。
976+
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/formatter.md#ParseCNAddress)]
977+
[[play](https://go.dev/play/p/o5l09hQopEV)]
978+
- **<big>ParsePersonInfo</big>** : 从地址字符串中提取用户信息(姓名、电话、身份证、邮编)并将其与位置地址分离。
979+
[[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/formatter.md#ParsePersonInfo)]
980+
[[play](https://go.dev/play/p/JO-uTlJlTy7)]
975981

976982
<h3 id="function"> 13. function 函数包控制函数执行流程,包含部分函数式编程。&nbsp; &nbsp; &nbsp; &nbsp;<a href="#index">回到目录</a></h3>
977983

docs/api/packages/formatter.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import (
3131
- [BinaryBytes](#BinaryBytes)
3232
- [ParseDecimalBytes](#ParseDecimalBytes)
3333
- [ParseBinaryBytes](#ParseBinaryBytes)
34-
- [Smart](#Smart)
35-
- [Decompose](#Decompose)
34+
- [ParseCNAddress](#ParseCNAddress)
35+
- [ParsePersonInfo](#ParsePersonInfo)
3636

3737
<div STYLE="page-break-after: always;"></div>
3838

@@ -312,17 +312,17 @@ func main() {
312312
}
313313
```
314314

315-
### <span id="Smart">Smart</span>
315+
### <span id="ParseCNAddress">ParseCNAddress</span>
316316

317317
<p>智能解析中国地址字符串并提取结构化信息。可以解析带或不带用户信息(姓名、电话、身份证等)的地址。当 withUser 为 true 时,从地址字符串中提取用户信息。当 withUser 为 false 时,仅解析位置信息。支持多种地址格式:标准格式、紧凑格式、带关键词格式、县级市格式等。</p>
318318

319319
<b>函数签名:</b>
320320

321321
```go
322-
func Smart(str string, withUser bool) *AddressInfo
322+
func ParseCNAddress(str string, withUser bool) *AddressInfo
323323
```
324324

325-
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/HtTw0FSzenp)</span></b>
325+
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/o5l09hQopEV)</span></b>
326326

327327
```go
328328
package main
@@ -335,25 +335,25 @@ import (
335335

336336
func main() {
337337
// 解析包含用户信息的完整地址
338-
result1 := formatter.Smart("张三 13800138000 北京市朝阳区建国路1号", true)
338+
result1 := formatter.ParseCNAddress("张三 13800138000 北京市朝阳区建国路1号", true)
339339
jsonData1, _ := json.MarshalIndent(result1, "", " ")
340340
fmt.Println("示例 1 - 带用户信息:")
341341
fmt.Println(string(jsonData1))
342342

343343
// 仅解析地址,不提取用户信息
344-
result2 := formatter.Smart("北京市海淀区中关村大街1号", false)
344+
result2 := formatter.ParseCNAddress("北京市海淀区中关村大街1号", false)
345345
fmt.Printf("\n示例 2 - 仅地址:\n")
346346
fmt.Printf("省: %s, 市: %s, 区: %s, 街道: %s\n",
347347
result2.Province, result2.City, result2.Region, result2.Street)
348348

349349
// 解析县级市地址
350-
result3 := formatter.Smart("河北省石家庄市新乐市经济开发区兴工街10号", false)
350+
result3 := formatter.ParseCNAddress("河北省石家庄市新乐市经济开发区兴工街10号", false)
351351
fmt.Printf("\n示例 3 - 县级市:\n")
352352
fmt.Printf("省: %s, 市: %s, 区/县: %s, 街道: %s\n",
353353
result3.Province, result3.City, result3.Region, result3.Street)
354354

355355
// 紧凑格式
356-
result4 := formatter.Smart("马云13593464918陕西省西安市雁塔区丈八沟街道", true)
356+
result4 := formatter.ParseCNAddress("马云13593464918陕西省西安市雁塔区丈八沟街道", true)
357357
fmt.Printf("\n示例 4 - 紧凑格式:\n")
358358
fmt.Printf("姓名: %s, 电话: %s, 地址: %s%s%s%s\n",
359359
result4.Name, result4.Mobile, result4.Province, result4.City, result4.Region, result4.Street)
@@ -383,17 +383,17 @@ func main() {
383383
}
384384
```
385385

386-
### <span id="Decompose">Decompose</span>
386+
### <span id="ParsePersonInfo">ParsePersonInfo</span>
387387

388388
<p>从地址字符串中提取用户信息(姓名、电话、身份证、邮编)。将个人信息与地址分离,支持带标签格式、紧凑格式、带分隔符格式。返回包含提取的用户信息和清理后地址字符串的 AddressInfo。</p>
389389

390390
<b>函数签名:</b>
391391

392392
```go
393-
func Decompose(str string) *AddressInfo
393+
func ParsePersonInfo(str string) *AddressInfo
394394
```
395395

396-
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/wXsE5aKfhPk)</span></b>
396+
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/JO-uTlJlTy7)</span></b>
397397

398398
```go
399399
package main
@@ -406,17 +406,17 @@ import (
406406

407407
func main() {
408408
// 提取姓名和手机号
409-
result1 := formatter.Decompose("张三 13800138000 北京市朝阳区")
409+
result1 := formatter.ParsePersonInfo("张三 13800138000 北京市朝阳区")
410410
fmt.Println("示例 1 - 姓名和手机号:")
411411
fmt.Printf("姓名: %s, 手机: %s, 地址: %s\n", result1.Name, result1.Mobile, result1.Addr)
412412

413413
// 提取身份证号
414-
result2 := formatter.Decompose("李四 110101199001011234 上海市")
414+
result2 := formatter.ParsePersonInfo("李四 110101199001011234 上海市")
415415
fmt.Println("\n示例 2 - 身份证号:")
416416
fmt.Printf("姓名: %s, 身份证: %s, 地址: %s\n", result2.Name, result2.IDN, result2.Addr)
417417

418418
// 带标签格式
419-
result3 := formatter.Decompose("收货人:王五 电话:13900139000 收货地址:天津市河西区友谊路20号")
419+
result3 := formatter.ParsePersonInfo("收货人:王五 电话:13900139000 收货地址:天津市河西区友谊路20号")
420420
jsonData3, _ := json.MarshalIndent(result3, "", " ")
421421
fmt.Println("\n示例 3 - 带标签格式:")
422422
fmt.Println(string(jsonData3))

docs/en/api/packages/formatter.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import (
3131
- [BinaryBytes](#BinaryBytes)
3232
- [ParseDecimalBytes](#ParseDecimalBytes)
3333
- [ParseBinaryBytes](#ParseBinaryBytes)
34-
- [Smart](#Smart)
35-
- [Decompose](#Decompose)
34+
- [ParseCNAddress](#ParseCNAddress)
35+
- [ParsePersonInfo](#ParsePersonInfo)
3636

3737
<div STYLE="page-break-after: always;"></div>
3838

@@ -312,17 +312,17 @@ func main() {
312312
}
313313
```
314314

315-
### <span id="Smart">Smart</span>
315+
### <span id="ParseCNAddress">ParseCNAddress</span>
316316

317317
<p>Parses a Chinese address string intelligently and extracts structured information. It can parse addresses with or without user information (name, phone, ID card, etc.). When withUser is true, it extracts user information from the address string. When withUser is false, it only parses the location information. Supports various address formats: standard format, compact format, labeled format, county-level cities format, etc.</p>
318318

319319
<b>Signature:</b>
320320

321321
```go
322-
func Smart(str string, withUser bool) *AddressInfo
322+
func ParseCNAddress(str string, withUser bool) *AddressInfo
323323
```
324324

325-
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/HtTw0FSzenp)</span></b>
325+
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/o5l09hQopEV)</span></b>
326326

327327
```go
328328
package main
@@ -335,25 +335,25 @@ import (
335335

336336
func main() {
337337
// Parse complete address with user information
338-
result1 := formatter.Smart("张三 13800138000 北京市朝阳区建国路1号", true)
338+
result1 := formatter.ParseCNAddress("张三 13800138000 北京市朝阳区建国路1号", true)
339339
jsonData1, _ := json.MarshalIndent(result1, "", " ")
340340
fmt.Println("Example 1 - With user info:")
341341
fmt.Println(string(jsonData1))
342342

343343
// Parse address only, without extracting user information
344-
result2 := formatter.Smart("北京市海淀区中关村大街1号", false)
344+
result2 := formatter.ParseCNAddress("北京市海淀区中关村大街1号", false)
345345
fmt.Printf("\nExample 2 - Address only:\n")
346346
fmt.Printf("Province: %s, City: %s, Region: %s, Street: %s\n",
347347
result2.Province, result2.City, result2.Region, result2.Street)
348348

349349
// Parse county-level city address
350-
result3 := formatter.Smart("河北省石家庄市新乐市经济开发区兴工街10号", false)
350+
result3 := formatter.ParseCNAddress("河北省石家庄市新乐市经济开发区兴工街10号", false)
351351
fmt.Printf("\nExample 3 - County-level city:\n")
352352
fmt.Printf("Province: %s, City: %s, Region: %s, Street: %s\n",
353353
result3.Province, result3.City, result3.Region, result3.Street)
354354

355355
// Compact format
356-
result4 := formatter.Smart("马云13593464918陕西省西安市雁塔区丈八沟街道", true)
356+
result4 := formatter.ParseCNAddress("马云13593464918陕西省西安市雁塔区丈八沟街道", true)
357357
fmt.Printf("\nExample 4 - Compact format:\n")
358358
fmt.Printf("Name: %s, Phone: %s, Address: %s%s%s%s\n",
359359
result4.Name, result4.Mobile, result4.Province, result4.City, result4.Region, result4.Street)
@@ -383,17 +383,17 @@ func main() {
383383
}
384384
```
385385

386-
### <span id="Decompose">Decompose</span>
386+
### <span id="ParsePersonInfo">ParsePersonInfo</span>
387387

388388
<p>Extracts user information (name, phone, ID card, postal code) from an address string. It separates personal information from the address, supporting labeled format, compact format, and formats with separators. Returns an AddressInfo with extracted user information and cleaned address string.</p>
389389

390390
<b>Signature:</b>
391391

392392
```go
393-
func Decompose(str string) *AddressInfo
393+
func ParsePersonInfo(str string) *AddressInfo
394394
```
395395

396-
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/wXsE5aKfhPk)</span></b>
396+
<b>Example:<span style="float:right;display:inline-block;">[Run](https://go.dev/play/p/JO-uTlJlTy7)</span></b>
397397

398398
```go
399399
package main
@@ -406,17 +406,17 @@ import (
406406

407407
func main() {
408408
// Extract name and phone
409-
result1 := formatter.Decompose("张三 13800138000 北京市朝阳区")
409+
result1 := formatter.ParsePersonInfo("张三 13800138000 北京市朝阳区")
410410
fmt.Println("Example 1 - Name and phone:")
411411
fmt.Printf("Name: %s, Phone: %s, Address: %s\n", result1.Name, result1.Mobile, result1.Addr)
412412

413413
// Extract ID card number
414-
result2 := formatter.Decompose("李四 110101199001011234 上海市")
414+
result2 := formatter.ParsePersonInfo("李四 110101199001011234 上海市")
415415
fmt.Println("\nExample 2 - ID card number:")
416416
fmt.Printf("Name: %s, ID Card: %s, Address: %s\n", result2.Name, result2.IDN, result2.Addr)
417417

418418
// Labeled format
419-
result3 := formatter.Decompose("收货人:王五 电话:13900139000 收货地址:天津市河西区友谊路20号")
419+
result3 := formatter.ParsePersonInfo("收货人:王五 电话:13900139000 收货地址:天津市河西区友谊路20号")
420420
jsonData3, _ := json.MarshalIndent(result3, "", " ")
421421
fmt.Println("\nExample 3 - Labeled format:")
422422
fmt.Println(string(jsonData3))

formatter/address.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type fuzzyResult struct {
3030
Street string // Street address / 街道地址
3131
}
3232

33-
// Smart parses a Chinese address string intelligently and extracts structured information.
33+
// ParseCNAddress parses a Chinese address string intelligently and extracts structured information.
3434
// It can parse addresses with or without user information (name, phone, ID card, etc.).
3535
// When withUser is true, it extracts user information from the address string.
3636
// When withUser is false, it only parses the location information.
@@ -39,7 +39,7 @@ type fuzzyResult struct {
3939
// - Compact format: "Name Phone Province City District Street"
4040
// - With keywords: "Name: xxx Phone: xxx Address: xxx"
4141
// - County-level cities: "Province City CountyCity District" (e.g., "河北省石家庄市新乐市")
42-
// Smart 智能解析中国地址字符串并提取结构化信息。
42+
// ParseCNAddress 智能解析中国地址字符串并提取结构化信息。
4343
// 可以解析带或不带用户信息(姓名、电话、身份证等)的地址。
4444
// 当 withUser 为 true 时,从地址字符串中提取用户信息。
4545
// 当 withUser 为 false 时,仅解析位置信息。
@@ -48,12 +48,12 @@ type fuzzyResult struct {
4848
// - 紧凑格式:"姓名 电话 省 市 区 街道"
4949
// - 带关键词:"姓名:xxx 电话:xxx 地址:xxx"
5050
// - 县级市:"省 市 县级市 区"(如"河北省石家庄市新乐市")
51-
func Smart(str string, withUser bool) *AddressInfo {
51+
func ParseCNAddress(str string, withUser bool) *AddressInfo {
5252
result := &AddressInfo{}
5353

5454
if withUser {
55-
decompose := Decompose(str)
56-
result = decompose
55+
ParsePersonInfo := ParsePersonInfo(str)
56+
result = ParsePersonInfo
5757
} else {
5858
result.Addr = str
5959
}
@@ -98,19 +98,19 @@ func Smart(str string, withUser bool) *AddressInfo {
9898
return result
9999
}
100100

101-
// Decompose extracts user information (name, phone, ID card, postal code) from an address string.
101+
// ParsePersonInfo extracts user information (name, phone, ID card, postal code) from an address string.
102102
// It separates personal information from the address, supporting various formats:
103103
// - Labeled format: "Name: xxx Phone: xxx Address: xxx"
104104
// - Compact format: "Name Phone Address" (e.g., "张三13800138000北京市朝阳区")
105105
// - With separators: using colons, commas, newlines as delimiters
106106
// Returns an AddressInfo with extracted user information and cleaned address string in Addr field.
107-
// Decompose 从地址字符串中提取用户信息(姓名、电话、身份证、邮编)。
107+
// ParsePersonInfo 从地址字符串中提取用户信息(姓名、电话、身份证、邮编)。
108108
// 将个人信息与地址分离,支持多种格式:
109109
// - 带标签格式:"姓名:xxx 电话:xxx 地址:xxx"
110110
// - 紧凑格式:"姓名 电话 地址"(如"张三13800138000北京市朝阳区")
111111
// - 带分隔符:使用冒号、逗号、换行符作为分隔符
112112
// 返回包含提取的用户信息和清理后地址字符串(在 Addr 字段中)的 AddressInfo。
113-
func Decompose(str string) *AddressInfo {
113+
func ParsePersonInfo(str string) *AddressInfo {
114114
compose := &AddressInfo{}
115115

116116
// 先尝试提取带标签的信息

formatter/address_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"testing"
66
)
77

8-
func TestSmart(t *testing.T) {
8+
func TestParseCNAddress(t *testing.T) {
99
tests := []struct {
1010
name string
1111
input string
@@ -176,7 +176,7 @@ func TestSmart(t *testing.T) {
176176

177177
for _, tt := range tests {
178178
t.Run(tt.name, func(t *testing.T) {
179-
got := Smart(tt.input, tt.withUser)
179+
got := ParseCNAddress(tt.input, tt.withUser)
180180

181181
// 打印结果便于调试
182182
jsonData, _ := json.MarshalIndent(got, "", " ")
@@ -202,7 +202,7 @@ func TestSmart(t *testing.T) {
202202
}
203203
}
204204

205-
func TestDecompose(t *testing.T) {
205+
func TestParsePersonInfo(t *testing.T) {
206206
tests := []struct {
207207
name string
208208
input string
@@ -248,7 +248,7 @@ func TestDecompose(t *testing.T) {
248248

249249
for _, tt := range tests {
250250
t.Run(tt.name, func(t *testing.T) {
251-
got := Decompose(tt.input)
251+
got := ParsePersonInfo(tt.input)
252252
jsonData, _ := json.MarshalIndent(got, "", " ")
253253
t.Logf("Result: %s", jsonData)
254254
tt.verify(t, got)
@@ -345,16 +345,16 @@ func TestFuzz(t *testing.T) {
345345
}
346346
}
347347

348-
func ExampleSmart() {
348+
func ExampleParseCNAddress() {
349349
// 解析包含用户信息的完整地址
350-
result := Smart("张三 13800138000 北京市朝阳区建国路1号", true)
350+
result := ParseCNAddress("张三 13800138000 北京市朝阳区建国路1号", true)
351351
jsonData, _ := json.MarshalIndent(result, "", " ")
352352
println(string(jsonData))
353353
}
354354

355-
func ExampleDecompose() {
355+
func ExampleParsePersonInfo() {
356356
// 分离用户信息
357-
result := Decompose("收货人:李四 电话:18612345678 地址:上海市浦东新区世纪大道100号")
357+
result := ParsePersonInfo("收货人:李四 电话:18612345678 地址:上海市浦东新区世纪大道100号")
358358
jsonData, _ := json.MarshalIndent(result, "", " ")
359359
println(string(jsonData))
360360
}

0 commit comments

Comments
 (0)