Node.js

SDK使用指南

请参考 开始使用

NLP基础服务2.0依赖

npm install @alicloud/alinlp20200629 -S

代码示例

TypeScript

import Client, * as $Alinlp from '@alicloud/alinlp20200629';
import * as $OpenApi from '@alicloud/openapi-client';

export default class Test {
  static async main(): Promise<void> {
    const config = new $OpenApi.Config({
      // 您的AccessKey ID
      accessKeyId: '<your-access-key-id>',
      // 您的AccessKey Secret
      accessKeySecret: '<your-access-key-secret>',
      // 访问的区域
      regionId: 'cn-hangzhou',
      endpoint: 'alinlp.cn-hangzhou.aliyuncs.com'
    });
    const client = new Client(config);
    const request = new $Alinlp.GetNerChEcomRequest({
      serviceCode: "alinlp",
      text: "电动多功能磨浆机"
    });
    const resp = await client.getNerChEcom(request);
    console.log(resp.body);
  }
}

Test.main();

注:代码GetNerChEcomRequest中的GetNerChEcom是算法的actionName,可以替换成您需要的算法的值,可以在API参考文档中的请求参数-Action-示例值中找到;

示例:需要调用基础版-中文分词-通用,进入中文分词(基础版),复制下图中的示例值,将GetNerChEcomRequest替换为GetWsChGeneralRequest替换后要注意算法的请求参数也要更改,参考API文档即可。

actionName值的位置

JavaScript

const { default: Client, GetNerChEcomRequest } = require('@alicloud/alinlp20200629');
const { Config } = require('@alicloud/openapi-client');

async function main() {
  let config = new Config({
    // 您的AccessKey ID
    accessKeyId: '<your-access-key-id>',
    // 您的AccessKey Secret
    accessKeySecret: '<your-access-key-secret>',
    // 访问的区域
    regionId: 'cn-hangzhou',
    endpoint: 'alinlp.cn-hangzhou.aliyuncs.com'
  });
  const client = new Client(config);
  const request = new GetNerChEcomRequest({
    serviceCode: "alinlp",
    text: "电动多功能磨浆机"
  });
  const resp = await client.getNerChEcom(request);
  console.log(resp.body);
}

main();

备注:如需调用其他算法也需要替换代码中的GetNerChEcomRequest,可参考上述中的替换方式。

调用异常自助排查

若调用过程中出现了异常可对照调用异常自助排查(错误码汇总),找到表格中对应的描述,描述中包含具体错误原因和解决方案

阿里云首页 自然语言处理 相关技术圈