Commit cfb77325 authored by Mersi Stafa's avatar Mersi Stafa
Browse files

final report

parent c528fdc7
This diff is collapsed.
Not confident Kay was sad. One day she was watching dramatic Telenovela. She saw a pretty and confident Mersi. Mersi was eating in fancy restaurant "Beautiful". Mersi ordered Greek Salad with feta cheese. The Italian waiter came and brought her bloody steak instead. The vegetarian Mersi was offended. She she did not say a word. Mersi ate the whole steak with tears on her eyes. Mersi was a drama-queen. When drama-queen Mersi ate the steak she stood up, slapped rude waiter and went away. This dramatic event changed life of Kay. Today Kay is strong and independent woman. Kay likes to slap Italian men in their face.
Not confident Kay, was sad. One day she was watching a dramatic Telenovela.
She saw the pretty and confident Mersi. Mersi was eating in a fancy restaurant "Beautiful".
Mersi ordered a Greek Salad with feta cheese. The Italian waiter came and brought her a bloody
steak instead. The vegetarian Mersi was offended. But she did not say a word. Mersi ate the
whole steak with tears on her eyes. Mersi was a drama-queen. When drama-queen Mersi ate the
steak she stood up, slapped the rude waiter and went away. This dramatic event changed the
life of Kay. Today, Kay is a strong and independent woman. Kay likes to slap Italian men
in their face.
......@@ -6,7 +6,7 @@
"q" : "Martin has blond hair"
}
SEARCH EXAMPLE
//SEARCH EXAMPLE
{
"lang" : "eng",
......
......@@ -6,10 +6,11 @@ module.exports = function (router) {
let request = require('request');
let querystring = require('querystring');
let elasticsearch = require('elasticsearch');
let Promise = require('bluebird');
let rp = require('request-promise');
/**
*
* Index mapping for elasticsearch
*/
let indexMapping = {
"properties": {
"Name": {
......@@ -94,11 +95,18 @@ module.exports = function (router) {
}
};
/**
*
*
*/
let client = new elasticsearch.Client({
host: 'elastic-mis.cs.univie.ac.at:9200',
log: 'trace'
});
/**
*
*/
client.ping({
// ping usually has a 3000ms timeout
requestTimeout: 1000
......@@ -113,7 +121,7 @@ module.exports = function (router) {
router.post('/save', function (req, res) {
/// delete all indexes
// delete all indexes
client.indices.delete({
index: '_all'
}, function (err, res) {
......@@ -126,7 +134,6 @@ module.exports = function (router) {
});
// create index
client.indices.create({
index: indexName,
body: {
......@@ -175,7 +182,11 @@ module.exports = function (router) {
});
});
/**
* Search request when typing in a question with Is + AspectName(adj)
* where the EntityDirectAspect is true and as response is an answer
* that is Yes/No
*/
router.post('/search', function (req, res) {
// let sentencesForm = splitSentences(req.body.q);
......@@ -185,7 +196,7 @@ module.exports = function (router) {
let isQuestion = false;
// is pretty Mersi
if (req.body.q.startsWith("Is") || req.body.q.startsWith("is") || req.body.q.startsWith("did") || req.body.q.startsWith("does") || req.body.q.startsWith("Did") || req.body.q.startsWith("Do") || req.body.q.startsWith("Does")) {
isQuestion = true;
}
......@@ -201,7 +212,8 @@ module.exports = function (router) {
let arrayMatch = [];
// fake call if nothing came
// who is pretty?
if (JSON.parse(body).EntitySet.length === 0) {
let formData = querystring.stringify({lang: 'eng', q: "Test " + req.body.q});
......@@ -219,8 +231,6 @@ module.exports = function (router) {
JSON.parse(body2).EntitySet.map(entity => {
entity.Aspects.map(a => {
arrayMatch.push({
"bool": {
"must": [{"match": {"Aspects.AspectName": a.AspectName}},
......@@ -258,7 +268,7 @@ module.exports = function (router) {
});
} else {
// who is pretty mersi
JSON.parse(body).EntitySet.map(entity => {
if (entity.Aspects.length > 0) {
......@@ -273,10 +283,9 @@ module.exports = function (router) {
}
});
});
} else {
// who is mersi
arrayMatch.push({"match": {"Name": entity.Name}});
}
......@@ -330,37 +339,13 @@ module.exports = function (router) {
});
function makeFakeRequest(sentence) {
let fakeSentence = "Test " + sentence;
}
};
function buildEntityQuery(resp) {
let arrayMatch = [];
resp.EntitySet.map(entity => {
console.log(entity);
arrayMatch.push({"match": {"Name": entity.Name}});
});
return {
"query": {
"bool": {"should": arrayMatch}
}
};
}
function splitSentences(sentences) {
let slitted = sentences.match(/[^\.!\?]+[\.!\?]+/g);
let spittedFoamData = [];
slitted.map(sent => {
spittedFoamData.push({lang: 'eng', q: sent});
});
return spittedFoamData;
}
/**
*
* removes duplicate names or adj from the answer list
*/
function removeDublicates(a) {
return Array.from(new Set(a));
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment