MediaWiki查询和/或WikidataQuery来查找维基百科文章 [英] MediaWiki Query and/or WikidataQuery to find Wikipedia article

查看:774
本文介绍了MediaWiki查询和/或WikidataQuery来查找维基百科文章的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与AngularJS相比,这不是一个关于维基媒体和维基数据查询API的问题。

虽然我想在做一个不是问题的特定查询后,在AngularJS中显示维基百科文章的内容。我已经知道如何显示它......问题在于搜索文章或文章。



我试图通过历史事件日期查询维基百科以及地理位置。



让我们挑选一个随机事件,任何事件。比如说1986年莫桑比克图波列夫图-134撞车。链接: http://en.wikipedia.org/wiki/1986_Mozambican_Tupolev_Tu-134_crash p>

从文章中,我可以看到确切日期: 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] 

$ b

它返回这个:


{status:{error: OK,items: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]}

使用wikidata的查询工具:

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



我可以看到 950273 代表文章以某种方式。我只是不确定如何使用它来将我引导到wikipedia中的实际文章。



我不知道 items是什么:[950273 ] 表示,或者如何使用它来使我能够访问维基百科文章并在AngularJS中显示该文章的内容。



有没有办法按历史事件的日期以及地理位置查询,可以使用mediawiki或wikidata或两者的组合? $ b

编辑:
这是我上面问题的解决方案,它看起来有点像黑客......但它起作用了,现在已经足够了。控制器。
$ b $

  .controller('WikiQueryCtrl',['$ scope','$ http',function($ scope,$ http){
$ http({
//这些地理坐标和日期范围最终将是动态的。
url:'https://wdq.wmflabs.org/api?q= AROUND [625,-25.911389,31.957222,5]%20于是%20BETWEEN [585,1985,1987]&安培; CAL lback = 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&回调= 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'

})。成功(函数(response4){
var query = response4.query;
var pageID = respons e4.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;
});
});
});
}]);


解决方案

950273 是维基数据实体ID。您可以在 https://www.wikidata.org/wiki/Q950273 找到实体本身。



通过使用它,您可以使用API​​和动作 wbgetentities 查询连接到它的文章的维基数据并请求 sitelinks 附加链接/ url 像这样: http://wikidata.org/w/api.php?action=wbgetentities&format=json& ids = Q950273& props = sitelinks%7Csitelinks%2Furls



或者尝试直接使用特选语言版本:GoToLinkedPage。例如。 https://www.wikidata.org/wiki/Special:GoToLinkedPage/enwiki/Q950273


This isn't so much a question abut AngularJS as it is about the Wikimedia and Wikidata query API's.

Although I am trying to display the content of a Wikipedia article in AngularJS after doing a certain query that isn't the problem. I already know how to display it... the problem is the search for an article or articles.

I'm trying to query Wikipedia by historical event date as well as by geo-location.

Let's pick a random event, any event. Let's say "1986 Mozambican Tupolev Tu-134 crash". Link: http://en.wikipedia.org/wiki/1986_Mozambican_Tupolev_Tu-134_crash

From the article, I can see the exact date: 19 October 1986
as well as the geo-location of the event: -25.911389, 31.957222

I'm trying to build a search in AngularJS that can use either a date-range and/or geolocation coordinates to find an event.

I am aware that mediawiki has a geolocation API now, and I am able to find the above event by either keyword or coordinates. The result also turns up any other articles that exist within a certain radius around it using this:

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

However, there is no way to do a search with mediawiki by a point in time or the date of the event.

Wikidata on the other hand has two methods of searching data... it has a date range as well as geolocation.

However, when a query is run, I have no idea what is being returned.

For example, when I use this query string:

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

it returns this:

{"status":{"error":"OK","items":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]}

Using wikidata's query tool:

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

I can see that 950273 represents the article in some way. I'm just not sure how to use that to direct me to the actual article in wikipedia.

I don't know what "items": [950273]" represents, or how to use it to get me to the wikipedia article and display the contents of that article in AngularJS.

Is there a way to do both a query by date of the historical event as well as by geolocation. Either by using mediawiki or wikidata or a combination of the two?


EDIT: This is the solution to my question above. It seems like a bit of a hack... but it works. Good enough for now. Here is my controller.

.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;
                    });
                });
        });
}]);

解决方案

950273 is the Wikidata entity ID. You find the entity itself at https://www.wikidata.org/wiki/Q950273

By using that you can query Wikidata for the articles connected to it using the API and the action wbgetentities and ask for sitelinks and sitelinks/url like this: http://wikidata.org/w/api.php?action=wbgetentities&format=json&ids=Q950273&props=sitelinks%7Csitelinks%2Furls

Or try going to the language version of your choice directly using Special:GoToLinkedPage. Eg. https://www.wikidata.org/wiki/Special:GoToLinkedPage/enwiki/Q950273

这篇关于MediaWiki查询和/或WikidataQuery来查找维基百科文章的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