I have the following procedure that counts the document frequency for each entry of doctionary (freq)
foreach (var termIndex in freq.Select(entry => GetTermIndex(entry.Key)))
{
_docFreq[i][termIndex]++;
}
And also the procedure for getting term index
rivate int GetTermIndex(string term)
{
int i;
if (_wordsIndex.TryGetValue(term, out i))
return i;
else
return 0;
}
Where, all terms are indexed in another dictionary (_wordsIndex).
Based on above procedures, if the entry.Key in freq not exist, then the GetTermIndex will return 0 and that will count up the _docFreq (_docFreq[i][0]) and that is the problem.
So, how could i avoid counting when the entry.Key not exist ?? I tried to do something like
rivate int GetTermIndex(string term)
{
int i;
if (_wordsIndex.TryGetValue(term, out i))
return i;
else
return -1;
}
But of course an error “Index was outside the bounds of the array” appeared, because there no index for _docFreq[i][-1].
Could any help please ?? many Thanks
Just don’t count it if
termIndexis -1:or using LINQ
Where: