2015-04-23 36 views
1

這不是一個關於AngularJS的問題,因爲它是關於維基媒體和維基數據查詢API的。MediaWiki查詢和/或WikidataQuery查找維基百科文章

雖然我試圖在做一個不是問題的特定查詢後在AngularJS中顯示維基百科文章的內容。我已經知道如何顯示它......問題在於搜索文章或文章。

我試圖通過歷史事件日期以及地理位置來查詢維基百科。

讓我們挑選一個隨機事件,任何事件。讓我們說「1986莫桑比克圖波列夫塗134碰撞」。鏈接:http://en.wikipedia.org/wiki/1986_Mozambican_Tupolev_Tu-134_crash

從文章中,我可以看到的確切日期:1986年10月19日
以及事件的地理位置:-25.911389,31.957222

我想在AngularJS中構建一個可以使用日期範圍和/或地理位置座標來查找事件的搜索。

我知道,mediawiki現在有一個地理位置API,我可以通過關鍵字或座標找到上述事件。結果也變成了周圍一定半徑範圍內的存在利用這一點,任何其他文章:

http://en.wikipedia.org/w/api.php?action=query&list=geosearch&gsradius=10000&gscoord=-25.911389|31.957222&prop=extracts|info&exintro&titles=1986_Mozambican_Tupolev_Tu-134_crash&format=json&explaintext&redirects&inprop=url&indexpageids&format=json&callback=JSON_CALLBACK

但是,有沒有辦法做到MediaWiki的一個時間點或搜索的日期事件。

另一方面,Wikidata有兩種搜索數據的方法......它有一個日期範圍以及地理位置。

但是,查詢運行時,我不知道什麼是返回。

例如,當我使用這個查詢字符串:

https://wdq.wmflabs.org/api?q=AROUND[625,-25.911389,31.957222,5]%20AND%20BETWEEN[585,1985,1987] 

它返回:

{ 「地位」:{ 「錯誤」: 「OK」, 「項目」:1 ,「querytime」:「544ms」,「parsed_query」:「(AROUND [625,-25.9114,31.9572,5] AND BETWEEN [585,+ 00000001985-00-00T00:00:00Z,+ 00000001987-00-00T00 :00:00Z])「},」items「:[950273]}

使用維基數據的查詢工具:

http://tools.wmflabs.org/autolist/autolist1.html?q=AROUND[625,-25.911389,31.957222,5]%20AND%20BETWEEN[585,1985,1987]

我可以看到表示以某種方式的文章。我只是不知道如何使用它來指導我在維基百科的實際文章。

我不知道什麼「條目」:[950273]「代表或如何使用它來使我訪問維基百科文章並在AngularJS中顯示該文章的內容。

有沒有辦法按歷史事件日期查詢以及地理定位。通過使用mediawiki或wikidata或兩者的組合?


編輯: 這是解決上面我的問題。這似乎有點破解...但它的工作原理。現在夠好了。這是我的控制器。

.controller('WikiQueryCtrl', ['$scope', '$http', function($scope, $http) { 
    $http({ 
      //these geo coordinates and the date ranges will eventually be dynamic. 
      url: 'https://wdq.wmflabs.org/api?q=AROUND[625,-25.911389,31.957222,5]%20AND%20BETWEEN[585,1985,1987]&callback=JSON_CALLBACK', 
      method: 'jsonp' 
     }) 
     .success(function(response) { 
      var items = response.items; 
      $scope.jason = items; 
      var wikiDataString = 'http://www.wikidata.org/w/api.php?action=wbgetentities&format=json&ids=Q' + items + '&props=sitelinks%7Csitelinks%2Furls&callback=JSON_CALLBACK'; 
      $http({ 
        url: wikiDataString, 
        method: 'jsonp' 
       }) 
       .success(function(response2) { 
        $scope.jason2 = response2; 
        var url = response2.entities["Q" + items].sitelinks.enwiki.url; 
        var wikipediaTitle = url.substr(24, url.length); 
        var wikipediaURL = 'http://en.wikipedia.org/w/api.php?action=query&prop=extracts|info&exintro&titles=' + wikipediaTitle + '&format=json&explaintext&redirects&inprop=url&indexpageids&format=json&callback=JSON_CALLBACK'; 
        $http({ 
         url: wikipediaURL, 
         method: 'jsonp' 

        }).success(function(response4) { 
         var query = response4.query; 
         var pageID = response4.query.pageids; 
         var title = response4.query.pages[pageID].title; 
         var fullurl = response4.query.pages[pageID].fullurl; 
         var content = response4.query.pages[pageID].extract; 
         $scope.title = title; 
         $scope.content = content; 
         $scope.fullurl = fullurl; 
         $scope.jason = query; 
        }); 
       }); 
     }); 
}]); 

回答

4

是維基數據實體ID。你會發現在https://www.wikidata.org/wiki/Q950273

實體本身使用,你可以使用API​​和行動wbgetentities查詢維基數據用於連接到它的文章,並要求sitelinkssitelinks/url這樣的:http://wikidata.org/w/api.php?action=wbgetentities&format=json&ids=Q950273&props=sitelinks%7Csitelinks%2Furls

或者嘗試去直接使用Special:GoToLinkedPage選擇您選擇的語言版本。例如。 https://www.wikidata.org/wiki/Special:GoToLinkedPage/enwiki/Q950273

+0

你的建議奏效。我花了一段時間才弄清楚如何從步驟A去到C和通過B,但是我做到了。它似乎有點破解,但它的工作原理。我把我的控制器放在「編輯」所在的位置。 – Livi17