Skip to content

Commit

Permalink
final done
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiago-Seven committed May 20, 2018
1 parent b749f91 commit e13d1c1
Show file tree
Hide file tree
Showing 7 changed files with 361 additions and 685 deletions.
45 changes: 2 additions & 43 deletions dados.pl
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
verbo_atributo(possuir).
verbo_atributo(ter).

% rating estrelas e categoria
% Rating Estrelas e Categoria
verbo_REC(possuir).
verbo_REC(ter).

Expand All @@ -280,20 +280,10 @@
determinante(p-f,umas) --> [umas].
conjuncao(_-_) --> [e].

% testes semanticos

hotel(Hotel) :-
hotel(Hotel,_,_,_,_).

possuir(X,"rating") :- hotel(X,_,_,_,_).
possuir(X,"servicos") :- hotel(X,_,_,_,_).
possuir(X,"categoria") :- hotel(X,_,_,_,_).
possuir(X,"quartos") :- hotel(X,_,_,_,_).
possuir(X,"estrelas") :- hotel(X,_,_,_,_).
disponibilizar(X,"servicos") :- hotel(X,_,_,_,_).
com(X,"rating") :- hotel(X,_,_,_,_).
com(X, "estrelas") :- hotel(X,_,_,_,_).
com(X, "categoria") :- hotel(X,_,_,_,_).
com(X, "servicos") :- hotel(X,_,_,_,_).
local(porto).
local(lisboa).
local(coimbra).
Expand All @@ -307,34 +297,3 @@
local(braga).
local(vilamoura).
local(figueira-da-foz).
ficar(X, Y) :- hotel(X,_,_,_,_), local(Y).
ser("restaurante,servico").
ser("vista de mar,servico").
ser("wifi,servico").
ser("piscina,servico").
ser("baby-sitting,servico").
ser("piso para fumadores,servico").
ser("pisos para fumadores,servico").
ser("estacionamento,servico").
ser(X, "hotel") :- hotel(X,_,_,_,_).
ser(X,"numero") :- integer(X).
comparador("superior").
comparador("inferior").
comparador("igual").
comparavel("estrelas", Y) :- caracteristica(Y).
comparavel("rating", Y) :- caracteristica(Y).
ter(X,"rating") :- hotel(X,_,_,_,_).
ter(X,"servico") :- hotel(X,_,_,_,_).
ter(X, Y) :- hotel(X,_,_,_,_), ser(Y,"servico").

/*rating(Hotel,Rating,igual) :- ser(rating,inteiro), ser(Hotel,hotel), hotel(X,_,Rating,_,_,_).
rating(Hotel,Rating,maior) :- ser(rating,inteiro), ser(Hotel,hotel), hotel(Hotel,_,RatingDB,_,_,_),RatingDB > Rating.
rating(Hotel,Rating,menor) :- ser(rating,inteiro), ser(Hotel,hotel), hotel(Hotel,_,RatingDB,_,_,_),RatingDB < Rating.
estrelas(Hotel,Estrelas,igual) :- ser(estrelas,inteiro), ser(Hotel,hotel), hotel(Hotel,_,_,_,Estrelas,_).
estrelas(Hotel,Estrelas,maior) :- ser(estrelas,inteiro), ser(Hotel,hotel), hotel(Hotel,_,_,_,EstrelasDB,_),EstrelasDB > Estrelas.
estrelas(Hotel,Estrelas,menor) :- ser(estrelas,inteiro), ser(Hotel,hotel), hotel(Hotel,_,_,_,EstrelasDB,_),EstrelasDB < Estrelas.
custo(Hotel,Custo,igual) :- ser(custo,inteiro), ser(Hotel,hotel), hotel(X,_,_,Custo,_,_).
custo(Hotel,Custo,maior) :- ser(custo,inteiro), ser(Hotel,hotel), hotel(Hotel,_,_,_,CustoDB,_),CustoDB > Custo.
custo(Hotel,Custo,menor) :- ser(custo,inteiro), ser(Hotel,hotel), hotel(Hotel,_,_,_,CustoDB,_),CustoDB < Custo.
servico(Hotel,Servico) :- ser(Hotel,hotel), hotel(Hotel,_,_,_,_,Servicos), member(Servico,Servicos).
local(Hotel,Local) :- ser(Hotel,hotel), hotel(Hotel,Local,_,_,_,_).*/
4 changes: 0 additions & 4 deletions front_end/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="libraries/p5.js" type="text/javascript"></script>
<script src="libraries/p5.dom.js" type="text/javascript"></script>
<script src="libraries/p5.sound.js" type="text/javascript"></script>
<script src="libraries/p5.speech.js" defer></script>
<script src="index.js" defer></script>

