Skip to content

Add Egypt locale for phone numbers#1119

Open
ahmeda335 wants to merge 1 commit intodottxt-ai:mainfrom
ahmeda335:patch-1
Open

Add Egypt locale for phone numbers#1119
ahmeda335 wants to merge 1 commit intodottxt-ai:mainfrom
ahmeda335:patch-1

Conversation

@ahmeda335
Copy link
Copy Markdown

Adding Regex for Phone Numbers in EGYPT

Adding Regex for Phone Numbers in EGYPT
@cpfiffer
Copy link
Copy Markdown
Contributor

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.

@rlouf
Copy link
Copy Markdown
Member

rlouf commented Sep 17, 2024

Thank you for your contribution! You need to add the Egypt locale in this file:

so users can call:

types.locale("eg").PhoneNumber

@rlouf rlouf changed the title Update phone_numbers.py Add Egypt locale for phone numbers Sep 17, 2024
@rlouf rlouf added this to the 0.1.3 milestone Nov 8, 2024
@RobinPicard
Copy link
Copy Markdown
Contributor

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.

# Phone numbers in Egypt.
EGYPT_PHONE_NUMBER = r"^01[0-2,5]{1}[0-9]{8}$"

EgpytPhoneNumber = Annotated[
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EgyptPhoneNumber

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants