Giter VIP home page Giter VIP logo

phonewords's Introduction

phonewords

Join the chat at https://gitter.im/azee/phonewords Jenkins Build

Reasoning

I have selected 1-800-CODING-CHALLENGE because:

  • always wanted to build a real-life application that involves trie-trees
  • even if I won't sucseed this code can be used for my future projects

Design

Parts

Code is divided into 3 major parts.

  1. Core. Business logic of trie-tree traversal
  2. Dictionary provider - a possibility to implement words providers from different sources
  3. Executor. A possibility to implement different user interaction strategies

Core

The core of the solution is a trie-tree. The point is to build a trie-tree out of the list of words in the dictionary. Each edge will be a number which represents a letter. A node may or may not contain a list of words from the dictionary. The idea is to traverse all possible recursive branches for each provided number trying to build a list of possible substitutions as we hit a node with a words list.

Dictionary tree is build on application startup and can be used for each phone number provided.

Dictionary provider

As we may want to use different dictionary sources (e.g. default, file specific, network specific, database) a dictionary provider factory is implemented.

If -Ddictionary="PATH_TO_DICTIONARY" is passed we read data from file. Otherwise we use the default one. It uses a list of 5000 most popular English words and is stored in resources.

Executor

We may want to implement different kind of interactions with user. It may be an single-run output for a provided file with phone numbers listed. Or it may be an interactive console application when user enters numbers one by one. We also may want to implement a web service or database scheduled actions or something else.

Executor factory is implemented for that reason. If -Ddata="PATH_TO_NUMBERS_LIST" is provided — data will be fetched from a file. If not — STDIN executor will take place. CTRL + C or type «quit» or «exit» to exit.

It is also possible to override printValues method of executor base class so it is possible to work with other output streams (DB, http).

Building

To build a project you have to run maven:

mvn clean install

Running

Default dictionary and interactive IO:

java -jar phonenumbers.jar

Customisation - dictionary and data parameters are optional

java -jar  -Ddictionary="PATH_TO_DICTIONARY" -Ddata="PATH_TO_NUMBERS_LIST"  phonenumbers.jar

Source

Code: https://github.com/azee/phonewords

Release: https://github.com/azee/phonewords/releases/latest

phonewords's People

Contributors

azee avatar

Watchers

James Cloos avatar  avatar

Forkers

gitter-badger

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.