# Word similarity calculation
This interface, from the plug-in 1.1.3 Start Support
Word similarity calculation. The input is two words and the output is the similarity of the two words Examples: Input: ShanghaiBeijing Output: 0.6184172034263611
# to initialize
Plugin version number in the document, only for example reference, the latest version of the plugin,Subject to this
{
"pages": [
"pages/index/index"
],
"plugins": {
"chatbot": {
"version": "1.2.23",
"provider": "wx8c631f7e9f2465e1"
}
},
"requiredBackgroundModes": [
"audio"
],
"sitemapLocation": "sitemap.json"
}
var plugin = requirePlugin("chatbot")
App({
onLaunch: function () {
plugin.init({
appid: "P5Ot9PHJDechCYqDFAW1AiK6OtG3Ja", //Mini Program sample account, for learning and reference only
openid: "", //User's openid, not required, it is recommended to pass this parameter
success: () => {}, //Not required
fail: (error) => {}, //Not required
})
},
})
# Call the Text Similarity Interface
const txt1 = "Shanghai" //Input text, UTF-8 encoding
const txt2 = "Beijing" //Input text, UTF-8 encoding
plugin.api.wordSim(txt1, txt2).then((nothing) => {
console.log("sentenceSim result : ", nothing)
})
# Dxplaination of parameters:
field | type | describe |
---|---|---|
txt1 | string | Input Text, UTF-8 coding |
txt2 | string | Input Text, UTF-8 coding |
# Similarity results
{
"similarity": 0.6184172034263611
}
# Return value:
field | type | describe |
---|---|---|
similarity | float | The likelihood that two words are similar |