0

So, I am trying to pass multiple of ids ("Array of concept") on a query using Curl on IBM Concept Insights. According to the documentation on this site, I should be able to do it, but I cannot figure out how to make it work -> http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/concept-insights/api/v2/?curl#conceptual_search

If I use the "example request" prodiveded on the link and modify it to at least add another query on the same get data command, this is how I think it would work.

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"

When I enter that command, I get no results back. Not even an error.

Any thoughts?

Please don't point out the obvious... of course, I am replacing "{username}":"{password}" with my credentials. :)

blacknred0
  • 36
  • 3

2 Answers2

1

Instead of -d "ids=..." you should use --data-urlencode "ids=..."

This should work:

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"
Garrett M
  • 93
  • 1
  • 5
0

In your example, ids is being sent as a part of the body in a POST request but the API expects it to be in the query and the request to be GET.

Try the curl command below:

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"

It will do a conceptual search using two concepts Artificial Intelligence and HTML.

Output:

{
  "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
  }]
}

You need to url encode the json array so for the concepts below:

["/graphs/wikipedia/en-20120601/concepts/Artificial_intelligence", "/graphs/wikipedia/en-20120601/concepts/Machine_learning"]

Using an online URL encoder like http://meyerweb.com/eric/tools/dencoder/

%5B%22%2Fgraphs%2Fwikipedia%2Fen-20120601%2Fconcepts%2FArtificial_intelligence%22%2C%20%22%2Fgraphs%2Fwikipedia%2Fen-20120601%2Fconcepts%HTML%22%5D

Finally use ids=<encoded array> as part of the URL.

German Attanasio
  • 22,217
  • 7
  • 47
  • 63
  • 1
    Thanks, German! That make sense. Maybe the IBM documentation needs to be updated to illustrate if multiple of ids would be used, then would need to have the JSON array encoded for URL use. – blacknred0 Apr 22 '16 at 13:07