

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 创建同义词库文件
<a name="index-synonyms-creating-thesaurus-file"></a>

 Amazon Kendra 同义词库文件是一个 UTF-8 编码的文件，其中包含 Solr 同义词列表格式的同义词列表。同义词库文件必须小于 5 MB。

指定同义词映射的方法有两种：
+ *双向同义词*是逗号分隔的词汇列表。如果您的用户查询任何词汇，则列表中的所有词汇都将用于搜索文档，其中包括原始查询词。
+ *单向同义词*是用符号 “=>” 分隔的词汇，意思是将词汇映射到其同义词。如果用户查询符号 “=>” 左边的词汇，则该词汇会映射到右边的词汇以使用同义词搜索文档。反之亦然，它不被映射，因而是单向的。

同义词本身区分大小写，但它们映射到的词汇不区分大小写。例如，`ML => Machine Learning` 表示如果您的用户查询“ML”或“ml”或使用其他大小写，它将映射到 “Machine Learning”。反之，如果您要这样映射 `Machine Learning => ML`，那么“Machine Learning”、“machine learning”或其他情况将映射到“ML”。

同义词不会搜索特殊字符的完全匹配项。例如，如果搜索 dead-letter-queue “”，则 Amazon Kendra 可以返回与 “死信队列”（无连字符）匹配的文档。如果您的文档包含连字符（例如 dead-letter-queue “”），则会在搜索过程中 Amazon Kendra 处理文档以删除连字符。对于内置于同义词库文件中 Amazon Kendra 且不应包含在同义词库文件中的通用英语同义词术语， Amazon Kendra 可以同时搜索该术语的连字符版本和该术语的非连字符版本。例如，如果您搜索 “第三方” 和 “第三方”，则 Amazon Kendra 返回与这两个术语的任一版本相匹配的文档。

对于包含停用词或常用词的同义词， Amazon Kendra 返回与包括停用词在内的术语匹配的文档。例如，您可以创建同义词规则来映射“on boarding”和“onboarding”。不得单独使用停用词作为同义词。例如，如果搜索 “on”，则 Amazon Kendra 无法返回所有包含 “on” 的文档。

搜索也会忽略某些同义词规则。例如，`a => b` 是一条规则，但搜索会将 `a => a` 忽略，不会将其算作规则。

词汇计数是同义词库文件中唯一词汇的数量。下面的示例文件包括术语 `AWS CodeStar`、`ML`、`Machine Learning`、`autoscaling group`、`ASG` 等。

每个同义词库有同义词规则数量上限，每个术语有同义词数量上限。有关更多信息，请参阅 [的配额 Amazon Kendra](quotas.md)。

以下示例显示了一个同义词库文件，其中包含同义词规则。每行都包含一条同义词规则。搜索会忽略空行和注释。

```
# Lines starting with pound are comments and blank lines are ignored.

# Synonym relationships can be defined as unidirectional or bidirectional relationships.

# Unidirection relationships are represented by any term sequence 
# on the left hand side (LHS) of "=>" followed by synonyms on the right hand side (RHS)
CodeStar => AWS CodeStar
# This will map CodeStar to AWS CodeStar, but not vice-versa

# To map terms vice versa
ML => Machine Learning
Machine Learning => ML

# Multiple synonym relationships may be defined in one line as well by comma seperation.
autoscaling group, ASG => Auto Scaling group, autoscaling
# The above is equivalent to:
# autoscaling group => Auto Scaling group, autoscaling
# ASG => Auto Scaling group, autoscaling

# Bi-directional synonyms are comma separated terms with no "=>"
DNS, Route53, Route 53
# DNS, Route53, and Route 53 map to one another and are interchangeable at match time
# The above is equivalent to:
# DNS => Route53, Route 53
# Route53 => DNS, Route 53
# Route 53 => DNS, Route53

# Overlapping LHS terms will be merged
Beta => Alpha
Beta => Gamma
Beta, Delta
# is equivalent to:
# Beta => Alpha, Gamma, Delta
# Delta => Beta

# Each line contains a single synonym rule.
# Synonym rule count is the total number of lines defining synonym relationships
# Term count is the total number of unique terms for all rules.  
# Comments and blanks lines do not count.
```