New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

spacy

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spacy - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

src/__mocks__/language.js

4

dist/index.js
parcelRequire=function(e,r,n,t){var i="function"==typeof parcelRequire&&parcelRequire,o="function"==typeof require&&require;function u(n,t){if(!r[n]){if(!e[n]){var f="function"==typeof parcelRequire&&parcelRequire;if(!t&&f)return f(n,!0);if(i)return i(n,!0);if(o&&"string"==typeof n)return o(n);var c=new Error("Cannot find module '"+n+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[n][1][r]||r},p.cache={};var l=r[n]=new u.Module(n);e[n][0].call(l.exports,p,l,l.exports,this)}return r[n].exports;function p(e){return u(p.resolve(e))}}u.isParcelRequire=!0,u.Module=function(e){this.id=e,this.bundle=u,this.exports={}},u.modules=e,u.cache=r,u.parent=i,u.register=function(r,n){e[r]=[function(e,r){r.exports=n},{}]};for(var f=0;f<n.length;f++)u(n[f]);if(n.length){var c=u(n[n.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=c:"function"==typeof define&&define.amd?define(function(){return c}):t&&(this[t]=c)}return u}({"Y/Oq":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.makeRequest=i,exports.getSimilarity=o;var e=r(require("node-fetch")),t=r(require("url"));function r(e){return e&&e.__esModule?e:{default:e}}async function i(r,i,o,a="POST"){const n={Accept:"application/json","Content-Type":"application/json"},s=JSON.stringify(o),c=t.default.resolve(r,i);try{const t=await(0,e.default)(c,{method:a,headers:n,credentials:"same-origin",body:s});return await t.json()}catch(l){console.log(`Error fetching data from API: ${r}`)}}async function o(e,t,r,o){return(await i(e,"/similarity",{model:t,text1:r,text2:o})).similarity}
},{}],"nJFl":[function(require,module,exports) {
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Token=exports.Span=exports.Doc=void 0;var t=require("./util");class s{constructor(t,s,i={}){this._doc=i.doc||{},this._tokens=i.tokens||[],this._ents=i.ents||[],this._sents=i.sents||[],this._chunks=i.chunks||[],this._model=i.model,this._api=i.api,this.tokens=t.map((t,i)=>new e(this,t,s[i],this._tokens[i]));for(let e=0;e<this.tokens.length;e++)this[e]=this.tokens[e];this.cats=this._doc.cats,this.isTagged=this._doc.is_tagged,this.isParsed=this._doc.is_parsed,this.isSentenced=this._doc.is_sentenced}inspect(){return this.text}get text(){let t="";for(let s of this.tokens)t+=s.textWithWs;return t}get length(){return this.tokens.length}get ents(){return this._ents.map(({start:t,end:s,label:e})=>new i(this,t,s,e))}get sents(){return this._sents.map(({start:t,end:s})=>new i(this,t,s))}get nounChunks(){return this._chunks.map(({start:t,end:s})=>new i(this,t,s))}*[Symbol.iterator](){let t=0;for(;void 0!==this.tokens[t];)yield this.tokens[t],++t}toString(){return this.text}map(t){let s=[];for(let i of this)s.push(t(i));return s}slice(t,s){return new i(this,t,s)}async similarity(s){return await(0,t.getSimilarity)(this._api,this._model,this.text,s.text)}}exports.Doc=s;class i{constructor(t,s,i,e){this.doc=t,this.start=s,this.end=i,this.label=e,this.tokens=[...this.doc].slice(this.start,this.end);for(let h=0;h<this.tokens.length;h++)this[h]=this.tokens[0]}get text(){let t="";for(let s of this.tokens)t+=s.textWithWs;return t}get length(){return this.tokens.length}*[Symbol.iterator](){let t=0;for(;void 0!==this.tokens[t];)yield this.tokens[t],++t}slice(t,s){return new i(this,t,s)}toString(){return this.text}inspect(){return this.text}async similarity(s){return await(0,t.getSimilarity)(this.doc._api,this.doc._model,this.text,s.text)}}exports.Span=i;class e{constructor(t,s,i,e={}){this.doc=t,this.whitespace=i?" ":"",this.text=s,this.textWithWs=this.text+this.whitespace,this.orth=e.orth,this.i=e.i,this.entType=e.ent_type,this.entIob=e.ent_iob,this.lemma=e.lemma,this.norm=e.norm,this.lower=e.lower,this.shape=e.shape,this.prefix=e.prefix,this.suffix=e.suffix,this.pos=e.pos,this.tag=e.tag,this.dep=e.dep,this.lang=e.lang,this.isAlpha=e.is_alpha,this.isAscii=e.is_ascii,this.isDigit=e.is_digit,this.isLower=e.is_lower,this.isUpper=e.is_upper,this.isTitle=e.is_title,this.isPunct=e.is_punct,this.isLeftPunct=e.is_left_punct,this.isRightPunct=e.is_right_punct,this.isSpace=e.is_space,this.isBracket=e.is_bracket,this.isCurrency=e.is_currency,this.likeUrl=e.like_url,this.likeNum=e.like_num,this.likeEmail=e.like_email,this.isOov=e.is_oov,this.isStop=e.is_stop,this.isSentStart=e.is_sent_start,this._head=e.head}get head(){return this.doc[this._head]}toString(){return this.text}inspect(){return this.text}async similarity(s){return await(0,t.getSimilarity)(this.doc._api,this.doc._model,this.text,s.text)}}exports.Token=e;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Token=exports.Span=exports.Doc=void 0;var t=require("./util");class s{constructor(t,s,i={}){this._doc=i.doc||{},this._tokens=i.tokens||[],this._ents=i.ents||[],this._sents=i.sents||[],this._chunks=i.noun_chunks||[],this._model=i.model,this._api=i.api,this.tokens=t.map((t,i)=>new e(this,t,s[i],this._tokens[i]));for(let e=0;e<this.tokens.length;e++)this[e]=this.tokens[e];this.cats=this._doc.cats,this.isTagged=this._doc.is_tagged,this.isParsed=this._doc.is_parsed,this.isSentenced=this._doc.is_sentenced}inspect(){return this.text}get text(){let t="";for(let s of this.tokens)t+=s.textWithWs;return t}get length(){return this.tokens.length}get ents(){return this._ents.map(({start:t,end:s,label:e})=>new i(this,t,s,e))}get sents(){return this._sents.map(({start:t,end:s})=>new i(this,t,s))}get nounChunks(){return this._chunks.map(({start:t,end:s})=>new i(this,t,s))}*[Symbol.iterator](){let t=0;for(;void 0!==this.tokens[t];)yield this.tokens[t],++t}toString(){return this.text}map(t){let s=[];for(let i of this)s.push(t(i));return s}slice(t,s){return new i(this,t,s)}async similarity(s){return await(0,t.getSimilarity)(this._api,this._model,this.text,s.text)}}exports.Doc=s;class i{constructor(t,s,i,e){this.doc=t,this.start=s,this.end=i,this._label=e,this.tokens=[...this.doc].slice(this.start,this.end);for(let h=0;h<this.tokens.length;h++)this[h]=this.tokens[0]}get text(){let t="";for(let s of this.tokens)t+=s.textWithWs;return t.trim()}get length(){return this.tokens.length}get label(){if(this._label)return this._label;for(let t of this.doc.ents)if(t.start===this.start&&t.end==this.end)return t.label}*[Symbol.iterator](){let t=0;for(;void 0!==this.tokens[t];)yield this.tokens[t],++t}slice(t,s){return new i(this,t,s)}toString(){return this.text}inspect(){return this.text}async similarity(s){return await(0,t.getSimilarity)(this.doc._api,this.doc._model,this.text,s.text)}}exports.Span=i;class e{constructor(t,s,i,e={}){this.doc=t,this.whitespace=i?" ":"",this.text=s,this.textWithWs=this.text+this.whitespace,this.orth=e.orth,this.i=e.i,this.entType=e.ent_type,this.entIob=e.ent_iob,this.lemma=e.lemma,this.norm=e.norm,this.lower=e.lower,this.shape=e.shape,this.prefix=e.prefix,this.suffix=e.suffix,this.pos=e.pos,this.tag=e.tag,this.dep=e.dep,this.isAlpha=e.is_alpha,this.isAscii=e.is_ascii,this.isDigit=e.is_digit,this.isLower=e.is_lower,this.isUpper=e.is_upper,this.isTitle=e.is_title,this.isPunct=e.is_punct,this.isLeftPunct=e.is_left_punct,this.isRightPunct=e.is_right_punct,this.isSpace=e.is_space,this.isBracket=e.is_bracket,this.isCurrency=e.is_currency,this.likeUrl=e.like_url,this.likeNum=e.like_num,this.likeEmail=e.like_email,this.isOov=e.is_oov,this.isStop=e.is_stop,this.isSentStart=e.is_sent_start,this._head=e.head}get length(){return this.text.length}get head(){return this.doc[this._head]}toString(){return this.text}inspect(){return this.text}async similarity(s){return await(0,t.getSimilarity)(this.doc._api,this.doc._model,this.text,s.text)}}exports.Token=e;
},{"./util":"Y/Oq"}],"hk5u":[function(require,module,exports) {

@@ -9,2 +9,2 @@ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var e=require("./tokens"),t=require("./util");class s{constructor(t,s="http://localhost:8080"){const a=this;return async function(o){const{words:r,spaces:c,attrs:n}=await a.makeDoc(t,o,s);return new e.Doc(r,c,n)}}async makeDoc(e,s,a){const o=await(0,t.makeRequest)(a,"parse",{model:e,text:s});return{words:o.tokens.map(({text:e})=>e),spaces:o.tokens.map(({whitespace:e})=>Boolean(e)),attrs:Object.assign({},o,{api:a})}}}exports.default=s;

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"Doc",{enumerable:!0,get:function(){return r.Doc}}),Object.defineProperty(exports,"Token",{enumerable:!0,get:function(){return r.Token}}),Object.defineProperty(exports,"Span",{enumerable:!0,get:function(){return r.Span}}),exports.default=void 0;var e=t(require("./language")),r=require("./tokens");function t(e){return e&&e.__esModule?e:{default:e}}var n={load:function(r,t){return new e.default(r,t)}};exports.default=n;
},{"./language":"hk5u","./tokens":"nJFl"}]},{},["Focm"], null)
},{"./language":"hk5u","./tokens":"nJFl"}]},{},["Focm"], "spacy")
{
"name": "spacy",
"version": "0.0.3",
"version": "0.0.4",
"description": "JavaScript API for spaCy with Python REST API",

@@ -8,4 +8,4 @@ "main": "dist/index.js",

"test": "jest",
"build": "parcel build src/index.js --target node --no-source-maps",
"dev": "parcel src/index.js --target node --no-source-maps",
"build": "parcel build src/index.js --target node --no-source-maps --global spacy",
"dev": "parcel src/index.js --target node --no-source-maps --global spacy",
"package": "npm run build && npm pack"

@@ -12,0 +12,0 @@ },

