How to return more than one search results by Wikipedia API? - wikipedia-api

I'm trying to fetch results using Wikipedia API. My query is below. I want to fetch 5 results on searched topic. Like if I search "India" it should return 5 search results on India, with 2-3 sentences on each result. I'm trying to limit search results with exlimit but it is not working.
https://en.wikipedia.org/w/api.php?action=query&titles=india&format=jsonfm&prop=extracts&exintro=true&exlimit=5&exsentences=3
This query is returning only one result. I want 10 such results.

By using action=query&titles=india you will get exactly the India Wikipedia page. For your case you need to use search option:
https://en.wikipedia.org/w/api.php?action=query&generator=search&gsrsearch=india&gsrnamespace=0&gsrlimit=5&prop=extracts&exchars=200&exlimit=max&explaintext=1&exintro=1
where gsrlimit=5 is how many results to be returned and exchars=200 is how many characters to be taken from each result.

Related

is it possible to get multiple results sorted by best match?

I need the mapquest geocoding API to return multiple results that best match an incomplete or incorrect address. Is that possible or the API can only return one single result that is correct or not?
The MapQuest Geocode API returns results in the order of the most likely match determined by MapQuest.com usage. If an exact match is found, only one result is returned.

How to Search Amazon using Multiple ASIN in Product URL

Previously, I've successfully used the following URL structure to search Amazon by ASIN:
https://www.amazon.com/s?k=B00DAG60A0+%7CB00DTXA578+%7CB00CIVO9R4+%7CB009SZ2P4C+%7CB00962GUEI
In the past this returned expected results - one product representing each ASIN in URL. However, this no longer works and Amazon either returns a single product for all ASIN(s) or even worse may return message:
No results for..
I tried replacing the '|' with the OR operator but unfortunately the results are the same.
Interestingly, if I search for a single ASIN I get the expected result but when I string together multiple ASIN I get 1 matching product or no results at all.
Is there a way to manipulate the HTTP request / URL structure so that Amazon returns search results matching each ASIN in search query? Any search operators I'm unaware of?
Thanks!
That is because only two of the asins you specified are still available.
For the url you provided I got the two results.

Getting search results from wikidata website, but not API

I'm trying out the wikidata API but have some trouble with the search query "Jas 39 C Gripen". It returns results on the wikidata website, but not if I use the API.
On The wikidata website I get two search results for the query
https://www.wikidata.org/w/index.php?search=Jas+39+C+Gripen&title=Special:Search&fulltext=1
The same query using the API, does not return a result
https://www.wikidata.org/w/api.php?action=wbsearchentities&format=json&language=en&type=item&continue=0&search=Jas%2039%20C%20Gripen
Am I missing some parameters or using the wrong parameters? For many other queries I get results from the API.
It seems that the native Wikidata search applies some "fuzzy logic" when interpreting the user's entries. In your case, it shows two results, although the character C is missing in the first one.
Coming back to the API and the action you have chosen, you could use Jas 39 Gripen as search term (which will show one result) as well as Jas 39C Gripen (which will also show one result). But it seems that you can't use Jas 39 C Gripen (note the space character between 9 and C).
In other words,
https://www.wikidata.org/w/api.php?action=wbsearchentities&format=json&language=en&type=item&continue=0&search=Jas%2039%20Gripen
https://www.wikidata.org/w/api.php?action=wbsearchentities&format=json&language=en&type=item&continue=0&search=Jas%2039C%20Gripen
both work, but
https://www.wikidata.org/w/api.php?action=wbsearchentities&format=json&language=en&type=item&continue=0&search=Jas%2039%20C%20Gripen
does not.
I have investigated this issue further and finally found the solution. Try this:
https://www.wikidata.org/w/api.php?action=query&list=search&format=json&srsearch=Jas+39+C+Gripen
The action query allows some "fuzziness" in the search term. Please refer to the API documentation for further details. In short, this action performs a full text search (which you obviously want) and allows for a nearmatch search type.
The reason seems to be that the English label is JAS 39C Gripen. By removing one space from your query, you will get the result you are looking for:
https://www.wikidata.org/w/api.php?action=wbsearchentities&format=json&language=en&type=item&continue=0&search=Jas%2039C%20Gripen

