Skip to content

Commit

Permalink
youTube embedded support; fixed list param. (and x and x); link card …
Browse files Browse the repository at this point in the history
…auto trigger;
  • Loading branch information
fquirin committed May 26, 2019
1 parent 185bd84 commit 9f6607b
Show file tree
Hide file tree
Showing 20 changed files with 436 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,11 @@ public NluResult interpret(NluInput input) {
//web search
if (NluTools.stringContains(text, "(websuche|websearch|web suche|"
+ "(durchsuche|suche|schau|finde|zeig)( mir|)( mal| bitte|)( bitte| mal|)( im| das) (web|internet))|"
+ "^google|^bing|^yahoo|^duck duck|^duck duck go|"
+ "^google|^bing|^yahoo|^duck duck|^duck duck go|^youtube|"
+ "^(bild(ern|er|)|rezept(en|e|)|video(s|)|movie(s|)|film(en|e|)|\\w*(-|)aktie(n|)|aktien(wert|kurs)|buecher(n|)|buch)|"
+ "(wie|wo) (ist|steht|stehen) (der|die) (aktienkurs|aktienwert|aktie(n|)|kurs|wert) (von|vom|der)|(wie|wo) (steht|stehen) .*aktie(n|)|"
+ "(durchsuche|suche|schau|finde|zeig)( | .* )(im (web|internet))|"
+ "(durchsuche|suche|schau|finde|zeig)( | .* )(mit|per|via|auf|ueber|mittels|bei) (google|bing|duck duck go|duck duck|yahoo)|"
+ "(durchsuche|suche|schau|finde|zeig)( | .* )(mit|per|via|auf|ueber|mittels|bei) (google|bing|duck duck go|duck duck|yahoo|youtube)|"
+ "(durchsuche|suche|schau|finde|zeig)( | .* )(bilder(n|)|rezepte(n|)|video(s|)|youtube|movies|filme(n|)|buecher(n|)|(-|)aktie(n|)|aktien(wert|kurs))")
//|| NLU_Tools.stringContains(text, "suche(n|)|finde(n|)|zeig(en|)")
//|| (NLU_Tools.stringContains(text, "suche(n|)|finde(n|)|zeig(en|)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ public NluResult interpret(NluInput input) {
//web search
//TODO: optimize exceptions
if (NluTools.stringContains(text, "websearch|web search|search the web|"
+ "^google|^bing|^yahoo|^duck duck|^duck duck go|"
+ "^google|^bing|^yahoo|^duck duck|^duck duck go|^youtube|"
+ "^(picture(s|)|recipe(s|)|video(s|)|movie(s|)|film(s|)|share(s|)|stock(s|)|book(s|))|"
+ "what is the (stock|share) (value|price)|"
+ "(search|find|show|look|searching|looking)( | .* )((on |)the (web|internet))|"
+ "(search|find|show|look|searching|looking)( | .* )(with|on|via|per|over|by) (google|bing|duck duck go|duck duck|yahoo)|"
+ "(search|find|show|look|searching|looking)( | .* )(with|on|via|per|over|by) (google|bing|duck duck go|duck duck|yahoo|youtube)|"
+ "(search|find|show|look|searching|looking)( | .* )(picture(s|)|recipe(s|)|video(s|)|youtube|book(s|)|share(s|)|stock(s|))")
//|| NLU_Tools.stringContains(text, "search|find|show|look for|searching for|looking for")
//|| (NLU_Tools.stringContains(text, "search|find|show")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ public static String getStringAndNextWords(String input, String start, int N){

/**
* Capitalize first letter of all words in a sentence.
* @param low - input with low case sentence
* @return sentence with every first letter of a word capital
* @param low - input with lower-case sentence
* @return sentence where ALL words begin with a capital letter
*/
public static String capitalizeAll(String low){
public static String capitalizeAllFirstLetters(String low){
StringBuffer res = new StringBuffer();
String[] strArr = low.split("\\s+");
for (String str : strArr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public String extract(String input) {
off = "(mach|schalte|dreh) .*\\b(aus)|"
+ "^\\w+\\b (aus$)|"
+ "schliessen|schliesse|deaktivieren|deaktiviere|"
+ "beenden|beende|ausschalten|aus schalten|ausmachen|aus machen|ausdrehen|aus drehen|stoppen|stoppe|stop|exit";
+ "beenden|beende|ausschalten|aus schalten|ausmachen|aus machen|ausdrehen|aus drehen|stop(pen|pe|p|)|exit";
pause = "pausieren|pause|anhalten|halte .*\\b(an)";
increase = "(mach|dreh) .*\\b(auf|hoch)|"
+ "(?<!(wie ))hoch|rauf|hoeher|groesser|erhoehen|aufdrehen|erhoehe|verstaerk(en|e)|heller|(?<!(ist ))schneller|(?<!(ist ))staerker|waermer|warm|lauter|laut";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,37 @@ public static enum Type {
//-------data-------
public static HashMap<String, String> local_de = new HashMap<>();
public static HashMap<String, String> local_en = new HashMap<>();
public static HashMap<String, String> buttons_de = new HashMap<>();
public static HashMap<String, String> buttons_en = new HashMap<>();
static {
local_de.put("<settings>", "die Einstellungen");
local_de.put("<volume>", "die Lautstärke");
local_de.put("<alwaysOn>", "der Always-On Modus");
local_de.put("<meshNode>", "die Mesh-Node");
local_de.put("<clexi>", "CLEXI");
local_de.put("<media>", "die Medienwiedergabe");
//Button names
buttons_de.put("<default>", "Funktion");
buttons_de.put("<volume>", "Lautstärke");
buttons_de.put("<alwaysOn>", "Always-On Modus");
buttons_de.put("<meshNode>", "Mesh-Node");
buttons_de.put("<clexi>", "CLEXI");
buttons_de.put("<media>", "Medienwiedergabe");

local_en.put("<settings>", "the settings");
local_en.put("<volume>", "the volume");
local_en.put("<alwaysOn>", "the Always-On mode");
local_en.put("<meshNode>", "the mesh-node");
local_en.put("<clexi>", "CLEXI");
local_en.put("<media>", "the media player");
//Button names
buttons_en.put("<default>", "Function");
buttons_en.put("<settings>", "Settings");
buttons_en.put("<volume>", "Volume");
buttons_en.put("<alwaysOn>", "Always-On Mode");
buttons_en.put("<meshNode>", "Mesh-Node");
buttons_en.put("<clexi>", "CLEXI");
buttons_en.put("<media>", "Media Player");
}
/**
* Translate generalized value.
Expand All @@ -76,6 +93,31 @@ public static String getLocal(String value, String language){
}
return localName;
}
/**
* Get localized name of the function for e.g. button names.
* If generalized value is unknown returns empty string, if it is null returns a default name.
* @param value - generalized value
* @param language - ISO language code
*/
public static String getLocalButtonName(String value, String language){
String localName = "";
String valueWithBrackets = value;
if (Is.nullOrEmpty(value)){
valueWithBrackets = "<default>";
}else if (!value.startsWith("<")){
valueWithBrackets = "<" + value + ">";
}
if (language.equals(LANGUAGES.DE)){
localName = buttons_de.get(valueWithBrackets);
}else if (language.equals(LANGUAGES.EN)){
localName = buttons_en.get(valueWithBrackets);
}
if (localName == null){
Debugger.println("ClientFunction.java - getLocalButtonName() has no '" + language + "' version for '" + value + "'", 3);
return "";
}
return localName;
}
//------------------

public User user;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public String extract(String input) {
//German
if (language.equals(LANGUAGES.DE)){
//old: (\\w+ |)(to do |\\w+(-| |)(\\w+-|))
genericListWithPrefix = "(\\w+ und |)(\\w+ |)((to do )|(\\w+-\\w+(-| ))|(\\w+(-| |)))(list(en|e|)|zettel|note(s|)|notiz(en|))(?! (\\w+ |)(auf|von|zu(r|)))";
genericListWithPrefix = "(\\w+ (und|oder) |)+(\\w+ |)((to do )|(\\w+-\\w+(-| ))|(\\w+(-| |)))(list(en|e|)|zettel|note(s|)|notiz(en|))(?! (\\w+ |)(auf|von|zu(r|)))";
extractedRawTerm = NluTools.stringFindFirst(input, genericListWithPrefix);
extractedRawTerm = extractedRawTerm.replaceFirst("\\b(auf |von |zu(r|) )\\b", "").trim();
extractedRawTerm = extractedRawTerm.replaceFirst(".*\\b(meine(n|r|m|)|die|der|den|eine|einer|einen|einem|mir)\\b", "").trim();
Expand All @@ -81,7 +81,7 @@ public String extract(String input) {

//English and other
}else{
genericListWithPrefix = "(\\w+ and |)(\\w+ |)((to do )|(\\w+-\\w+(-| ))|(\\w+(-| )))(list(s|)|note(s|))(?! (\\w+ |)(onto|on|to|at|from))";
genericListWithPrefix = "(\\w+ (and|or) |)+(\\w+ |)((to do )|(\\w+-\\w+(-| ))|(\\w+(-| )))(list(s|)|note(s|))(?! (\\w+ |)(onto|on|to|at|from))";
extractedRawTerm = NluTools.stringFindFirst(input, genericListWithPrefix);
extractedRawTerm = extractedRawTerm.replaceFirst("\\b(on |onto |to |at |from )\\b", "").trim();
extractedRawTerm = extractedRawTerm.replaceFirst(".*\\b(my|a|the)\\b", "").trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ public class MusicService implements ParameterHandler{
public static enum Service {
spotify,
spotify_link,
spotify_embedded,
apple_music,
apple_music_link,
apple_music_embedded,
amazon_music,
deezer,
soundcloud,
youtube,
youtube_embedded,
vlc_media_player
}

Expand All @@ -41,12 +44,15 @@ public static enum Service {
static {
musicServices.put("<spotify>", "Spotify");
musicServices.put("<spotify_link>", "Spotify");
musicServices.put("<spotify_embedded>", "Spotify");
musicServices.put("<apple_music>", "Apple Music");
musicServices.put("<apple_music_link>", "Apple Music");
musicServices.put("<apple_music_embedded>", "Apple Music");
musicServices.put("<amazon_music>", "Amazon Music");
musicServices.put("<deezer>", "Deezer");
musicServices.put("<soundcloud>", "SoundCloud");
musicServices.put("<youtube>", "YouTube");
musicServices.put("<youtube_embedded>", "YouTube");
musicServices.put("<vlc_media_player>", "VLC Media Player");
}
/**
Expand Down Expand Up @@ -118,7 +124,7 @@ public String extract(String input) {
soundCloud + "|" +
youTube + "|" +
vlc +
")( link|)"
")( link| embedded|)"
);
}else{
//OTHER LANGUAGES
Expand All @@ -131,7 +137,7 @@ public String extract(String input) {
soundCloud + "|" +
youTube + "|" +
vlc +
")( link|)"
")( link| embedded|)"
);
}

Expand All @@ -144,6 +150,14 @@ public String extract(String input) {
}else if (NluTools.stringContains(service, appleMusic)){
service = "<" + Service.apple_music_link.name() + ">";
}
}else if (NluTools.stringContains(service, "(embedded)$")){
if (NluTools.stringContains(service, spotify)){
service = "<" + Service.spotify_embedded.name() + ">";
}else if (NluTools.stringContains(service, appleMusic)){
service = "<" + Service.apple_music_embedded.name() + ">";
}else if (NluTools.stringContains(service, youTube)){
service = "<" + Service.youtube_embedded.name() + ">";
}
}else if (NluTools.stringContains(service, spotify)){
service = "<" + Service.spotify.name() + ">";
}else if (NluTools.stringContains(service, appleMusic)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,23 @@
public class SearchSection implements ParameterHandler{

//-----data-----

//TODO: section names should become an enumerator (e.g. used in WebsearchBasic)

public static HashMap<String, String> sections_de = new HashMap<>();
public static HashMap<String, String> sections_en = new HashMap<>();
static {
sections_de.put("<pictures>", "Bilder");
sections_de.put("<recipes>", "Rezepte");
sections_de.put("<music>", "Musik");
sections_de.put("<videos>", "Videos");
sections_de.put("<movies>", "Filme");
sections_de.put("<shares>", "Aktien");
sections_de.put("<books>", "Bücher");

sections_en.put("<pictures>", "pictures");
sections_en.put("<recipes>", "recipes");
sections_en.put("<music>", "music");
sections_en.put("<videos>", "videos");
sections_en.put("<movies>", "movies");
sections_en.put("<shares>", "shares");
Expand Down Expand Up @@ -83,11 +88,25 @@ public static String getSearchSection(String input, String language){
String type = "";
//German
if (language.matches(LANGUAGES.DE)){
type = NluTools.stringFindFirst(input, "(-|)(bild(ern|er|)|rezept(en|e|)|video(s|)|movie(s|)|film(en|e|)|aktie(n|)|aktien(kurs|wert)|buecher(n|)|buch)");
type = NluTools.stringFindFirst(input, "(-|)"
+ "(bild(ern|er|)|"
+ "rezept(en|e|)|"
+ "video(s|)|"
+ "movie(s|)|film(en|e|)|"
+ "musik|lied(ern|er|)|song(s|)|"
+ "aktie(n|)|aktien(kurs|wert)|"
+ "buecher(n|)|buch)");

//English and other
}else{
type = NluTools.stringFindFirst(input, "(-|)(picture(s|)|recipe(s|)|video(s|)|movie(s|)|film(s|)|share(s|)|stock(s|)|book(s|))");
type = NluTools.stringFindFirst(input, "(-|)"
+ "(picture(s|)|"
+ "recipe(s|)|"
+ "video(s|)|"
+ "movie(s|)|film(s|)|"
+ "music|song(s|)|"
+ "share(s|)|stock(s|)|"
+ "book(s|))");
}
//System.out.println("searchType: " + type); //debug
return type.replaceFirst("-", "");
Expand All @@ -105,6 +124,8 @@ public String extract(String input) {
return "<videos>";
}else if (NluTools.stringContains(valueFound, "movie(s|)|film(s|)|film(en|e|)")){
return "<movies>";
}else if (NluTools.stringContains(valueFound, "music|song(s|)|musik|lied(ern|er|)")){
return "<music>";
}else if (NluTools.stringContains(valueFound, "aktie(n|)|aktien(kurs|wert)|share(s|)|stock(s|)")){
return "<shares>";
}else if (NluTools.stringContains(valueFound, "buecher(n|)|buch|book(s|)")){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@

public class WebSearchEngine implements ParameterHandler{

//Common
public static final String GOOGLE = "google";
public static final String BING = "bing";
public static final String YAHOO = "yahoo";
public static final String DUCK_DUCK_GO = "duck duck go";
//Specialized
public static final String YOUTUBE = "youtube";

//-----data-----
/* may cause confusion
public static final String GOOGLE = "Google";
public static final String YAHOO = "Yahoo";
public static final String BING = "Bing";
public static final String DUCK_DUCK_GO = "DuckDuckGo"; */

public static final String names = "(google|bing|duck duck go|duck duck|duckduckgo|yahoo|youtube)";

//--------------

User user;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public String extract(String input) {
if (NluTools.stringContains(input, "^" + engine)){
search = input.replaceFirst("^" + engine + "( suche|)\\b", "").trim();

}else if (NluTools.stringContains(input, "((durch|)suche)( mit(tels|)| auf| ueber| bei| via| per| )" + engine + "( nach| fuer| auf)")){
search = input.replaceFirst(".*? (nach|fuer|auf)\\b", "").trim();

}else if (NluTools.stringContains(input, "(suche|finde|zeig|schau|suchen nach) .* (mit|per|via|auf|ueber|mittels|bei) " + engine + "$")){
search = input.replaceFirst(".*?\\b(suche|finde|zeig|schau|suchen nach)\\b", "").trim();
search = search.replaceFirst("(mit|per|via|auf|ueber|mittels|bei) " + engine + "$", "").trim();
Expand All @@ -56,7 +59,6 @@ public String extract(String input) {
//clean up
search = search.replaceFirst("^(mir)", "").trim();
search = search.replaceFirst("^(mal bitte|bitte mal|mal|bitte)", "").trim();
search = search.replaceFirst("^bei youtube( nach|)", "videos").trim();
search = search.replaceFirst("^(nach|.*\\b(suchen( (im|das) (web|internet) | )nach))\\b", "").trim();
//some adaptations
/*
Expand All @@ -69,6 +71,9 @@ public String extract(String input) {
if (NluTools.stringContains(input, "^" + engine)){
search = input.replaceFirst("^" + engine + "( search|)", "").trim();

}else if (NluTools.stringContains(input, "(search)( with| on| over| by| via| per| )" + engine + "( for| after)")){
search = input.replaceFirst(".*? (for|after)\\b", "").trim();

}else if (NluTools.stringContains(input, "(search|find|show|look|searching|looking) .* (with|on|via|per|over|by) " + engine + "$")){
search = input.replaceFirst(".*?\\b(search|find|show|look|searching|looking)", "").trim();
search = search.replaceFirst("(with|on|via|per|over|by) " + engine + "$", "").trim();
Expand All @@ -79,7 +84,6 @@ public String extract(String input) {
}
//clean up
search = search.replaceFirst("^(me)", "").trim();
search = search.replaceFirst("^(with|on|via|per|over|by) youtube( for|)", "videos").trim();
search = search.replaceFirst("^(for)", "").trim();
//some adaptations
/*
Expand Down Expand Up @@ -132,13 +136,29 @@ public String build(String input) {
if (input.matches("(?i)^(wie|wo) .* die .*aktie(n|)$")){
reduced = input.replaceFirst("(?i).* die (.*?)(-| |)aktie(n|)", "$1");
}else{
reduced = input.replaceFirst("(?i)^(bild(ern|er|)|rezept(en|e|)|video(s|)|movie(s|)|film(en|e|)|aktie(n|)|aktien(kurs|wert)|buecher(n|)|buch) (von|vom|ueber|mit|fuer|)|"
+ "(?i) (bild(ern|er|)|rezept(en|e|)|video(s|)|movie(s|)|film(en|e|)|(-|)aktie(n|)|buecher(n|)|buch)$|"
reduced = input.replaceFirst("(?i)^(bild(ern|er|)|rezept(en|e|)|"
+ "video(s|)|movie(s|)|film(en|e|)|"
+ "lied(ern|er|)|musik|song(s|)|"
+ "aktie(n|)|aktien(kurs|wert)|buecher(n|)|buch)"
+ " (von|vom|ueber|mit|fuer|)|"
+ "(?i) (bild(ern|er|)|rezept(en|e|)|"
+ "video(s|)|movie(s|)|film(en|e|)|"
+ "lied(ern|er|)|musik|song(s|)|"
+ "(-|)aktie(n|)|buecher(n|)|buch)"
+ "$|"
+ "(?i)^((wie|wo) (ist|steht|stehen) (der|die) (aktienkurs|aktienwert|aktie(n|)|kurs|wert) (von|vom|der|))", "").trim();
}
}else if (language.equals(LANGUAGES.EN)){
reduced = input.replaceFirst("(?i)^(picture(s|)|recipe(s|)|video(s|)|movie(s|)|film(s|)|share(s|)|stock(s|)|book(s|)) (of|with|by|for|)|"
+ "(?i) (picture(s|)|recipe(s|)|video(s|)|movie(s|)|film(s|)|share(s|)|stock(s|)|book(s|))$|"
reduced = input.replaceFirst("(?i)^(picture(s|)|recipe(s|)|"
+ "video(s|)|movie(s|)|film(s|)|"
+ "song(s|)|music|"
+ "share(s|)|stock(s|)|book(s|))"
+ " (of|with|by|for|)|"
+ "(?i) (picture(s|)|recipe(s|)|"
+ "video(s|)|movie(s|)|film(s|)|"
+ "song(s|)|music|"
+ "share(s|)|stock(s|)|book(s|))"
+ "$|"
+ "(?i)^(what is the (stock|share) (value|price) (of|))", "").trim();
}
//build default result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,21 +143,19 @@ public ServiceResult getResult(NluResult nluResult) {

Parameter controlFunP = nluResult.getRequiredParameter(PARAMETERS.CLIENT_FUN);
String controlFun = controlFunP.getValueAsString().replaceAll("^<|>$", "").trim();
String controlFunLocal = (String) controlFunP.getDataFieldOrDefault(InterviewData.VALUE_LOCAL);
if (Is.nullOrEmpty(controlFunLocal)){
controlFunLocal = "Control";
}else{
try{
controlFunLocal = NluTools.capitalizeAll(controlFunLocal.split("\\s")[1]);
}catch(Exception e){}
}

boolean isSettings = controlFun.equals(ClientFunction.Type.settings.name());
boolean isAlwaysOn = controlFun.equals(ClientFunction.Type.alwaysOn.name());
boolean isMeshNode = controlFun.equals(ClientFunction.Type.meshNode.name());
boolean isClexi = controlFun.equals(ClientFunction.Type.clexi.name());
boolean isMedia = controlFun.equals(ClientFunction.Type.media.name()); //NOTE: media and volume can exist simultaneously
boolean isVolume = controlFun.equals(ClientFunction.Type.volume.name()) || mediaControls.startsWith("volume_");

if (isVolume){
controlFun = ClientFunction.Type.volume.name();
}
String controlFunLocal = ClientFunction.getLocalButtonName(controlFun, nluResult.language);

Parameter dataP = nluResult.getOptionalParameter(PARAMETERS.DATA, "");
String data = dataP.getValueAsString();

Expand Down
Loading

0 comments on commit 9f6607b

Please sign in to comment.