Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7406453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:33:37+00:00 2026-05-29T05:33:37+00:00

Im making my final project in my studies. and I’m trying to create sentiment

  • 0

Im making my final project in my studies.

and I’m trying to create sentiment analysis of Twitter messages.

I’m using Bayesian algorithm, and bag of words.

Do you have an example of bag of words algorithm in PHP?

I can’t find anything, maybe list of positive and negative words or something

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:33:37+00:00Added an answer on May 29, 2026 at 5:33 am

    I haven’t implemented Bag of Words in PHP but I’ve done it in java. A simple way to implement it would be by taking the training data and tokenizing it (example Stanford Tokenizer). Once you have tokenized all your training data, you can then extract 1-grams from it. I use this http://homepages.inf.ed.ac.uk/lzhang10/ngram.html to extract the grams and then remove the count of words from the output and just use the words. This becomes your Bag of Words corpus which can be used during training and classification. Make sure, you use the same tokenizer during training and testing or classification and also use the same corpus while training the models.

    Now implementing it is pretty easy, just take a string of data and tokenize it using the same tokenizer used to create the bag of words corpus. Now take each token and then find whether that token is available in your corpus and at what position. For example, you have a corpus which has words as follows :-

    a

    name

    the

    hello

    world

    ,

    And you have a string “hello, my name is Jas”. Tokenizing it would give the following tokens {hello,,,my,name,is,Jas} and when you try to match these tokens with the corpus your result would be :-

    2:1 4:1 6:1

    This means, the words name, hello and comma which are present in the location 2, 4 and 6 in your corpus are present in the incoming test string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a fighting game in Java for a project and trying to get
I'm making a game for my final project in an XNA class I'm taking,
So for our Final Year Project we are making a nifty lil app that
While making some final tests of a class-library that I'm writing for Windows Mobile
I am thinking of making a simple game engine for my course final year
Making my first steps with NHibernate, I'm trying to have it creating my Tables
When making changes using SubmitChanges() , LINQ sometimes dies with a ChangeConflictException exception with
I'm making minesweeper for a school project. When the player wins or loses, the
When compiling our project, we create several archives (static libraries), say liby.a and libz.a
I am new to android coding and was making a project with ListView. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.