Package com.tnsai.context.entity
Interface EntityResolver
public interface EntityResolver
Interface for resolving entities across multiple sources.
EntityResolver implementations are responsible for:
- Finding entities by ID or attributes across registered sources
- Merging entity data from multiple sources
- Detecting and handling duplicate entities
- Managing entity sources
Usage Example
EntityResolver resolver = new InMemoryEntityResolver();
// Register sources
resolver.registerSource(salesforceSource);
resolver.registerSource(slackSource);
// Resolve by ID
Optional<Entity> entity = resolver.resolve("customer-123");
// Resolve by attributes
EntityResolutionResult result = resolver.resolveByAttributes(Map.of(
"email", "john@example.com",
"company", "Acme Corp"
));
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordStatistics about the entity resolver. -
Method Summary
Modifier and TypeMethodDescriptionbooleanDeletes an entity.findPotentialDuplicates(Entity entity, double similarityThreshold) Finds potential duplicates for an entity.Gets a specific source by ID.Gets all registered sources.Gets statistics about the resolver.listBySource(String sourceId) Lists all entities from a specific source.listByType(EntityType type) Lists all entities of a specific type.mergeEntities(List<Entity> candidates, ConflictResolution strategy) Merges multiple entities that represent the same real-world entity.voidregisterSource(EntitySource source) Registers a new entity source.Resolves an entity by its identifier.resolveByAttributes(Map<String, Object> attributes) Resolves an entity by matching attributes.default EntityResolutionResultresolveByAttributes(Map<String, Object> attributes, EntityType type) Resolves an entity by matching attributes with type constraint.searchByAttribute(String attributeName, Object attributeValue) Searches entities by attribute value.voidStores or updates an entity.voidStores an entity from a specific source.booleanunregisterSource(String sourceId) Unregisters an entity source.
-
Method Details
-
resolve
Resolves an entity by its identifier.- Parameters:
entityId- entity identifier- Returns:
- Optional containing the resolved entity if found
-
resolveByAttributes
Resolves an entity by matching attributes.This method searches for entities that match the provided attributes and returns a resolution result with confidence score.
- Parameters:
attributes- map of attribute name to expected value- Returns:
- resolution result with entity, confidence, and alternatives
-
resolveByAttributes
Resolves an entity by matching attributes with type constraint.- Parameters:
attributes- map of attribute name to expected valuetype- expected entity type- Returns:
- resolution result
-
registerSource
Registers a new entity source.- Parameters:
source- the source to register
-
unregisterSource
Unregisters an entity source.- Parameters:
sourceId- source identifier to unregister- Returns:
- true if source was removed
-
getSources
List<EntitySource> getSources()Gets all registered sources.- Returns:
- list of registered sources
-
getSource
Gets a specific source by ID.- Parameters:
sourceId- source identifier- Returns:
- Optional containing the source if found
-
store
Stores or updates an entity.- Parameters:
entity- entity to store
-
store
Stores an entity from a specific source.- Parameters:
entity- entity to storesourceId- source identifier
-
delete
Deletes an entity.- Parameters:
entityId- entity identifier- Returns:
- true if entity was deleted
-
mergeEntities
Merges multiple entities that represent the same real-world entity.- Parameters:
candidates- entities to mergestrategy- conflict resolution strategy- Returns:
- merged entity
-
findPotentialDuplicates
Finds potential duplicates for an entity.- Parameters:
entity- entity to find duplicates forsimilarityThreshold- minimum similarity score (0.0-1.0)- Returns:
- list of potential duplicate entities
-
listByType
Lists all entities of a specific type.- Parameters:
type- entity type- Returns:
- list of entities
-
listBySource
Lists all entities from a specific source.- Parameters:
sourceId- source identifier- Returns:
- list of entities
-
searchByAttribute
Searches entities by attribute value.- Parameters:
attributeName- attribute to searchattributeValue- value to match- Returns:
- list of matching entities
-
getStatistics
EntityResolver.ResolverStatistics getStatistics()Gets statistics about the resolver.- Returns:
- resolver statistics
-