public void AddEntities(params Entity[] entities) { int id = _entities.Count(); foreach (var entity in entities) { _entities.Add(entity); for (int i = 0; i < entity.Tokens.Length; ++i) { var position = new EntityPosition(id, i); var token = entity.Tokens[i]; List <EntityPosition> matches; if (_tokenToEntities.TryGetValue(token, out matches)) { matches.Add(position); } else { _tokenToEntities[token] = new List <EntityPosition> { position }; } } ++id; } }
/// <summary> /// Adds an array of entities to the EntitiesDictionary /// Their position can overlap with the entities already in the dictionary /// Supports entity strings occurring multiple times in the input string /// </summary> /// <param name="entities"></param> public void AddEntities(params Entity[] entities) { // id is the start id we use to store this new list of entities int id = _entities.Count(); foreach (var entity in entities) { _entities.Add(entity); for (int i = 0; i < entity.Tokens.Length; ++i) { var position = new EntityPosition(id, i); var tokenString = entity.Tokens[i].TokenString; List <EntityPosition> matches; if (_tokenToEntities.TryGetValue(tokenString, out matches)) { matches.Add(position); } else { _tokenToEntities[tokenString] = new List <EntityPosition> { position }; } } ++id; } }