{"action":"created","issue":{"url":"https://api.github.com/repos/Program-O/Program-O/issues/432","repository_url":"https://api.github.com/repos/Program-O/Program-O","labels_url":"https://api.github.com/repos/Program-O/Program-O/issues/432/labels{/name}","comments_url":"https://api.github.com/repos/Program-O/Program-O/issues/432/comments","events_url":"https://api.github.com/repos/Program-O/Program-O/issues/432/events","html_url":"https://github.com/Program-O/Program-O/issues/432","id":343736609,"node_id":"MDU6SXNzdWUzNDM3MzY2MDk=","number":432,"title":"Bot does not find the learned from the table \"aiml_userdefined\"","user":{"login":"Josef-Meier","id":40842710,"node_id":"MDQ6VXNlcjQwODQyNzEw","avatar_url":"https://avatars1.githubusercontent.com/u/40842710?v=4","gravatar_id":"","url":"https://api.github.com/users/Josef-Meier","html_url":"https://github.com/Josef-Meier","followers_url":"https://api.github.com/users/Josef-Meier/followers","following_url":"https://api.github.com/users/Josef-Meier/following{/other_user}","gists_url":"https://api.github.com/users/Josef-Meier/gists{/gist_id}","starred_url":"https://api.github.com/users/Josef-Meier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Josef-Meier/subscriptions","organizations_url":"https://api.github.com/users/Josef-Meier/orgs","repos_url":"https://api.github.com/users/Josef-Meier/repos","events_url":"https://api.github.com/users/Josef-Meier/events{/privacy}","received_events_url":"https://api.github.com/users/Josef-Meier/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":26,"created_at":"2018-07-23T18:04:29Z","updated_at":"2018-09-09T23:17:43Z","closed_at":null,"author_association":"NONE","body":"On Version: 2.6.10\r\n\r\nbecause in the php-file \"parse_aiml_as_XML.php\" with the function \"parse_learn_tag\"\r\nthe \"user_id\" is stored in the table \"aiml_userdefined\" and in the php-file \"find_aiml.php\" in field \"user_id\" is effectively selected with the \"convo_id\" (because line 828).\r\nFollowing could be first help:\r\nchange at line 828 in ../admin/\"find_aiml.php\":\r\n    //$c_id = $convoArr['conversation']['convo_id']; //$convoArr['conversation'][''];user_id\r\n    $c_id = $convoArr['conversation']['user_id'];\r\n\r\nBut I have found the following definition for AIML tag \"learn\" at https://www.botlibre.com/forum-post?id=1156738:\r\n_\"...The new \"learn\" and \"learnf\" tags allow the bot to learn new response. The difference between the two is that for learn the new response is only remembered for the conversation, and for learnf the new response will be remembered persistently. However, in Bot Libre everything is always persistent, so both tag will learn persistently. ...\"_\r\n\r\nI am not sure how this is intended in AIML, but it is more practical for me if the learned can be queried at any time to all users.\r\nBut then you would probably have to change the SQL query in the file \"find_aiml.php\". \r\nFor example:\r\n```\r\n    $sql = <<<endSQL\r\nSELECT `id`, `bot_id`, `pattern`, `thatpattern`, `template` FROM `$dbn`.`aiml_userdefined` WHERE\r\n    `bot_id` = :bot_id\r\n    AND ([pattern_like][thatpattern_like])\r\n   ORDER BY `id` ASC, `pattern` ASC, `thatpattern` ASC;\r\nendSQL;\r\n```\r\n\r\n**here are the examples for problem:**\r\nAIML-Example for testing learn tag :\r\n```\r\n<aiml>\r\n   <category>\r\n    <pattern>LEARN QUESTION * ANSWER *</pattern>\r\n    <template>\r\n       <think>\r\n          <learn>\r\n             <category>\r\n                <pattern><eval><star/></eval></pattern>\r\n                <template><eval><star index=\"2\"/></eval></template>\r\n             </category>\r\n           </learn>\r\n       </think>\r\n       Okay, I will answer \"<star index=\"2\"/>\" to \"<star/>\" next time\r\n    </template>\r\n  </category>\r\n</aiml>\r\n```\r\n**conversation:**\r\n1) User Say: _Learn question WHAT IS BLUE answer BLUE IS A COLOR_\r\n    Bot Response: _Okay, I will answer \" BLUE IS A COLOR \" to \" WHAT IS BLUE \" next time_\r\n\r\n2) User Say: _What is Blue?_\r\n    Bot Response:  ( an output from RANDOM PICKUP LINE )\r\n       after listed above change i get what I expected:\r\n    Bot Response:  _BLUE IS A COLOR_\r\n\r\n**relevant section of sourcecode in file \"parse_aiml_as_XML.php\":**\r\n```\r\nfunction parse_learn_tag(&$convoArr, $element, $parentName, $level)\r\n{\r\n    runDebug(__FILE__, __FUNCTION__, __LINE__, 'Parsing a LEARN tag.', 2);\r\n    $bot_id = $convoArr['conversation']['bot_id'];\r\n    $user_id = $convoArr['conversation']['user_id'];\r\n    $convo_id = $convoArr['conversation']['convo_id'];\r\n    $params = array();\r\n    $sql = '';\r\n    $failure = false;\r\n    $category = $element->category;\r\n    runDebug(__FILE__, __FUNCTION__, __LINE__, 'Category XML = ' . $category->asXML(), 2);\r\n\r\n    // pull out the necessary info to save to the DB\r\n\r\n    // pattern\r\n    $pattern = $category->pattern;\r\n    runDebug(__FILE__, __FUNCTION__, __LINE__, 'pattern XML = ' . $pattern->asXML(), 2);\r\n    $patternEvalXpath = $pattern->xpath('//eval');\r\n    $patternText = $pattern->asXML();\r\n    $pattern2store = (!empty($patternEvalXpath)) ?\r\n        quickParseEval($convoArr, $patternText, 'pattern', 0) :\r\n        remove_text_tag($patternText, 'pattern');\r\n    runDebug(__FILE__, __FUNCTION__, __LINE__, \"Evaluated pattern = {$pattern2store}.\", 2);\r\n    $params[':pattern'] = $pattern2store;\r\n\r\n    // thatpattern\r\n    $thatpattern = $category->that;\r\n    runDebug(__FILE__, __FUNCTION__, __LINE__, 'thatpattern XML = ' . $thatpattern->asXML(), 2);\r\n    $thatpatternEvalXpath = $thatpattern->xpath('//eval');\r\n    $thatpatternText = $thatpattern->asXML();\r\n    $thatpattern2store = (!empty($thatpatternEvalXpath)) ?\r\n        quickParseEval($convoArr, $thatpatternText, 'that', 0) :\r\n        remove_text_tag($thatpatternText, 'that');\r\n    runDebug(__FILE__, __FUNCTION__, __LINE__, \"Evaluated thatpattern = {$thatpattern2store}.\", 2);\r\n    $params[':thatpattern'] = $thatpattern2store;\r\n\r\n    // template\r\n    $curTemplate = $category->template;\r\n    runDebug(__FILE__, __FUNCTION__, __LINE__, 'template XML = ' . $curTemplate->asXML(), 2);\r\n    $templateEvalXpath = $curTemplate->xpath('//eval');\r\n    $templateText = $curTemplate->asXML();\r\n    $template2store = (!empty($templateEvalXpath)) ?\r\n        quickParseEval($convoArr, $templateText, 'template', 0) :\r\n        remove_text_tag($templateText, 'template');\r\n    runDebug(__FILE__, __FUNCTION__, __LINE__, \"Evaluated template = {$template2store}.\", 2);\r\n    $params[':template'] = $template2store;\r\n\r\n    /** @noinspection SqlDialectInspection */\r\n    $sql = 'INSERT INTO `aiml_userdefined` (`id`, `bot_id`, `pattern`, `thatpattern`, `template`, `user_id`)\r\n      VALUES (\r\n        NULL,\r\n        :bot_id,\r\n        :pattern,\r\n        :thatpattern,\r\n        :template,\r\n        :user_id\r\n      );';\r\n\r\n    $params[':bot_id'] = $bot_id;\r\n    $params[':user_id'] = $user_id;\r\n    $debugSQL = db_parseSQL($sql, $params);\r\n    runDebug(__FILE__, __FUNCTION__, __LINE__, \"user defined insert SQL = {$debugSQL}.\", 2);\r\n    $numRows = db_write($sql, $params, false, __FILE__, __FUNCTION__, __LINE__);\r\n    runDebug(__FILE__, __FUNCTION__, __LINE__, \"Inserted {$numRows} row(s) into the user defined AIML table.\", 2);\r\n\r\n    return '';\r\n}\r\n\r\n```\r\n**relevant section log-file:**\r\n```\r\n23-07-2018 15:30:03.49400[2][4] - Elapsed time: 0.013 milliseconds\r\n[parse_aiml_as_XML.php][parse_learn_tag][1346]\r\nuser defined insert SQL = INSERT INTO `aiml_userdefined` (`id`, `bot_id`, `pattern`, `thatpattern`, `template`, `user_id`)\r\n      VALUES (\r\n        NULL,\r\n        1,\r\n        'WHAT IS BLUE',\r\n        '',\r\n        'BLUE IS A COLOR',\r\n        48\r\n      );. \r\n-----------------------\r\n```\r\n\r\n**here is the relevant part of sourcecode of \"find_aiml.php\":**\r\n\r\n```\r\nfunction find_userdefined_aiml(&$convoArr)\r\n{\r\n    runDebug(__FILE__, __FUNCTION__, __LINE__, 'Looking for user defined responses', 4);\r\n    global $dbn;\r\n\r\n    $i = 0;\r\n    $allrows = array();\r\n    $bot_id = $convoArr['conversation']['bot_id'];\r\n    $bot_parent_id = $convoArr['conversation']['bot_parent_id'];\r\n    $c_id = $convoArr['conversation']['convo_id']; //$convoArr['conversation'][''];user_id\r\n    $lookingfor = _strtoupper($convoArr['aiml']['lookingfor']);\r\n    $params = array(\r\n        ':user_id' => $c_id,\r\n        ':bot_id'  => $bot_id\r\n    );\r\n\r\n    //build sql\r\n    /** @noinspection SqlDialectInspection */\r\n    $sql = <<<endSQL\r\nSELECT `id`, `bot_id`, `pattern`, `thatpattern`, `template` FROM `$dbn`.`aiml_userdefined` WHERE\r\n    `bot_id` = :bot_id AND\r\n    `user_id` = :user_id\r\n    AND ([pattern_like][thatpattern_like])\r\n   ORDER BY `id` ASC, `pattern` ASC, `thatpattern` ASC;\r\nendSQL;\r\n\r\n    $rplTemplate = \"'[search]' LIKE (REPLACE(REPLACE(`[field]`, '*', '%'), '_', '%'))\";\r\n\r\n    // Build the pattern search\r\n    $pattern_like = \"\\n        \" . str_replace('[search]', $lookingfor, $rplTemplate);\r\n    $pattern_like = str_replace('[field]', 'pattern', $pattern_like);\r\n\r\n    // Placeholder for thatpattern, in case it's empty\r\n    $thatpattern_like = '';\r\n\r\n    // Build the thatpattern search\r\n    $lastthat = (isset ($convoArr['that'][1][1])) ? $convoArr['that'][1][1] : '';\r\n    $lastthat = rtrim(_strtoupper($lastthat));\r\n    if (!empty($lastthat))\r\n    {\r\n        $thatpattern_like = \"\\n        OR \" . str_replace('[search]', $lastthat, $rplTemplate);\r\n        $thatpattern_like = str_replace('[field]', 'thatpattern', $thatpattern_like);\r\n    }\r\n\r\n\r\n    // now let's replace stuff\r\n    $sql = str_replace('[pattern_like]', $pattern_like, $sql);\r\n    $sql = str_replace('[thatpattern_like]', $thatpattern_like, $sql);\r\n\r\n    $debugSQL = db_parseSQL($sql, $params);\r\n\r\n    runDebug(__FILE__, __FUNCTION__, __LINE__, \"User defined SQL:\\n$debugSQL\", 3);\r\n```\r\n\r\n**relevant section of logfile:**\r\n\r\n```\r\n23-07-2018 16:37:01.91709[3][4] - Elapsed time: 0.024 milliseconds\r\n[find_aiml.php][find_userdefined_aiml][886]\r\nUser defined SQL:\r\nSELECT `id`, `bot_id`, `pattern`, `thatpattern`, `template` FROM `po`.`aiml_userdefined` WHERE\r\n    `bot_id` = 1 AND\r\n    `user_id` = 'hc4r8v98cihc1vuuo0fqdgpu729ccpjah14tno40sfcroeg5mj50'\r\n    AND (\r\n        'WHAT IS BLUE' LIKE (REPLACE(REPLACE(`pattern`, '*', '%'), '_', '%'))\r\n        OR 'BLUE IS A COLOR' LIKE (REPLACE(REPLACE(`thatpattern`, '*', '%'), '_', '%')))\r\n   ORDER BY `id` ASC, `pattern` ASC, `thatpattern` ASC; \r\n-----------------------\r\n23-07-2018 16:37:01.91860[2][4] - Elapsed time: 1.507 milliseconds\r\n[find_aiml.php][find_userdefined_aiml][912]\r\nUser defined rows found: '0' \r\n-----------------------\r\n```\r\n\r\n**After the proposed change, it looks like this:**\r\n\r\n```\r\n23-07-2018 17:45:56.33969[3][4] - Elapsed time: 0.023 milliseconds\r\n[find_aiml.php][find_userdefined_aiml][886]\r\nUser defined SQL:\r\nSELECT `id`, `bot_id`, `pattern`, `thatpattern`, `template` FROM `po`.`aiml_userdefined` WHERE\r\n    `bot_id` = 1 AND\r\n    `user_id` = 48\r\n    AND (\r\n        'WHAT IS BLUE' LIKE (REPLACE(REPLACE(`pattern`, '*', '%'), '_', '%'))\r\n        OR 'DAS SAGT MIR GERADE NICHTS' LIKE (REPLACE(REPLACE(`thatpattern`, '*', '%'), '_', '%')))\r\n   ORDER BY `id` ASC, `pattern` ASC, `thatpattern` ASC; \r\n-----------------------\r\n23-07-2018 17:45:56.33984[3][4] - Elapsed time: 0.158 milliseconds\r\n[find_aiml.php][find_userdefined_aiml][894]\r\nResults returned: Array\r\n(\r\n    [0] => Array\r\n        (\r\n            [id] => 12\r\n            [bot_id] => 1\r\n            [pattern] => WHAT IS BLUE\r\n            [thatpattern] => \r\n            [template] => BLUE IS A COLOR\r\n        )\r\n\r\n)\r\n \r\n-----------------------\r\n23-07-2018 17:45:56.33985[2][4] - Elapsed time: 0.010 milliseconds\r\n[find_aiml.php][find_userdefined_aiml][912]\r\nUser defined rows found: '1' \r\n-----------------------\r\n```\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/Program-O/Program-O/issues/comments/419752377","html_url":"https://github.com/Program-O/Program-O/issues/432#issuecomment-419752377","issue_url":"https://api.github.com/repos/Program-O/Program-O/issues/432","id":419752377,"node_id":"MDEyOklzc3VlQ29tbWVudDQxOTc1MjM3Nw==","user":{"login":"OverlanAI","id":36704725,"node_id":"MDQ6VXNlcjM2NzA0NzI1","avatar_url":"https://avatars1.githubusercontent.com/u/36704725?v=4","gravatar_id":"","url":"https://api.github.com/users/OverlanAI","html_url":"https://github.com/OverlanAI","followers_url":"https://api.github.com/users/OverlanAI/followers","following_url":"https://api.github.com/users/OverlanAI/following{/other_user}","gists_url":"https://api.github.com/users/OverlanAI/gists{/gist_id}","starred_url":"https://api.github.com/users/OverlanAI/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OverlanAI/subscriptions","organizations_url":"https://api.github.com/users/OverlanAI/orgs","repos_url":"https://api.github.com/users/OverlanAI/repos","events_url":"https://api.github.com/users/OverlanAI/events{/privacy}","received_events_url":"https://api.github.com/users/OverlanAI/received_events","type":"User","site_admin":false},"created_at":"2018-09-09T23:17:43Z","updated_at":"2018-09-09T23:17:43Z","author_association":"NONE","body":"@Josef-Meier \r\nOh, i mean that is no longer called as a function because you moved all of that out and made it its own function. I could not find anything that calls `function make_learn()` now so i think it just leftover code.\r\nAnyway i commented that function out since it does nothing after the changes.\r\nI was just checking to see if i was right or not why i was cleaning the code up.\r\nTNX"}}
{"actor":{"display_login":"OverlanAI"}}