Skip to content

Commit 02c304b

Browse files
committed
Release SARAH v2.8 RC + Plugins
1 parent 5753e13 commit 02c304b

File tree

248 files changed

+52038
-2669
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

248 files changed

+52038
-2669
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ overview.docx
2828
README/SayStatic/
2929
README/ScanSoftTTS/
3030
README/changelog.txt
31+
plugins/karotz/java/jre
32+
3133

3234
# External tool builders
3335
.externalToolBuilders/

plugins/allocine/allocine.js

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
exports.action = function(data, callback, config, SARAH){
2+
3+
var place = data.place || 'B0172';
4+
5+
var url = 'http://iphone.allocine.fr/salle/seances_gen_csalle='+place+'.html';
6+
var request = require('request');
7+
request({ 'uri' : url }, function (err, response, body){
8+
9+
if (err || response.statusCode != 200) {
10+
callback({'tts': "L'action a échoué"});
11+
return;
12+
}
13+
14+
var $ = require('cheerio').load(body, { xmlMode: true, ignoreWhitespace: false, lowerCaseTags: false });
15+
var options = list($);
16+
options.tts = 'Voici la liste des films au ' + options.theatre + ': ' + options.movies.join(', ');
17+
18+
if (data.movie){
19+
options.hours = hours($, data.movie);
20+
options.tts = 'Voici les horaries de '+ options.movies[data.movie] +' au ' + options.theatre + ': ';
21+
options.tts += options.hours.join('. ');
22+
} else {
23+
update(data.directory, options.movies, place);
24+
}
25+
26+
callback(options);
27+
});
28+
}
29+
30+
31+
// ------------------------------------------
32+
// SCRAPING
33+
// ------------------------------------------
34+
35+
var list = function($){
36+
var theatre = $('DIV.titre B').text();
37+
var movies = $('DIV.cell A[href^="/film"]').map(function(){ return $(this).text(); });
38+
return {
39+
'theatre' : theatre,
40+
'movies' : movies
41+
};
42+
}
43+
44+
var hours = function($, pos){
45+
return $('DIV.cell').eq(pos).find('DIV[style*=red]').map(function(){ return clean($(this).text()); });
46+
}
47+
48+
var clean = function(hours){
49+
hours = hours.replace(/<br>/g,'. ').replace(/Lun[-,]* /g,'Lundi ')
50+
.replace(/Mar[-,]* /g,'Mardi ').replace(/Mer[-,]* /g,'Mercredi ')
51+
.replace(/Jeu[-,]* /g,'Jeudi ').replace(/Ven[-,]* /g,'Vendredi ')
52+
.replace(/Sam[-,]* /g,'Samedi ').replace(/Dim[-,]* /g,'Dimanche ');
53+
return hours;
54+
}
55+
56+
// ------------------------------------------
57+
// UPDATING XML
58+
// ------------------------------------------
59+
60+
var update = function(directory, movies, place){
61+
if (!directory){ return; }
62+
if (!movies || movies.length == 0){ return; }
63+
64+
var fs = require('fs');
65+
var file = directory + '/../plugins/allocine/allocine.xml';
66+
var xml = fs.readFileSync(file,'utf8');
67+
68+
var replace = '§ -->\n';
69+
replace += '<rule id="ruleMovieName">\n';
70+
replace += ' <tag>out.place="'+place+'";</tag>\n';
71+
replace += ' <one-of>\n';
72+
73+
for(var i = 0 ; i < movies.length ; i++){
74+
var movie = movies[i]; movie = movie.indexOf(':') > 0 ? movie.substring(0,movie.indexOf(':')) : movie; // Split at ':'
75+
replace += ' <item>'+movie+'<tag>out.movie="'+i+'";</tag></item>\n';
76+
}
77+
replace += ' </one-of>\n';
78+
replace += '</rule>\n';
79+
replace += '<!-- §';
80+
81+
var regexp = new RegExp('§[^§]+§','gm');
82+
var xml = xml.replace(regexp,replace);
83+
84+
fs.writeFileSync(file, xml, 'utf8');
85+
}
86+

plugins/allocine/allocine.prop

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"modules" : {
3+
"allocine" : {
4+
"description": "Scraping de Allociné",
5+
"version" : "2.0"
6+
}
7+
}
8+
}

