A Kotlin library for extracting mentions from a text based on specified patterns. It provides flexible configuration options for handling mentions in a text.
To use the MentionExtractor library:
-
Create a
MentionPatterninstance and configure it according to your requirements. -
Use the
MentionExtractor.Builderto construct an instance ofMentionExtractor, providing the configuredMentionPatternand any additional settings such as the maximum number of mentions to handle. -
Use the methods provided by
MentionExtractorto extract mentions from text, check if a text contains a mention, or count the number of mentions in a text.
Here's an example of how to use MentionExtractor:
// Configure MentionPattern
val mentionPattern = MentionPattern().withSpecialChars()
// Create MentionExtractor instance
val extractor = MentionExtractor.Builder()
.pattern(mentionPattern)
.maxMentions(5)
.build()
// Extract mentions from text
val text = "Hey @user1, did you see @user2's message?"
val mentions = extractor.fromString(text)
// Check if text contains a mention
val containsMention = extractor.containsMention(text)
// Count the number of mentions in text
val mentionCount = extractor.countMentions(text)The recommended way to get MentionExtractor is to use a build manager, like Gradle or Maven.
Maven-central Dependency
Gradle
implementation group: 'io.github.brenoepics', name: 'MentionExtractor', version: '1.0.0'Maven
<dependency>
<groupId>io.github.brenoepics</groupId>
<artifactId>MentionExtractor</artifactId>
<version>1.0.0</version>
</dependency>Sbt
libraryDependencies += "io.github.brenoepics" % "MentionExtractor" % "1.0.0"We use JUnit 5 for testing the MentionExtractor. To run the tests:
-
Ensure you have Maven installed on your system.
-
Navigate to the root directory of the project containing the
pom.xmlfile. -
Run the following Maven command:
mvn test
This will execute the JUnit tests defined in the test package and provide the test results.
This project is licensed under the Apache 2.0 License—see the LICENSE file for details.