2016-04-21 80 views
0

因此,我試圖在使用IBM Concept Insights上的Curl的查詢上傳遞多個ids(「概念數組」)。根據本網站上的文檔,我應該能夠做到這一點,但我不知道如何使其工作 - >http://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/concept-insights/api/v2/?curl#conceptual_searchIBM Watson概念洞察使用Curl進行概念搜索將多個/ ID數組作爲參數

如果我使用鏈接上的「示例請求」,並將其修改爲最少在同一個get data命令上添加另一個查詢,這是我認爲它會工作的方式。

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" 

當我輸入該命令時,我沒有得到任何結果。甚至沒有錯誤。

有什麼想法?

請不要指出顯而易見的......當然,我用我的憑據替換「{用戶名}」:「{密碼}」。 :)

回答

1

而不是-d "ids=..."你應該使用--data-urlencode "ids=..."

這應該工作:

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" 
+0

這個伎倆! – blacknred0

0

在你的榜樣,ids來發送的身體在POST請求的一部分,但API希望它是在查詢和請求是GET

嘗試下面的curl命令:

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的概念搜索。

輸出:

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

你需要URL編碼JSON數組所以下面的概念:

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

使用在線URL編碼器一樣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 

最後使用ids=<encoded array>作爲URL的一部分。

+1

感謝,德語!有道理。可能需要更新IBM文檔來說明是否會使用多個ID,然後需要將JSON數組編碼爲URL使用。 – blacknred0