private Dictionary<int, List<EntityWrapper>> PopulateEntityDictionary(JsonResp jsonResp)//, string uiLang)
        {
            List<Entity> entities = jsonResp.results.entity.Where(x => x.label == "reference" || x.label == "concept" || x.label == "term").OrderBy(x => x.begin).ToList();
            Dictionary<int, List<EntityWrapper>> dict = new Dictionary<int, List<EntityWrapper>>();
            foreach (var entity in entities)
            {
                var newEntityWrapperStart = new EntityWrapper();
                newEntityWrapperStart.Entity = entity;
                var newEntityWrapperEnd = new EntityWrapper();
                newEntityWrapperEnd.Entity = entity;
                if (entity.label == "reference")
                {
                    newEntityWrapperStart.EntityType = EntityType.StartReference;
                    string id = entity.value,
                        eurlex_uri = "http://eur-lex.europa.eu/legal-content/" + entity.language + "/TXT/?uri=CELEX:" + id,
                        //clr = entity.label == "reference" ? "green" : "red";
                        clr = "green";
                    if (entity.toPar != "") eurlex_uri += "#" + entity.toPar;//"#"?
                    newEntityWrapperStart.EntityNode = "<a href=\"" + eurlex_uri + "\" style=\"color:" + clr + "\">";
                    if (dict.ContainsKey(entity.begin))
                    {
                        dict[entity.begin].Add(newEntityWrapperStart);
                        dict[entity.begin].Sort();
                    }
                    else
                    {
                        dict.Add(entity.begin, new List<EntityWrapper>() { newEntityWrapperStart });
                    }
                    newEntityWrapperEnd.EntityType = EntityType.EndReference;
                    newEntityWrapperEnd.EntityNode = "</a>";
                    if (dict.ContainsKey(entity.end))
                    {
                        dict[entity.end].Add(newEntityWrapperEnd);
                        dict[entity.end].Sort();
                    }
                    else
                    {
                        dict.Add(entity.end, new List<EntityWrapper>() { newEntityWrapperEnd });
                    }
                }
                else if (entity.label == "concept" || entity.label == "term")
                {
                    int lastKey = 0;
                    if (dict.Keys.Count > 0)
                    {
                        lastKey = dict.Keys.Max();
                    }
                    if (entity.begin < lastKey && entity.end > lastKey)
                    {
                        int end = entity.end;
                        entity.end = lastKey;
                        this.AddConcept(newEntityWrapperStart, newEntityWrapperEnd, entity, dict);

                        entity.begin = lastKey;
                        entity.end = end;
                        this.AddConcept(newEntityWrapperStart, newEntityWrapperEnd, entity, dict);
                    }
                    else
                    {
                        this.AddConcept(newEntityWrapperStart, newEntityWrapperEnd, entity, dict);
                    }
                }
            }
            return dict.OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
        }
 public string ProcessV1(string html, JsonResp jsonResp)//html is InpHtml; MainMethod Variant 1
 {
     StringBuilder sb = new StringBuilder();
     int index = 0;
     if (jsonResp != null && jsonResp.status == "OK")
     {
         if (jsonResp.results.entity != null && jsonResp.results.entity.Count > 0)
         {
             // string hint = AddHint(jsonResp.results.entity, langId, uiLangId);
             // sb.Append(hint);
             Dictionary<int, List<EntityWrapper>> dict = this.PopulateEntityDictionary(jsonResp);//, uiLang);
             foreach (var item in dict)
             {
                 sb.Append(html.Substring(index, item.Key - index));
                 index = item.Key;
                 foreach (var node in item.Value)
                 {
                     sb.Append(node.EntityNode);
                 }
             }
         }
     }
     sb.Append(html.Substring(index, html.Length - index));
     return sb.ToString();
 }