Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing.Design;
  4. using System.Linq;
  5. using System.Runtime.InteropServices;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace PocketGoogle
  10. {
  11.     public class Indexer : IIndexer
  12.     {
  13.         public Dictionary<string, Dictionary<int, List<int>>> Dict =
  14.             new Dictionary<string, Dictionary<int, List<int>>>();
  15.  
  16.         public int[] Intcol = new int[] { };
  17.  
  18.         // public Dictionary<int,Dictionary<int,char>> dict2 = new Dictionary<int, Dictionary<int, char>>();
  19.         public Dictionary<int, char[]> Dict2 = new Dictionary<int, char[]>();
  20.  
  21.         public void Add(int id, string documentText)
  22.         {
  23.             var split = new char[] {' ', '.', ',', '!', '?', ':', '-', '\r', '\n'};
  24.             var positionofWord = 0;
  25.             var a = new List<int>();
  26.             foreach (var word in documentText.Split(split))
  27.             {
  28.                 if (!Dict.ContainsKey(word))
  29.                 {
  30.                     var dictof = new Dictionary<int, List<int>>();
  31.                     dictof.Add(id, new List<int> {positionofWord});
  32.                     Dict.Add(word, dictof);
  33.                 }
  34.                 else if (!Dict[word].ContainsKey(id))
  35.                     Dict[word][id] = new List<int> {positionofWord};
  36.                 else
  37.                 {
  38.                     Dict[word][id].Add(positionofWord);
  39.                 }
  40.  
  41.                 positionofWord += word.Length + 1;
  42.             }
  43.         }
  44.  
  45.         /*  int k = 0;
  46.           var dict3 = new Dictionary<int,char>();
  47.          var bukovki= new char[]{};
  48.         */
  49.  
  50.  
  51.         public List<int> GetIds(string word)
  52.         {
  53.             var result = new List<int>();
  54.  
  55.             if (Dict.ContainsKey(word))
  56.             {
  57.                 foreach (var i in Dict[word].Keys)
  58.                 {
  59.                     result.Add(i);
  60.                 }
  61.             }
  62.  
  63.             return result;
  64.         }
  65.  
  66.         public List<int> GetPositions(int id, string word)
  67.         {
  68.             if (Dict.ContainsKey(word) && Dict[word].ContainsKey(id))
  69.             {
  70.                 return Dict[word][id];
  71.             }
  72.  
  73.             return new List<int>();
  74.         }
  75.  
  76.         public void Remove(int id)
  77.         {
  78.             foreach (var el in Dict.Values)
  79.             {
  80.                 if (el.ContainsKey(id)) el.Remove(id);
  81.             }
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement