outlines icon indicating copy to clipboard operation
outlines copied to clipboard

Add Egypt locale for phone numbers

Open ahmeda335 opened this issue 1 year ago • 3 comments

Adding Regex for Phone Numbers in EGYPT

ahmeda335 avatar Aug 27 '24 09:08 ahmeda335

This might actually be a good time to look at using something more general. I was able to get phonenumbers to spit out the regex(s):

import phonenumbers
from phonenumbers.phonemetadata import PhoneMetadata

metadata = PhoneMetadata.metadata_for_region("EG")  # Replace "US" with the country code you need

metadata.number_format

# [NumberFormat(pattern='(\\d)(\\d{7,8})', format='\\1 \\2', leading_digits_pattern=['[23]'], national_prefix_formatting_rule='0\\1'), NumberFormat(pattern='(\\d{2})(\\d{6,7})', format='\\1 \\2', leading_digits_pattern=['1[35]|[4-6]|8[2468]|9[235-7]'], national_prefix_formatting_rule='0\\1'), NumberFormat(pattern='(\\d{3})(\\d{3})(\\d{4})', format='\\1 \\2 \\3', leading_digits_pattern=['[89]'], national_prefix_formatting_rule='0\\1'), NumberFormat(pattern='(\\d{2})(\\d{8})', format='\\1 \\2', leading_digits_pattern=['1'], national_prefix_formatting_rule='0\\1')]

Not quite sure how to combine these though.

cpfiffer avatar Aug 27 '24 21:08 cpfiffer

Thank you for your contribution! You need to add the Egypt locale in this file: https://github.com/dottxt-ai/outlines/blob/289ef5d7db674fc159f56fa14f5bcf45b4e4bec2/outlines/types/locales.py#L7 so users can call:

types.locale("eg").PhoneNumber

rlouf avatar Sep 17 '24 13:09 rlouf

Hi @ahmeda335! We modified the organization of the output type files in the recently released Outlines v1. locale is now a directory containing one file per country.

RobinPicard avatar Jun 19 '25 14:06 RobinPicard