GithubHelp home page GithubHelp logo

rhymepingpong's Introduction

Rhyme Ping Pong

Go back and forth with rhymes instead of a ping pong ball and see if you can have the last word! The application uses inputs of previous players to come up with its rhymes as a response to yours.

The rhythm and flow of most poems, sometimes felt like a game of ping pong to me, which became the inspiration behind the simple game, Rhyme Ping Pong. 😁

This application tries to come up with a rhyme for each sentence entered and simultaneously builds up its knowledge by storing each unique sentence entered so that it can be used as a rhyme in the future.

Screenshots

Overview video

Here's a short video that explains the project and how it uses Redis:

Embed your YouTube video

How it works

New sentences input by the user are stored along with the word ending of the sentence’s final word, which is then used to query for a rhyming sentence each time a user inputs a new sentence. The word ending consists of the final 2 (or 3 if the 2nd to last letter is a consonant) letters of the last word in a sentence.

How the data is stored:

The data (sentences received) is stored in as a JSON data structure and a sentence is stored according to the the following schema:

  • sentenceString - String
  • wordEnding - String

Saving a new sentence

  • Checking for duplicates first,
  const duplicate = await sentenceRepository
    .search()
    .where("sentenceString")
    .equals(req.body.string)
    .return.first();
  • Then saving the sentence if no duplicates were found. wordEnding contains the word ending of the final word of that senetnce.
  if (duplicate === null) {
    const sentence = sentenceRepository.createEntity(req.body.string);
    sentence.sentenceString = req.body.string;
    sentence.wordEnding = req.body.wordEnding;
    const id = await sentenceRepository.save(sentence);
    res.send(id);
  }

How the data is accessed:

RediSearch was used for querying, and data was accessed in the follwong ways, where sentenceRepository creates the main access point for reading and writing entities on Redis.:

  • Searching for a rhyming sentence
    • Sentences are checked for how well they rhyme by querying the wordEnding attribute
    • Then the record with a sentence identical to the user input sentence is removed if available, to avoid repeating the same sentence in the case of a user sending a sentence that is already n the database.
    • A random sentence is picked to be displayed from the retrieved list to avoid displaying the same rhyming sentence each time.
  const rhymes = await sentenceRepository
      .search()
      .where("wordEnding")
      .equals(req.params.word)
      .and("sentenceString")
      .not.equals(req.params.sentence)
      .return.all();
  • Retrieving all stored sentences
  const allSentences = await sentenceRepository.search().returnAll();

How to run it locally

Prerequisites

  • Node - version ">=14.17.0"

Local installation

Frontend

  1. Open a terminal in the root of the project folder.
  2. Run cd frontend to enter the folder.
  3. Run npm install.
  4. After package installation completes, run npm start.
  5. Open http://localhost:3000/ in your browser.

Backend

  1. Open a terminal in the root of the project folder.
  2. Run cd backend to enter the folder.
  3. Run npm install.
  4. Create a free account on Redis Cloud and create your database.
  5. Create a new user for the database.
  6. In a .env file in the root of /backend folder, add the values for:
REDIS_DB_ENDPOINT=<Public endpoint>
REDIS_USER=<Database user's name>
REDIS_PWD=<Database user's password>
  1. Run npm start.

Feel free to try this game out! πŸ“

More Information about Redis Stack

Here some resources to help you quickly get started using Redis Stack. If you still have questions, feel free to ask them in the Redis Discord or on Twitter.

Getting Started

  1. Sign up for a free Redis Cloud account using this link and use the Redis Stack database in the cloud.
  2. Based on the language/framework you want to use, you will find the following client libraries:

The above videos and guides should be enough to get you started in your desired language/framework. From there you can expand and develop your app. Use the resources below to help guide you further:

  1. Developer Hub - The main developer page for Redis, where you can find information on building using Redis with sample projects, guides, and tutorials.
  2. Redis Stack getting started page - Lists all the Redis Stack features. From there you can find relevant docs and tutorials for all the capabilities of Redis Stack.
  3. Redis Rediscover - Provides use-cases for Redis as well as real-world examples and educational material
  4. RedisInsight - Desktop GUI tool - Use this to connect to Redis to visually see the data. It also has a CLI inside it that lets you send Redis CLI commands. It also has a profiler so you can see commands that are run on your Redis instance in real-time
  5. Youtube Videos

rhymepingpong's People

Contributors

methminug avatar

Stargazers

Baasit Khawaja avatar

Watchers

 avatar

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.