コード例 #1
0
ファイル: LanguageDetector.cs プロジェクト: 0000duck/latino
        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));
        }
コード例 #2
0
ファイル: LanguageDetector.cs プロジェクト: mgrcar/Detextive
        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));
        }
コード例 #3
0
ファイル: LanguageDetector.cs プロジェクト: mgrcar/Detextive
        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);
        }
コード例 #4
0
ファイル: LanguageDetector.cs プロジェクト: mgrcar/Detextive
        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);
        }
コード例 #5
0
ファイル: LanguageDetector.cs プロジェクト: 0000duck/latino
        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);
        }
コード例 #6
0
 public uint CalcOutOfPlace(NGramProfile p)
 {
     return CalcOutOfPlace(p, /*cutOff=*/500); // throws ArgumentNullException, ArgumentOutOfRangeException, InvalidOperationException
 }
コード例 #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;
 }
コード例 #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);
 }
コード例 #9
0
 public ArrayList<KeyDat<double, LanguageProfile>> DetectLanguageAll(NGramProfile p)
 {
     return DetectLanguageAll(p, /*cutOff=*/500); // throws ArgumentNullException, ArgumentValueException, InvalidOperationException
 }
コード例 #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;
 }
コード例 #11
0
 public LanguageProfile DetectLanguage(NGramProfile p)
 {
     return DetectLanguage(p, /*cutOff=*/500); // throws ArgumentNullException, ArgumentValueException, InvalidOperationException
 }
コード例 #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;
 }
コード例 #13
0
ファイル: LanguageDetector.cs プロジェクト: mgrcar/Detextive
 public ArrayList <KeyDat <double, LanguageProfile> > DetectLanguageAll(NGramProfile p)
 {
     return(DetectLanguageAll(p, /*cutOff=*/ 500)); // throws ArgumentNullException, ArgumentValueException, InvalidOperationException
 }
コード例 #14
0
ファイル: LanguageDetector.cs プロジェクト: mgrcar/Detextive
 public LanguageProfile DetectLanguage(NGramProfile p)
 {
     return(DetectLanguage(p, /*cutOff=*/ 500)); // throws ArgumentNullException, ArgumentValueException, InvalidOperationException
 }