Coder Social home page Coder Social logo

rub3nlh / wikidata-subset-search-engine Goto Github PK

View Code? Open in Web Editor NEW

This project forked from inventaire/entities-search-engine

0.0 2.0 0.0 21 KB

Tools to setup an ElasticSearch instance fed with subsets of Wikidata

Home Page: https://data.inventaire.io

Shell 8.71% CoffeeScript 46.99% HTML 44.30%

wikidata-subset-search-engine's Introduction

Wikidata Subset Search Engine

Tools to setup an ElasticSearch instance fed with subsets of Wikidata, to answer questions like "give me all the humans with a name starting by xxx" in a super snappy way, typically for the needs of an autocomplete field.

Powering data.inventaire.io, and tailored for inventaire's needs, but could probably be adapted to other use cases

Setup

Dependencies

see setup to install dependencies:

Wikidata filtered-dump import

#### import a filtered Wikidata dump into ElasticSearch

# the wikidata claim that entities have to match to be in the subset
claim=P31:Q5
# the type that will be passed to ElasticSearch 'wikidata' index
datatype=humans

./bin/dump_wikidata_subset $claim $datatype
# time for a coffee!

What happens here:

  • we download the latest Wikidata dump
  • pipe it to wikidata-filter to keep only entities matching the claim P31:Q5 and keeping only the entities attributes required by a full-text search engine, that is: id, labels, aliases, descriptions
  • pipe those filtered entities to ElasticSearch wikidata index under the datatype humans, making those entities searchable from the endpoint http://localhost:9200/wikidata/humans/_search (see ElasticSearch API doc)

⚠️ you are about to download a whole Wikidata dump that is something like 7GB compressed. Only the filtered output should be written to your disk though.

#### import multiple Wikidata subsets into ElasticSearch The same as the above but saving the Wikdiata dump to disk to avoid downloading 7GB multiple times when one time would be enough. This time, you do need the 7GB disk space, plus the space that will take your subsets in ElasticSearch

alias wdfilter=./node_modules/wikidata-filter/bin/wikidata-filter
alias import_to_elastic=./bin/import_to_elasticsearch

curl -s https://dumps.wikimedia.org/wikidatawiki/entities/latest-all.json.gz > wikidata-dump.json.gz

cat wikidata-dump.json.gz | gzip -d | wdfilter --claim P31:Q5 --omit type,claims,sitelinks | import_to_elastic humans
# => will be available at http://localhost:9200/wikidata/humans

cat wikidata-dump.json.gz | gzip -d | wdfilter --claim P31:Q571 --omit type,claims,sitelinks | import_to_elastic books
# => will be available at http://localhost:9200/wikidata/books

## Query ElasticSearch

curl "http://localhost:9200/wikidata/humans/_search?q=Victor%20Hugo"

or try the result on data.inventaire.io

curl "https://data.inventaire.io/wikidata/humans/_search?q=Victor%20Hugo"

data.inventaire.io

Whitelisted endpoints:

References

wikidata-subset-search-engine's People

Contributors

maxlath avatar

Watchers

 avatar  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.