3

I am developing an app that lets smartphone users upload a picture to Wikimedia Commons. The user must categorize the picture by typing Commons category names. Typing on a smartphone is slow/painful/erratic, and category names are not obvious, so the app should do its best to guess what category the user is trying to find.

QUESTION: Is there an API that takes a string, and returns 1~10 Commons category names that fuzzy-match the beginning of the string?

Requirements:

  • Response of the server must be very fast (as-you-type)
  • Free, as there is no budget for the app
  • Scalability should not be a problem for now, less than 5 concurrent users at any one time

For instance, Category:Power plants in New Zealand‎ should be found even if the typed string is:

  • Power plants in New Z (as-you-type)
  • power plants in new zealand (lowercase)
  • Power plants in New-Zealand (dash instead of space)
  • Power plant in New Zealand (singular)
  • Pwer plants in New Zeland (typo - ideally)
  • New Zeland power plant (word order - ideally)
3

First variant: MediaWiki API for Commons with search query for pages of type "Category" (srnamespace=14), maximum 10 results (srlimit=10), and searched string your_string:

https://commons.wikimedia.org/w/api.php?action=query&list=search&srwhat=text&srenablerewrites=1&srnamespace=14&srlimit=10&srsearch=your_string

Second variant: MediaWiki API for Commons with opensearch for maximum 10 results (limit=10), and searched string your_string:

https://commons.wikimedia.org/w/api.php?action=opensearch&limit=10&suggest=1&search=Category:your_string

For your example:

  • Power plants in New Z returns the desired category on 1st place for the second variant
  • power plants in new zealand returns the desired category on 1st place for both variants
  • Power plants in New-Zealand returns the desired category on 4th place for the first variant
  • Power plant in New Zealand returns the desired category on 4th place for the first variant
  • Pwer plants in New Zeland and New Zeland power plant returns suggestion for the first variant

I couldn't find something better, so if you want you can make some combination of these two variants or you can do compromise and will use one of them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.