Skip to content

Reetan Singh#22

Open
reetansingh wants to merge 9 commits intogrc-cohort-21:mainfrom
reetansingh:main
Open

Reetan Singh#22
reetansingh wants to merge 9 commits intogrc-cohort-21:mainfrom
reetansingh:main

Conversation

@reetansingh
Copy link

No description provided.

Copy link

@auberonedu auberonedu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you didn't quite finish, but great job on the tokenizer!

Comment on lines +19 to +29
@Test
void testTokenizeWithManySpaces() {
LowercaseSentenceTokenizer tokenizer = new LowercaseSentenceTokenizer();
String input = "hello hi hi hi hello hello";
Scanner scanner = new Scanner(input);

List<String> tokens = tokenizer.tokenize(scanner);
List<String> expected = List.of("hello", "hi", "hi", "hi", "hello", "hello");

assertEquals(expected, tokens, "Tokens did not match ");
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice test!

Comment on lines +33 to +48
public List<String> tokenize(Scanner scanner) {
List<String> tokens = new ArrayList<>();

while (scanner.hasNext()) {
String token = scanner.next().toLowerCase();
if (token.endsWith(".")) {
if (token.length() == 1) {
tokens.add(".");

}else {
String wordWithoutPeriod = token.substring(0, token.length() - 1);
tokens.add(wordWithoutPeriod);
tokens.add(".");
}
} else {
tokens.add(token);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great logic!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants