Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
180 additions
and
33 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
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
72 changes: 72 additions & 0 deletions
72
wdtk-examples/src/main/java/org/wikidata/wdtk/examples/OnlineMediaInfoExample.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,72 @@ | ||
package org.wikidata.wdtk.examples; | ||
|
||
/* | ||
* #%L | ||
* Wikidata Toolkit Examples | ||
* %% | ||
* Copyright (C) 2014 - 2015 Wikidata Toolkit Developers | ||
* %% | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* #L% | ||
*/ | ||
|
||
import org.wikidata.wdtk.datamodel.interfaces.*; | ||
import org.wikidata.wdtk.wikibaseapi.WikibaseDataFetcher; | ||
import org.wikidata.wdtk.wikibaseapi.apierrors.MediaWikiApiErrorException; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* This example shows how to retrieve MediaInfo data from the API. | ||
* | ||
* @author Thomas Pellissier Tanon | ||
* | ||
*/ | ||
public class OnlineMediaInfoExample { | ||
|
||
public static void main(String[] args) throws IOException, MediaWikiApiErrorException { | ||
ExampleHelpers.configureLogging(); | ||
printDocumentation(); | ||
|
||
WikibaseDataFetcher commonsDataFetcher = WikibaseDataFetcher.getWikimediaCommonsDataFetcher(); | ||
WikibaseDataFetcher wikidataDataFetcher = WikibaseDataFetcher.getWikidataDataFetcher(); | ||
|
||
System.out.println("*** Retrieving a media info document ..."); | ||
MediaInfoDocument mediaInfoDocument = (MediaInfoDocument) commonsDataFetcher.getEntityDocumentByTitle("commonswiki", "File:Black hole - Messier 87 crop max res.jpg"); | ||
|
||
// Print the English caption | ||
System.out.println("Caption: " + mediaInfoDocument.getLabels().get("en").getText()); | ||
|
||
// Print the depict with labels from Wikidata: | ||
for(Statement statement : mediaInfoDocument.findStatementGroup("P180").getStatements()) { | ||
Value value = statement.getValue(); | ||
if(value instanceof ItemIdValue) { | ||
ItemDocument depict = (ItemDocument) wikidataDataFetcher.getEntityDocument(((ItemIdValue) value).getId()); | ||
System.out.println("Depict: " + depict.getLabels().get("en").getText() + "(" + depict.getEntityId().getIri() + ")"); | ||
} | ||
} | ||
|
||
System.out.println("*** Done."); | ||
} | ||
|
||
/** | ||
* Prints some basic documentation about this program. | ||
*/ | ||
public static void printDocumentation() { | ||
System.out.println("********************************************************************"); | ||
System.out.println("*** Wikidata Toolkit: MediaInfoDataExample"); | ||
System.out.println("*** "); | ||
System.out.println("*** It does not download any dump files. See source code for details."); | ||
System.out.println("********************************************************************"); | ||
} | ||
} |
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
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
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
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
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
22 changes: 22 additions & 0 deletions
22
wdtk-wikibaseapi/src/test/resources/wbgetentities-RandomImage.jpg.json
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,22 @@ | ||
{ | ||
"entities": { | ||
"M65057": { | ||
"pageid": 65057, | ||
"ns": 6, | ||
"title": "File:RandomImage 4658098723742867.jpg", | ||
"lastrevid": 146188, | ||
"modified": "2019-11-19T20:36:58Z", | ||
"type": "mediainfo", | ||
"id": "M65057", | ||
"labels": { | ||
"en": { | ||
"language": "en", | ||
"value": "ddddd" | ||
} | ||
}, | ||
"descriptions": {}, | ||
"statements": [] | ||
} | ||
}, | ||
"success": 1 | ||
} |