# Sentence similarity calculation
This interface, from the plug-in 1.1.8 Start Support
Sentence similarity calculation and ordering. Input a reference sentence and several candidate sentences, the service can calculate the semantic similarity between each candidate sentence and reference sentence, and arrange the candidate sentences in descending order of similarity.
# 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 sentence similarity calculation interface
const txt = "Beijing to Shanghai train ticket"
plugin.api.nlp('rank', {query: txt, candidates: [
{text: "Shanghai to Beijing train ticket"},
{text: "Beijing to Shanghai air ticket"},
{text: "Beijing to Shanghai high-speed rail ticket"}
]}).then(nothing => {
console.log("rank result : ", nothing)
})
# Request parameters
field | type | describe |
---|---|---|
q | string | Input Text, UTF-8 Encoding, with a maximum length of 1024 The word |
candidates | Array | ["candidates to be compared," " Contain 1 One or more sentences "] |
# Return to Results
name | type | Introductions |
---|---|---|
results | list | The similarity of each candidate is scored, in descending order of scoring |
exact_match | bool | Are there any exact match The candidate |
Example:
{
"error": "",
"results": [
{
"question": "Beijing to Shanghai high-speed rail ticket,"
"score": 0.9875847458814624
},
{
"question": "flight tickets from Beijing to shanghai,"
"score": 0.9707289708500416
},
{
"question": "shanghai to Beijing train ticket,"
"score": 0.9169014875286918
}
],
"exact_match " : false
}