New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

wikidata-sdk

Package Overview
Dependencies
Maintainers
1
Versions
173
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wikidata-sdk - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

.npmignore

14

package.json
{
"name": "wikidata-sdk",
"version": "0.0.1",
"version": "0.0.2",
"description": "a javascript tool suite to query wikidata data",

@@ -24,3 +24,5 @@ "main": "build/wikidata-sdk.js",

],
"author": "maxlath",
"author": {
"name": "maxlath"
},
"license": "MIT",

@@ -36,3 +38,9 @@ "bugs": {

"should": "^4.6.1"
}
},
"readme": "![wikidata](https://upload.wikimedia.org/wikipedia/commons/f/ff/Wikidata-logo.svg)\nA javascript tool-suite to query [wikidata](http://wikidata.org/) and handle its results.\n\nused APIs:\n- [wikidata API](https://www.wikidata.org/w/api.php)\n- [wmlabs WDQ](http://wdq.wmflabs.org/api_documentation.html)\n\n# Installation\n\nin a terminal at your project root:\n\n```bash\nnpm install wikidata-sdk --save\n```\n\nthen in your javascript project:\n```javascript\nvar wdk = require('wikidata-sdk')\n```\n\n# How-to\n\n## Build queries urls to\n\n### search in wikidata entities\n\n```javascript\nvar url = wdk.searchEntities('Ingmar Bergman');\n```\n\nor with more parameters:\n```javascript\nvar search = 'Ingmar Bergman'\nvar languages = 'fr' // will default to 'en'\nvar limit = 10 // default 20\nvar format = 'json' // default to json\n\nvar url = wdk.searchEntities(search, languages, limit, format);\n```\nthis returns a query url that you are then free to request with the tool you like\n```\nhttps://www.wikidata.org/w/api.php?action=wbsearchentities&search=Ingmar%20Bergman&language=en&limit=20&format=json\n```\n\n### get entities by id\n\non the same pattern\n\n```javascript\nvar url = wdk.getEntities(ids, languages, properties, format)\n```\n\nproperties being wikidata entities' properties: info, sitelinks, labels, descriptions, claims.\n\nids, languages, properties can get either one single value as a string or several values in a array\n\n\n### get entities reverse claims\n\nIn wikidata API answers, you can only access claims on the entity's page, not claims pointing to this entity (what would be in the \"what links here\" page).\n\nFortunatly, you can query wikimedia awesome WDQ tool \\o/\n\nFor instance, let's say you want to find all the entities that have Leo Tolstoy ([Q7243](http://www.wikidata.org/entity/Q7243)) for author ([P50](http://www.wikidata.org/entity/P50))\n\n```javascript\nvar url = wdk.getReverseClaims('P50', 'Q7243');\n```\n\nand you can then query the obtained entities ids\n\n```javascript\nrequest(url, function(err, response){\n if err dealWithError(err);\n var entities = wdk.parseWdqResponse(response);\n var url2 = wdk.getEntities(entities);\n request(url2 ....\n});\n```\n\nit also work for string values: e.g. let's say you want to find which book as 978-0-465-06710-7 for ISBN-13 ([P212](http://www.wikidata.org/entity/P212)):\n\n```javascript\nvar url = wdk.getReverseClaims('P212', '978-0-465-06710-7');\n```\n\n## Other utils\n\n### simplify claims results\nFor each entities claims, Wikidata's API returns a deep object that requires some parsing that could be avoided for simple uses.\n\nSo instead of:\n```json\n\"P279\": [\n {\n \"rank\": \"normal\",\n \"type\": \"statement\",\n \"mainsnak\": {\n \"datavalue\": {\n \"type\": \"wikibase-entityid\",\n \"value\": {\n \"numeric-id\": 340169,\n \"entity-type\": \"item\"\n }\n },\n \"datatype\": \"wikibase-item\",\n \"property\": \"P279\",\n \"snaktype\": \"value\"\n },\n \"id\": \"Q571$0115863d-4f02-0337-38c2-5e2bb7a0f628\"\n },\n {\n \"rank\": \"normal\",\n \"type\": \"statement\",\n \"mainsnak\": {\n \"datavalue\": {\n \"type\": \"wikibase-entityid\",\n \"value\": {\n \"numeric-id\": 2342494,\n \"entity-type\": \"item\"\n }\n },\n \"datatype\": \"wikibase-item\",\n \"property\": \"P279\",\n \"snaktype\": \"value\"\n },\n \"id\": \"Q571$04c87c4e-4bce-a9ab-eb75-d9a3ed695077\"\n },\n {\n \"rank\": \"normal\",\n \"type\": \"statement\",\n \"mainsnak\": {\n \"datavalue\": {\n \"type\": \"wikibase-entityid\",\n \"value\": {\n \"numeric-id\": 386724,\n \"entity-type\": \"item\"\n }\n },\n \"datatype\": \"wikibase-item\",\n \"property\": \"P279\",\n \"snaktype\": \"value\"\n },\n \"id\": \"Q571$afe3b5c3-424e-eb7b-60e6-c2ce0d122823\"\n }\n]\n```\n\nwe could have\n\n```json\nP279: [ 'Q340169', 'Q2342494', 'Q386724' ]\n```\n\nyou just need to pass your entity' claims object to simplifyClaims as such:\n```javascript\nvar simpleClaims = wdk.simplifyClaims(claims);\n\n```\n\nin your workflow, that could give something like:\n\n```javascript\nvar url = wdk.getEntities('Q535');\nrequest(url, function(err, response){\n if err dealWithError(err);\n var entity = response.entities.Q535;\n entity.claims = wdk.simplifyClaims(entity.claims);\n});\n```\n\n\n### Misc\n\n- isNumericId\n- isWikidataId\n- isWikidataEntityId\n- isWikidataPropertyId\n- normalizeId\n- normalizeIds\n- normalizeWikidataTime\n- toPropertiesArray\n\n\n### A little [CoffeeScript](coffeescript.org) / [Promises](https://www.youtube.com/watch?v=qbKWsbJ76-s) workflow demo\nthat's how I love to work :)\n\n```coffeescript\nbreq = require 'bluereq' # a little request lib returning bluebird-based promises\n\nids = ['Q647268', 'Q771376', 'Q860998', 'Q965704']\nurl = wdk.getEntities ids, user.language\n\nentities = breq.get(url).then wdk.parse.wd.entities\n\n# do useful stuff with those entities data\n```\n",
"readmeFilename": "README.md",
"gitHead": "1d7c87447ecb9fbf5dce0adfbeb084585cc3a80e",
"_id": "wikidata-sdk@0.0.1",
"_shasum": "ab97d82344f07822e3105a0b6e1105159190a859",
"_from": "wikidata-sdk"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc