Skip to content

Instantly share code, notes, and snippets.

@SnowMasaya
Created November 6, 2016 22:28
Show Gist options
  • Save SnowMasaya/2f10f68dc3f611422bab579cc99ba1b9 to your computer and use it in GitHub Desktop.
Save SnowMasaya/2f10f68dc3f611422bab579cc99ba1b9 to your computer and use it in GitHub Desktop.
AWS Lambda Chat Bot Hackthonに参加して画像検索用のChat Botを作成してみました。 ref: http://qiita.com/GushiSnow/items/3000fd4fc5a94b3e9e72
query = "curl -XGET {your elasticsearch endpoint}:9200/_all/_search?pretty -d\'"
command_text = event['text'].replace("bot_lambda_out ", "")
python execute_wiki_pedia_xml_to_json.py -xml enwiki-20080312-abstract.xml -img True
python execute_wiki_pedia_xml_to_json.py -xml enwiki-20080312-abstract.xml -img True
parallel --linebuffer -j 40-100 :::: jobs.txt
gzip {your git clone folder}/Data/wiki_image/*.json
[vagrant]
{あなたが設定したVagrantのipアドレス(デフォルトは192.168.33.25に設定しています。)} ansible_ssh_private_key_file=.vagrant/machines/default/virtualbox/private_key ansible_ssh_user=vagrant
cd {your git clone folder}/ansible_setting
ansible-playbook -i vagrant_host vagrant_lambda_docker.yml
vagrant reload
vagrant ssh
cd /home/vagrant/AWS_Lambda_Chatbot/docker
make test-elasticsearch-english
docker tag {docker elasticsearch image} elasticsearch_english
docker login
docker tag elasticsearch_english:latest {your docker repository name}:{tag name}
docker push {your docker repository name}:{tag name}
cd {your git clone folder}/ansible_setting
ansible-playbook -i aws_lambda_chatbot_host aws_lambda_chatbot.yml
## convert HTML POST data or HTTP GET query string to JSON
## get the raw post data from the AWS built-in variable and give it a nicer name
#if ($context.httpMethod == "POST")
#set($rawAPIData = $input.path('$'))
#elseif ($context.httpMethod == "GET")
#set($rawAPIData = $input.params().querystring)
#set($rawAPIData = $rawAPIData.toString())
#set($rawAPIDataLength = $rawAPIData.length() - 1)
#set($rawAPIData = $rawAPIData.substring(1, $rawAPIDataLength))
#set($rawAPIData = $rawAPIData.replace(", ", "&"))
#else
#set($rawAPIData = "")
#end
## first we get the number of "&" in the string, this tells us if there is more than one key value pair
#set($countAmpersands = $rawAPIData.length() - $rawAPIData.replace("&", "").length())
## if there are no "&" at all then we have only one key value pair.
## we append an ampersand to the string so that we can tokenise it the same way as multiple kv pairs.
## the "empty" kv pair to the right of the ampersand will be ignored anyway.
#if ($countAmpersands == 0)
#set($rawPostData = $rawAPIData + "&")
#end
## now we tokenise using the ampersand(s)
#set($tokenisedAmpersand = $rawAPIData.split("&"))
## we set up a variable to hold the valid key value pairs
#set($tokenisedEquals = [])
## now we set up a loop to find the valid key value pairs, which must contain only one "="
#foreach( $kvPair in $tokenisedAmpersand )
#set($countEquals = $kvPair.length() - $kvPair.replace("=", "").length())
#if ($countEquals == 1)
#set($kvTokenised = $kvPair.split("="))
#if ($kvTokenised[0].length() > 0)
## we found a valid key value pair. add it to the list.
#set($devNull = $tokenisedEquals.add($kvPair))
#end
#end
#end
## next we set up our loop inside the output structure "{" and "}"
{
#foreach( $kvPair in $tokenisedEquals )
## finally we output the JSON for this pair and append a comma if this isn't the last pair
#set($kvTokenised = $kvPair.split("="))
"$util.urlDecode($kvTokenised[0])" : #if($kvTokenised[1].length() > 0)"$util.urlDecode($kvTokenised[1])"#{else}""#end#if( $foreach.hasNext ),#end
#end
}
ssh -i {your key} ubuntu@{your ip address}
docker login
docker pull {your docker repository name}:{tag name}
git clone https://github.com/SnowMasaya/AWS_Lambda_ChatBot.git
cd {your git clone folder}/Question_Answer
sh elastic_start_english.sh 1 5 True elasticsearch_english
sh elastic_start_english.sh [PIPE_NUMBER] [PARALLEL_NUMBER] [IMAGE_FLAG (True or False)] [ELS_IMAGE_NAME]
query = "curl -XGET {your elasticsearch endpoint}:9200/_all/_search?pretty -d\'"
TYPE=InnoDB;
1: create database enwiki
2: use enwiki
2: source enwiki-20080312-imagelinks.sql
for extract_data in doc:
if extract_data.tag in self.extract_dict_array:
# replace method for title extract
if extract_data.text is not None:
self.index_json.update({ "index" : { "_index" : "wikipedia", "_type" : "contents", "_id" : str(index_count) } })
replace_text = extract_data.text.replace("Wikipedia: ", "")
self.json_data.update({extract_data.tag: replace_text})
if extract_data.tag == "title" and self.image_Flag is True and len(replace_text) > 1:
self.__get_image(replace_text)
else:
self.index_json.update({ "index" : { "_index" : "wikipedia", "_type" : "contents", "_id" : str(index_count) } })
self.json_data.update({extract_data.tag: extract_data.text})
if extract_data.tag == "title" and self.image_Flag is True and len(replace_text) > 1:
self.__get_image(replace_text)
SELECT DISTINCT il_to from imagelinks WHERE (il_to LIKE " + "'" + search_word + "%" + ".jpg')" + "OR" + \
"(il_to LIKE " + "'" + search_word + "%" + ".JPG')" + "order by (il_to = '" + search_word + "') desc"
http://〇〇.jpg
{"index": {"_id": "20", "_index": "wikipedia_image", "_type": "contents"}}
42 {"abstract": "(Arabic)The Pledge", "image": "https://upload.wikimedia.org/wikipedia/commons/d/d4/Algeria%2C_Ottawa.JPG", "title": "Algeria", "url": "http://en.wikipedia.org/wiki/Algeria"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment