電話號碼資料正規化 (Phone number normalization)

目前 OSM 上的電話號碼及分機格式都亂成一鍋粥了,趁熱喝了吧。(悲
亟待討論,想聽聽大家意見。

背景資訊

參考OSM wiki 的 Key:phone 電話格式説明,目前常見格式有幾種:

  1. 北美式 NANP: +1-905-688-5550x3369 or +1-905-688-5550 x3369
  2. E.123: +1-978-750-1900 ext. 4309
  3. DIN 5008: +49 123 4567-1234(只有德國)。

台灣現況,特別是分機 一個一個一個 的不同啊:
目前資料裡分機的寫法混雜,已知有 ~,#ext 這幾種,尚未統一。
# 是台灣日常生活中常見的分機寫法,或許可以以此為主。

寫了一個正規化腳本,目前跑出來的結果如截圖,可以看到現有資料裡有多種分機格式。

+886 (2) 2706-5995x6
+886 4 2873-6548#101、107            
+886 2 2883 2130ext106     

討論主題

需要討論正規化的問題大致上有二:

一、號碼格式
號碼本體要用哪種分隔方式?

  • NANP/ RFC 3966 變體: +886-2-1234-5678 (加連字號(dashes))
  • ITU E.123: +886 2 1234 5678(空白)

二、分機格式

  1. 直接接受 # — 民間慣用,不強制轉換正確格式
  2. 轉換成某個統一格式 — 但要選哪個?
    • E.123 (+886 2 2NNN NNNN ext. NNN)
    • NANP (+886-2-2NNN-NNNN xNNN)
    • RFC3966 (+886-2-2NNN-NNNN;ext=NNN)

+886-3-8771024;ext=13
不過 ;ext=NNN 有分號衝突的問題,解析成兩支電話,皂化弄人啊

PS-RFC3966 加 backslash 也不是好的解決方案,+886-3-8771024;ext=13 大多數 APP 無法辨認

  1. 直接跳過分機?
    • 只正規化號碼本體,跳過分機 — # , ~ ext 這類字元整個略過,只處理主號碼
    • 用號碼長度過濾 — 主號碼至少六碼,靠長度區分主號與分機

延伸閲讀

—— 徇眾要求,已投稿日記

1 Like

分機格式在這裏討論過 Proposal to replace documented syntax for telephone extensions
其中一個想法 phone:tel= (/ phone:uri=tel:*= ?) 的好處是可以先獨立加上,不會影響 phone= 的現狀。這還能明確定義、表達其格式,而且是網上使用的標準。可待其後再討論 phone= 的格式,該怎麼用它。

1 Like

Minh 的那篇貼文有納入參考,但是 Stale 好一陣了,所以又重新發明輪子。(悲

I saw the diary post from @assanges in WeeklyOSM 819 about phone numbers in Taiwan, and after waiting for the formatting in libphonenumber to be fixed, I have added Taiwan to my phone number validator.

我在 WeeklyOSM 819 看到了 @assanges 關於台灣電話號碼的日記貼文。在等待 libphonenumber 的格式設定修正後,我已將台灣加入我的電話號碼驗證器中。

This provides suggested fixes for many of the common mapping/formatting errors for phone numbers:

這項工具針對許多常見的電話號碼標記或格式錯誤提供修正建議:

And also allows them to be fixed easily from the website itself.

並且可以直接在網站上輕鬆完成修正。

Additionally, there is a bot edit running in a few other countries to automatically fix such issues, and new ones as they occur. If the edits are acceptable, then I would be happy to enable this for Taiwan as well.

此外,目前在其他幾個國家有機器人正在執行自動編輯,用於修復這類既存問題以及後續出現的新錯誤。如果社群認為這些編輯內容是可以接受的,我也很樂意為台灣啟用這項功能。

Let me know of any issues with the site, including any translation issues since it was machine translated from English, and I can fix them.

若網站有任何問題,包括翻譯方面的錯誤(因為目前是從英文機器翻譯而來),請隨時告知我,我會進行修正。

1 Like

Splendid! Since the extension hasn’t concluded,
this could be a solid approach for automated formatting.

Just one note—the 800 toll-free number should be +886 800.
Not sure if that’s related to google/libphonenumber?
Let’s see what the other community members think.


太棒了!由於分機號碼尚未充分討論,
這或許是對電話號碼格式批次處理的可靠方法。

只是有一點——那個 800 免付費號碼應該是 +886 800。
不確定這是否與 google/libphonenumber 有關?
但在此之前我們需要先看看其他社群成員的意見。

1 Like

Yes, it is a libphonenumber issue, all formatting of numbers comes directly from that library, so it seems another issue needs to be opened there.

1 Like