public void AddEntity(EntityName entityName, EntityForm canonicalForm, EntityForm[] otherForms) { foreach (var entitySpecification in _entitySpecifications) { entitySpecification.AssertDoesNotConflictWith(entityName, canonicalForm, otherForms); } _entitySpecifications.Add(new EntitySpecification(entityName, canonicalForm, otherForms)); }
public void AssertDoesNotConflictWith(EntityName entityName, EntityForm value, EntityForm[] otherForms) { var externalPhrases = new[] { value }.Concat(otherForms); ; foreach (var internalPhrase in _allForms) { if (externalPhrases.Contains(internalPhrase)) { throw new ConflictingEntityException(entityName, _entityName, internalPhrase); } } }
public EntitySpecification(EntityName entityName, EntityForm canonicalForm, EntityForm[] synonyms) { _entityName = entityName; _canonicalForm = canonicalForm; _allForms = new[] { canonicalForm }.Concat(synonyms); }
public ConflictingEntityException(EntityName attemptedEntityName, EntityName existingEntityName, EntityForm conflictingForm) : base($"The phrase '{conflictingForm}' cannot be added for the entity '{attemptedEntityName}', " + $"because it is already present for entity '{existingEntityName}', which would be matched earlier") { }
public RecognizedEntity(EntityName entityName, EntityForm recognizedValue, EntityForm canonicalForm) { Entity = entityName; RecognizedValue = recognizedValue; CanonicalForm = canonicalForm; }
public static RecognizedEntity ByCanonicalForm(EntityName entityName, EntityForm canonicalForm) { return(new RecognizedEntity(entityName, canonicalForm, canonicalForm)); }
public static RecognizedEntity Value(EntityName name, EntityForm recognizedValue, EntityForm canonicalForm) { return(new RecognizedEntity(name, recognizedValue, canonicalForm)); }
public void AddEntity(EntityName entityName, EntityForm canonicalForm) { AddEntity(entityName, canonicalForm, new EntityForm[] { }); }
public void AddEntity(string entityName, string value) { _recognitionModel.AddEntity(EntityName.Value(entityName), EntityForm.Value(value)); }
public void AddEntity(string entityName, string value, string[] synonyms) { _recognitionModel.AddEntity(EntityName.Value(entityName), EntityForm.Value(value), synonyms.Select(EntityForm.Value).ToArray()); }