@@ -2,6 +2,7 @@ const wdService = function ($http, $q) {
22
33 const service = {
44 getById : getById ,
5+ getLabels : getLabels ,
56 getRecursive : getRecursive ,
67 getSearch : getSearch ,
78 getSPARQL : getSPARQL ,
@@ -40,13 +41,20 @@ const wdService = function ($http, $q) {
4041 * @returns {Promise }
4142 */
4243 function get ( data ) {
43- let params = angular . extend ( angular . copy ( defaultParams ) , data ) ;
44+ let params = angular . extend ( { } , defaultParams , data ) ;
4445 return $http . jsonp ( 'https://www.wikidata.org/w/api.php' , {
4546 params : mapValues ( params , p => angular . isArray ( p ) ? p . join ( '|' ) : p ) ,
4647 cache : false
4748 } ) ;
4849 }
4950
51+ function getLabels ( ids ) {
52+ return get ( {
53+ ids : ids ,
54+ props : [ 'labels' ]
55+ } ) . then ( response => mapValues ( response . data . entities , entity => simplifyLabels ( entity . labels ) ) ) ;
56+ }
57+
5058 function getRecursive ( element , recursiveProperty ) {
5159 let query = `SELECT ?parent ?parentLabel WHERE {
5260 wd:` + element + ` wdt:` + recursiveProperty + `* ?parent .
@@ -154,11 +162,7 @@ const wdService = function ($http, $q) {
154162 ids = ids . filter ( ( item , pos , self ) => item && self . indexOf ( item ) === pos ) ;
155163 return ids ;
156164 } )
157- . then ( labelsIDs => get ( {
158- ids : labelsIDs ,
159- props : [ 'labels' ]
160- } ) )
161- . then ( response => mapValues ( response . data . entities , entity => simplifyLabels ( entity . labels ) ) )
165+ . then ( labelsIDs => getLabels ( labelsIDs ) )
162166 . then ( labels => {
163167 forOwn ( entities , entity => {
164168 entity . claims = mapValues ( entity . claims , ( values , key ) => ( {
0 commit comments