maxlath / wikibase-sdk

JS utils functions to query a Wikibase instance and simplify its results
MIT License
326 stars 47 forks source link

Idea: ActivityStreams JSON-LD #85

Open sebilasse opened 2 years ago

sebilasse commented 2 years ago

Hey Max,

a feature request:

currently I am using the simplified versions of getManyEntities reducing it for simplify like

.reduce((oneObject, fromMany) => {
    for (const wikibaseId in fromMany) {
      oneObject[wikibaseId] = fromMany[wikibaseId];
    }
    return o;
  }, {});

then I do map it to an ActivityStreams JSON-LD "type": "Profile" with e.g. "describes": "wdt:Q1055" ( simple, with default AS context and "wdt" prefix for wikidata and in the following example alternativeNameMap: { "@id": "wdt:P4970", "@container": "@language" }, ) by just renaming modified -> updated labels -> nameMap aliases -> alternativeNameMap descriptions -> summaryMap and prefixing other properties with "wdt:" we would have a nice ActivityStreams representation for further use in ActivityPub. I do also have a mapping from all properties to tag, url, image, icon … I mean, ActivityStreams is well defined and it would just need a few changes and could become a valuable option.

const res: any = {
  id: wd.id,
  updated: wd.modified || new Date().toISOString(),
  nameMap: wd.claims && wd.claims.labels ? wd.claims.labels : {},
  alternativeNameMap: wd.claims && wd.claims.aliases ? wd.claims.aliases : {},
  summaryMap: wd.claims && wd.claims.descriptions  ? wd.claims.descriptions : {},
  tag: [],
  url: [],
  image: [],
  icon: [],
  // all wikidata properties as "wdt:P..."
};
maxlath commented 2 years ago

Hi Seb! This seems to be quite specific to a certain use case, I don't think it belongs in this lib, but if you turn it into a lib, I would happily link to it from this repo's readme "see also" section :)