Wikipedia api with Plain Text Search Results

How to use the Wikipedia api to produce search responses as plain text and display the result in a Label.

How to use the Wikipedia api to produce html search responses using the WebViewer is discussed in Making sense of the Wikipedia API - #4 by SteveJG .

wikipediaChristmas

The Wikipedia api with Plain Text Search Results app shows how to display search results as text.

The example Making sense of the Wikipedia API - #4 by SteveJG produces a WebViewer html and can not produce plain text. I discovered a version of the Wikipedia api is able to search a topic and produce plain text output in a Label by modifying the original App Inventor Wikipedia example api calls.

When the output is text, the search result can be read out loud using the TextToSpeech object. The example app allows a user to listen to the search result. Buttons are used to start and stop reading.

The original App Inventor Wikipedia api example returns multiple search results and a List of urls with the search results. This search method produces a single result topic in plain text.

The search with text results is based on Method 3 described in API:Get the contents of a page - MediaWiki . One of the two other search Methods described in the link might be useful to return multiple search results as text. I tried the other methods and had difficulty parsing the output. Experiment and you might have better results. If you are successful, please post your solution to share with the community.

Coding

Searching using Method 3, the first letter of the search string must be capitalized. For example, a search for "pet door" requires the user input Pet door , not pet door. The app properly capitalizes the first letter of the search string with the code in the join Block. The code formats the content of the TextBox1 allowing you to properly format the search query.

The api Query and Dictionary to Display the Search Result

Is the ability to return search results as text useful?

The example is the basis for an app for individuals with vision impairment. Include a SpeechRecognizer to the app and a blind person might be able to use it to search.

Speech input is not part of the example code. By vocalizing the search criteria it should be possible to post the search criteria to TextBox1. If you need this ability, code your solution and post your version of the app here.

Notes:

  • Not all search terms will produce results. This is not a Google search and is less robust because it searches only the Wikipedia data base.
  • Experiment with the various methods recommended in the api documents. The method shown results in a Get response that can be parsed.
  • The example code was tested on both an Android 8.1 tablet and an Android 11 phone.

wikipediaDictionary2.aia (101.3 KB)

I hope developers of apps for the visually impaired will find this example useful and will experiment with the &exsentences=10 setting and other settings to improve results.

Regards,
Steve

7 Likes

It's amazing, it's perfect, it's a nice to talk with you and the community. I will continue to contribute what I can. Thank you so much for everything.

3 Likes