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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:37:56+00:00 2026-05-17T21:37:56+00:00

I am trying to figure out what the best method would be for me

  • 0

I am trying to figure out what the best method would be for me to use to parse word phrases passed to me and build different groupings based on those phrases.

Example XML:

<root>
   <keyword value=""My First Phrase""/>
   <keyword value=""My First Phrase Again""/>
   <keyword value=""My First Phrase Again and Again""/>
</root>

So I would extract these out of the xml:

My First Phrase
My First Phrase Again
My First Phrase Again and Again

I would then like to build these new phrases from the original:

My First Phrase   
My First
First Phrase
My
First
Phrase

My First Phrase Again
My First Phrase
First Phrase Again
My First
First Phrase
Phrase Again
My
First
Phrase
Again

This would let me break down the phrases and build a sort of ranking out of those words. I am have built some lists and iterated over them, but it isn’t work the way I would expect.

So for the ranking I mean this:

My First Phrase Again    Rank: 1 (Exact Match)
My First Phrase          Rank: 2
First Phrase Again       Rank: 2
My First                 Rank: 3
First Phrase             Rank: 3
Phrase Again             Rank: 3
My                       Rank: 4
First                    Rank: 4
Phrase                   Rank: 4
Again                    Rank: 4

Not sure what the best approach would be to parse this data.

Thanks,

S

  • 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-17T21:37:57+00:00Added an answer on May 17, 2026 at 9:37 pm

    If i understand correctly your definition of ‘rank’, you can solve it with something like this:

    public class PhraseRanking : IEnumerable<KeyValuePair<string, int>>
    {
        private readonly Dictionary<string, int> _ranking;
    
        public PhraseRanking()
        {
            _ranking = new Dictionary<string, int>();
        }
    
        public PhraseRanking(string phrase)
            : this()
        {
            var words = phrase.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var sb = new StringBuilder(phrase.Length);
            for(int i = words.Length; i > 0; --i)
            {
                int rank = words.Length - i + 1;
                int lastFirstWordIndex = words.Length - i;
                for(int j = 0; j <= lastFirstWordIndex; ++j)
                {
                    sb.Clear();
                    int lastWordIndex = j + i - 1;
                    for(int k = j; k <= lastWordIndex; ++k)
                    {
                        sb.Append(words[k]);
                        if(k != lastWordIndex) sb.Append(' ');
                    }
                    _ranking[sb.ToString()] = rank;
                }
            }
        }
    
        public int this[string phrase]
        {
            get { return _ranking[phrase]; }
        }
    
        public int Count
        {
            get { return _ranking.Count; }
        }
    
        public IEnumerator<KeyValuePair<string, int>> GetEnumerator()
        {
            return _ranking.GetEnumerator();
        }
    
        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return _ranking.GetEnumerator();
        }
    }
    

    Usage:

    var ranking = new PhraseRanking("My First Phrase Again");
    var sb = new StringBuilder();
    foreach(var rank in ranking)
    {
        sb.AppendLine(rank.Value.ToString() + ": " + rank.Key);
    }
    MessageBox.Show(sb.ToString());
    

    Output:

    1: My First Phrase Again
    2: My First Phrase
    2: First Phrase Again
    3: My First
    3: First Phrase
    3: Phrase Again
    4: My
    4: First
    4: Phrase
    4: Again
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to figure out what would be the best method for storing
I'm trying to figure out the best method of getting/displaying the shortest distance between
I'm trying to figure out the best option to use anonymous event listeners that
While trying to figure out the best method to ping (ICMP) something from python,
The Quetion Hello. I'm trying to figure out the best way to use one
I am trying to figure out the best method to relate country, region and
I'm trying to figure out the best way to build an easily maintainable and
Trying to figure out how to use the Jquery .on() method with a specific
I am trying to figure out what the best method is for writing an
I'm trying to figure out the best method to programmatically embed a logo onto

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.