<commit_before>'use strict';

const express = require('express');
const bodyParser = require('body-parser');

const data=[
  {
    "country": "Israel",
    "cost_of_live": "500",
    "cities": [
      {
        "name": "<NAME>",
        "cost_of_live": "320",
        "cost_of_rent":[
            {
                "type_of_flat":"entire flat",
                "cost_employee": "1500",
                "cost_general": "1600",
            },
            {
                "type_of_flat":"private room",
                "cost_employee": "500",
                "cost_general": "600",
            },
            {
                "type_of_flat":"shared room",
                "cost_employee": "300",
                "cost_general": "300",
            }

        ]
      }
    ]
  },
  {
    "country": "UK",
    "cost_of_live": "500",
    "cities": [
      {
        "name": "London",
        "cost_of_live": "800"
      },
      {
        "name": "Liverpool",
        "cost_of_live": "400"
      },
      {
        "name": "Oxford",
        "cost_of_live": "500"
      }
    ]
  },
  {
    "country": "Germany",
    "cost_of_live": "300",
    "cities": [
      {
        "name": "Berlin",
        "cost_of_live": "500"
      },
      {
        "name": "Munich",
        "cost_of_live": "200"
      }
    ]
  }
];

const restService = express();
restService.use(bodyParser.json());

var func=function (req, res) {

    console.log('hook request');

    try {
        var speech = 'empty speech';
        let  cost_of_live="Unknown";

        if (req.body) {
            var requestBody = req.body;

            if (requestBody.result) {
                speech = '';

                if (requestBody.result.action=="input.city") {
                    if (requestBody.result.parameters) {
                        if (requestBody.result.parameters["geo-city"]) {
                            let  cost_of_live="Unknown";
                            data.forEach(function(element) {
                                element.cities.forEach(function(city) {
                                    if(requestBody.result.parameters["geo-city"]==city.name){
                                        cost_of_live=city.cost_of_live; 
                                    }
                                }); 
                            });

                            speech="cost of living in " +requestBody.result.parameters["geo-city"]+ " is "+cost_of_live+"GBP per month ";
                        }
                        else{
                            speech="no geo-city"
                        }
                    }
                    else{
                        speech="no parameters"
                    }
                }
                if (requestBody.result.action=="input.city") {
                    if (requestBody.result.parameters) {
                        if (requestBody.result.parameters["geo-city"]) {
                            data.forEach(function(element) {
                                element.cities.forEach(function(city) {
                                    if(requestBody.result.parameters["geo-city"]==city.name){
                                        cost_of_live=city.cost_of_live; 
                                    }
                                }); 
                            });

                            speech="cost of living in " +requestBody.result.parameters["geo-city"]+ " is "+cost_of_live+"GBP per month ";
                        }
                        else{
                            speech="no geo-city"
                        }
                    }
                    else{
                        speech="no parameters"
                    }
                }
                else{
                    speech="no action"
                }
            }
        }

        console.log('result: ', speech);

        return res.json({
//            speech: speech,
//            displayText: speech,
            source: 'apiai-webhook-sample',
            contextOut: [{"name":"datakeeper", "lifespan":99, "parameters":{"cost_of_live":cost_of_live,"cost_of_live_in":requestBody.result.parameters["geo-city"]}}]
        });
    } catch (err) {
        console.error("Can't process request", err);

        return res.status(400).json({
            status: {
                code: 400,
                errorType: err.message
            }
        });
    }
}


restService.get('/hook',function(req,res) {
    var req={"body":
                    {
                "id": "8f89439f-ea75-42a0-a095-cc33e3787673",
                "timestamp": "2017-07-25T18:37:38.374Z",<commit_msg>context out doesn't work with speech<commit_after>'use strict';

const express = require('express');
const bodyParser = require('body-parser');

const data=[
  {
    "country": "Israel",
    "cost_of_live": "500",
    "cities": [
      {
        "name": "<NAME>",
        "cost_of_live": "320",
        "cost_of_rent":[
            {
                "type_of_flat":"entire flat",
                "cost_employee": "1500",
                "cost_general": "1600",
            },
            {
                "type_of_flat":"private room",
                "cost_employee": "500",
                "cost_general": "600",
            },
            {
                "type_of_flat":"shared room",
                "cost_employee": "300",
                "cost_general": "300",
            }

        ]
      }
    ]
  },
  {
    "country": "UK",
    "cost_of_live": "500",
    "cities": [
      {
        "name": "London",
        "cost_of_live": "800"
      },
      {
        "name": "Liverpool",
        "cost_of_live": "400"
      },
      {
        "name": "Oxford",
        "cost_of_live": "500"
      }
    ]
  },
  {
    "country": "Germany",
    "cost_of_live": "300",
    "cities": [
      {
        "name": "Berlin",
        "cost_of_live": "500"
      },
      {
        "name": "Munich",
        "cost_of_live": "200"
      }
    ]
  }
];

const restService = express();
restService.use(bodyParser.json());

var func=function (req, res) {

    console.log('hook request');

    try {
        var speech = 'empty speech';
        let  cost_of_live="Unknown";

        if (req.body) {
            var requestBody = req.body;

            if (requestBody.result) {
                speech = '';

                if (requestBody.result.action=="input.city") {
                    if (requestBody.result.parameters) {
                        if (requestBody.result.parameters["geo-city"]) {
                            let  cost_of_live="Unknown";
                            data.forEach(function(element) {
                                element.cities.forEach(function(city) {
                                    if(requestBody.result.parameters["geo-city"]==city.name){
                                        cost_of_live=city.cost_of_live; 
                                    }
                                }); 
                            });

                            speech="cost of living in " +requestBody.result.parameters["geo-city"]+ " is "+cost_of_live+"GBP per month ";
                        }
                        else{
                            speech="no geo-city"
                        }
                    }
                    else{
                        speech="no parameters"
                    }
                }
                if (requestBody.result.action=="input.city") {
                    if (requestBody.result.parameters) {
                        if (requestBody.result.parameters["geo-city"]) {
                            data.forEach(function(element) {
                                element.cities.forEach(function(city) {
                                    if(requestBody.result.parameters["geo-city"]==city.name){
                                        cost_of_live=city.cost_of_live; 
                                    }
                                }); 
                            });

                            speech="cost of living in " +requestBody.result.parameters["geo-city"]+ " is "+cost_of_live+"GBP per month ";
                        }
                        else{
                            speech="no geo-city"
                        }
                    }
                    else{
                        speech="no parameters"
                    }
                }
                else{
                    speech="no action"
                }
            }
        }

        console.log('result: ', speech);

        return res.json({
            speech: speech,
            displayText: speech,
            source: 'apiai-webhook-sample',
            contextOut: [{"name":"datakeeper", "lifespan":99, "parameters":{"cost_of_live":cost_of_live,"cost_of_live_in":requestBody.result.parameters["geo-city"]}}]
        });
    } catch (err) {
        console.error("Can't process request", err);

        return res.status(400).json({
            status: {
                code: 400,
                errorType: err.message
            }
        });
    }
}


restService.get('/hook',function(req,res) {
    var req={"body":
                    {
                "id": "8f89439f-ea75-42a0-a095-cc33e3787673",
                "timestamp": "2017-07-25T18:37:38.374Z",
{'fraction_non_alphanumeric': 0.1292853304674906, 'fraction_numerical': 0.02041912950026867, 'mean_word_length': 1.0652463382157125, 'pattern_counts': {'":': 78, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3531910', 'n_tokens_mistral': 2688, 'n_tokens_neox': 2414, 'n_words': 368}