Package: vanitynumber
Vanity Toll-free Number Python ModuleAvanity numberis a local or toll-free telephone number for which a subscriber requests an easily remembered sequence of numbers for marketing purposes. For example, '1-866-386-6481' => '1-866-FUNMIT1'This is a Python Module implementing functionalities related toVanity Toll-free Phone Numbers, like wordification generation, Number mapping, validation, etc. For example:Number to word Generation: the Toll Free Number "1-800-724-6837" could be wordified to "1-800-PAINTER" for remembering easily, and there could be other wordifications.Word to number mapping: The telephone number corresponding to the wordified number '1-866-FUNMIT1' is '1-866-386-6481'Phone Number validation: '404739-92' and '6504939270' are NOT valid US Phone Numbers.See the Python Module published in PyPihttps://pypi.org/project/vanitynumber/Approach and Algorithm usedMain files arewordify.pyandhelper.pyall_wordificationsGiven a valid Toll-free Number (e.g."1-800-724-6837"), we would like to generate and return various possible Vanity Numbers (e.g.["1-800-PAINTER", ...]), which are valid word combinations. This problem of generating valid word combinations of a phone number is approached by considering it as a graph problem, with Nodes calledT9_Graph_Noderepresenting possible combinations of characters for each of the digit, and Breadth first search is performed from the first digit, till the end of the number.Comparator operatorshas been over-ridden forT9_Graph_Nodefor performing custom comparison operations between Graph Nodes, during operations like sorting, min, max, etc.While doing graph search, since it is required to frequently check if the prefix word is a valid dictionary word,Trie Data structureis Used. To populate the Trie, Dictionaries.txt is read and Trie Data Structure has been created and saved in a global variable. Python Dictionary type could also have been used for checking for a valid dictionary word, but it will Be more memory intensive to store all dictionary words in local memory while the program is running, and the program may crash for larger number of dictionary entries. Trie data structure can support much larger dictionary sizes.The List of possible outputs are stored in Max Heap / Priority Queue for faster insertion and deletion queries and retrieving best N words, which is defined by comparator function (most number of English characters in wordified_number)Graph Search (BFS): For performing graph search,BFSis used, which is more intuitive to this problem thatDFSNumber Validation: Since US phone numbers can come in slightly different formats (1-800-724-6837, 4046639270, 404-663-9270, 1-(866)-(724)-(6836), etc ) and to validate them handling these cases,Regular Expressionsis used to validate, as well as compare phone numbers and fetch groups of area codes. Though sometimes it is recommended to avoid Regex, this usecase of fetching US phone number area codes looked more suitable for its use, to avoid writing complex and repeating logic for validating, matching and fetching groups of numbers in the US phone number, Regular expression approach is used.number_to_words->words_to_number-> After sanity validation, converts each character to its corresponding T9 digit based on defined hash map.
`Performance OptimizationChecking for valid dictionary words Using Trie Data structure.Trie data is populated and stored as aGlobal Constant. This avoids re-computation (dictionary file read and Trie populate) between multiple functions, and will save considerable time if dictionary file is larger.When doing Graph search, if valid prefix of a dictionary word is Not formed, the graph search is pre-maturely discontinued at that stage.AssumptionsAssumptions Made in this programThere are many words in the dictionary which are NOT Useful (yo, ey, si, fr) and Needs data cleaning.
I've attempted to do data cleaning indata_cleaning.pybut saved it for a later day.
Hence the program has IGNORED ALL TWO LETTER WORDSThe Approach currently considers only maximum of combination of two words together, though it can be extended for more words.Data structures and libraries usedThe VanityNumber module uses Most Popular 20,000 words in adictionary_20k.txttaken fromgoogle-10000-englishIt uses the following Libraries for Data Structure:pygtrie- Python library implementing a trie data structure, for checking valid dictionary word.heapq- Python library for implementing a Min Heap Priority Queue, for returning top N nodes.deque- Deque for implementing a Queue Data-structure for Breadth first graph searchMain files arewordify.pyandhelper.pyGetting StartedUsers Installation (Alpha version)See the Alpha Release Python Module published in PyPihttps://pypi.org/project/vanitynumber/pip install vanitynumberDevelopers InstallationInstructions for installing in your development environmentgit clone https://github.com/sreenivasanac/vanitynumber
cd vanitynumber/

virtualenv -p python3 my_env
source my_env/bin/activate

pip install -r requirements.txt
python setup.py installUsagepython

>>>import vanitynumber

>>>vanitynumber.number_to_words("1-866-386-6481")
>'1-866-FUNMIT1'

>>>vanitynumber.words_to_number("1-866-COOLBEE")
>'1-866-266-5233'

>>>vanitynumber.words_to_number("866-4FUNMIT")
>'866-438-6648'

>>>vanitynumber.all_wordifications("1-800-266-5233")
>['1-800-BOOKBEE', '1-800-CNNJADE',...]

>>>vanitynumber.is_valid_phone_number("1-800-266-5233")
>TrueRunning the testspytestAuthorsSreenivasan ACLicenseThis project is licensed under EULA Restrictive License - see theLICENSEfile for details