gpt4 book ai didi

javascript - 如何识别字符串中的某些单词并返回结果? (AngularJS)

转载 作者:行者123 更新时间:2023-12-03 05:10:15 28 4
gpt4 key购买 nike

我正在尝试从谷歌云API识别某些单词后返回结果,例如有关它的信息。我只是将硬编码结果返回到应用程序。

例如,使用谷歌云文本API,应用程序将返回Panadol盒子上的文本字符串。在字符串中,他们将识别单词“panadol”并显示结果,例如描述。

这是我从以下网站获得的谷歌云 API 教程: https://www.sitepoint.com/image-recognition-with-the-google-vision-api-and-ionic/

index.html:

这里将显示返回:

listCtrl.image_description 是来自 Google Cloud Api 的字符串listCtrl.identify_result为识别后的描述

<h3 class="text-center" ng-show="listCtrl.image_description"> {{ listCtrl.image_description }}</h3>
<h3 class="text-center" ng-show="listCtrl.identify_result"> {{ listCtrl.product_result }}</h3>

homecontroller.js:

res.responses[0][key][0].description为API返回的结果

 var key = me.detection_types[me.detection_type] + 'Annotations';
me.image_description = res.responses[0][key][0].description;

这是我用来识别的代码,但它不起作用

function contains(str,text) {
return str.indexOf(text) >= 0 ;
}
if (contains(res.responses[0][key][0].description,'panadol')){
me.product_word = 'Panadol is a drug';
}

App.js

nameApp.factory('Authorization', function() {

authorization = {};
authorization.image_description = '';
authorization.product_result = '';

return authorization;
});

nameApp.controller('listCtrl', function($scope, Authorization) {
$scope.test = Authorization;
});

任何有关创建函数的帮助将不胜感激。谢谢!

当前错误:res 未定义

最佳答案

已经解决了。

通过将 Controller 中的代码移至响应下方即可解决此问题。感谢大家的帮助:)

 function contains(str,text) {
return str.indexOf(text) >= 0 ;
}
if (contains(me.image_description,'panadol')){
me.product_result = 'test';

}

关于javascript - 如何识别字符串中的某些单词并返回结果? (AngularJS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41853501/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com