</head>
Expand Down
65 changes: 41 additions & 24 deletions front_end/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
var me = {};
me.avatar = "user.png";

let storeToArrowUp = [];
let index = 0;
var you = {};
you.avatar = "bot.png";
let recognition = new webkitSpeechRecognition();
recognition.lang = "pt-PT";
recognition.continuous = true;
let mic = document.querySelector('.fa-microphone')
mic.onmousedown = function(){
recognition.start();
}

mic.onmouseup = function() {
recognition.stop();
}
let isWebkit = 'webkitSpeechRecognition' in window;
let speak = new SpeechSynthesisUtterance();
if (isWebkit){
let recognition = new webkitSpeechRecognition();
recognition.lang = "pt-PT";
recognition.continuous = true;
let mic = document.querySelector('.fa-microphone')
mic.onmousedown = function(){
recognition.start();
}

mic.onmouseup = function() {
recognition.stop();
}

recognition.onresult = function (event) {
let textInput = document.querySelector(".mytext");
textInput.value = event.results[0][0].transcript;


};
recognition.onresult = function (event) {
let textInput = document.querySelector(".mytext");
textInput.value = event.results[0][0].transcript;
};
}



Expand Down Expand Up @@ -75,11 +77,15 @@ function resetChat() {
$("ul").empty();
}



$(".mytext").on("keydown", function (e) {
if (e.which == 13) {
var text = $(this).val();
if (text !== "") {
insertChat("you", text);
storeToArrowUp.unshift(text);
index = 0;
$(this).val('');
text = text.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()\?]/g, " ");
text = text.trim();
Expand All @@ -88,16 +94,27 @@ $(".mytext").on("keydown", function (e) {
let message = JSON.stringify(array);
message = message.replace(/"/g, "");
response = makeRequest("responde(" + message +")");
if(response == "yes")
response = "Sim! :)"

if (response == "no")
response = "Não :("

if (response == "syntax_error" || response == "Bad Request")
response = "Não percebi o que escreveste, verifica se a frase tem algum erro por favor :)"

insertChat("me",response,500);
speak.text = response;
speak.lang = 'pt-PT';
speechSynthesis.speak(speak);

}
}
if (e.which == 38) {
if(index < storeToArrowUp.length){
$(this).val(storeToArrowUp[index]);
index++;
}
}
if (e.which == 40) {
if (index >= 0) {
$(this).val(storeToArrowUp[index]);
index--;
}
}
});
Expand Down Expand Up @@ -472,7 +489,7 @@ $('body > div > div > div:nth-child(2) > span').click(function () {
resetChat();

//-- Print Messages
insertChat("me", "Hello :D", 0);
insertChat("me", "Ola :D", 0);



Expand Down
2 changes: 1 addition & 1 deletion front_end/server.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
:-use_module(library(codesio)).
:- use_module(library(random)).
:- use_module(library(system)).
:- consult('../novaGramatica.pl').
:- consult('../gramatica.pl').

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Server %%%%
Expand Down
Loading

0 comments on commit e13d1c1

Please sign in to comment.