Skip to content

Commit

Permalink
Added a simple darft for Wikidata APi requests
Browse files Browse the repository at this point in the history
Task: #9
  • Loading branch information
eldur committed Feb 18, 2014
1 parent 2806785 commit 74970a3
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@ public ApiRequestBuilder action(String action) {
return this;
}

/**
* @deprecated use json instead (you have to change response handling)
*/
@Deprecated
public ApiRequestBuilder formatXml() {
param("format", "xml");
return this;
}

public ApiRequestBuilder formatJson() {
param("format", "json");
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package net.sourceforge.jwbf.mediawiki.wikidata;

import static org.junit.Assert.assertEquals;
import net.sourceforge.jwbf.TestHelper;
import net.sourceforge.jwbf.core.actions.Get;
import net.sourceforge.jwbf.core.actions.util.HttpAction;
import net.sourceforge.jwbf.mediawiki.ApiRequestBuilder;
import net.sourceforge.jwbf.mediawiki.actions.util.MWAction;
import net.sourceforge.jwbf.mediawiki.bots.MediaWikiBot;

import org.junit.Test;

public class WikiDataTest {

@Test
public void test() {
// GIVEN
// TODO do not work with a live system
String wikidataApiLiveUrl = "https://www.wikidata.org/w/api.php";
TestHelper.assumeReachable(wikidataApiLiveUrl); // will skip the test if not
MediaWikiBot bot = new MediaWikiBot(wikidataApiLiveUrl);

// WHEN
GetClaims getClaims = new GetClaims(bot, "Q4115189");
bot.performAction(getClaims);

// THEN
// TODO better assertions
assertEquals("{\"claims\":", getClaims.getResult().substring(0, 10));
}

// TODO extract to file
// TODO what is a claim?

This comment has been minimized.

Copy link
@fer-rum

fer-rum Mar 11, 2014

Short answer:
A claim is a statement made about an item. (Be careful though, since the word statement is also used in this context with a slightly different meaning.)
For example: I do regard the item Berlin then there is a statement group abot what Berlin is an instance of. One particular claim is that Berlin is a city with millions of inhabitants. This claim has a qualifier telling us that this is so since 1877.

If you need further information on this topic feel free to contact me :)

private static class GetClaims extends MWAction {

private final Get buildGet;
private String result = "";

public GetClaims(MediaWikiBot bot, String entity) {
buildGet = new ApiRequestBuilder() //
.action("wbgetclaims") //
.formatJson() //
.param("entity", entity) //
.buildGet();

}

@Override
public String processAllReturningText(String text) {
result = text;
return "doNotCallThis";
}

// TODO this have to be a complex type, not a string
public String getResult() {
return result;
}

@Override
public HttpAction getNextMessage() {
return buildGet;
}

}

}

0 comments on commit 74970a3

Please sign in to comment.