Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
 public uint CalcOutOfPlace(NGramProfile p)
 {
     return CalcOutOfPlace(p, /*cutOff=*/500); // throws ArgumentNullException, ArgumentOutOfRangeException, InvalidOperationException
 }
Esempio n. 7
0
 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;
 }
Esempio n. 8
0
 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);
 }
Esempio n. 9
0
 public ArrayList<KeyDat<double, LanguageProfile>> DetectLanguageAll(NGramProfile p)
 {
     return DetectLanguageAll(p, /*cutOff=*/500); // throws ArgumentNullException, ArgumentValueException, InvalidOperationException
 }
Esempio n. 10
0
 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;
 }
Esempio n. 11
0
 public LanguageProfile DetectLanguage(NGramProfile p)
 {
     return DetectLanguage(p, /*cutOff=*/500); // throws ArgumentNullException, ArgumentValueException, InvalidOperationException
 }
Esempio n. 12
0
 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;
 }
Esempio n. 13
0
 public ArrayList <KeyDat <double, LanguageProfile> > DetectLanguageAll(NGramProfile p)
 {
     return(DetectLanguageAll(p, /*cutOff=*/ 500)); // throws ArgumentNullException, ArgumentValueException, InvalidOperationException
 }
Esempio n. 14
0
 public LanguageProfile DetectLanguage(NGramProfile p)
 {
     return(DetectLanguage(p, /*cutOff=*/ 500)); // throws ArgumentNullException, ArgumentValueException, InvalidOperationException
 }