compromise-plugin

2019-05-16 admin

compromise-plugin是什么

什么是compromise-plugin,author and compress nlp-compromise plugins

compromise-plugin使用教程帮助文档

<div align=“center”>

<g-emoji class=“g-emoji” alias=“sunglasses” fallback-src=“https://github.githubassets.com/images/icons/emoji/unicode/1f60e.png”>😎</g-emoji><g-emoji class=“g-emoji” alias=“sunglasses” fallback-src=“https://github.githubassets.com/images/icons/emoji/unicode/1f60e.png”>😎</g-emoji><g-emoji class=“g-emoji” alias=“sunglasses” fallback-src=“https://github.githubassets.com/images/icons/emoji/unicode/1f60e.png”>😎</g-emoji><g-emoji class=“g-emoji” alias=“sunglasses” fallback-src=“https://github.githubassets.com/images/icons/emoji/unicode/1f60e.png”>😎</g-emoji>

make a plugin for compromise

</div>

compromise works by compressing its data in lots of weird ways. With compromise-plugin, you can ship thousands, or tens-of-thousands of custom words and patterns to the client-side, for any natural-language-processing behaviour you’d like.

//take this plugin,
var plugin = {
  name:'compromise-dinosaur',
  words: {
    brontosaurus:'Dinosaur',
    trex: 'Dinosaur'
  },
  tags: {
    Dinosaur: {
      isA: 'Animal'
    },
    Animal: {
      isA: 'Noun'
    }
  },
  regex: {
    '.osaurus$': 'Dinosaur',
    'uuu+': 'Exaggeration'
  }
};

var pack = require('compromise-plugin');
var tinyPlugin= pack(plugin) //CRAZY_SMALL!

//then load it in nlp-compromise (it unpacks automatically)
nlp.plugin(tinyPlugin);
var doc = nlp('i saw a HUUUUGE trex').debug()
/*
  'i'           - Pronoun, Noun, Singular
  'saw'         - PastTense, Verb, VerbPhrase
  'a'           - Determiner
  'HUUUUGE'     - Exaggeration
  'trex'        - Dinosaur, Animal, Noun, Singular
*/

the cool thing about this process is that the pack() step can be as slow as we’d like. It can do all-sorts of laborious things up-front, to ensure the plugin can ‘pop’ back into uncompressed form very quickly.

CLI

if you prefer, you can integrate compromise-plugin into your workflow from the command-line:

npm i -g compromise-plugin
#pack it..
compromise-pack ./path/to/myPlugin.js | ./plugin.min.js

#unpack it..
compromise-unpack ./path/to/plugin.min.js

Compatibility

the compromise plugin spec will change over time, and to avoid having to remember which versions line-up, we will try to use the same major-version numbers as compromise.

so if you want a plugin to work with comprimise v12, publish it with compromise-plugin@12.*.*

Other examples

//military-words
{
  plurals:{
    barracks:'barracks'
  },
  patterns:{
    "#Ordinal infantry? division":'Noun',
    "major (general|lieutenant|#Person)":'Person',
    "#Posessive six":'Noun',
    "over$":'Expression'
  },
  words:{
    'niner':'Value',
    'buck sergeant':'Person'
  }
}

MIT

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-65046.html

文章标题:compromise-plugin

回到顶部