summaryrefslogtreecommitdiff
path: root/adservices/tests/unittest/service-core/src/com/android/adservices/service/topics/classifier/PreprocessorTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'adservices/tests/unittest/service-core/src/com/android/adservices/service/topics/classifier/PreprocessorTest.java')
-rw-r--r--adservices/tests/unittest/service-core/src/com/android/adservices/service/topics/classifier/PreprocessorTest.java115
1 files changed, 86 insertions, 29 deletions
diff --git a/adservices/tests/unittest/service-core/src/com/android/adservices/service/topics/classifier/PreprocessorTest.java b/adservices/tests/unittest/service-core/src/com/android/adservices/service/topics/classifier/PreprocessorTest.java
index 25fb0e5197..82e047c603 100644
--- a/adservices/tests/unittest/service-core/src/com/android/adservices/service/topics/classifier/PreprocessorTest.java
+++ b/adservices/tests/unittest/service-core/src/com/android/adservices/service/topics/classifier/PreprocessorTest.java
@@ -42,21 +42,24 @@ public final class PreprocessorTest {
@Test
public void removeStopWords_removesLegitStopWords() {
- assertThat(mPreprocessor.removeStopWords("sample it they them input string is are"))
- .isEqualTo("sample input string");
- assertThat(mPreprocessor.removeStopWords("do does sample it they them input string is are"))
- .isEqualTo("sample input string");
+ assertThat(mPreprocessor.removeStopWords(
+ "sample it they them input string is CustomStopWord1"))
+ .isEqualTo("sample it they them input string is");
+ assertThat(mPreprocessor.removeStopWords(
+ "do CustomStopWord1 sample it they them input string"))
+ .isEqualTo("do sample it they them input string");
}
@Test
public void removeStopWords_checksFinalTrimming() {
- assertThat(mPreprocessor.removeStopWords(" do does sample it they them input is are "))
- .isEqualTo("sample input");
+ assertThat(mPreprocessor.removeStopWords(
+ " do does sample it they them input is CustomStopWord1 "))
+ .isEqualTo("do does sample it they them input is");
}
@Test
public void removeStopWords_justStopWords() {
- assertThat(mPreprocessor.removeStopWords("can will now")).isEqualTo("");
+ assertThat(mPreprocessor.removeStopWords("CustomStopWord1")).isEqualTo("");
}
@Test
@@ -72,43 +75,58 @@ public final class PreprocessorTest {
@Test
public void testPreprocessing_forHttpsURLRemoval() {
assertThat(preprocessAppDescription("The website is https://youtube.com"))
- .isEqualTo("the website is ");
+ .isEqualTo("the website is");
assertThat(preprocessAppDescription("https://youtube.com is the website"))
- .isEqualTo(" is the website");
+ .isEqualTo("is the website");
assertThat(preprocessAppDescription("https://www.tensorflow.org/lite/tutorials")).isEmpty();
}
@Test
public void testPreprocessing_forHttpURLRemoval() {
assertThat(preprocessAppDescription("The website is http://google.com"))
- .isEqualTo("the website is ");
+ .isEqualTo("the website is");
assertThat(preprocessAppDescription("http://google.com is the website"))
- .isEqualTo(" is the website");
+ .isEqualTo("is the website");
assertThat(preprocessAppDescription("http://google.com")).isEmpty();
}
@Test
+ public void testPreprocessing_forNotHttpURLRemoval() {
+ assertThat(preprocessAppDescription("The website is www.youtube.com"))
+ .isEqualTo("the website is");
+ assertThat(preprocessAppDescription("www.youtube.com is the website"))
+ .isEqualTo("is the website");
+ assertThat(preprocessAppDescription("www.tensorflow.org/lite/tutorials")).isEmpty();
+ }
+
+ @Test
public void testPreprocessing_forMentionsRemoval() {
- assertThat(preprocessAppDescription("Code author: @xyz123")).isEqualTo("code author ");
+ assertThat(preprocessAppDescription("Code author: @xyz123")).isEqualTo("code author:");
assertThat(preprocessAppDescription("@xyz123 Code author: @xyz123"))
- .isEqualTo(" code author ");
+ .isEqualTo("code author:");
assertThat(preprocessAppDescription("Code @xyz123 author: @xyz123"))
- .isEqualTo("code author ");
+ .isEqualTo("code author:");
assertThat(preprocessAppDescription("@xyz123")).isEmpty();
}
@Test
- public void testPreprocessing_forUpperCaseToLowerCase() {
- String inputDescription = "SOCIAL MEDIA APP";
- String result = preprocessAppDescription(inputDescription);
- assertThat(result).isEqualTo("social media app");
+ public void testPreprocessing_forHtmlTagsRemoval() {
+ assertThat(preprocessAppDescription("<title>Google is a search engine.</title>"))
+ .isEqualTo("google is a search engine.");
+ assertThat(preprocessAppDescription("<!DOCTYPE html>"
+ + "<html lang=\"en\">"
+ + "<head>"
+ + "<title>Hello World!</title>"
+ + "</head>"))
+ .isEqualTo("hello world!");
+ assertThat(preprocessAppDescription("<p></p>")).isEmpty();
}
@Test
- public void testPreprocessing_forPunctuationRemoval() {
- String inputDescription = "This. is a test, to check! punctuation removal?!@#$%^&*()_+";
+ public void testPreprocessing_forUpperCaseToLowerCase() {
+ String inputDescription = "SOCIAL MEDIA APP";
String result = preprocessAppDescription(inputDescription);
- assertThat(result).isEqualTo("this is a test to check punctuation removal");
+ assertThat(result).isEqualTo("social media app");
}
@Test
@@ -119,17 +137,17 @@ public final class PreprocessorTest {
}
@Test
- public void testPreprocessing_forNumberRemoval() {
- String inputDescription = "Remove 11 numbers 0.";
+ public void testPreprocessing_forTabRemoval() {
+ String inputDescription = "check\tmultiple\t\ttabs.";
String result = preprocessAppDescription(inputDescription);
- assertThat(result).isEqualTo("remove numbers ");
+ assertThat(result).isEqualTo("check multiple tabs.");
}
@Test
public void testPreprocessing_forRemovingMultipleSpaces() {
String inputDescription = "This sentence \n has multiple spaces.";
String result = preprocessAppDescription(inputDescription);
- assertThat(result).isEqualTo("this sentence has multiple spaces");
+ assertThat(result).isEqualTo("this sentence has multiple spaces.");
}
@Test
@@ -139,16 +157,55 @@ public final class PreprocessorTest {
+ " has multiple spaces, 234 4 (). \n"
+ " @Mention &*\n"
+ " BLOCK LETTERS\n"
- + " http://sampleURL.com as well!";
+ + " http://sampleURL.com as well!"
+ + " <p>Hello world!</p>";
String result = preprocessAppDescription(inputDescription);
- assertThat(result).isEqualTo("this description has multiple spaces block letters as well");
+ assertThat(result).isEqualTo("this description has multiple spaces, 234 4 (). &* "
+ + "block letters as well! hello world!");
+ }
+
+ @Test
+ public void testPreprocessing_forRealAppDescription() {
+ String googleTranslateDescription =
+ "• Text translation: Translate between 108 languages by typing\n"
+ + "• Tap to Translate: Copy text in any app and tap the Google Translate "
+ + "icon to translate (all languages)\n"
+ + "• Offline: Translate with no internet connection (59 languages)\n"
+ + "• Instant camera translation: Translate text in images instantly by "
+ + "just pointing your camera (94 languages)\n"
+ + "• Photos: Take or import photos for higher quality translations (90 "
+ + "languages)\n"
+ + "• Conversations: Translate bilingual conversations on the fly (70 "
+ + "languages)";
+ String googleTranslateResult = preprocessAppDescription(googleTranslateDescription);
+ assertThat(googleTranslateResult).isEqualTo(
+ "• text translation: translate between 108 languages by typing "
+ + "• tap to translate: copy text in any app and tap the google translate "
+ + "icon to translate (all languages) • offline: translate with no internet "
+ + "connection (59 languages) • instant camera translation: translate text "
+ + "in images instantly by just pointing your camera (94 languages) "
+ + "• photos: take or import photos for higher quality translations "
+ + "(90 languages) • conversations: translate bilingual conversations "
+ + "on the fly (70 languages)");
+
+ String googleDescription =
+ "• Use voice commands while navigating – even when your device has no connection."
+ + " Try saying \"cancel my navigation\" \"what's my ETA?\" or \"what's my"
+ + " next turn?\"\n"
+ + "• It's easier to access privacy settings from the homescreen. Just tap"
+ + " your Google Account profile picture.";
+ String googleResult = preprocessAppDescription(googleDescription);
+ assertThat(googleResult).isEqualTo("• use voice commands while navigating – even when "
+ + "your device has no connection. try saying \"cancel my navigation\" \"what's my"
+ + " eta?\" or \"what's my next turn?\" • it's easier to access privacy settings "
+ + "from the homescreen. just tap your google account profile picture.");
}
@Test
public void testPreprocessing_forEmptyDescription() {
assertThat(preprocessAppDescription("")).isEmpty();
- assertThat(preprocessAppDescription(" ")).isEqualTo(" ");
- assertThat(preprocessAppDescription(" \n \n \n")).isEqualTo(" ");
+ assertThat(preprocessAppDescription(" ")).isEmpty();
+ assertThat(preprocessAppDescription(" \n \n \n")).isEmpty();
}
@Test