Beispiel #1
0
        /// <summary>
        /// Calculate similarity score between a pair of FingerprintMxs
        /// </summary>
        /// <param name="fp1"></param>
        /// <param name="fp2"></param>
        /// <returns></returns>

        public static float CalculateFingerprintPairSimilarityScore(
            FingerprintMx fp1,
            FingerprintMx fp2)
        {
            long[]     fp1Array  = fp1.ToLongArray();
            OpenBitSet fp1BitSet = new OpenBitSet(fp1Array, fp1Array.Length);
            int        fp1Card   = (int)fp1BitSet.Cardinality();

            long[]     fp2Array  = fp2.ToLongArray();
            OpenBitSet fp2BitSet = new OpenBitSet(fp2Array, fp2Array.Length);
            int        fp2Card   = (int)fp2BitSet.Cardinality();

            fp2BitSet.Intersect(fp1BitSet);
            int   commonCnt = (int)fp2BitSet.Cardinality();
            float simScore  = commonCnt / (float)(fp1Card + fp2Card - commonCnt);

            return(simScore);
        }
Beispiel #2
0
        /// <summary>
        /// Search a single file
        /// </summary>

        void SearchSingleFile(int fi)
        {
            StructSearchMatch sm = null;

            AssertMx.IsNotNull(FpDao, "FpDao");

            List <StructSearchMatch> matchList = FileMatchLists[fi];

            AssertMx.IsNotNull(matchList, "matchList");

            OpenBitSet queryObs = new OpenBitSet(QueryFpLongArray, QueryFpLongArray.Length);

            AssertMx.IsNotNull(queryObs, "queryObs");

            OpenBitSet dbObs = new OpenBitSet(QueryFpLongArray, QueryFpLongArray.Length);             // gets set to DB fp for intersect

            AssertMx.IsNotNull(dbObs, "dbObs");

            FileStream fs = FileStreamReaders[fi];

            AssertMx.IsNotNull(fs, "fs");

            ReadFingerprintRecArgs a = new ReadFingerprintRecArgs();

            a.Initialize(fs, QueryFpLongArray.Length);

            try
            {
                while (true)
                {
                    bool readOk = FpDao.ReadRawFingerprintRec(a);
                    if (!readOk)
                    {
                        break;
                    }

                    //if (IsSrcCidMatch("03435269", a)) a = a;  // debug

                    dbObs.Bits = a.fingerprint;
                    dbObs.Intersect(queryObs);
                    int   commonCnt = (int)dbObs.Cardinality();
                    float simScore  = commonCnt / (float)(a.cardinality + QueryFpCardinality - commonCnt);

                    if (simScore >= MinimumSimilarity)
                    {
                        sm            = ReadFingerprintRec_To_StructSearchMatch(a);
                        sm.SearchType = StructureSearchType.MolSim;
                        sm.MatchScore = simScore;

                        matchList.Add(sm);
                    }
                }
            }

            catch (Exception ex)
            {
                string msg = ex.Message;
                msg += string.Format("\r\nfi: {0}, fs.Name: {1}, sm: {2}", fi, fs.Name, sm != null ? sm.Serialize() : "");
                DebugLog.Message(DebugLog.FormatExceptionMessage(ex, msg));
                throw new Exception(msg, ex);
            }

            return;
        }