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

rdf-patricia-tree

v1.0.6

Published

Linked Data patricia tree construction

Downloads

3

Readme

RDF-Patricia-tree

Client side autocompletion using RDF data

This project investigates the usefulness and performance of client-side autocompletion using http requests over the web.

The datastructure used to provide this functionality is a distributed patricia tree. The patricia tree is created in a streaming fashion. The nodes of the tree are saved in linked data fragments. Adding nodes to the tree when written will parse the needed fragments, update them and write them back.

Nodes in the tree contain the data objects that were inserted with a given representation. Multiple different data objects can be contained in a single node if they have the same representation. These objects are stored as hydra:member elements in the jsonld fragments generated by the tree.

Nodes in the tree also contain suggestions (also provided as hydra:member elements in the jsonld fragments). These suggestions are data points from deeper in the tree, with the highest given score. These permit the client to stop querying the tree earlyer when an answer is found to the question in one of these suggestions.

The used ontology for the description of linked data trees can be found at https://w3id.org/tree# Querying the data fragments can be done using the linked data tree browser npm package 'ldtree-browser'.

Installation

github + node

git clone https://gitlab.ilabt.imec.be/lodi/RDF-autocomplete.git
npm install 
node bin/main.js {data source folder} {data folder} {fragment folder} {tree file folder} {tree file name} {fragment size} {max fragment cache elements}

npm

npm install rdf-patricia-tree
const treeManager = require('rdf-patricia-tree');

Usage

TreeManager

The tree is managed with a TreeManager object . This object allows the creation, reading and writing of a linked data tree. The folder layout in these methods is as follows. {sourceDirectory}/{dataLocation}/fragment{id}.jsonld<br/> {sourceDirectory}/{treeLocation}/{treeFile}.jsonld<br/> The sourceDirectory can be published online as base-folder for the data.

The interface of the treeManager object is:

// creating a tree using the treeManager object.
var tree = treeManager.createTree(sourceDirectory, dataFolder, maxCachedFragments = 10000, maxFragmentSize = 50, customBalancer = null)

// writing a tree using the treeManager object.
treeManager.writeTree(tree, treeLocation, treeFile);

// reading a tree using the treeManager object.
var readTree = treeManager.readTree(sourceDirectory, treeLocation, treeFile, dataLocation, maxCachedFragments)

The maxCachedFragments arguments defaults to 10000. This is the maximal amount of fragments that can be held in cache at the same time while creating the tree. Picking this number too low will result in frequent cache flushes, resulting in decreased performance.

The maxFragmentSize arguments defaults to 5O. This is the maximal amount of nodes that can be contained in a single tree fragment.

Tree

Reading a tree from a file or creating a new linked data tree returns a Tree object. Adding data to the tree is done by calling the following method on the tree object.

tree.addData(representation, data);

The representation argument is the searchstring on which the data will be placed in the Patricia Tree. Multiple different data objects can be stored in the same node in the tree. The data object can be any object except for undefined or null.

After all data has been added to the tree, the cache has to be flushed to make sure that all the latest data is written back into the tree files. We need to call:

tree.doneAdding();

after we have added all our data. This will ensure all the data has been written back from the cache.

Testing and statistics

npm install
node bin/testing_main.js {data source folder} {data folder} {fragment folder} {tree file folder} {tree file name} {fragment size} {max fragment cache elements}

This test file will test if all data has been added successfully, as well if there Statistics are printed in the file statistics.csv

Custom Balancers

Custom balancer classes can be passed to the treeManager.createTree() method. A custom balancer class needs to extend the lib/fragment_balancers/TreeBalancer.js class and follow its interface.

module.exports = class DefaultBalancer extends TreeBalancer{
    balance(fragment);    
}  

The balance method is called when a fragment is bigger than the maximal fragment size provided. Care should be taken to only replace nodes to a different fragment, and to not remove connections between different nodes. Documentation on Node and Fragment methods can be found in the files /lib/Node.js and /lib/Fragment.js, or on the github page. https://gitlab.ilabt.imec.be/lodi/RDF-autocomplete/blob/master/lib/Node.js https://gitlab.ilabt.imec.be/lodi/RDF-autocomplete/blob/master/lib/Fragment.js

Inspiration can be taken from the default balancer implementation: https://gitlab.ilabt.imec.be/lodi/RDF-autocomplete/blob/master/lib/fragment_balancers/DefaultBalancer.js

The use of the root_node in the Fragment objects is only for balancing purposes, and only have to be updated if you want to use them during rebalancing. Take note that this does not happen automatically, and should be manually set using fragment.set_root_node(node).