plugins/allocine/allocine.xml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<grammar version="1.0" xml:lang="fr-FR" mode="voice" root="ruleMovies" xmlns="http://www.w3.org/2001/06/grammar" tag-format="semantics/1.0">
2+
3+
<rule id="ruleMovies">
4+
<tag>out.action=new Object(); </tag>
5+
<item weight="2">Sarah</item>
6+
<one-of>
7+
<item><ruleref uri="#ruleMoviePlace"/><tag>out.action = rules.ruleMoviePlace;</tag></item>
8+
<item><ruleref uri="#ruleMovieTime"/><tag>out.action = rules.ruleMovieTime;</tag></item>
9+
</one-of>
10+
<tag>out.action._attributes.uri="http://127.0.0.1:8080/sarah/allocine";</tag>
11+
</rule>
12+
13+
<rule id="ruleMoviePlace">
14+
<example>Sarah qu'est ce qu'il y a au ciné à Vaucresson ?</example>
15+
<tag>out.place="B0172"; </tag>
16+
<one-of>
17+
<item>il y a quoi au ciné</item>
18+
<item>il y a quoi au cinéma</item>
19+
<item>qu'est qu'il y a au ciné</item>
20+
<item>qu'est qu'il y a au cinéma</item>
21+
</one-of>
22+
<item repeat="0-1">
23+
<one-of>
24+
<item>cette semaine</item>
25+
<item>en ce moment</item>
26+
<item>ce soir</item>
27+
</one-of>
28+
</item>
29+
<item repeat="0-1">
30+
<one-of>
31+
<item>à Parly 2 <tag>out.place="B0172";</tag></item>
32+
<item>à vaucresson<tag>out.place="B0099";</tag></item>
33+
</one-of>
34+
</item>
35+
</rule>
36+
37+
<rule id="ruleMovieTime">
38+
<example>Sarah a quelle heure passe Eureka ?</example>
39+
<one-of>
40+
<item>a quelle heure passe</item>
41+
<item>quand passe</item>
42+
<item>quelle sont les séances pour</item>
43+
</one-of>
44+
<ruleref uri="#ruleMovieName"/>
45+
</rule>
46+
47+
<!-- Automatic Generation § -->
48+
<rule id="ruleMovieName">
49+
50+
</rule>
51+
<!-- § Automatic Generation -->
52+
</grammar>

