Skip to content
This repository has been archived by the owner on Sep 17, 2020. It is now read-only.

maxlath/wikidata-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wikidata Agent

⚠️ this project's core is progressively being transfered into wikidata-edit and wikidata-cli, and it's gonna be even more awesome there. This project will stay relevent if you have a web interface that needs a server to handle CORS and authentification.

agent

A single-user server to communicate with the Wikidata API in a simple, minimalist way.

what does it mean: you have one server running on your computer to which you do your requests and which will then handle the communication with Wikidata

motivations:

  • being able to interact with Wikidata from a static web page (cf the original need: authors tomorrow), implying a more tolerant CORS policy
  • set your authentification once and then forget about it (using wikidata-token)
  • interact with a minimalist interface tailored to your needs

Summary

Installation

git clone https://github.com/maxlath/wikidata-agent.git
npm install
# you should now get a command prompt requesting your Wikidata username and password
npm start

How To

Create a claim

abstracting the wbcreateclaim API

to create a claim on an entity, just POST on the /claim endpoint with entity, property, and value specified in the body

  • with curl
curl -X POST http://localhost:4115/claim -d 'entity=Q4115189&property=P2002&value=Zorg'
request.post({
  url: 'http://localhost:4115/claim',
  body: {
    entity: 'Q4115189',
    property: 'P2002',
    value: 'Zorg'
  }
})

Before creating the claim, it will verify that no existing claim has this value. If such a claim already exists, the request will return a 400 error.

request.post({
  url: 'http://localhost:4115/claim',
  body: {
    entity: 'Q4115189',
    property: 'P2848',
    value: 'Q1543615',
    ref: 'http://example.org/your-reference-url'
  }
})

With a reference to the Wikipedia edition it is imported from

(see Wikipedia editions list)

request.post({
  url: 'http://localhost:4115/claim',
  body: {
    entity: 'Q4115189',
    property: 'P2848',
    value: 'Q1543615',
    ref: 'Q328' # English Wikipedia
  }
})

or

curl -X POST http://localhost:4115/claim -d 'entity=Q4115189&property=P2848&value=Q1543615&ref=Q328'

Set a label

request.post({
  url: 'http://localhost:4115/label',
  body: {
    entity: 'Q3938',
    language: 'fr',
    label: 'blabla',
  }
})

or

curl -X POST http://localhost:4115/label -d 'entity=Q3938&language=fr&label=blabla'

Create an entity

request.post({
  url: 'http://localhost:4115/entity',
  body: {
    labels: {
      en: 'a label',
      fr: 'un label',
      de: 'ein Label'
    },
    descriptions: {
      en: 'a description',
      fr: 'une description'
    }
    claims: {
      P31: 'Q571',
      P50: 'Q535'
    }
    summary: 'importing data from blablabla',
    key: "a hash of those data or some unique id specific to this set of data to make sure this entity isn't added twice"
  }
})

Supported properties

For the moment, only properties with the following data types are supported:

  • ExternalId
  • String
  • WikibaseItem
  • Time
  • Monolingualtext
  • Quantity
  • WikibaseProperty

Not Supported yet:

  • Math
  • GlobeCoordinate
  • CommonsMedia
  • Url

To add support:

  • fix find_property_type by attributing them one of the existing primary data types (string, claims, time, or quantity)
  • add corresponding functions in tests and builders

Donate

We are developing and maintaining tools to work with Wikidata from NodeJS, the browser, or simply the command line, with quality and ease of use at heart. Any donation will be interpreted as a "please keep going, your work is very much needed and awesome. PS: love". Donate

See Also

a javascript tool suite to query and work with wikidata data, heavily used by wikidata-cli

The command-line interface to Wikidata

A command-line tool to filter a Wikidata dump by claim

wikidata-subset-search-engine Tools to setup an ElasticSearch instance fed with subsets of Wikidata

Command-line tool to extract taxonomies from Wikidata

License

MIT

About

A single-user server to communicate with the Wikidata API in a simple, minimalist way

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published