-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CHECK-2437 add support for using analyzers by language #258
Changes from all commits
bd7f88e
14f7a9b
75c32b2
dbfe4d8
2474023
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,183 @@ | ||
import json | ||
from elasticsearch import Elasticsearch | ||
from flask import request, current_app as app | ||
SUPPORTED_LANGUAGES = ["en", "pt", "es", "hi", "bn"] | ||
#via https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-lang-analyzer.html#bengali-analyzer | ||
SETTINGS_BY_LANGUAGE = { | ||
"en": { | ||
"analysis": { | ||
"filter": { | ||
"english_stop": { | ||
"type": "stop", | ||
"stopwords": "_english_" | ||
}, | ||
"english_keywords": { | ||
"type": "keyword_marker", | ||
"keywords": ["example"] | ||
}, | ||
"english_stemmer": { | ||
"type": "stemmer", | ||
"language": "english" | ||
}, | ||
"english_possessive_stemmer": { | ||
"type": "stemmer", | ||
"language": "possessive_english" | ||
} | ||
}, | ||
"analyzer": { | ||
"rebuilt_english": { | ||
"tokenizer": "standard", | ||
"filter": [ | ||
"english_possessive_stemmer", | ||
"lowercase", | ||
"english_stop", | ||
"english_keywords", | ||
"english_stemmer" | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"es": { | ||
DGaffney marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"analysis": { | ||
"filter": { | ||
"spanish_stop": { | ||
"type": "stop", | ||
"stopwords": "_spanish_" | ||
}, | ||
"spanish_keywords": { | ||
"type": "keyword_marker", | ||
"keywords": ["ejemplo"] | ||
}, | ||
"spanish_stemmer": { | ||
"type": "stemmer", | ||
"language": "light_spanish" | ||
} | ||
}, | ||
"analyzer": { | ||
"rebuilt_spanish": { | ||
"tokenizer": "standard", | ||
"filter": [ | ||
"lowercase", | ||
"spanish_stop", | ||
"spanish_keywords", | ||
"spanish_stemmer" | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"pt": { | ||
DGaffney marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"analysis": { | ||
"filter": { | ||
"portuguese_stop": { | ||
"type": "stop", | ||
"stopwords": "_portuguese_" | ||
}, | ||
"portuguese_keywords": { | ||
"type": "keyword_marker", | ||
"keywords": ["exemplo"] | ||
}, | ||
"portuguese_stemmer": { | ||
"type": "stemmer", | ||
"language": "light_portuguese" | ||
} | ||
}, | ||
"analyzer": { | ||
"rebuilt_portuguese": { | ||
"tokenizer": "standard", | ||
"filter": [ | ||
"lowercase", | ||
"portuguese_stop", | ||
"portuguese_keywords", | ||
"portuguese_stemmer" | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"hi": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar blocks of code found in 2 locations. Consider refactoring. |
||
"analysis": { | ||
"filter": { | ||
"hindi_stop": { | ||
"type": "stop", | ||
"stopwords": "_hindi_" | ||
}, | ||
"hindi_keywords": { | ||
"type": "keyword_marker", | ||
"keywords": ["उदाहरण"] | ||
}, | ||
"hindi_stemmer": { | ||
"type": "stemmer", | ||
"language": "hindi" | ||
} | ||
}, | ||
"analyzer": { | ||
"rebuilt_hindi": { | ||
"tokenizer": "standard", | ||
"filter": [ | ||
"lowercase", | ||
"decimal_digit", | ||
"hindi_keywords", | ||
"indic_normalization", | ||
"hindi_normalization", | ||
"hindi_stop", | ||
"hindi_stemmer" | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"bn": { | ||
DGaffney marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"analysis": { | ||
"filter": { | ||
"bengali_stop": { | ||
"type": "stop", | ||
"stopwords": "_bengali_" | ||
}, | ||
"bengali_keywords": { | ||
"type": "keyword_marker", | ||
"keywords": ["উদাহরণ"] | ||
}, | ||
"bengali_stemmer": { | ||
"type": "stemmer", | ||
"language": "bengali" | ||
} | ||
}, | ||
"analyzer": { | ||
"rebuilt_bengali": { | ||
"tokenizer": "standard", | ||
"filter": [ | ||
"lowercase", | ||
"decimal_digit", | ||
"bengali_keywords", | ||
"indic_normalization", | ||
"bengali_normalization", | ||
"bengali_stop", | ||
"bengali_stemmer" | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
def init_indices(): | ||
es = Elasticsearch(app.config['ELASTICSEARCH_URL']) | ||
indices = es.cat.indices(h='index', s='index').split() | ||
for lang in SUPPORTED_LANGUAGES: | ||
index_name = app.config['ELASTICSEARCH_SIMILARITY'] "_" lang | ||
if index_name not in indices: | ||
es.indices.create(index=index_name) | ||
es.indices.close(index=index_name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bad indentation. Found 4 spaces, expected 8 |
||
es.indices.put_mapping( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bad indentation. Found 4 spaces, expected 8 |
||
body=json.load(open('./elasticsearch/alegre_similarity_base.json')), | ||
# include_type_name=True, | ||
index=index_name | ||
) | ||
es.indices.put_settings( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bad indentation. Found 4 spaces, expected 8 |
||
body=SETTINGS_BY_LANGUAGE['pt'], | ||
# include_type_name=True, | ||
index=index_name | ||
) | ||
es.indices.open(index=index_name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bad indentation. Found 4 spaces, expected 8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unable to import 'flask'