-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
261 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
Dealing with Human Language/Reducing Words to Their Root Form.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Elasticsearch: The Definitive Guide - Python\n", | ||
"\n", | ||
"Following the examples in the book, here are Python snippets that achieve the same effect.\n", | ||
"\n", | ||
"Documentation for the Python libs:\n", | ||
"\n", | ||
"Low-level API:\n", | ||
"\n", | ||
"https://elasticsearch-py.readthedocs.io/en/master/index.html\n", | ||
"\n", | ||
"Expressive DSL API (more \"Pythonic\")\n", | ||
"\n", | ||
"http://elasticsearch-dsl.readthedocs.io/en/latest/index.html\n", | ||
"\n", | ||
"Github repo for DSL API:\n", | ||
"\n", | ||
"https://github.com/elastic/elasticsearch-dsl-py\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import sys, os\n", | ||
"sys.path.insert(1, os.path.join(sys.path[0], '..'))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"14 items created\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import index\n", | ||
"from elasticsearch import Elasticsearch\n", | ||
"from elasticsearch_dsl import Search, Q\n", | ||
"from pprint import pprint\n", | ||
"\n", | ||
"es = Elasticsearch(\n", | ||
" 'localhost',\n", | ||
" # sniff before doing anything\n", | ||
" sniff_on_start=True,\n", | ||
" # refresh nodes after a node fails to respond\n", | ||
" sniff_on_connection_fail=True,\n", | ||
" # and also every 60 seconds\n", | ||
" sniffer_timeout=60\n", | ||
")\n", | ||
"\n", | ||
"r = index.populate()\n", | ||
"print('{} items created'.format(len(r['items'])))\n", | ||
"\n", | ||
"# Let's repopulate the index as we deleted 'gb' in earlier chapters:\n", | ||
"# Run the script: populate.ipynb" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"source": [ | ||
"### Reducing Words to Their Root Form\n", | ||
"\n", | ||
"Most languages of the world are inflected, meaning that words can change their form to express differences in the following:\n", | ||
"\n", | ||
"* Number: fox, foxes\n", | ||
"* Tense: pay, paid, paying\n", | ||
"* Gender: waiter, waitress\n", | ||
"* Person: hear, hears\n", | ||
"* Case: I, me, my\n", | ||
"* Aspect: ate, eaten\n", | ||
"* Mood: so be it, were it so" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": true | ||
}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.5.1" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |