Exemple #1
0
        public List <NlpEntity> MergeEntity(List <NlpEntity> tokens)
        {
            List <NlpEntity> res = new List <NlpEntity>();

            for (int i = 0; i < tokens.Count; i++)
            {
                NlpEntity     nlpEntity       = new NlpEntity();
                StringBuilder unionValue      = new StringBuilder(tokens[i].Value);
                StringBuilder unionEntity     = new StringBuilder(tokens[i].Entity);
                decimal       unoinConfidence = tokens[i].Confidence;

                int j = i + 1;
                while (j < tokens.Count && tokens[j].Entity == tokens[i].Entity && tokens[i].Entity != "O")
                {
                    unionValue.Append(" " + tokens[j].Value);
                    j++;
                }
                nlpEntity.Entity     = unionEntity.ToString();
                nlpEntity.Start      = tokens[i].Start;
                nlpEntity.Value      = unionValue.ToString();
                nlpEntity.Confidence = unoinConfidence;
                res.Add(nlpEntity);
                i = j - 1;
            }
            return(res);
        }
Exemple #2
0
        public List <NlpEntity> MergeEntity(string sentence, List <NlpEntity> tokens)
        {
            List <NlpEntity> res = new List <NlpEntity>();

            for (int i = 0; i < tokens.Count; i++)
            {
                NlpEntity nlpEntity = new NlpEntity();
                var       current   = tokens[i];

                if (current.Entity != "O")
                {
                    nlpEntity = current.ToObject <NlpEntity>();
                    // greedy search until next entity
                    int j = 0;
                    for (j = i + 1; j < tokens.Count; j++)
                    {
                        var next = tokens[j];
                        if (current.Entity == next.Entity)
                        {
                            i = j;
                            nlpEntity.Value = sentence.Substring(current.Start, next.End - current.Start + 1);
                        }
                        else
                        {
                            break;
                        }
                    }

                    res.Add(nlpEntity);
                }
            }
            return(res);
        }