Git Product home page Git Product logo

wordpos-web's Introduction

wordpos-web

NPM version

CDNs:

wordpos is a set of fast part-of-speech (POS) utilities for Node.js and browser using fast lookup in the WordNet database.

wordpos-web formats the WordNet DB files to allow running wordpos in the browser.

๐Ÿ“ฃ Demo

Installation

 npm install wordpos-web

wordpos API Docs

See wordpos/README.

Running inside the browsers

v2.0 of wordpos introduces the capability of running in the browser. The dictionary files are optimized for fast access (lookup by lemma), but they must be fetched, parsed and loaded into browser memory. The files are loaded on-demand (unless the option preload: true is given).

The dict files can be served locally or from CDN (see samples/cdn). Include the following scripts in your index.html:

<script src="wordpos/dist/wordpos.min.js"></script>
<script>
  let wordpos = new WordPOS({
    // preload: true,
    dictPath: '/wordpos/dict',
    profile: true
  });

  wordpos.getAdverbs('this is lately a likely tricky business this is')
    .then(res => {
      console.log(res); // ["lately", "likely"]
    });
</script>

Above assumes wordpos is installed to the directory ./wordpos. ./wordpos/dict holds the index and data WordNet files generated for the web in a postinstall script.

See samples/self-hosted.

Using preload option

When running inside the browse, you can request that the necessary index & data files be preloaded, rather than loaded on demand.

Use this when you're sure the files will be used and want to minimize the on-demand wait time.

let wordpos = new WordPOS({
  preload: 'a',       // Preload adjectives index file.
  includeData: true,  // Also preload the adjectives data file.
  dictPath: '/wordpos/dict'
});

wordpos.ready().then(()=> {
  // files are loaded
});

See wordpos#options for other preload options.

A note on file sizes

The original WordNet DB is around 35 MB. The size of the "index" and "data" files formatted for the web are as follows (before any compression):

POS data index
adverbs 525 KB 170 KB
verbs 2.7 MB 534 KB
adjectives 3.1 MB 851 KB
nouns 15 MB๐Ÿšฉ 4.8 MB
All (raw) 21.3 MB 6.4 MB
All (gzip) ~6 MB 1.7 MB

๐Ÿšฉ Be aware this is a very large file and may take some time to fetch.

Resources fetched over CDN will be compressed. For example, the compressed noun files are 4.1 MB (data) and 1.3 MB (index). If you are self-hosting, ensure gzip compression is on for your server.

Some wordpos API need just the "index" file, while others need both. Here's the breakdown:

API data index
get?() โœ–๏ธ โœ”๏ธ
is?() โœ–๏ธ โœ”๏ธ
lookup?() โœ”๏ธ โœ”๏ธ
seek() โœ”๏ธ โœ”๏ธ
rand?() โœ–๏ธ โœ”๏ธ

The following API will access all POS files:

  • getPOS() -- all index files
  • lookup() -- all index files & data files for matched word
  • rand() -- all index files

Dev

To run samples, npm i -g http-server, then:

$ npm run build
$ npm run start
Starting up http-server, serving ./
Available on:
  http://localhost:8080

and open your browser to that url.

Changes

  • 1.0.2 - Build samples/ to docs/.
  • 1.0.1 - Fix self-hosted sample dict/ path
  • 1.0.0 - Initial web version

License

https://github.com/moos/wordpos-web Copyright (c) 2012-2020 [email protected] (The MIT License)

wordpos-web's People

Contributors

moos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

wordpos-web's Issues

Webpack usage?

Is it possible to bundle wordpos and the WordNet data files with Webpack? I've tried the following configuration, but it fails to resolve the index files when run.

webpack.config.js:

resolve: {
  alias: {
    "wordpos-web": path.resolve(__dirname, "node_modules/wordpos-web/dist/wordpos.min.js")
  }
}

WordPOS construction:

import WordPOS from "wordpos-web"

let wordpos = new WordPOS({
  dictPath: "../../../node_modules/wordpos-web/dict", // also tried "../dict"
});

I tried importing the index files so they would be bundled:

import "../../../node_modules/wordpos-web/dict/index.adv.js"
import "../../../node_modules/wordpos-web/dict/index.noun.js"

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.