Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Drawing.Design;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- namespace PocketGoogle
- {
- public class Indexer : IIndexer
- {
- public Dictionary<string, Dictionary<int, List<int>>> Dict =
- new Dictionary<string, Dictionary<int, List<int>>>();
- public int[] Intcol = new int[] { };
- // public Dictionary<int,Dictionary<int,char>> dict2 = new Dictionary<int, Dictionary<int, char>>();
- public Dictionary<int, char[]> Dict2 = new Dictionary<int, char[]>();
- public void Add(int id, string documentText)
- {
- var split = new char[] {' ', '.', ',', '!', '?', ':', '-', '\r', '\n'};
- var positionofWord = 0;
- var a = new List<int>();
- foreach (var word in documentText.Split(split))
- {
- if (!Dict.ContainsKey(word))
- {
- var dictof = new Dictionary<int, List<int>>();
- dictof.Add(id, new List<int> {positionofWord});
- Dict.Add(word, dictof);
- }
- else if (!Dict[word].ContainsKey(id))
- Dict[word][id] = new List<int> {positionofWord};
- else
- {
- Dict[word][id].Add(positionofWord);
- }
- positionofWord += word.Length + 1;
- }
- }
- /* int k = 0;
- var dict3 = new Dictionary<int,char>();
- var bukovki= new char[]{};
- */
- public List<int> GetIds(string word)
- {
- var result = new List<int>();
- if (Dict.ContainsKey(word))
- {
- foreach (var i in Dict[word].Keys)
- {
- result.Add(i);
- }
- }
- return result;
- }
- public List<int> GetPositions(int id, string word)
- {
- if (Dict.ContainsKey(word) && Dict[word].ContainsKey(id))
- {
- return Dict[word][id];
- }
- return new List<int>();
- }
- public void Remove(int id)
- {
- foreach (var el in Dict.Values)
- {
- if (el.ContainsKey(id)) el.Remove(id);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement