首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用Curl传递多个/一个ids数组作为参数

使用Curl传递多个/一个ids数组作为参数
EN

Stack Overflow用户
提问于 2016-04-21 19:41:38
回答 2查看 78关注 0票数 0

因此,我试图在查询上传递多个ids (“概念数组”),使用的是IBM概念洞察上的Curl。根据这个站点上的文档,我应该能够做到这一点,但是我不知道如何使它工作-> search

如果我使用链接上标出的“示例请求”并修改它,至少在同一个get数据命令上添加另一个查询,我认为这就是它的工作方式。

代码语言:javascript
复制
curl -u "{username}":"{password}" -G -d "ids=[\"/graphs/wikipedia/en-20120601/concepts/Artificial_intelligence\", \"/graphs/wikipedia/en-20120601/concepts/HTML\"]" "https://gateway.watsonplatform.net/concept-insights/api/v2/corpora/public/ibmresearcher/conceptual_search"

当我输入该命令时,不会得到任何结果。连一个错误都没有。

有什么想法吗?

请不要指出显而易见的..。当然,我将"{username}":"{password}“替换为我的凭据。:)

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-04-22 14:48:22

而不是-d "ids=...",您应该使用--data-urlencode "ids=..."

这应该是可行的:

代码语言:javascript
复制
curl -u "%ci-username%":"%ci-password%" -G --data-urlencode "ids=[\"/graphs/wikipedia/en-20120601/concepts/Artificial_intelligence\", \"/graphs/wikipedia/en-20120601/concepts/HTML\"]" "https://gateway.watsonplatform.net/concept-insights/api/v2/corpora/public/ibmresearcher/conceptual_search"
票数 1
EN

Stack Overflow用户

发布于 2016-04-22 02:26:46

在您的示例中,ids是在POST请求中作为主体的一部分发送的,但是API希望它在查询中,请求是GET

试试下面的curl命令:

代码语言:javascript
复制
curl  -u "{username}":"{password}" "https://gateway.watsonplatform.net/concept-insights/api/v2/corpora/public/ibmresearcher/conceptual_search?ids=%5B%22%2Fgraphs%2Fwikipedia%2Fen-20120601%2Fconcepts%2FArtificial_intelligence%22%2C%20%22%2Fgraphs%2Fwikipedia%2Fen-20120601%2Fconcepts%HTML%22%5D&cursor=0&limit=10"

它将使用两个概念(、人工智能、HTML )进行概念搜索。

输出:

代码语言:javascript
复制
{
  "query_concepts": [{
    "id": "/graphs/wikipedia/en-20120601/concepts/Artificial_intelligence",
    "label": "Artificial intelligence"
  }, {
    "id": "/graphs/wikipedia/en-20120601/concepts/Machine_learning",
    "label": "Machine learning"
  }],
  "results": [{
    "explanation_tags": [{
      "concept": {
        "id": "/graphs/wikipedia/en-20120601/concepts/Machine_Learning",
        "label": "Machine Learning"
      },
      "score": 0.99816346,
      "parts_index": 0,
      "text_index": [
        1024,
        1089
      ]
    }, {
      "concept": {
        "id": "/graphs/wikipedia/en-20120601/concepts/Machine_Intelligence",
        "label": "Machine Intelligence"
      },
      "score": 0.9945005,
      "parts_index": 0,
      "text_index": [
        2097,
        2117
      ]
    }, {
      "concept": {
        "id": "/graphs/wikipedia/en-20120601/concepts/Artificial_intelligences",
        "label": "Artificial intelligences"
      },
      "score": 0.9945005,
      "parts_index": 0,
      "text_index": [
        2557,
        2580
      ]
    }, {
      "concept": {
        "id": "/graphs/wikipedia/en-20120601/concepts/International_Conference_on_Machine_Learning",
        "label": "International Conference on Machine Learning"
      },
      "score": 0.9817866,
      "parts_index": 0,
      "text_index": [
        2658,
        2712
      ]
    }, {
      "concept": {
        "id": "/graphs/wikipedia/en-20120601/concepts/ICML",
        "label": "ICML"
      },
      "score": 0.9817866,
      "parts_index": 0,
      "text_index": [
        2714,
        2718
      ]
    }, {
      "concept": {
        "id": "/graphs/wikipedia/en-20120601/concepts/Feature_selection",
        "label": "Feature selection"
      },
      "score": 0.97459584,
      "parts_index": 1,
      "text_index": [
        1521,
        1538
      ]
    }],
    "id": "/corpora/public/ibmresearcher/documents/il-NOAMS",
    "label": "Slonim, Noam",
    "score": 0.99739265
  }]
}

您需要对json数组进行url编码,以便对以下概念进行编码:

代码语言:javascript
复制
["/graphs/wikipedia/en-20120601/concepts/Artificial_intelligence", "/graphs/wikipedia/en-20120601/concepts/Machine_learning"]

使用像http://meyerweb.com/eric/tools/dencoder/这样的在线URL编码器

代码语言:javascript
复制
%5B%22%2Fgraphs%2Fwikipedia%2Fen-20120601%2Fconcepts%2FArtificial_intelligence%22%2C%20%22%2Fgraphs%2Fwikipedia%2Fen-20120601%2Fconcepts%HTML%22%5D

最后,使用ids=<encoded array>作为URL的一部分。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36779022

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档