예제 #1
0
        /// <summary>
        /// <para>Verifies if a sense that contains all query tokens is really a match.</para>
        /// </summary>
        /// <param name="txtTokenized">The tokenized query text.</param>
        /// <param name="sensePos">The data position of the tokenized sense to verify.</param>
        /// <param name="entryIdToInfo">Container for kept entry matches.</param>
        /// <param name="br">Binary data source to read up tokenized sense.</param>
        private void doVerifyTarget(ReadOnlyCollection <EquivToken> txtTokenized,
                                    int sensePos,
                                    Dictionary <int, EntryMatchInfo> entryIdToInfo,
                                    BinReader br)
        {
            // Load tokenized sense
            br.Position = sensePos;
            TokenizedSense ts = new TokenizedSense(br);
            // Find query tokens in tokenized sense
            // This will be our highlight too!
            CedictTargetHighlight hilite = doFindTargetQuery(txtTokenized, ts);

            // No highlight: no match
            if (hilite == null)
            {
                return;
            }
            // Score is length of query (in tokens) divided by count of tokense in sense
            float score = ((float)txtTokenized.Count) / ((float)ts.EquivTokens.Count);

            // If we found query string, it's a match; we can go on and record best score and hilight
            if (!entryIdToInfo.ContainsKey(ts.EntryId))
            {
                EntryMatchInfo emi = new EntryMatchInfo
                {
                    EntryId        = ts.EntryId,
                    BestSenseScore = score,
                };
                emi.TargetHilites.Add(hilite);
                entryIdToInfo[ts.EntryId] = emi;
            }
            else
            {
                EntryMatchInfo emi = entryIdToInfo[ts.EntryId];
                if (score > emi.BestSenseScore)
                {
                    emi.BestSenseScore = score;
                }
                emi.TargetHilites.Add(hilite);
            }
        }
예제 #2
0
 /// <summary>
 /// <para>Verifies if a sense that contains all query tokens is really a match.</para>
 /// </summary>
 /// <param name="txtTokenized">The tokenized query text.</param>
 /// <param name="sensePos">The data position of the tokenized sense to verify.</param>
 /// <param name="entryIdToInfo">Container for kept entry matches.</param>
 /// <param name="br">Binary data source to read up tokenized sense.</param>
 private void doVerifyTarget(ReadOnlyCollection<EquivToken> txtTokenized,
     int sensePos,
     Dictionary<int, EntryMatchInfo> entryIdToInfo,
     BinReader br)
 {
     // Load tokenized sense
     br.Position = sensePos;
     TokenizedSense ts = new TokenizedSense(br);
     // Find query tokens in tokenized sense
     // This will be our highlight too!
     CedictTargetHighlight hilite = doFindTargetQuery(txtTokenized, ts);
     // No highlight: no match
     if (hilite == null) return;
     // Score is length of query (in tokens) divided by count of tokense in sense
     float score = ((float)txtTokenized.Count) / ((float)ts.EquivTokens.Count);
     // If we found query string, it's a match; we can go on and record best score and hilight
     if (!entryIdToInfo.ContainsKey(ts.EntryId))
     {
         EntryMatchInfo emi = new EntryMatchInfo
         {
             EntryId = ts.EntryId,
             BestSenseScore = score,
         };
         emi.TargetHilites.Add(hilite);
         entryIdToInfo[ts.EntryId] = emi;
     }
     else
     {
         EntryMatchInfo emi = entryIdToInfo[ts.EntryId];
         if (score > emi.BestSenseScore)
             emi.BestSenseScore = score;
         emi.TargetHilites.Add(hilite);
     }
 }