<commit_before>[![Build Status](https://travis-ci.org/Fewlaps/mention-detector.svg?branch=master)](https://travis-ci.org/Fewlaps/mention-detector)
[![Coverage Status](https://coveralls.io/repos/github/Fewlaps/mention-detector/badge.svg?branch=master)](https://coveralls.io/github/Fewlaps/mention-detector?branch=master)

# mention-detector
Detect **@mentions** and **@sequence @of @mentions** with this fully tested library.

```java
String text = "Hello! This is a great introduction to @MentionDetector!";
//With MentionDetector you can... well. You can detect mentions!
MentionDetector detector = new MentionDetector(text);

detector.hasMentions(); //Returns if the text has any mention
detector.getMentions(); //Returns a list with the mention to @MentionDetector

Mention mention = detector.getMentions().get(0); //If we get a mention, we could ask:
mention.start(); //Where the mention starts? At 39!
mention.end(); //Where the mention ends? At 55!
mention.username(); //What's the mentioned username? @MentionDetector
mention.usernameWithoutAtSymbol(); //And what's the actual username? MentionDetector

//In addition, you can also get the mention sequences.
detector.getSequences();

//A sequence is a list of mentions only separated by spaces. For example:
String fourMentions = "Hello! I love @trains @bananas @pizza and @sushi";
//In this case, "@trains @bananas @pizza" is one sequence, and "@sushi" is another one.

Sequence sequence = new MentionDetector(fourMentions).getSequences().get(0);
sequence.start(); //Where the sequence starts? At 14!<commit_msg>Explain what's the problem that MentionDetector fixes<commit_after>[![Build Status](https://travis-ci.org/Fewlaps/mention-detector.svg?branch=master)](https://travis-ci.org/Fewlaps/mention-detector)
[![Coverage Status](https://coveralls.io/repos/github/Fewlaps/mention-detector/badge.svg?branch=master)](https://coveralls.io/github/Fewlaps/mention-detector?branch=master)

# mention-detector
Detect **@mentions** and **@sequence @of @mentions** with this fully tested library.

[QuitNow!](https://quitnow.app), our main application to help people quit smoking, has an inapp chat to create a beautiful community of ex-smokers. They like to mention each other in the chat, and sometimes, someone mentions lots of people. Everytime the app finds a mention, it creates a span to bold the mention. The bad news are that, sometimes, a message could include more than 10 or 20 mentions, and that's a lot of spans. In that case, the best thing to do is to join those 20 spans in only one, which improves the performance dramatically.

So, we needed a fast way to look for mentions and sequences of mentions. And here is it.

Time to introduce the library!

```java
String text = "Hello! This is a great introduction to @MentionDetector!";
//With MentionDetector you can... well. You can detect mentions!
MentionDetector detector = new MentionDetector(text);

detector.hasMentions(); //Returns if the text has any mention
detector.getMentions(); //Returns a list with the mention to @MentionDetector

Mention mention = detector.getMentions().get(0); //If we get a mention, we could ask:
mention.start(); //Where the mention starts? At 39!
mention.end(); //Where the mention ends? At 55!
mention.username(); //What's the mentioned username? @MentionDetector
mention.usernameWithoutAtSymbol(); //And what's the actual username? MentionDetector

//In addition, you can also get the mention sequences.
detector.getSequences();

//A sequence is a list of mentions only separated by spaces. For example:
String fourMentions = "Hello! I love @trains @bananas @pizza and @sushi";
//In this case, "@trains @bananas @pizza" is one sequence, and "@sushi" is another one.

Sequence sequence = new MentionDetector(fourMentions).getSequences().get(0);
sequence.start(); //Where the sequence starts? At 14!
{'fraction_non_alphanumeric': 0.1165325720218012, 'fraction_numerical': 0.0057098364910459385, 'mean_word_length': 5.196141479099678, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 9, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1105619', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1118, 'n_words': 428}