-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a simple darft for Wikidata APi requests
Task: #9
- Loading branch information
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/test/java/net/sourceforge/jwbf/mediawiki/wikidata/WikiDataTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Sorry, something went wrong. |
||
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; | ||
} | ||
|
||
} | ||
|
||
} |
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 :)