使用Postman测试Azure Translator的词典功能
分类: Azure翻译服务 ◆ 标签: #Azure #翻译 #Translator ◆ 发布于: 2023-06-15 21:03:17

我们前面已经学习了Azure Translator
的文本翻译,音译,断句,语言选择等等功能,我们本章来学习词典功能。
词典功能主要提供两个功能:
- 查词:单词或者短语查询,英译汉,汉译英等等。
- 词语例句:查词并显示该词的使用例句。
理解为词典功能就很容易理解了。
我们先来快速的使用postman
观察一波,至于怎么设置postman
, 请参考一下之前的文章。
请求接口:
/dictionary/lookup?api-version=3.0&from=en&to=zh-hans
这是标准的英译汉了。
request body
:
[ { "Text": "mutable" } ]
发送请求之后,请求的结果:
[ { "normalizedSource": "mutable", "displaySource": "mutable", "translations": [ { "normalizedTarget": "可变", "displayTarget": "可变", "posTag": "ADJ", "confidence": 1.0, "prefixWord": "", "backTranslations": [ { "normalizedText": "variable", "displayText": "variable", "numExamples": 15, "frequencyCount": 1312 }, { "normalizedText": "mutable", "displayText": "mutable", "numExamples": 5, "frequencyCount": 72 }, { "normalizedText": "variability", "displayText": "variability", "numExamples": 8, "frequencyCount": 69 }, { "normalizedText": "changeable", "displayText": "changeable", "numExamples": 5, "frequencyCount": 57 }, { "normalizedText": "alterable", "displayText": "alterable", "numExamples": 4, "frequencyCount": 21 }, { "normalizedText": "volatile", "displayText": "volatile", "numExamples": 0, "frequencyCount": 18 }, { "normalizedText": "adjustable", "displayText": "adjustable", "numExamples": 3, "frequencyCount": 15 } ] } ] } ]
关于返回结果里有一个属性很重要,posTag
用来表示这个词是什么类型的词,例如动词,形容词等等。
详细的解释可以参考文档:https://docs.microsoft.com/en-us/azure/cognitive-services/translator/reference/v3-0-dictionary-lookup,
另外返回结果中的属性:translations
->normalizedTarget
是用于lookup example
的输入的。
查词例句
我们叫查词例句,官方叫lookup example
, 上面已经说了,它的输入是什么了。我们继续看endpoint:
请求接口:
/dictionary/examples?api-version=3.0&from=en&to=zh-hans
需要注意的是request body
:
[ { "Text": "mutable", "Translation": "可变" } ]
然后观察一下它的返回结果:
[ { "normalizedSource": "mutable", "normalizedTarget": "可变", "examples": [ { "sourcePrefix": "It would likely not force you to use ", "sourceTerm": "mutable", "sourceSuffix": " objects.", "targetPrefix": "它不强迫你用", "targetTerm": "可变", "targetSuffix": "的对象。" }, { "sourcePrefix": "These values are always called ", "sourceTerm": "mutable", "sourceSuffix": ".", "targetPrefix": "这些价值往往被称之为", "targetTerm": "可变", "targetSuffix": "的。" }, { "sourcePrefix": "The current as complex and ", "sourceTerm": "mutable", "sourceSuffix": " as human life.", "targetPrefix": "复杂和人类生活的", "targetTerm": "可变", "targetSuffix": "电流。" }, { "sourcePrefix": "", "sourceTerm": "Mutable", "sourceSuffix": " state and locks are problematic for many reasons.", "targetPrefix": "出于多种原因,", "targetTerm": "可变", "targetSuffix": "状态和锁容易出问题。" }, { "sourcePrefix": "Every object is always ", "sourceTerm": "mutable", "sourceSuffix": ".", "targetPrefix": "所有对象都是", "targetTerm": "可变", "targetSuffix": "的。" } ] } ]
可以看到不仅仅有英文的例子,还有翻译后例子。