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 669701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:10:47+00:00 2026-05-14T00:10:47+00:00

Does anyone know how to or have some code on counting the number of

  • 0

Does anyone know how to or have some code on counting the number of unique phrases in a document? (Single word, two word phrases, three word phrases).

Thanks

Example of what I’m looking for:
What I mean is I have a text document, and i need to see what the most popular word phrases are. Example text

I took the car to the car wash.

I : 1
took : 1
the : 2
car: 2
to : 1
wash : 1
I took : 1
took the : 1
the car : 2
car to : 1
to the : 1
car wash : 1
I took the : 1
took the car : 1
the car to : 1
car to the : 1
to the car : 1
the car wash : 1
I took the car to : 1
took the car to the : 1
the car to the car : 1
car to the car wash : 1

I need the phrase, and the count that it shows up.

Any help would be appreciated. The closet thing I found to this was a PHP script from http://tools.seobook.com/general/keyword-density/source.php

I used to have some code for this, but I cannot find it.

  • 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-14T00:10:48+00:00Added an answer on May 14, 2026 at 12:10 am

    Here is some initial code that solves your problem.

    function CountWordSequences(const s:string; Counts:TStrings = nil):TStrings;
    var
      words, seqs : TStrings;
      nw,i,j:integer;
      t :string;
    begin
      if Counts=nil then Counts:=TStringList.Create;
      words:=TStringList.Create;        // build a list of all words
      words.DelimitedText:=s;
      seqs:=TStringList.Create;
      for nw:=1 to words.Count do       // build a list of all word sequences
       begin
        for i:=0 to words.Count-nw do
         begin
          t:='';
          for j:=0 to nw-1 do
           begin
            t:=t+words[i+j];
            if j<>nw-1 then t:=t+' ';
           end;
          seqs.Add(t);
         end;
       end;
      words.Destroy;
      for i:=0 to seqs.Count-1 do         // count repeated sequences
       begin
        j:=Counts.IndexOf(seqs.Strings[i]);
        if j=-1 then
          Counts.AddObject(seqs.Strings[i],TObject(1))
        else
          Counts.Objects[j] := TObject(Succ(Integer(Counts.Objects[j])));
       end;
      seqs.Destroy;
      result:=Counts;
    end;
    

    You will need to elaborate this code for real world production, for example, by recognizing more word delimiters (not only blanks), and by implementing some sort of case insensitivity.

    To test it, put a Button, an EntryField and a Memo in a Form, and add the following code.

    procedure TForm1.Button1Click(Sender: TObject);
    var i:integer; l:TStrings;
     begin
      l:=CountWordSequences(edit1.Text,TStringList.Create);
      for i:=1 to l.count do
        memo1.Lines.Add('"'+l.Strings[i-1]+'": '+inttostr(Integer(l.Objects[i-1])));
     end;
    

    I first try with I took the car to the car wash

    gives

    "I": 1
    "took": 1
    "the": 2
    "car": 2
    "to": 1
    "wash.": 1
    "I took": 1
    "took the": 1
    "the car": 2
    "car to": 1
    "to the": 1
    "car wash.": 1
    "I took the": 1
    "took the car": 1
    "the car to": 1
    "car to the": 1
    "to the car": 1
    "the car wash.": 1
    "I took the car": 1
    "took the car to": 1
    "the car to the": 1
    "car to the car": 1
    "to the car wash.": 1
    "I took the car to": 1
    "took the car to the": 1
    "the car to the car": 1
    "car to the car wash.": 1
    "I took the car to the": 1
    "took the car to the car": 1
    "the car to the car wash.": 1
    "I took the car to the car": 1
    "took the car to the car wash.": 1
    "I took the car to the car wash.": 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 395k
  • Answers 395k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer We had similar concerns when we adopted a 1:1 ViewModel… May 15, 2026 at 2:39 am
  • Editorial Team
    Editorial Team added an answer use jquery post and you can return a JSON data… May 15, 2026 at 2:39 am
  • Editorial Team
    Editorial Team added an answer Figured it out. The idea is to create the iframe… May 15, 2026 at 2:39 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.