Wikipedia search, problem with re-searching the first results
in
Programming Questions
•
2 months ago
Dear all readers,
I'm currently working on a tool that looks up related topics with the Wikipedia API.
The idea:
Search for one topic to get back related topics. Then these related topics should also be used in a new search. These words should also send back their related topics.
The next code does only the first part (getting all the results for one keyword):
I'm currently working on a tool that looks up related topics with the Wikipedia API.
The idea:
Search for one topic to get back related topics. Then these related topics should also be used in a new search. These words should also send back their related topics.
The next code does only the first part (getting all the results for one keyword):
- XML myXML;
- XML[] links;
- String keyword = "anders";
- String query;
- String search1;
- String search2;
- XML myXML2;
- XML[] links2;
- void setup() {
- }
- void draw() {
- query = "http://nl.wikipedia.org/w/api.php?titles="+keyword+"&format=xml&action=query&prop=links&pllimit=500";
- try {
- myXML = loadXML(query);
- links = myXML.getChildren("query/pages/page/links/pl");
- for (int i = 0; i < links.length; i++) {
- String title = links[i].getString("title");
- search1 = search1+","+title;
- }
- }
- catch (Exception exception) {
- println(exception);
- }
- println(search1);
- noLoop();
- }
This code should get the result of the first word, and then uses the results to search again, so every result of the first search should be a keyword to get results from.
- XML myXML;
- XML[] links;
- String keyword = "anders";
- String query;
- String search1;
- String search2;
- XML myXML2;
- XML[] links2;
- void setup() {
- }
- void draw() {
- query = "http://nl.wikipedia.org/w/api.php?titles="+keyword+"&format=xml&action=query&prop=links&pllimit=500";
- try {
- myXML = loadXML(query);
- links = myXML.getChildren("query/pages/page/links/pl");
- for (int i = 0; i < links.length; i++) {
- String title = links[i].getString("title");
- search1 = search1+","+title;
- }
- }
- catch (Exception exception) {
- println(exception);
- }
- String[] search1_results = split(search1, ',');
- for (int i = 0; i < search1_results.length; i++) {
- query = "http://nl.wikipedia.org/w/api.php?titles="+search1_results[i]+"&format=xml&action=query&prop=links&pllimit=500";
- myXML2 = loadXML(query);
- links = myXML.getChildren("query/pages/page/links/pl");
- for (int i2 = 0; i2 < links.length; i2++) {
- String title = links[i2].getString("title");
- search2 = search1+","+title;
- }
- }
- println(search1);
- }
The code above, however, is not working. I can't see what I'm doing wrong at this point. Hope you can help me out with this code.
Best,
Joshua
1