Coder Social home page Coder Social logo

wikidata's Introduction

Wikidata

Wikidata provides a API for searching and retrieving data from wikidata.org.

Installation

composer require freearhey/wikidata

Usage

$wikidata = new Wikidata;

Search

Search by entity title:

$result = $wikidata->search('steve jobs');

Check if no search results

if($result->isEmpty()) {
	echo 'no results';
	die();
}

Retrieve first entity in result list

$singleResult = $result->first();

Retrieve all results

$allResults = $result->get();

Get entity id

$entityId = $singleResult->getEntityId(); // Q26

Entities

Get single entity by id:

$entities = $wikidata->entities('Q26');

Get single entity with preset language (default: en)

$entities = $wikidata->entities('Q26', 'fr');

Get few entities by id and more languages

$entities = $wikidata->entities('Q26|Q106', 'en|fr|ch');

Retrieve first entity

$entity = $entities->first();

Get all entities

$entity = $entities->get();

Get single entity by id

$entity = $entities->get('Q26');

Get entity label and description (default language: en)

$label = $entity->getLabel(); // Steve Jobs
$description = $entity->getDescription('de'); // US-amerikanischer Unternehmer, Mitbegründer von Apple Computer

Get entity property values by property id (e.g. P21) if it exists. All list properties you can find here

$gender = $entity->getPropertyValues('P21'); // array(1) { [0]=> string(4) "male" }

And with language property (default: en)

$childs = $entity->getPropertyValues('P40', 'ru'); // array(1) { [0]=> string(35) "Бреннан-Джобс, Лиза" }

That's all.

License

Wikidata is licensed under the MIT license

wikidata's People

Contributors

freearhey avatar mpipet avatar

Watchers

James Cloos avatar Ruben Lang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.