Freebase API - listing a city's tourist attractions by relevance

I'm trying to use Freebase to list tourist attractions for cities by relevance.
Using the Topic API, it's simple to retrieve results for a certain city using its MID (e.g. "/m/04jpl" for London)
https:// www.googleapis.com/freebase/v1/topic/m/04jpl/?&filter=/travel/travel_destination/tourist_attractions
However, this gives a limited 10 results. The response ends with "count": 87.0". How do I get all 87? It's possible to click a "87 values total" link on London's Freebase page. Effectively, I want to do the same here.
I realise I could use MQL, but I want the results to be ranked by relevance, not by timestamp. Using the Search API, it's possible to rank by freebase, entity or schema, so I'd rather use that.
First, I looked at the Search Output schema for the Search API. However, even outputting "all" didn't produce Tourist Attraction results. Using metaschema with the Search API DID work. I used "part_of" to select London. However, it only works for some locations:
https:// www.googleapis.com/freebase/v1/search?limit=50&filter=(all%20type:/travel/tourist_attraction%20part_of:/m/04jpl)&indent=true
What I REALLY want to be able to do is make it work for a relatively unknown location like "Loughborough" (MID /m/01z21p). As you can see, substituting /m/04jpl for /m/01z21p produces no results:
https:// www.googleapis.com/freebase/v1/search?limit=50&filter=(all%20type:/travel/tourist_attraction%20part_of:/m/01z21p)&indent=true
Looking at "Loughborough", we see that its tourist attraction like "Loughborough Town Hall" has a "/travel/tourist_attraction/near_travel_destination" of "Loughborough". How would I compose this filter?
I want something like the following (that actually works):
https:// www.googleapis.com/freebase/v1/search?limit=50&filter=(all%20type:/travel/tourist_attraction)&filter=(/travel/tourist_attraction/near_travel_destination:/m/01z21p)&indent=true
Thanks!
NOTE: To enter the links into your browser you need to remove the space between the https:// and www. I would have done so, but I don't have the required permissions here yet to post more than 2 links.
I solved this problem using 2 Freebase API calls.
1) An MQL query that gets a list of all the tourist attractions for a particular MID. These results are not ranked in any useful way. I am also returning the result number to make processing a little easier later
https://www.googleapis.com/freebase/v1/mqlread?query={"mid":"/m/04jpl","/travel/travel_destination/tourist_attractions":[{"mid":null}],"resultnumber:/travel/travel_destination/tourist_attractions":[{"return":"count"}]}
The list of returned MIDs are then used to create a new query (using a for loop). You must enter all MIDs returned from the above query, so that they can all be ranked together.
2) https://www.googleapis.com/freebase/v1/search?limit=10&filter=(any%20mid:/m/0gsxw%20mid:/m/01d_0p%20mid:/m/07gyc)&scoring=entity
It's best to choose a return format that just returns MIDs, to ensure that loading times aren't extensive.
You then have a ranked list of MIDs! You'll need one final query to return whatever details you desire.
I hope this has proved helpful.

Query DBpedia for multiple keywords

I want to query DBpedia for multiple keywords, when I query freebase for example using this:
http://api.freebase.com/api/service/search?query=%2BEgypt%2BPyramids
I get reasonable results like: "Egyptian Pyramids", "Ancient Egypt", "Pyramids of Giza (Egypt)".
However whenever I try to query dbpedia with multiple keywords I get an empty ArrayofResult, although when I query for each keyword on its own I do get results..
I couldn't find any documentation for DBpedia's Keyword search service, only this: http://dbpedia.org/lookup
I write the query like this:
http://lookup.dbpedia.org/api/search.asmx/KeywordSearch?QueryClass=place&QueryString=Egypt+pyramid
Is this the right way of doing it?
Don't limit the results with place class, it seems doesn't work
http://lookup.dbpedia.org/api/search.asmx/KeywordSearch?QueryClass=&QueryString=Egyptian%20Pyramids