public boolean matchWord(String pattern, String str){
    //unify the pattern and string
    pattern = unifyString(pattern);
    str = unifyString(str);
    
    if(str.equals("NULL")) return false;
    if(pattern.equals("NULL")) return true;
    
    //splits the pattern into an array of words.
    String[] pattern_words = pattern.split(" ");
    //in case the pattern string as a single word.
    String pattern_word = pattern.replaceAll(" ","");
    
    //spilting the string into array of words.
    String[] str_words = str.split(" ");
    int index = 0;
    
    //Scaning the string word by word, check if the words pattern appears.
    for(String str_word:str_words){
      if(index>=pattern_words.length||str_word.equals(pattern_word)) return true;
      if(str_word.equals(pattern_words[index])) {index++;}
      else index = 0;
    }
    return false;
  }