npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

re-ontology

v0.0.4

Published

Ontology builder that saves to and loads from RethinkDB.

Downloads

1

Readme

ReOntology

ReOntology is a type system for JavaScript that conveniently saves to and loads from RethinkDB. To install, use npm:

npm install re-ontology --save

Requiring the module exposes the following object:

var reontology = require('re-ontology');
console.log(reontology) //=> { Type: {...}, Instance: {...}, db: { getInstance: {...}, getSystem: {...} } }

The type system consists of a heirarchy of types that lies over a set of instances. There is a minor semantic distinction in the code which is that a type has "features", abstract qualities that pertain to all subtypes and instances of that type, and an instance has a "description" which is a set of key/value pairs that describe that actual properties of that instance.

To create an ontology you start with a base class. For now every class and instance must have a unique name, features are optional, and descriptions are necessary to perform search queries.

// here is the root of our new class system //
var people = new Type({
	name: "Person",
	features: {
		Type: "Human"
	}
})

To extend a class with sub-classes use the addSubType method:

var men = people.addSubType({
	name: 'Male',
	features: {
		Gender: 'Male'
	}
})
var women = people.addSubType({
	name: 'Female',
	features: {
		Gender: 'Female'
	}
})

To add instances to a type or a sub-type use the addInstance method:

men.addInstance({
	name: 'Robert',
	description: {
		father: 'James',
		mother: 'Gladice',
		sons: ['Eric'],
		daughters: ['Susan', 'Carol', 'Annabelle']
	}
})

men.addInstance({
	name: 'Eric',
	description: {
		father: 'Robert',
		mother: 'Sylvia',
		sons: ['James', 'Wendell'],
		daughters: ['Emily']
	}
})

women.addInstance({
	name: 'Susan',
	description: {
		father: 'Robert',
		mother: 'Sylvia',
		sons: null,
		daughters: null
	}
})

women.addInstance({
	name: 'Samanthat',
	description: {
		father: 'Adam',
		mother: 'Beth',
		sons: null,
		daughters: null
	}
})

Now that we have a fleshed out ontology with a root class, two subclasses and four instances, we can save it to rethinkdb:

// creates a table called "people" in our database and saves the entire heirarchy into that table
people.createTable('people').then(function(){
	people.save();
});

Now we can reconstruct the entire heirarchy from the database:

var people;
// reconstructs a ReOntology tree starting from the root node found in the "people" table
db.getSystem('people', function(result){
	people = result;
})

Viewing Information

For now, there are two principle ways of viewing information in your ontology. The first is with the viewInstance method. Calling viewInstance on the root with the name of an instance will return an object that contains the instance data as well as the data for every class that instance belongs to.

people.viewInstance('Eric') //=> { name: "Eric", description: {...}, parent: { name: "Male"... } }

A much more interesting way to query the ontology is by using the search object. This object allows you to find instances with specific attributes or instances that share attributes with other instances. Examples of both kinds of queries follows below:

people.search() // this method returns a search object
.hasType('Male') // we constrain our search to men
.hasAttributes({father: "James"}, function(result){
// hasAttributes is a terminating method so it takes a callback
	console.log(result) // logs the Robert Object
})

Finding Eric's sisters is easy:

people.search()
.relatedTo('Eric') // this method enables use of the sharesAttributes method
.hasType('Female') // we want to find the women that share two attributes with Eric
.sharesAttributes(["father","mother"], function(result){
	console.log(result) // an array containing the Susan instance
})