Click here to Skip to main content
15,906,766 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
IDF( is a popular measure of a word's importance. The IDF invari- ably appears in a host of heuristic measures used in information retrieval. However, so far the IDF has itself been a heuristic.

mathamatically IDF is the

IDF(t,D)=log(Total Number documents/Number of Document matching term);
Actually i have develop one application for document clustering. in this i have

one IDF method like as

C#
private static float FindInverseDocumentFrequency(string term)
       {
          // DocumentVector dv = new DocumentVector();

           //find the  no. of document that contains the term in whole document collection
           int count = documentCollection.ToArray().Where(s => r.Split(s.ToUpper()).ToArray().Contains(term.ToUpper())).Count();
           /*
            * log of the ratio of  total no of document in the collection to the no. of document containing the term
            * we can also use Math.Log(count/(1+documentCollection.Count)) to deal with divide by zero case;
            */
           return (float)Math.Log((float)documentCollection.Count / (float)count);

       }


this method use the following declared statments in program


documentCollection like as

C#
documentCollection = collection.DocumentList[dv.content] as Hashtable;


DocumentList is like as

C#
private DocumentCollection docCollection=  new DocumentCollection() { DocumentList = new Hashtable() };


s is the string like as

C#
List<string> removeList = new List<string>(){"\"","\r","\n","(",")","[","]","{","}","","."," ",","};
            foreach (string s in removeList)
            {
                distinctTerms.Remove(s);
            }


r is the Regular expression
C#
private static Regex r = new Regex("([ \\t{}()\",:;. \n])");


IDF method have some error like as:

"
VB
 documentcollection.toarray() occur error like as

"'System.Collections.Hashtable' does not contain a definition for 'ToArray' and no extension method 'ToArray' accepting a first argument of type 'System.Collections.Hashtable' could be found (are you missing a using directive or an assembly reference?)



please slove this error.


please help me.thank u
Posted

1 solution

Don't use non-generic types (except specialized which are not applicable here). The have been rendered obsolete as early as of .NET v.2.0 when generics were introduced. Look what you are doing: using dynamic case with as operator. The whole point of generics (+ classic OOP) was to avoid it.

Use the type System.Collections.Generic.HashSet<T> instead, with its ToArray<T>() methods:
https://msdn.microsoft.com/en-us/library/bb359438%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/bb298736(v=vs.110).aspx[^],
https://msdn.microsoft.com/en-us/library/bb298736(v=vs.110).aspx[^].

—SA
 
Share this answer
 

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