public static void findSomeStringProperties ( ApiConnection connection ) throws MediaWikiApiErrorException , IOException { WikibaseDataFetcher wbdf = new WikibaseDataFetcher ( connection , siteIri ) ; wbdf . getFilter ( ) . excludeAllProperties ( ) ; wbdf . getFilter ( ) . setLanguageFilter ( Collections . singleton ( "en" ) ) ; ArrayList < PropertyIdValue > stringProperties = new ArrayList <> ( ) ; System . out . println ( "*** Trying to find string properties for the example ... " ) ; int propertyNumber = 1 ; while ( stringProperties . size ( ) < 5 ) { ArrayList < String > fetchProperties = new ArrayList <> ( ) ; for ( int i = propertyNumber ; i < propertyNumber + 10 ; i ++ ) { fetchProperties . add ( "P" + i ) ; } propertyNumber += 10 ; Map < String , EntityDocument > results = wbdf . getEntityDocuments ( fetchProperties ) ; for ( EntityDocument ed : results . values ( ) ) { PropertyDocument pd = ( PropertyDocument ) ed ; if ( DatatypeIdValue . DT_STRING . equals ( pd . getDatatype ( ) . getIri ( ) ) && pd . getLabels ( ) . containsKey ( "en" ) ) { stringProperties . add ( pd . getEntityId ( ) ) ; System . out . println ( "* Found string property " + pd . getEntityId ( ) . getId ( ) + " (" + pd . getLabels ( ) . get ( "en" ) + ")" ) ; } } } stringProperty1 = stringProperties . get ( 0 ) ; stringProperty2 = stringProperties . get ( 1 ) ; stringProperty3 = stringProperties . get ( 2 ) ; stringProperty4 = stringProperties . get ( 3 ) ; stringProperty5 = stringProperties . get ( 4 ) ; System . out . println ( "*** Done." ) ; }
Finds properties of datatype string on test . wikidata . org . Since the test site changes all the time we cannot hardcode a specific property here . Instead we just look through all properties starting from P1 to find the first few properties of type string that have an English label . These properties are used for testing in this code .