plugins/chatterbot/chatterbot.js

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
exports.action = function(data, callback, config, SARAH){
2+
3+
// Retrieve config
4+
config = config.modules.chatterbot;
5+
if (!config){
6+
console.log("Missing Chatterbot config");
7+
callback({'tts': 'Pas de configuration'});
8+
return;
9+
}
10+
11+
if (!data.dictation){
12+
console.log("Missing Chatterbot message");
13+
callback({'tts': 'pas de message'});
14+
return;
15+
}
16+
17+
// Clean question
18+
var question = cleanQuestion(data.dictation);
19+
20+
// Setup
21+
setup(function(bot){
22+
if (!bot){ callback({'tts': 'Error while loading'}); return; }
23+
var reply = bot.reply("local-user", unaccetuate(question));
24+
callback({'tts': reply});
25+
});
26+
}
27+
28+
var cleanQuestion = function(question){
29+
var rgxp1 = /ma question est (.+) Sarah/i
30+
var match = question.match(rgxp1);
31+
if (match && match.length > 1){
32+
return match[1];
33+
}
34+
35+
var rgxp2 = /dis-moi (.+) Sarah/i
36+
var match = question.match(rgxp2);
37+
if (match && match.length > 1){
38+
return match[1];
39+
}
40+
41+
return question;
42+
}
43+
44+
45+
var bot = false;
46+
var setup = function(cb){
47+
if (bot){ return cb(bot); }
48+
49+
var RiveScript = require('./riverscript/bin/RiveScript.js');
50+
bot = new RiveScript({ debug: false });
51+
52+
var brain = 'plugins/chatterbot/riverscript/eg/brain';
53+
bot.loadFile([
54+
brain + "/activitepresente.rs",
55+
brain + "/age.rs",
56+
brain + "/cerveaudebase.rs",
57+
brain + "/depart.rs",
58+
brain + "/reactionbot.rs",
59+
brain + "/substitutions.rs",
60+
brain + "/variables.rs",
61+
],
62+
function(count){ // Success
63+
bot.sortReplies();
64+
cb(bot);
65+
},
66+
function(ex, count){ // Error
67+
console.log("Loading error: ", ex, count);
68+
cb(false);
69+
});
70+
}
71+
72+
var unaccetuate = function(text) {
73+
text = text.replace(/[éèêë]/gi, "e");
74+
text = text.replace(/[àâä]/gi, "a");
75+
text = text.replace(/[ïî]/gi, "i");
76+
text = text.replace(/[üûù]/gi, "u");
77+
text = text.replace(/[öô]/gi, "o");
78+
text = text.replace(/[ç]/gi, "c");
79+
text = text.replace(/[']/gi, " ");
80+
text = text.replace(/[-]/gi, " ");
81+
text = text.replace(/[?]/gi, " ");
82+
text = text.replace(/[!]/gi, " ");
83+
text = text.replace(/[\s]{2,}/g," "); // Enlève les espaces doubles, triples, etc.
84+
text = text.trim();
85+
return text
86+
}
87+
88+

plugins/chatterbot/chatterbot.prop

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"modules" : {
3+
"chatterbot": {
4+
"description": "Chatterbot Riversccript",
5+
"version" : "2.0"
6+
}
7+
}
8+
}
+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
RiveScript-JS
2+
=============
3+
4+
INTRODUCTION
5+
------------
6+
7+
This is a RiveScript interpreter library for JavaScript.
8+
RiveScript is a scripting language for chatterbots, making it
9+
easy to write trigger/response pairs for building up a bot's
10+
intelligence.
11+
12+
This library can be used both in a web browser or as a Node.JS
13+
module. See the `eg/` folder for a web browser example. There's
14+
a `node/` folder with a Node.JS example.
15+
16+
USAGE
17+
-----
18+
19+
var bot = new RiveScript();
20+
21+
// Load a directory full of RiveScript documents (.rs files). This is for
22+
// Node.JS only: it doesn't work on the web!
23+
bot.loadDirectory("brain", loading_done, loading_error);
24+
25+
// Load an individual file.
26+
bot.loadFile("brain/testsuite.rs", loading_done, loading_error);
27+
28+
// Load a list of files all at once (the best alternative to loadDirectory
29+
// for the web!)
30+
bot.loadFile([
31+
"brain/begin.rs",
32+
"brain/admin.rs",
33+
"brain/clients.rs"
34+
], loading_done, loading_error);
35+
36+
// All file loading operations are asynchronous, so you need handlers
37+
// to catch when they've finished. If you use loadDirectory (or loadFile
38+
// with multiple file names), the success function is called only when ALL
39+
// the files have finished loading.
40+
function loading_done (batch_num) {
41+
console.log("Batch #" + batch_num + " has finished loading!");
42+
43+
// Now the replies must be sorted!
44+
bot.sortReplies();
45+
46+
// And now we're free to get a reply from the brain!
47+
var reply = bot.reply("local-user", "Hello, bot!");
48+
console.log("The bot says: " + reply);
49+
}
50+
51+
// It's good to catch errors too!
52+
function loading_error (batch_num, error) {
53+
console.log("Error when loading files: " + error);
54+
}
55+
56+
COPYRIGHT AND LICENSE
57+
---------------------
58+
59+
The JS RiveScript interpreter library is dual licensed. For open
60+
source applications the module is using the GNU General Public License. If
61+
you'd like to use the RiveScript module in a closed source or commercial
62+
application, contact the author for more information.
63+
64+
RiveScript - Rendering Intelligence Very Easily
65+
Copyright (C) 2012 Noah Petherbridge
66+
67+
This program is free software; you can redistribute it and/or modify
68+
it under the terms of the GNU General Public License as published by
69+
the Free Software Foundation; either version 2 of the License, or
70+
(at your option) any later version.
71+
72+
This program is distributed in the hope that it will be useful,
73+
but WITHOUT ANY WARRANTY; without even the implied warranty of
74+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
75+
GNU General Public License for more details.
76+
77+
You should have received a copy of the GNU General Public License
78+
along with this program; if not, write to the Free Software
79+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
80+
81+
SEE ALSO
82+
--------
83+
84+
The official RiveScript website, http://www.rivescript.com/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>JsRiveObjects</title>
5+
<link rel="stylesheet" type="text/css" href="docs.css">
6+
</head>
7+
<body>
8+
9+
<h1>JsRiveObjects</h1>
10+
11+
<hr>
12+
13+
<h1>Methods</h1>
14+
15+
<h2>JsRiveObjects (RiveScript master)</h2>
16+
<br>
17+
A default Object handler that can deal with JavaScript code.
18+
19+
<hr>
20+
21+
<h2>void load (string name, string[] code)</h2>
22+
23+
<br>
24+
Called by the RiveScript object to load JavaScript code.<hr>
25+
26+
<h2>string call (RiveScript rs, string name, string[] fields)</h2>
27+
28+
<br>
29+
Called by the RiveScript object to execute JavaScript code.<hr>
30+
31+
</body>
32+
</html>

0 commit comments

Comments
 (0)