Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
kompasim committed Sep 8, 2022
1 parent e927e7d commit e0d64fb
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 354 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

## 0. notice

> the chatbot is writen according to AIML 2.5 and [Program-P](https://github.com/pe77/Program-P),it uses utf-8 and i made some customizaton , there are some differences between standard aiml tags and the tags uses in this program.
> the chatbot is written according to AIML 2.5 and [Program-P](https://github.com/pe77/Program-P),it uses utf-8 and i made some customization , there are some differences between standard aiml tags and the tags used in this program.
## 1. description

Expand All @@ -26,7 +26,7 @@
## 5. about aiml files

> * `aiml` files should be paleced in `aiml`directory.
> * `aiml` files should be paleced in `aiml` directory.
> * `chatbot.aiml`is the entrance ,the `aiml` tag in it can contain various `category` tag , a `default`tag and various `include`tag。
Expand Down Expand Up @@ -154,7 +154,9 @@ if ($this->_config->multiChatbot){


---

# Enjoy it
# Enjoy it

![screenshot](./screenshot.jpg)

---
5 changes: 4 additions & 1 deletion aiml/chatbot.aiml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
<pattern>DEFAULT</pattern>
<template>
<random>
<li>كەچۈرۈڭ ، چۈشىنەلمىدىم ...</li>
<li>I didn't understand, what you mean ?</li>
<li>what the fuck are you talking about man!</li>
<li>sounds good, but i have no idea about it.</li>
<li>teach me something in aiml files.</li>
</random>
</template>
</category>
Expand Down
7 changes: 5 additions & 2 deletions api.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@

// talk
if ($_REQUEST['requestType'] == 'talk') {
$res = $chatbot->talk($_REQUEST['userInput']);
//
$userInput = $_REQUEST['userInput'];
$chatbotReply = $chatbot->talk($userInput);
//
$data = $chatbot->getData();
$result['status'] = 'success';
$result['type'] = 'talk';
$result['message'] = trim(preg_replace("/\s+/", " ", $res));
$result['message'] = trim(preg_replace("/\s+/", " ", $chatbotReply));
$result['data'] = $data;
} elseif ($_REQUEST['requestType'] == 'forget') {
$chatbot->forget();
Expand Down
303 changes: 193 additions & 110 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,122 +1,103 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<link rel="shortcut icon" href="web/favicon.ico"/>
<title>AIML 2.5 Web Test</title>
<script src="web/js/jquery.js" type="text/javascript"></script>
<link rel="stylesheet" href="web/css/main.css" type="text/css"/>
<script type="text/javascript">
$(document).ready(function () {
var localUrl = window.location.href;
localUrl = localUrl.replace('web/', '');
// só um advinhador simples
var webServiceUrl = window.location.href + 'api.php';
console.log(webServiceUrl);
$('.clean').click(function () {
Clear();
AddText('system ', 'cleaning...');
$('.userMessage').hide();
$.ajax({
type: "GET",
url: webServiceUrl,
data: {
requestType: 'forget'
},
success: function (response) {
AddText('system ', 'Ok!');
$('.userMessage').show();
},
error: function (request, status, error) {
Clear();
alert('error');
$('.userMessage').show();
}
});
});
$('#fMessage').submit(function () {
// get user input
var userInput = $('input[name="userInput"]').val();
// basic check
if (userInput == '')
return false;
//
// clear
$('input[name="userInput"]').val('');
// hide button
$(this).hide();
// show user input
AddText('A ', userInput);
$.ajax({
type: "GET",
url: webServiceUrl,
data: {
userInput: userInput,
requestType: 'talk'
},
success: function (response) {
console.log(webServiceUrl);
console.log(userInput);
AddText('B ', response.message);
$('#fMessage').show();
$('input[name="userInput"]').focus();
},
error: function (request, status, error) {
console.log(error);
alert('error');
$('#fMessage').show();
}
});
return false;
});
function Clear() {
$('.chatBox').html('');
}
function AddText(user, message) {
console.log(user);
console.log(message);
var div = $('<div>');
var name = $('<labe>').addClass('name');
var text = $('<span>').addClass('message');
name.text(user + ':');
text.text('\t' + message);
div.append(name);
div.append(text);
$('.chatBox').append(div);
$('.chatBox').scrollTop($(".chatBox").scrollTop() + 100);
}
});
</script>
<link rel="shortcut icon" href="https://github.githubassets.com/favicons/favicon-dark.png"/>
<title>Chatbot</title>
<script src="https://code.jquery.com/jquery-1.12.4.js" integrity="sha256-Qw82+bXyGq6MydymqBxNPYTaUXXq7c8v3CwiYwLLNXU=" crossorigin="anonymous"></script>
</head>
<style type="text/css">
* {
padding: 0px;
margin: 0px;
}
#body {
background-image: linear-gradient(to right, rgb(18, 17, 17) , rgb(15, 17, 19));
background-size: cover;
height: 100%;
width: 100%;
}
#box1 {
height: 75%;
width: 80%;
display: block;
}
#box2 {
height: 25%;
width: 80%;
}
h2 {
height: 10%;
}
a {
color: white;
text-decoration: none;
font-size: 34px;
}
a:hover {
text-shadow: 2px 2px 2px rgb(120, 120, 120);
}
.chatBox {
cursor: pointer;
display: inline-block;
background: rgba(55,55,55,0.5);
height: 50%;
width: 90%;
overflow: auto;
text-align: left;
text-indent: 10%;
color: white;
text-shadow: 1px 1px 1px black;
font-size: 20px;
padding-top: 20px;
}
form {
height: 100%;
widows: 100%;
}
#userInput {
display:inline-block;
width: 50%;
height: 30%;
font-size: 24px;
background: rgba(55,55,55,0.5);
outline:0;
border:3px rgba(155,155,155,0.3) solid;
border-left:5px rgba(22,22,22,0.9) solid;
box-shadow:5px 5px 5px black;
color:rgba(200,200,200,0.8);
text-decoration: none;
text-indent: 0.5em;
}
#send, #clean {
display:inline-block;
width: 15%;
height: 30%;
font-size: 24px;
background: rgba(150, 150, 150, 0.3);
outline:0;
color:white;
border:3px rgba(155,155,155,0.5) solid;
box-shadow:5px 5px 5px black;
cursor: pointer;
text-shadow: 1px 1px 1px black;
text-overflow: hidden;
}
</style>
<body id="body">
<center>
<div id="box1">
<br>
<br>
<h2><a target="_blank" href="https://github.com/kompasim/chatbot-utf8">Chatbot</a></h2>
<h2><a target="_blank" href="https://github.com/kompasim/chatbot">Chatbot</a></h2>
<br>
<br>
<div class="chatBox">
Expand All @@ -136,6 +117,108 @@ function AddText(user, message) {
</div>
</center>
</body>
<script type="text/javascript">
$(document).ready(function () {
var localUrl = window.location.href;
localUrl = localUrl.replace('web/', '');
// só um advinhador simples
var webServiceUrl = window.location.href + 'api.php';
console.log(webServiceUrl);
$('.clean').click(function () {
Clear();
AddText('system ', 'cleaning...');
$('.userMessage').hide();
$.ajax({
type: "GET",
url: webServiceUrl,
data: {
requestType: 'forget'
},
success: function (response) {
AddText('system ', 'Ok!');
$('.userMessage').show();
},
error: function (request, status, error) {
Clear();
alert('error');
$('.userMessage').show();
}
});
});
$('#fMessage').submit(function () {
// get user input
var userInput = $('input[name="userInput"]').val();
// basic check
if (userInput == '')
return false;
//
// clear
$('input[name="userInput"]').val('');
// hide button
$(this).hide();
// show user input
AddText('A ', userInput);
$.ajax({
type: "GET",
url: webServiceUrl,
data: {
userInput: userInput,
requestType: 'talk'
},
success: function (response) {
console.log(webServiceUrl);
console.log(userInput);
AddText('B ', response.message);
$('#fMessage').show();
$('input[name="userInput"]').focus();
},
error: function (request, status, error) {
console.log(error);
alert('error');
$('#fMessage').show();
}
});
return false;
});
function Clear() {
$('.chatBox').html('');
}
function AddText(user, message) {
console.log(user);
console.log(message);
var div = $('<div>');
var name = $('<labe>').addClass('name');
var text = $('<span>').addClass('message');
name.text(user + ':');
text.text('\t' + message);
div.append(name);
div.append(text);
$('.chatBox').append(div);
$('.chatBox').scrollTop($(".chatBox").scrollTop() + 100);
}
});
</script>
</html>
Binary file added screenshot.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit e0d64fb

Please sign in to comment.