public LanguageProfile FindMatchingLanguage(string str) { Utils.ThrowException(languageProfiles.Count == 0 ? new InvalidOperationException() : null); Utils.ThrowException(str == null ? new ArgumentNullException("str") : null); NGramProfile p = new NGramProfile(n); p.AddTokensFromString(str); if (p.IsEmpty) { return(null); } p.DoRanking(); return(FindMatchingLanguage(p)); }
public ArrayList <KeyDat <double, LanguageProfile> > DetectLanguageAll(string str) { Utils.ThrowException(mLanguageProfiles.Count == 0 ? new InvalidOperationException() : null); Utils.ThrowException(str == null ? new ArgumentNullException("str") : null); NGramProfile p = new NGramProfile(mN); p.AddTokensFromString(str); if (p.IsEmpty) { return(null); } p.DoRanking(); return(DetectLanguageAll(p)); }
public ArrayList <KeyDat <double, LanguageProfile> > DetectLanguageAll(NGramProfile p, int cutOff) { Utils.ThrowException(mLanguageProfiles.Count == 0 ? new InvalidOperationException() : null); Utils.ThrowException(p == null ? new ArgumentNullException("p") : null); Utils.ThrowException((!p.IsRanked) ? new ArgumentValueException("p") : null); Utils.ThrowException(cutOff < 1 ? new ArgumentOutOfRangeException("cutOff") : null); ArrayList <KeyDat <double, LanguageProfile> > result = new ArrayList <KeyDat <double, LanguageProfile> >(); foreach (LanguageProfile l in mLanguageProfiles) { double dist = p.CalcOutOfPlace(l, cutOff); result.Add(new KeyDat <double, LanguageProfile>(dist, l)); } return(result); }
public LanguageProfile DetectLanguage(NGramProfile p, int cutOff) { Utils.ThrowException(mLanguageProfiles.Count == 0 ? new InvalidOperationException() : null); Utils.ThrowException(p == null ? new ArgumentNullException("p") : null); Utils.ThrowException((!p.IsRanked) ? new ArgumentValueException("p") : null); Utils.ThrowException(cutOff < 1 ? new ArgumentOutOfRangeException("cutOff") : null); LanguageProfile matchingLang = null; double minDist = Double.MaxValue; foreach (LanguageProfile l in mLanguageProfiles) { double dist = p.CalcOutOfPlace(l, cutOff); if (dist < minDist) { matchingLang = l; minDist = dist; } } return(matchingLang); }
public uint CalcOutOfPlace(NGramProfile p, int cutOff) { Utils.ThrowException(p == null ? new ArgumentNullException("p") : null); Utils.ThrowException(cutOff < 1 ? new ArgumentOutOfRangeException("cutOff") : null); Utils.ThrowException(!isRanked ? new InvalidOperationException() : null); int dist = 0; uint v = 0; uint sum = 0; int penalty = Math.Min(cutOff, p.hist.Count); // sums up distances of each N-gram in this profile to // the same N-gram in profile 'p' foreach (KeyValuePair <string, uint> kvp in hist) { if (kvp.Value > cutOff) { continue; } if (p.hist.TryGetValue(kvp.Key, out v)) { if (v > cutOff) { dist = penalty; } else { dist = (int)Math.Abs(v - kvp.Value); } } else { dist = penalty; } sum += (uint)dist; } return(sum); }
public uint CalcOutOfPlace(NGramProfile p) { return CalcOutOfPlace(p, /*cutOff=*/500); // throws ArgumentNullException, ArgumentOutOfRangeException, InvalidOperationException }
public uint CalcOutOfPlace(NGramProfile p, int cutOff) { Utils.ThrowException(p == null ? new ArgumentNullException("p") : null); Utils.ThrowException(cutOff < 1 ? new ArgumentOutOfRangeException("cutOff") : null); Utils.ThrowException(!mIsRanked ? new InvalidOperationException() : null); int dist = 0; uint v = 0; uint sum = 0; int penalty = Math.Min(cutOff, p.mHist.Count); // sum up distances from each n-gram in this profile to the same n-gram in profile p foreach (KeyValuePair<string, uint> kvp in mHist) { if (kvp.Value > cutOff) { continue; } if (p.mHist.TryGetValue(kvp.Key, out v)) { if (v > cutOff) { dist = penalty; } else { dist = (int)Math.Abs(v - kvp.Value); } } else { dist = penalty; } sum += (uint)dist; } return sum; }
public ArrayList<KeyDat<double, LanguageProfile>> DetectLanguageAll(string str) { Utils.ThrowException(mLanguageProfiles.Count == 0 ? new InvalidOperationException() : null); Utils.ThrowException(str == null ? new ArgumentNullException("str") : null); NGramProfile p = new NGramProfile(mN); p.AddTokensFromString(str); if (p.IsEmpty) { return null; } p.DoRanking(); return DetectLanguageAll(p); }
public ArrayList<KeyDat<double, LanguageProfile>> DetectLanguageAll(NGramProfile p) { return DetectLanguageAll(p, /*cutOff=*/500); // throws ArgumentNullException, ArgumentValueException, InvalidOperationException }
public ArrayList<KeyDat<double, LanguageProfile>> DetectLanguageAll(NGramProfile p, int cutOff) { Utils.ThrowException(mLanguageProfiles.Count == 0 ? new InvalidOperationException() : null); Utils.ThrowException(p == null ? new ArgumentNullException("p") : null); Utils.ThrowException((!p.IsRanked) ? new ArgumentValueException("p") : null); Utils.ThrowException(cutOff < 1 ? new ArgumentOutOfRangeException("cutOff") : null); ArrayList<KeyDat<double, LanguageProfile>> result = new ArrayList<KeyDat<double, LanguageProfile>>(); foreach (LanguageProfile l in mLanguageProfiles) { double dist = p.CalcOutOfPlace(l, cutOff); result.Add(new KeyDat<double, LanguageProfile>(dist, l)); } return result; }
public LanguageProfile DetectLanguage(NGramProfile p) { return DetectLanguage(p, /*cutOff=*/500); // throws ArgumentNullException, ArgumentValueException, InvalidOperationException }
public LanguageProfile DetectLanguage(NGramProfile p, int cutOff) { Utils.ThrowException(mLanguageProfiles.Count == 0 ? new InvalidOperationException() : null); Utils.ThrowException(p == null ? new ArgumentNullException("p") : null); Utils.ThrowException((!p.IsRanked) ? new ArgumentValueException("p") : null); Utils.ThrowException(cutOff < 1 ? new ArgumentOutOfRangeException("cutOff") : null); LanguageProfile matchingLang = null; double minDist = Double.MaxValue; foreach (LanguageProfile l in mLanguageProfiles) { double dist = p.CalcOutOfPlace(l, cutOff); if (dist < minDist) { matchingLang = l; minDist = dist; } } return matchingLang; }
public ArrayList <KeyDat <double, LanguageProfile> > DetectLanguageAll(NGramProfile p) { return(DetectLanguageAll(p, /*cutOff=*/ 500)); // throws ArgumentNullException, ArgumentValueException, InvalidOperationException }
public LanguageProfile DetectLanguage(NGramProfile p) { return(DetectLanguage(p, /*cutOff=*/ 500)); // throws ArgumentNullException, ArgumentValueException, InvalidOperationException }