Entity Classifier is a .NET library for entity recognition, relationship discovery, and text transformation. It allows you to classify sentences, extract entities and their relationships, and replace entities with entity labels.
Entity Classifier is a powerful tool for natural language processing tasks that involve entity recognition and relationship extraction. It provides a flexible and rule-based approach to discover entities, detect relationships between them, and transform text by replacing entities with labels.
- Entity recognition: Detects entities from a list of predefined entity types.
- Relationship discovery: Finds relationships between entities based on user-defined patterns/rules.
- Text transformation: Replaces detected entities with their corresponding entity labels.
- Supports multiple entity types: Handles various types of entities and their respective entity lists.
To use Entity Classifier in your .NET project, follow these steps:
- Install the EntityClassifier NuGet package (See Installation section).
- Create an instance of the
EntityClassifier
class by providing entity lists, entity types, and relationship patterns. - Call the
Classify
method to classify sentences and extract entities with their relationships. - Use the extracted information as needed in your application.
To install the EntityClassifier NuGet package, run the following command in the Package Manager Console:
Install-Package EntityClassifier
using Recognition.Classifer;
// Define entity lists and relationship patterns
var entityList = new List<string> { "car", "driver", "manufacturer" };
var entityType = "Vehicle";
var relations = new List<string> { "drives", "is manufactured by" };
// Create an instance of the EntityClassifier
var classifier = new EntityClassifier(entityList, entityType, relations);
// Classify a sample sentence and extract entities
var sentence = "The driver drives a car that is manufactured by a company.";
var discoveredEntities = classifier.Classify(sentence);
// Use the extracted entities and relationships in your application
foreach (var entity in discoveredEntities)
{
Console.WriteLine($"Entity: {entity.DiscoveredEntitys}, Type: {entity.EntityType}");
foreach (var relationship in entity.Relationships)
{
Console.WriteLine($"Relationship: {relationship.SourceEntity} {relationship.RelationshipType} {relationship.TargetEntity}");
}
}
Imports Recognition.Classifer
Module Program
Sub Main()
' Define entity lists and relationship patterns
Dim entityList As New List(Of String) From {"car", "driver", "manufacturer"}
Dim entityType As String = "Vehicle"
Dim relations As New List(Of String) From {"drives", "is manufactured by"}
' Create an instance of the EntityClassifier
Dim classifier As New EntityClassifier(entityList, entityType, relations)
' Classify a sample sentence and extract entities
Dim sentence As String = "The driver drives a car that is manufactured by a company."
Dim discoveredEntities As List(Of DiscoveredEntity) = classifier.Classify(sentence)
' Use the extracted entities and relationships in your application
For Each entity As DiscoveredEntity In discoveredEntities
Console.WriteLine($"Entity: {entity.DiscoveredEntitys}, Type: {entity.EntityType}")
For Each relationship As DiscoveredEntity.EntityRelationship In entity.Relationships
Console.WriteLine($"Relationship: {relationship.SourceEntity} {relationship.RelationshipType} {relationship.TargetEntity}")
Next
Next
End Sub
End Module
For more examples and detailed usage, refer to the documentation.
Contributions are welcome! If you find any issues, have feature requests, or want to improve the library, please feel free to open an issue or submit a pull request.
This project is licensed under the MIT License.