Git Product home page Git Product logo

triplestore.js's Introduction

MIT LICENSE This JavaScript code is based on the Python implementation in the book "Programming The Semantic Web" by Toby Segaran, Colin Evans, Jamie Taylor, O'Reilly Press.

Example:

var SimpleGraph = require('./SimpleGraph').SimpleGraph;

var placeGraph = new SimpleGraph();

placeGraph.load('place_triples.txt', function () {
    console.log('Information about San Francisco\n---------------------------------');
    placeGraph.triples(undefined, 'name', 'San Francisco').forEach(function (triple) {
        var nameId = triple[0];
        console.log(nameId);

        var cityData = placeGraph.triples(nameId, undefined, undefined);
        console.log(cityData);
    });

    console.log('\nList of all mayors\n---------------------------------');
    var mayors = placeGraph.triples(undefined, 'mayor', undefined);

    mayors.forEach(function (triple) {
        var mayor = triple[2],
            cityId = triple[0],
            city = placeGraph.value(cityId, 'name', undefined);

        console.log(mayor, 'is the mayor of', city);
    });

    console.log('\nCities with their population\n---------------------------------');
    var populations = placeGraph.triples(undefined, 'population', undefined);

    populations
        .sort(function (a, b) {
            return b[2] - a[2];
        })
        .forEach(function (triple) {
            var cityId = triple[0],
                population = triple[2],
                city = placeGraph.value(cityId, 'name', undefined);

            console.log(city, 'has a population of', population);
        });
});

Yields to:

Information about San Francisco
---------------------------------
San_Francisco_California
[ [ 'San_Francisco_California', 'name', 'San Francisco' ],
  [ 'San_Francisco_California', 'inside', 'California' ],
  [ 'San_Francisco_California', 'longitude', '-122.4183' ],
  [ 'San_Francisco_California', 'latitude', '37.775' ],
  [ 'San_Francisco_California', 'mayor', 'Gavin Newsom' ],
  [ 'San_Francisco_California', 'population', '744042' ] ]

List of all mayors
---------------------------------
John F. Street is the mayor of Philadelphia
Norman Mineta is the mayor of San Jose
Mark Nuaimi is the mayor of Fontana
Acquanetta Warren is the mayor of Fontana
John Muller is the mayor of Half Moon Bay
Bonnie McClung is the mayor of Half Moon Bay
Frank Murphy is the mayor of Detroit
Michael Sessions is the mayor of Hillsdale
Mark Rosen is the mayor of Garden Grove
William Dalton is the mayor of Garden Grove
Lena Tam is the mayor of Alameda
Beverly Johnson is the mayor of Alameda
Gavin Newsom is the mayor of San Francisco
Harvey Hall is the mayor of Bakersfield
Steve Nolan is the mayor of Corona
Jeff Miller is the mayor of Corona
Bill Smith is the mayor of Edmonton
Sarah Palin is the mayor of Wasilla
Brenda Salas is the mayor of Banning
Debbie Franklin is the mayor of Banning
John Drayman is the mayor of Glendale
Thomas G. Ferrini is the mayor of Portsmouth
John Blalock is the mayor of Portsmouth
Richard M. Daley is the mayor of Chicago
Dora Bakoyannis is the mayor of Athens
Manfred Rommel is the mayor of Stuttgart
Jerry Springer is the mayor of Cincinnati
Dennis Kucinich is the mayor of Cleveland
Frank G. Jackson is the mayor of Cleveland
Newton D. Baker is the mayor of Cleveland
Michael Bloomberg is the mayor of New York
Curt Pringle is the mayor of Anaheim
Cheryl Cox is the mayor of Chula Vista
Charley B. Glasper is the mayor of Adelanto
Steven R. Baisden is the mayor of Adelanto
Alan Autry is the mayor of Fresno
William Phillips is the mayor of Aliso Viejo
Donald Garcia is the mayor of Aliso Viejo
Bob Wasserman is the mayor of Fremont
Bill Harrison is the mayor of Fremont

Cities with their population
---------------------------------
Mexico City has a population of 8720916
New York has a population of 8214426
Hong Kong has a population of 6980412
Los Angeles has a population of 3849378
Athens has a population of 3370000
Chicago has a population of 2833321
Detroit has a population of 1514063
Philadelphia has a population of 1448394
San Jose has a population of 929936
Edmonton has a population of 752412
San Francisco has a population of 744042
Stuttgart has a population of 590429
Cleveland has a population of 478403
Fresno has a population of 466714
Christchurch has a population of 359900
Anaheim has a population of 334425
Cincinnati has a population of 332252
Bakersfield has a population of 328692
Chula Vista has a population of 212756
Fremont has a population of 201691
Glendale has a population of 199463
Fontana has a population of 170099
Garden Grove has a population of 166296
Corona has a population of 150253
Alameda has a population of 72259
Aliso Viejo has a population of 45037
Banning has a population of 23562
Adelanto has a population of 23419
Portsmouth has a population of 20784
Half Moon Bay has a population of 11842
Wasilla has a population of 9780
Hillsdale has a population of 8233

triplestore.js's People

Contributors

srad avatar

Watchers

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