Coder Social home page Coder Social logo

bbc-things's Introduction

BBC Things

http://www.bbc.co.uk/things/

This is an unoffical client for the BBC Things Linked Data Platform.

You can pass a string (or an array of strings) and get back matching Things from a search query. You can then fetch extended properties for any Thing.

You might want to combine it with something like the npm module gramophone to do entity extraction on bodies of text and find relevant Things to tag content with.

Passing a string

var BBCThings = require('bbc-things');
var text = "David Cameron";
BBCThings.search(text)
.then(function(things) {
    console.log(things);
});

Example response object

[ { label: 'David Cameron',
    hint: 'Politician',
    uri: 'http://www.bbc.co.uk/things/ed9d1ef3-eded-4f81-b158-be49cfc1ea8f#id',
    properties: [Function] } ]

Passing an array of strings

var BBCThings = require('bbc-things');
var arrayOfStrings = ["Kenya", "Nairobi"];
BBCThings.search(arrayOfStrings)
.then(function(things) {
    console.log(things);
});

Example response object

{ Kenya: 
   [ { label: 'Kenya',
       hint: 'Kenya',
       uri: 'http://www.bbc.co.uk/things/7d7c35fa-f724-4b36-90a0-21f71d99857d#id',
       properties: [Function] },
     { label: 'Jomo Kenyatta',
       hint: 'Politician',
       uri: 'http://www.bbc.co.uk/things/d760ca99-2b63-499e-9be5-8aab0b64ca6e#id',
       properties: [Function] },
     { label: 'Uhuru Kenyatta',
       hint: 'Kenyan politician.',
       uri: 'http://www.bbc.co.uk/things/f9e4f58f-cb89-46b6-ab75-e44e84229404#id',
       properties: [Function] } ],
  Nairobi: 
   [ { label: 'Nairobi',
       hint: 'Kenya',
       uri: 'http://www.bbc.co.uk/things/bfe2de9d-fde7-4781-89ca-1735ede10982#id',
       properties: [Function] } ] 
}

Additional properties

You can access additional information by calling .properties() on a Thing.

The properties vary depending on the entity (e.g. places have lat/lon properties).

var BBCThings = require('bbc-things');
BBCThings.search("Ed Miliband")
.then(function(things) {
    thing[0].properties()
    .then(function(properties) {
        console.log ( properties );        
    });
});

Example .properties() response object

[ { label: 'Ed Miliband',
    hint: 'Politician',
    uri: 'http://www.bbc.co.uk/things/b13fa1f6-2799-404f-bfae-91632ec66b10#id',
    properties: [Function] } ]
{ '@id': 'http://www.bbc.co.uk/things/b13fa1f6-2799-404f-bfae-91632ec66b10#id',
  '@type': 
   [ 'owl:Thing',
     'ManagedThing',
     'Thing',
     'Person',
     'rdfs:Resource',
     'tagging:TagConcept',
     'tag:TagConcept' ],
  disambiguationHint: 'Politician',
  label: 'Ed Miliband',
  preferredLabel: 'Ed Miliband',
  primaryTopicOf: 
   [ 'http://en.wikipedia.org/wiki/Ed_Miliband',
     'http://news.bbc.co.uk/democracylive/hi/representatives/profiles/40791.stm',
     'http://www.edmiliband.org',
     'http://www.guardian.co.uk/politics/person/8711/' ],
  sameAs: 
   [ 'http://dbpedia.org/resource/Ed_Miliband',
     'http://rdf.freebase.com/ns/m.04qdjv',
     'http://www.wikidata.org/entity/Q216594' ] }

Requesting exact matches only

If if you want to return Things who's labels are exact matches only (ignoring case sensitivity) then you can pass 'true' as the second parameter to instruct it to return 'exact matches only'.

For example, if you want to get the Thing for "Kenya", but were not interested in the data for Kenyan Politican "Uhuru Kenyatta" returned you could do this:

var BBCThings = require('bbc-things');
BBCThings.search("Kenya", true)
.then(function(things) {
    console.log(things);
});

Contributions and thanks

This is a very simple library and is entirely unofficial and was not created by the folks who've created the excellent BBC Things site which it uses.

It was created to make it easier to do experiments with linked data and to try out different approaches to entity extraction.

bbc-things's People

Contributors

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