Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to compare the contents of two text files and get the match percentage.

I compared two strings and was able to get the total percentage match.
ex:
string s1 = Manju is good guy;
string s2 = Manju is good guy;

The percentage is 100%
The code I have used is.
C#
protected void Button1_Click(object sender, EventArgs e)
      {
          int count = 0;
          string[] str1 = TextBox1.Text.Split(' ');
          string[] str2 = TextBox2.Text.Split(' ');
          for (int i = 0; i < str1.Length; i++)
          {
              for (int j = 0; j <str2.length;>              {
                  if (str1[i] == str2[j])
                  { 
                      count++;
                  }
              }
          }
           double per=0.0;
           if (count <= str1.Length)
               per = (count * 100) / str1.Length;
           else
               per = 100;
          Response.Write(per.ToString());

But the problem is, when I give the following data.
string s1 = Manju is good guy;
string s2 = Manju is bad guy;

The percentage is 75%

The meaning is totally different, but the matching is of 80%
Is there any algorithm or codes where in I can compare the word and also the meaning or something like that.
Please help me out.

Thanks in advance.

Update:
My bad. I said 80% because, my string was Manju is a good guy. So, the mistake while posting the problem. Heh.
Posted
Updated 25-May-11 21:54pm
v3
Comments
Sandeep Mewara 25-May-11 9:59am    
Formating code part with PRE tags makes the question readable.

Have you considered looking into Antelope?
http://www.proxem.com/Default.aspx?tabid=119[^]

SA is indeed correct.... "Either forget it or dedicate your whole life to it."
 
Share this answer
 
No! Analysis of the semantics and comparison of semantics of natural human speech is well above the level of the modern technology. You may only find some highly experimental works, but I doubt they effectively do that.

If you don't believe it, try to do any computer translation; it will demonstrate it how far it is.

Either forget it or dedicate your whole life to it.

—SA
 
Share this answer
 
Comments
Manfred Rudolf Bihy 26-May-11 4:27am    
And automated translation is that bad, because the translating system is only applying "some" rules but it does not understand the meaning of that which it is translating. Capturing the meaning, more often than not, is of utmost importance in translation as it will allow the system to also translate idioms and metaphorical expressions.
Sergey Alexandrovich Kryukov 26-May-11 12:52pm    
Exactly! Thank you very much for this explanation. I just failed to explain this important difference in short.
--SA
One out of four words is different so match is 75%. How do you arrive at 80?

It is not at all going to be easy if you want to take meanings to into account. And how would you match the sentences then? What should be the percentage for the following two sentences:

Manju is good guy
Manju is better guy


You will have to use a dictionary and define every possible match percentage based upon English grammar. This really tough job. All the best and if you implement this, let us know. :)
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 25-May-11 12:18pm    
What are you even talking about? It's a problem for whole humankind, pretty hopeless right now.

Please see my answer. Seriously.
--SA
dan!sh 26-May-11 15:25pm    
I know that. Read my answer again. Carefully.
Sergey Alexandrovich Kryukov 26-May-11 12:53pm    
My 5 for this answer, by the way.
--SA
If you are able to program a system that will be able to reliably extract the semantic (meaning) of words and phrases (leave alone sentences for now) from a sentence in a given language and make them comparable too, I'll promise you will be a greatly admired and very rich man.

(I can't really see how you would get there though when you are effectively stating above that 75 == 80)

Cheers!

-MRB
 
Share this answer
 
v3
Comments
fjdiewornncalwe 25-May-11 11:37am    
Same thing I was thinking, but I love how you expressed it. Cheers.
Sergey Alexandrovich Kryukov 25-May-11 12:18pm    
What are you even talking about? It's a problem for whole humankind, pretty hopeless right now.

Please see my answer. Seriously.
--SA
Dalek Dave 26-May-11 3:59am    
Good answer.
Sergey Alexandrovich Kryukov 26-May-11 12:53pm    
My 5 for this answer, by the way.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900