@@ -271,5 +271,30 @@ <a href="https://explosion.ai"><img src="https://explosion.ai/assets/img/logo.svg" width="125" height="125" align="right" /></a>

## 🔔 Run Tests
### Python
First, make sure you have `pytest` and all dependencies installed. You can then
run the tests by pointing `pytest` to [`/tests`](/tests):
```bash
python -m pytest tests
```
### JavaScript
This project uses [Jest](https://jestjs.io) for testing. Make sure you have
all dependencies and development dependencies installed. You can then run:
```bash
npm run test
```
To allow testing the code without a REST API providing the data, the test suite
currently uses a [mock of the `Language` class](src/__mocks__), which returns
static data located in [`tests/util.js`](tests/util.js).
## ✅ Ideas and Todos
- [ ] Add JavaScript tests.
- [ ] Add Travis CI integration.
- [ ] Improve JavaScript tests.
- [ ] Experiment with NodeJS bindings to make Python integration easier. To be fair, running a separate API in an environment controlled by the user and *not* hiding it a few levels deep is often much easier. But maybe there are some modern Node tricks that this project could benefit from.

@@ -9,3 +9,3 @@ import { getSimilarity } from './util'

this._sents = attrs.sents || [];
this._chunks = attrs.chunks || [];
this._chunks = attrs.noun_chunks || [];
this._model = attrs.model;

@@ -85,3 +85,3 @@ this._api = attrs.api;

this.end = end;
this.label = label;
this._label = label;
this.tokens = [...this.doc].slice(this.start, this.end);

@@ -98,3 +98,3 @@ for (let i = 0; i < this.tokens.length; i++) {

}
return text;
return text.trim();
}

@@ -106,2 +106,14 @@

get label() {
if (this._label) {
return this._label;
}
// Manually check if span is an entity
for (let ent of this.doc.ents) {
if (ent.start === this.start && ent.end == this.end) {
return ent.label;
}
}
}
*[Symbol.iterator]() {

@@ -151,3 +163,2 @@ let i = 0;

this.dep = attrs.dep;
this.lang = attrs.lang;
this.isAlpha = attrs.is_alpha;

@@ -175,2 +186,6 @@ this.isAscii = attrs.is_ascii;

get length() {
return this.text.length;
}
get head() {

@@ -177,0 +192,0 @@ return this.doc[this._head];

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc