-
Notifications
You must be signed in to change notification settings - Fork 3.2k
add create_synonym_map_from_file #18811
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
Changes from 2 commits
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 |
|---|---|---|
|
|
@@ -403,7 +403,7 @@ class SynonymMap(msrest.serialization.Model): | |
| :vartype format: str | ||
| :param synonyms: Required. A series of synonym rules in the specified synonym map format. The | ||
| rules must be separated by newlines. | ||
| :type synonyms: str | ||
| :type synonyms: list[str] | ||
| :param encryption_key: A description of an encryption key that you create in Azure Key Vault. | ||
| This key is used to provide an additional level of encryption-at-rest for your data when you | ||
| want full assurance that no one, not even Microsoft, can decrypt your data in Azure Cognitive | ||
|
|
@@ -463,6 +463,16 @@ def _from_generated(cls, synonym_map): | |
| e_tag=synonym_map.e_tag | ||
| ) | ||
|
|
||
| @classmethod | ||
| def create_from_file(cls, name, file_path): | ||
| f = open(file_path, "r") | ||
| solr_format_synonyms = f.read() | ||
| synonyms = solr_format_synonyms.split("\n") | ||
|
||
| return cls( | ||
| name=name, | ||
| synonyms=synonyms | ||
| ) | ||
|
|
||
| class SearchIndexerDataSourceConnection(msrest.serialization.Model): | ||
| """Represents a datasource connection definition, which can be used to configure an indexer. | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| USA, United States, United States of America | ||
| Washington, Wash. => WA |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # ------------------------------------ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
| # ------------------------------------ | ||
| from os.path import dirname, join, realpath | ||
| from azure.search.documents.indexes.models import SynonymMap | ||
|
|
||
| def test_create_synonym_map_from_file(): | ||
| CWD = dirname(realpath(__file__)) | ||
| path = join(CWD, "synonym_map.txt") | ||
| synonym_map = SynonymMap.create_from_file('test', path) | ||
| assert len(synonym_map.synonyms) == 2 | ||
| assert synonym_map.synonyms[0] == 'USA, United States, United States of America' | ||
| assert synonym_map.synonyms[1] == 'Washington, Wash. => WA' |
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.
I think it might make sense to open the file in a context manager so the file gets closed