Code Monkey home page Code Monkey logo

diction_dictionary_scraping's Introduction

Diction & dictionary scrapping

git clone https://github.com/ryanmwakio/diction_dictionary_scraping.git

Navigate into the project:
*NB: make sure you have node installed if you haven't node installation

npm install

This is a command line app so run the command below with the url of the page to scrape

npm start "your_url"

The app return all words from the page and the count of each word. The english words are separated from non english and the english words are logged to your terminal.


When not successful the output will give the following prompt text output image

when successful you will get the following output output image output image


The folder structure

DICTION_DICTIONARY_SCRAPING
+----   node_modules
│----   README.md
│----   index.js (main file all code resides)
│----   .gitignore


The code

//The main function that does the processing
scrapePage(url);
//The function checks if the word is in the English dictionary of words
function check_if_word_exists(word) {
  return words.check(word);
}
//Loop through filtering the words and sorting them from all the content from the page
for (let i = 0; i < pageContent.length; i++) {
  if (!wordCount[pageContent[i]]) {
    wordCount[pageContent[i]] = 1; //if the word doesn't exist then add it to the object and set count as 1
    if (check_if_word_exists(pageContent[i])) {
      englishWords.push(pageContent[i]);
    } else {
      nonEnglishWords.push(pageContent[i]);
    }
  } else {
    wordCount[pageContent[i]] += 1; // else add the count of the word
    if (check_if_word_exists(pageContent[i])) {
      englishWords.push(pageContent[i]);
    } else {
      nonEnglishWords.push(pageContent[i]);
    }
  }
}
//we then return the word instance of every word and its count and the english words
console.log(englishWords);
return [wordCount, englishWords];

//You can also access the non-english words incase ever needed(they are in a list)
nonEnglishWords;

Tasks:

  • create a program
  • receives a web page
  • return words and the count
  • separate english and non-english
  • compare english and non english

diction_dictionary_scraping's People

Contributors

ryanmwakio avatar

Stargazers

 avatar Victor Kirui 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.