Skip to content

Commit

Permalink
Fix for empty tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
rabidgremlin committed Jun 26, 2017
1 parent e4a5776 commit 166b4be
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 9 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,10 @@ repositories {
}
dependencies {
compile 'com.rabidgremlin:mutters-ink-bot:4.0.0'
compile 'com.rabidgremlin:mutters-opennlp-intent:4.0.0'
compile 'com.rabidgremlin:mutters-opennlp-ner:4.0.0'
compile 'com.rabidgremlin:mutters-slots:4.0.0'
compile 'com.rabidgremlin:mutters-ink-bot:4.0.1'
compile 'com.rabidgremlin:mutters-opennlp-intent:4.0.1'
compile 'com.rabidgremlin:mutters-opennlp-ner:4.0.1'
compile 'com.rabidgremlin:mutters-slots:4.0.1'
}
```

Expand All @@ -244,10 +244,10 @@ repositories {
}
dependencies {
compile 'com.rabidgremlin:mutters-ink-bot:4.0.0-SNAPSHOT'
compile 'com.rabidgremlin:mutters-opennlp-intent:4.0.0-SNAPSHOT'
compile 'com.rabidgremlin:mutters-opennlp-ner:4.0.0-SNAPSHOT'
compile 'com.rabidgremlin:mutters-slots:4.0.0-SNAPSHOT'
compile 'com.rabidgremlin:mutters-ink-bot:4.0.1-SNAPSHOT'
compile 'com.rabidgremlin:mutters-opennlp-intent:4.0.1-SNAPSHOT'
compile 'com.rabidgremlin:mutters-opennlp-ner:4.0.1-SNAPSHOT'
compile 'com.rabidgremlin:mutters-slots:4.0.1-SNAPSHOT'
}
```

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=4.0.0-SNAPSHOT
version=4.0.1

# These are place holder values. Real values should be set in user's home gradle.properties
# and are only needed when signing and uploading to central maven repo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ public IntentMatch match(String utterance, Context context, Set<String> expected

String[] cleanedUtterance = tokenizer.tokenize(utterance);

// do we have some tokens after cleaning ?
if (cleanedUtterance.length == 0)
{
return null;
}

for (TemplatedIntent intent : intents)
{
TemplatedUtteranceMatch utteranceMatch = intent.matches(cleanedUtterance, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.rabidgremlin.mutters.core.IntentMatch;
import com.rabidgremlin.mutters.core.SlotMatch;
import com.rabidgremlin.mutters.slots.CustomSlot;
import com.rabidgremlin.mutters.slots.LiteralSlot;
import com.rabidgremlin.mutters.slots.NumberSlot;
import com.rabidgremlin.mutters.templated.SimpleTokenizer;
import com.rabidgremlin.mutters.templated.TemplatedIntent;
Expand Down Expand Up @@ -86,4 +87,35 @@ public void testBrokenAirportMatch()
assertThat(intentMatch, is(nullValue()));
}


@Test
public void testHandlingOfEmptyOrTokenizedOutInputs()
{
TemplatedIntentMatcher matcher = new TemplatedIntentMatcher(tokenizer);
TemplatedIntent intent = matcher.addIntent("AcceptAnything");

intent.addUtterance("{AnyThing}");

LiteralSlot slot = new LiteralSlot("AnyThing");
intent.addSlot(slot);

IntentMatch intentMatch = matcher.match("Bob", new Context(), null, null);
assertThat(intentMatch, is(notNullValue()));

intentMatch = matcher.match("", new Context(), null, null);
assertThat(intentMatch, is(nullValue()));

intentMatch = matcher.match(" ", new Context(), null, null);
assertThat(intentMatch, is(nullValue()));

intentMatch = matcher.match("?", new Context(), null, null);
assertThat(intentMatch, is(nullValue()));

intentMatch = matcher.match("...", new Context(), null, null);
assertThat(intentMatch, is(nullValue()));

intentMatch = matcher.match(" ?", new Context(), null, null);
assertThat(intentMatch, is(nullValue()));
}

}

0 comments on commit 166b4be

Please sign in to comment.