diff --git a/examples/browser/corenlp.min.js b/examples/browser/corenlp.min.js index 4d26fdf..f9f3baa 100644 --- a/examples/browser/corenlp.min.js +++ b/examples/browser/corenlp.min.js @@ -1 +1 @@ -!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).CoreNLP=e()}}(function(){return function(){return function e(t,n,r){function o(s,i){if(!n[s]){if(!t[s]){var u="function"==typeof require&&require;if(!i&&u)return u(s,!0);if(a)return a(s,!0);var p=new Error("Cannot find module '"+s+"'");throw p.code="MODULE_NOT_FOUND",p}var l=n[s]={exports:{}};t[s][0].call(l.exports,function(e){var n=t[s][1][e];return o(n||e)},l,l.exports,e,t,n,r)}return n[s].exports}for(var a="function"==typeof require&&require,s=0;s-1}function f(e,t,n){for(var r=-1,o=e?e.length:0;++r=n&&(i=m,u=!1,t=new R(t));e:for(;++s-1},E.prototype.set=function(e,t){var n=this.__data__,r=J(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},C.prototype.clear=function(){this.__data__={hash:new D,map:new(I||E),string:new D}},C.prototype.delete=function(e){return F(this,e).delete(e)},C.prototype.get=function(e){return F(this,e).get(e)},C.prototype.has=function(e){return F(this,e).has(e)},C.prototype.set=function(e,t){return F(this,e).set(e,t),this},R.prototype.add=R.prototype.push=function(e){return this.__data__.set(e,r),this},R.prototype.has=function(e){return this.__data__.has(e)};var B,W,U=(B=function(e,t){return K(e)?$(e,function e(t,n,r,o,a){var s=-1,i=t.length;for(r||(r=q),a||(a=[]);++s0&&r(u)?n>1?e(u,n-1,r,o,a):h(a,u):o||(a[a.length]=u)}return a}(t,1,K,!0)):[]},W=T(void 0===W?B.length-1:W,0),function(){for(var e=arguments,t=-1,n=T(e.length-W,0),r=Array(n);++t-1&&e%1==0&&e<=o}(e.length)&&!Q(e)}function K(e){return function(e){return!!e&&"object"==typeof e}(e)&&H(e)}function Q(e){var t=X(e)?P.call(e):"";return t==s||t==i}function X(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}t.exports=U}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],3:[function(e,t,n){(function(e){var n=9007199254740991,r="[object Arguments]",o="[object Function]",a="[object GeneratorFunction]",s="object"==typeof e&&e&&e.Object===Object&&e,i="object"==typeof self&&self&&self.Object===Object&&self,u=s||i||Function("return this")();function p(e,t){for(var n=-1,r=t.length,o=e.length;++n-1&&e%1==0&&e<=n}(e.length)&&!function(e){var t=function(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}(e)?d.call(e):"";return t==o||t==a}(e)}(e)}(e)&&c.call(e,"callee")&&(!h.call(e,"callee")||d.call(e)==r)}(e)||!!(g&&e&&e[g])}var _=Array.isArray;t.exports=function(e){return e&&e.length?function e(t,n,r,o,a){var s=-1,i=t.length;for(r||(r=m),a||(a=[]);++s0&&r(u)?n>1?e(u,n-1,r,o,a):p(a,u):o||(a[a.length]=u)}return a}(e,1):[]}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],4:[function(e,t,n){t.exports=function(e){return e&&e.length?e[0]:void 0}},{}],5:[function(e,t,n){(function(e){var r=200,o="Expected a function",a="__lodash_hash_undefined__",s=1,i=2,u=1/0,p=9007199254740991,l="[object Arguments]",c="[object Array]",d="[object Boolean]",f="[object Date]",h="[object Error]",g="[object Function]",m="[object GeneratorFunction]",_="[object Map]",v="[object Number]",b="[object Object]",x="[object RegExp]",y="[object Set]",j="[object String]",w="[object Symbol]",O="[object ArrayBuffer]",P="[object DataView]",k=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,S=/^\w*$/,A=/^\./,N=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,V=/\\(\\)?/g,T=/^\[object .+?Constructor\]$/,I=/^(?:0|[1-9]\d*)$/,M={};M["[object Float32Array]"]=M["[object Float64Array]"]=M["[object Int8Array]"]=M["[object Int16Array]"]=M["[object Int32Array]"]=M["[object Uint8Array]"]=M["[object Uint8ClampedArray]"]=M["[object Uint16Array]"]=M["[object Uint32Array]"]=!0,M[l]=M[c]=M[O]=M[d]=M[P]=M[f]=M[h]=M[g]=M[_]=M[v]=M[b]=M[x]=M[y]=M[j]=M["[object WeakMap]"]=!1;var D="object"==typeof e&&e&&e.Object===Object&&e,E="object"==typeof self&&self&&self.Object===Object&&self,C=D||E||Function("return this")(),R="object"==typeof n&&n&&!n.nodeType&&n,J=R&&"object"==typeof t&&t&&!t.nodeType&&t,$=J&&J.exports===R&&D.process,z=function(){try{return $&&$.binding("util")}catch(e){}}(),F=z&&z.isTypedArray;function L(e,t,n,r){var o=-1,a=e?e.length:0;for(r&&a&&(n=e[++o]);++o-1},ke.prototype.set=function(e,t){var n=this.__data__,r=Te(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},Se.prototype.clear=function(){this.__data__={hash:new Pe,map:new(de||ke),string:new Pe}},Se.prototype.delete=function(e){return Be(this,e).delete(e)},Se.prototype.get=function(e){return Be(this,e).get(e)},Se.prototype.has=function(e){return Be(this,e).has(e)},Se.prototype.set=function(e,t){return Be(this,e).set(e,t),this},Ae.prototype.add=Ae.prototype.push=function(e){return this.__data__.set(e,a),this},Ae.prototype.has=function(e){return this.__data__.has(e)},Ne.prototype.clear=function(){this.__data__=new ke},Ne.prototype.delete=function(e){return this.__data__.delete(e)},Ne.prototype.get=function(e){return this.__data__.get(e)},Ne.prototype.has=function(e){return this.__data__.has(e)},Ne.prototype.set=function(e,t){var n=this.__data__;if(n instanceof ke){var o=n.__data__;if(!de||o.lengthp))return!1;var c=a.get(e);if(c&&a.get(t))return c==t;var d=-1,f=!0,h=o&s?new Ae:void 0;for(a.set(e,t),a.set(t,e);++d-1&&e%1==0&&e-1&&e%1==0&&e<=p}function it(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function ut(e){return!!e&&"object"==typeof e}function pt(e){return"symbol"==typeof e||ut(e)&&oe.call(e)==w}var lt=F?function(e){return function(t){return e(t)}}(F):function(e){return ut(e)&&st(e.length)&&!!M[oe.call(e)]};function ct(e){return ot(e)?Ve(e):Fe(e)}function dt(e){return e}t.exports=function(e,t,n){var r=rt(e)?L:B,o=arguments.length<3;return r(e,ze(t),n,o,De)}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],6:[function(e,t,n){(function(e){var n=200,r="__lodash_hash_undefined__",o="[object Function]",a="[object GeneratorFunction]",s=/^\[object .+?Constructor\]$/,i="object"==typeof e&&e&&e.Object===Object&&e,u="object"==typeof self&&self&&self.Object===Object&&self,p=i||u||Function("return this")();function l(e,t){return!!(e?e.length:0)&&function(e,t,n){if(t!=t)return function(e,t,n,r){var o=e.length,a=n+(r?1:-1);for(;r?a--:++a-1}function c(e,t,n){for(var r=-1,o=e?e.length:0;++r-1},V.prototype.set=function(e,t){var n=this.__data__,r=M(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},T.prototype.clear=function(){this.__data__={hash:new N,map:new(k||V),string:new N}},T.prototype.delete=function(e){return C(this,e).delete(e)},T.prototype.get=function(e){return C(this,e).get(e)},T.prototype.has=function(e){return C(this,e).has(e)},T.prototype.set=function(e,t){return C(this,e).set(e,t),this},I.prototype.add=I.prototype.push=function(e){return this.__data__.set(e,r),this},I.prototype.has=function(e){return this.__data__.has(e)};var E=S&&1/h(new S([,-0]))[1]==1/0?function(e){return new S(e)}:function(){};function C(e,t){var n,r,o=e.__data__;return("string"==(r=typeof(n=t))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof t?"string":"hash"]:o.map}function R(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return D(n)?n:void 0}function J(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}t.exports=function(e){return e&&e.length?function(e,t,r){var o=-1,a=l,s=e.length,i=!0,u=[],p=u;if(r)i=!1,a=c;else if(s>=n){var d=t?null:E(e);if(d)return h(d);i=!1,a=f,p=new I}else p=t?[]:u;e:for(;++othis._exec(`java ${n.concat([`-file ${e.path}`]).join(" ")}`).then(e=>{const t=(e.stdout||e.stderr).match(/writing to (.*\.json)/)[1];return this._loadJSONFile(t)}))}}},{"child-process-promise":1,"load-json-file":1,"tmp-file":1}],8:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r,o=Object.assign||function(e){for(var t=1;t0===e.indexOf(`${a}.`)).map(e=>`${e.replace(`${a}.`,"")}=${encodeURI(n[e])}`).join("&")}`),this._makeRequest(i,u,t)}_makeRequest(e,t,n){const r={method:"POST",uri:`${e}?${t}`,headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},body:n,json:!0};return this._rp(r)}}},{"request-promise-native":11}],9:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.ConnectorServer=n.ConnectorCli=n.Service=n.Pipeline=n.Properties=void 0;var r=P(e("./simple/document")),o=P(e("./simple/sentence")),a=P(e("./simple/token")),s=P(e("./simple/expression")),i=P(e("./simple/annotable")),u=P(e("./simple/annotator")),p=P(e("./simple/annotator/tokenize")),l=P(e("./simple/annotator/ssplit")),c=P(e("./simple/annotator/pos")),d=P(e("./simple/annotator/lemma")),f=P(e("./simple/annotator/ner")),h=P(e("./simple/annotator/parse")),g=P(e("./simple/annotator/depparse")),m=P(e("./simple/annotator/relation")),_=P(e("./simple/annotator/regexner")),v=P(e("./simple/annotator/coref")),b=P(e("./util/tree")),x=P(e("./properties")),y=P(e("./pipeline")),j=P(e("./service")),w=P(e("./connector/connector-cli")),O=P(e("./connector/connector-server"));function P(e){return e&&e.__esModule?e:{default:e}}n.Properties=x.default,n.Pipeline=y.default,n.Service=j.default,n.ConnectorCli=w.default,n.ConnectorServer=O.default;n.default={simple:{Annotable:i.default,Annotator:u.default,Document:r.default,Sentence:o.default,Token:a.default,Expression:s.default,annotator:{TokenizerAnnotator:p.default,WordsToSentenceAnnotator:l.default,POSTaggerAnnotator:c.default,MorphaAnnotator:d.default,NERClassifierCombiner:f.default,ParserAnnotator:h.default,DependencyParseAnnotator:g.default,RelationExtractorAnnotator:m.default,RegexNERAnnotator:_.default,CorefAnnotator:v.default}},util:{Tree:b.default}}},{"./connector/connector-cli":7,"./connector/connector-server":8,"./pipeline":10,"./properties":12,"./service":13,"./simple/annotable":14,"./simple/annotator":15,"./simple/annotator/coref":16,"./simple/annotator/depparse":17,"./simple/annotator/lemma":19,"./simple/annotator/ner":20,"./simple/annotator/parse":21,"./simple/annotator/pos":24,"./simple/annotator/regexner":27,"./simple/annotator/relation":28,"./simple/annotator/ssplit":29,"./simple/annotator/tokenize":30,"./simple/document":33,"./simple/expression":36,"./simple/sentence":38,"./simple/token":39,"./util/tree":40}],10:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=Object.assign||function(e){for(var t=1;t(new e).toString()),this._getAnnotatorsKeys()).length>0)throw new Error(`Assert: ${e} requires ${t.join()} within the annotators list.`)}annotateTokensRegex(e,t=!1){var n=this;return x(function*(){return n.assert("TokensRegex",[i.default,u.default]),e.fromJSON(yield n._service.getTokensRegexData(e.text(),e.pattern(),n._getAnnotatorsKeys(),n._getAnnotatrosOptions())),e.setLanguageISO(j[n._language]),e.addAnnotator(v.TokensRegexAnnotator),t?n._annotateExpression(e):e})()}annotateSemgrex(e,t=!1){var n=this;return x(function*(){return n.assert("Semgrex",[i.default,u.default,f.default]),e.fromJSON(yield n._service.getSemgrexData(e.text(),e.pattern(),n._getAnnotatorsKeys(),n._getAnnotatrosOptions())),e.setLanguageISO(j[n._language]),e.addAnnotator(v.SemgrexAnnotator),t?n._annotateExpression(e):e})()}annotateTregex(e,t=!1){var n=this;return x(function*(){return n.assert("Tregex",[i.default,u.default,d.default]),e.fromJSON(yield n._service.getTregexData(e.text(),e.pattern(),n._getAnnotatorsKeys(),n._getAnnotatrosOptions())),e.setLanguageISO(j[n._language]),e.addAnnotator(v.TregexAnnotator),t?n._annotateExpression(e):e})()}_annotateExpression(e){var t=this;return x(function*(){const n=yield t.annotate(new _.default(e.text()));return n.setLanguageISO(j[t._language]),e.mergeTokensFromDocument(n),e})()}_semgrex(e,t){var n=this;return x(function*(){return yield n._service.getSemgrexData(e,t,n._getAnnotatorsKeys(),n._getAnnotatrosOptions())})()}_getAnnotatorsKeys(){return this._properties.getProperty("annotators","").split(",").map(e=>e.trim())}_getAnnotators(){return this._getAnnotatorsKeys().map(e=>y[e])}_getAnnotatrosOptions(){const e=this._properties.getProperties(),t=Object.keys(y);return Object.keys(e).filter(e=>0===t.indexOf(e)).reduce((e,t,n)=>r({},e,{[n]:t}),{})}}},{"./connector/connector-server":8,"./service":13,"./simple/annotator/coref":16,"./simple/annotator/depparse":17,"./simple/annotator/lemma":19,"./simple/annotator/ner":20,"./simple/annotator/parse":21,"./simple/annotator/pos":24,"./simple/annotator/regexner":27,"./simple/annotator/relation":28,"./simple/annotator/ssplit":29,"./simple/annotator/tokenize":30,"./simple/document":33,"./simple/expression":36,"lodash.difference":2}],11:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=Object.assign||function(e){for(var t=1;tfetch(encodeURI(e.uri),r({},e,{withCredentials:!0})).then(e=>e.json()))},{}],12:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=Object.assign||function(e){for(var t=1;t`${e} = ${this._props[e]}`).join("\n")}}},{}],13:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r,o=Object.assign||function(e){for(var t=1;tthis.addAnnotator(e))}removeAnnotator(e){delete this._annotators[e.toString()]}hasAnnotator(e){return!!this._annotators[e.toString()]}hasAnyAnnotator(e){return e.some(e=>!!~Object.keys(this._annotators).indexOf(e.toString()))}}},{}],15:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=Object.assign||function(e){for(var t=1;te.pipeline())).concat([this.toString()]))}pipelineOptions(){return(0,s.default)(this.dependencies().map(e=>e.pipelineOptions()).concat(Object.keys(this.options()).map(e=>({[`${this}.${e}`]:this.option(e)}))),(e,t)=>r({},e,t),{})}}},{"lodash.flatten":3,"lodash.reduce":5,"lodash.uniq":6}],16:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=Object.assign||function(e){for(var t=1;te.isRepresentativeMention())}nonRepresentatives(){return this._mentions.filter(e=>!e.isRepresentativeMention())}document(e=null){return e&&(this._document=e),this._document}fromDocument(e){return this._mentions.forEach(t=>{const n=e.sentence(t.sentNum()-1),r=n.token(t.startIndex()-1);t.sentence(n),t.token(r)}),this}fromJSON(e){return this._mentions=e.map(e=>a.default.fromJSON(e)),this}toJSON(){return[...this._mentions]}static fromJSON(e){return(new this).fromJSON(e)}}},{"./coref-mention":32}],32:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=Object.assign||function(e){for(var t=1;te.toString()).join(". ")}sentences(){if(!this.hasAnnotator(o.default))throw new Error("Asked for sentences on Document, but there are unmet annotator dependencies.");return this._sentences}sentence(e){return this.sentences()[e]}corefs(){if(!this.hasAnnotator(i.default))throw new Error("Asked for corefs on Document, but there are unmet annotator dependencies.");return this._corefs}coref(e){return this.corefs()[e]}setLanguageISO(e){super.setLanguageISO(e),this._sentences.forEach(t=>t.setLanguageISO(e))}fromJSON(e){return e.sentences&&(this.addAnnotator(o.default),this._sentences=e.sentences.map(e=>a.default.fromJSON(e,!0))),e.corefs&&(this.addAnnotator(i.default),this._corefs=Object.keys(e.corefs).filter(e=>"length"!==e).map(t=>s.default.fromJSON(e.corefs[t]).fromDocument(this))),this}toJSON(){return{text:this._text,sentences:this._sentences}}static fromJSON(e){return(new this).fromJSON(e)}}},{"./annotable":14,"./annotator/coref":16,"./annotator/ssplit":29,"./coref-chain":31,"./sentence":38}],34:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=Object.assign||function(e){for(var t=1;tthis.group(e)))}group(e){return this._data[`$${e}`]}labels(){return Object.keys(this._data).filter(e=>/^\$/.test(e)).map(e=>e.substr(1))}fromJSON(e){return this._data=e,this}toJSON(){return r({},this._data)}static fromJSON(e){return(new this).fromJSON(e)}}},{}],35:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r,o=e("./expression-sentence-match"),a=(r=o)&&r.__esModule?r:{default:r};n.default=class{constructor(e){this._matches=e}matches(){return this._matches}match(e){return this._matches[e]}mergeTokensFromSentence(e){return this.matches().forEach(t=>t.groups().forEach(t=>{t.token=(t=>e.tokens().find(e=>e.index()===t.begin+1&&e.toString()===t.text))(t)||t.token})),this}fromJSON(e){return this._matches=Object.keys(e).filter(e=>"length"!==e).map(t=>a.default.fromJSON(e[t])),this}toJSON(){return[...this._matches]}static fromJSON(e){return(new this).fromJSON(e)}}},{"./expression-sentence-match":34}],36:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.TregexAnnotator=n.SemgrexAnnotator=n.TokensRegexAnnotator=void 0;var r=s(e("./annotable")),o=s(e("./annotator")),a=s(e("./expression-sentence"));function s(e){return e&&e.__esModule?e:{default:e}}n.TokensRegexAnnotator=class extends o.default{};n.SemgrexAnnotator=class extends o.default{};n.TregexAnnotator=class extends o.default{};n.default=class extends r.default{constructor(e,t){super(e),this._pattern=t,this._sentences=[]}toString(){return this._text}pattern(){return this._pattern}sentences(){return this._sentences}sentence(e){return this.sentences()[e]}mergeTokensFromDocument(e){return e.sentences().forEach((e,t)=>this.sentence(t).mergeTokensFromSentence(e)),this}fromJSON(e){return e.sentences&&(this._sentences=e.sentences.map(e=>a.default.fromJSON(e))),this}toJSON(){return{text:this._text,sentences:this._sentences}}static fromJSON(e){return(new this).fromJSON(e)}}},{"./annotable":14,"./annotator":15,"./expression-sentence":35}],37:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r,o=e("../service"),a=(r=o)&&r.__esModule?r:{default:r};n.default=class{constructor(e,t,n=null){this._dep=e,this._dependentToken=t,this._governorToken=n}toString(){return this._dep}governor(){return this._governorToken}governorGloss(){return this._governorToken?this._governorToken.word():""}dependent(){return this._dependentToken}dependentGloss(){return this._dependentToken.word()?this._dependentToken.word():""}dep(){return this._dep}depInfo(){return a.default.getGovernorDepInfo(this._dep)}toJSON(){return{dep:this._dep,governor:this._governorToken?this._governorToken.index():0,governorGloss:this._governorToken?this._governorToken.word():"ROOT",dependent:this._dependentToken.index(),dependentGloss:this._dependentToken.word()}}static fromJSON(){throw Error("Not implemented")}}},{"../service":13}],38:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=Object.assign||function(e){for(var t=1;te.toString()).join(" ")}index(){return this._index}parse(){return this._parse}words(){if(!this.hasAnnotator(s.default))throw new Error("Asked for words on Sentence, but there are unmet annotator dependencies.");return this._tokens.map(e=>e.word())}word(e){if(!this.hasAnnotator(s.default))throw new Error("Asked for a word on Sentence, but there are unmet annotator dependencies.");if(!this._tokens[e])throw new Error(`Sentence instance does not contain a token with index ${e}`);return this._tokens[e].word()}[Symbol.iterator](){return this._tokens.values()}posTags(){return this._tokens.map(e=>e.pos())}posTag(e){if(!this._tokens[e])throw new Error(`Sentence instance does not contain a token with index ${e}`);return this._tokens[e].pos()}lemmas(){return this._tokens.map(e=>e.lemma())}lemma(e){if(!this._tokens[e])throw new Error(`Sentence instance does not contain a token with index ${e}`);return this._tokens[e].lemma()}nerTags(){return this._tokens.map(e=>e.ner())}nerTag(e){if(!this._tokens[e])throw new Error(`Sentence instance does not contain a token with index ${e}`);return this._tokens[e].ner()}governors(){if(!this.hasAnnotator(u.default))throw new Error("Asked for governors on Sentence, but there are unmet annotator dependencies.");return this._governors}governor(e){if(!this.hasAnnotator(u.default))throw new Error("Asked for a governor on Sentence, but there are unmet annotator dependencies.");return this._governors[e]}incommingDependencyLabel(e){}natlogPolarities(){}natlogPolarity(e){}openie(){}openieTriples(e){}tokens(){if(!this.hasAnnotator(s.default))throw new Error("Asked for tokens on Sentence, but there are unmet annotator dependencies.");return this._tokens}token(e){if(!this.hasAnnotator(s.default))throw new Error("Asked for a token on Sentence, but there are unmet annotator dependencies.");return this._tokens[e]}algorithms(){}setLanguageISO(e){super.setLanguageISO(e),this._tokens.forEach(t=>t.setLanguageISO(e))}toJSON(){let e={index:this._index,tokens:this._tokens.map(e=>e.toJSON()),basicDependencies:this._governors.map(e=>e.toJSON()),enhancedDependencies:this._enhancedDependencies,enhancedPlusPlusDependencies:this._enhancedPlusPlusDependencies};return this._parse&&(e=r({},e,{parse:this._parse})),e}fromJSON(e,t=!1){const n=t?e:(0,o.default)(e.sentences);return this._index=e.index,n.tokens&&(this.addAnnotator(s.default),this._tokens=n.tokens.map(e=>p.default.fromJSON(e))),n.parse&&(this.addAnnotator(i.default),this._parse=n.parse),n.basicDependencies&&(this.addAnnotator(u.default),this._governors=n.basicDependencies.map(e=>new l.default(e.dep,this._tokens[e.dependent-1],this._tokens[e.governor-1])),this._basicDependencies=n.basicDependencies,this._enhancedDependencies=n.enhancedDependencies,this._enhancedPlusPlusDependencies=n.enhancedPlusPlusDependencies),this}static fromJSON(e,t=!1){return(new this).fromJSON(e,t)}}},{"./annotable":14,"./annotator/depparse":17,"./annotator/parse":21,"./annotator/tokenize":30,"./governor":37,"./token":39,"lodash.head":4}],39:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=a(e("../service")),o=a(e("./annotable"));function a(e){return e&&e.__esModule?e:{default:e}}n.default=class extends o.default{constructor(e){super(e)}toString(){return this._text}index(){return this._index}word(){return this._text}originalText(){return this._originalText}characterOffsetBegin(){return this._characterOffsetBegin}characterOffsetEnd(){return this._characterOffsetEnd}before(){return this._before}after(){return this._after}lemma(){return this._lemma}pos(){return this._pos}posInfo(){return r.default.getTokenPosInfo(this._pos,this.getLanguageISO())}ner(){return this._ner}speaker(){return this._speaker}toJSON(){return{index:this._index,word:this._text,originalText:this._originalText,characterOffsetBegin:this._characterOffsetBegin,characterOffsetEnd:this._characterOffsetEnd,before:this._before,after:this._after,pos:this._pos,lemma:this._lemma,ner:this._ner,speaker:this._speaker}}static fromJSON(e){const t=new this;return t._index=e.index,t._text=e.word,t._originalText=e.originalText,t._characterOffsetBegin=e.characterOffsetBegin,t._characterOffsetEnd=e.characterOffsetEnd,t._before=e.before,t._after=e.after,t._pos=e.pos,t._lemma=e.lemma,t._ner=e.ner,t._speaker=e.speaker,t}}},{"../service":13,"./annotable":14}],40:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.Node=void 0;var r,o=e("../service"),a=(r=o)&&r.__esModule?r:{default:r};class s{constructor(e="",t="",n=[],r=null){this._pos=e,this._word=t,this._children=n,this._parent=r}pos(){return this._pos}posInfo(){return this._children.length?a.default.getSentenceParseInfo(this._pos,this.getLanguageISO()):a.default.getTokenPosInfo(this._pos,this.getLanguageISO())}token(e=null){return e&&(this._token=e),this._token}word(){return this._word}setLanguageISO(e){this._language=e}getLanguageISO(){return this._language}children(){return this._children}appendChild(e){this._children.push(e)}parent(e=null){return e&&(this._parent=e),this._parent}toJSON(){return{pos:this._pos,posInfo:this.posInfo(),word:this._word,token:this._token,children:this._children}}}n.Node=s;class i{constructor(e){this.rootNode=e}dump(){return JSON.stringify(this.rootNode,(e,t)=>t instanceof s?t.children().length?{pos:t.pos(),info:t.info(),children:t.children()}:{pos:t.pos(),info:t.info(),word:t.word(),token:t.token()}:t,2)}visitDeepFirst(e,t=this.rootNode){t.children().forEach(t=>{this.visitDeepFirst(e,t),e(t)}),e(t)}visitDeepFirstRight(e,t=this.rootNode){t.children().reverse().forEach(t=>{this.visitDeepFirstRight(e,t),e(t)}),e(t)}visitLeaves(e,t=this.rootNode){t.children().forEach(t=>{t.children().length?this.visitLeaves(e,t):e(t)}),t.children().length||e(t)}static fromSentence(e,t=!1){const n=e.parse();if(!n)throw new Error("Unable to create Tree from Sentence, did you run ParserAnnotator first?");const r=i.fromString(n,t);let o=0;r.visitLeaves(t=>t.token(e.token(o++)));const a=e.getLanguageISO();return a&&r.visitDeepFirst(e=>e.setLanguageISO(a)),r}static fromString(e,t=!1){return new i(this._transformTree(this._buildTree(e),t))}static _buildTree(e){let t={children:[]};const n=[t],r=e.length;for(let o=0;o-1?(e.pos=t.substr(0,n),e.word=t.substr(n+1)):e.pos=t}static _transformTree(e,t){if(t){const t=new s(e.pos,e.word);return e.children.forEach(e=>{const n=this._transformTree(e);n.parent(t),t.appendChild(n)}),t}return new s(e.pos,e.word,e.children.map(e=>this._transformTree(e)))}}n.default=i},{"../service":13}]},{},[9])(9)}); \ No newline at end of file +!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).CoreNLP=e()}}(function(){return function(){return function e(t,n,r){function o(s,i){if(!n[s]){if(!t[s]){var u="function"==typeof require&&require;if(!i&&u)return u(s,!0);if(a)return a(s,!0);var l=new Error("Cannot find module '"+s+"'");throw l.code="MODULE_NOT_FOUND",l}var p=n[s]={exports:{}};t[s][0].call(p.exports,function(e){return o(t[s][1][e]||e)},p,p.exports,e,t,n,r)}return n[s].exports}for(var a="function"==typeof require&&require,s=0;s-1}function f(e,t,n){for(var r=-1,o=e?e.length:0;++r=n&&(i=m,u=!1,t=new R(t));e:for(;++s-1},D.prototype.set=function(e,t){var n=this.__data__,r=J(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},C.prototype.clear=function(){this.__data__={hash:new E,map:new(M||D),string:new E}},C.prototype.delete=function(e){return L(this,e).delete(e)},C.prototype.get=function(e){return L(this,e).get(e)},C.prototype.has=function(e){return L(this,e).has(e)},C.prototype.set=function(e,t){return L(this,e).set(e,t),this},R.prototype.add=R.prototype.push=function(e){return this.__data__.set(e,r),this},R.prototype.has=function(e){return this.__data__.has(e)};var B,W,U=(B=function(e,t){return K(e)?$(e,function e(t,n,r,o,a){var s=-1,i=t.length;for(r||(r=q),a||(a=[]);++s0&&r(u)?n>1?e(u,n-1,r,o,a):h(a,u):o||(a[a.length]=u)}return a}(t,1,K,!0)):[]},W=T(void 0===W?B.length-1:W,0),function(){for(var e=arguments,t=-1,n=T(e.length-W,0),r=Array(n);++t-1&&e%1==0&&e<=o}(e.length)&&!Q(e)}function K(e){return function(e){return!!e&&"object"==typeof e}(e)&&H(e)}function Q(e){var t=X(e)?P.call(e):"";return t==s||t==i}function X(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}t.exports=U}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],3:[function(e,t,n){(function(e){var n=9007199254740991,r="[object Arguments]",o="[object Function]",a="[object GeneratorFunction]",s="object"==typeof e&&e&&e.Object===Object&&e,i="object"==typeof self&&self&&self.Object===Object&&self,u=s||i||Function("return this")();function l(e,t){for(var n=-1,r=t.length,o=e.length;++n-1&&e%1==0&&e<=n}(e.length)&&!function(e){var t=function(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}(e)?d.call(e):"";return t==o||t==a}(e)}(e)}(e)&&c.call(e,"callee")&&(!h.call(e,"callee")||d.call(e)==r)}(e)||!!(g&&e&&e[g])}var _=Array.isArray;t.exports=function(e){return e&&e.length?function e(t,n,r,o,a){var s=-1,i=t.length;for(r||(r=m),a||(a=[]);++s0&&r(u)?n>1?e(u,n-1,r,o,a):l(a,u):o||(a[a.length]=u)}return a}(e,1):[]}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],4:[function(e,t,n){t.exports=function(e){return e&&e.length?e[0]:void 0}},{}],5:[function(e,t,n){(function(e){var r=200,o="Expected a function",a="__lodash_hash_undefined__",s=1,i=2,u=1/0,l=9007199254740991,p="[object Arguments]",c="[object Array]",d="[object Boolean]",f="[object Date]",h="[object Error]",g="[object Function]",m="[object GeneratorFunction]",_="[object Map]",v="[object Number]",b="[object Object]",y="[object RegExp]",x="[object Set]",j="[object String]",w="[object Symbol]",O="[object ArrayBuffer]",P="[object DataView]",k=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,S=/^\w*$/,A=/^\./,N=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,V=/\\(\\)?/g,T=/^\[object .+?Constructor\]$/,M=/^(?:0|[1-9]\d*)$/,I={};I["[object Float32Array]"]=I["[object Float64Array]"]=I["[object Int8Array]"]=I["[object Int16Array]"]=I["[object Int32Array]"]=I["[object Uint8Array]"]=I["[object Uint8ClampedArray]"]=I["[object Uint16Array]"]=I["[object Uint32Array]"]=!0,I[p]=I[c]=I[O]=I[d]=I[P]=I[f]=I[h]=I[g]=I[_]=I[v]=I[b]=I[y]=I[x]=I[j]=I["[object WeakMap]"]=!1;var E="object"==typeof e&&e&&e.Object===Object&&e,D="object"==typeof self&&self&&self.Object===Object&&self,C=E||D||Function("return this")(),R="object"==typeof n&&n&&!n.nodeType&&n,J=R&&"object"==typeof t&&t&&!t.nodeType&&t,$=J&&J.exports===R&&E.process,z=function(){try{return $&&$.binding("util")}catch(e){}}(),L=z&&z.isTypedArray;function F(e,t,n,r){var o=-1,a=e?e.length:0;for(r&&a&&(n=e[++o]);++o-1},ke.prototype.set=function(e,t){var n=this.__data__,r=Te(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},Se.prototype.clear=function(){this.__data__={hash:new Pe,map:new(de||ke),string:new Pe}},Se.prototype.delete=function(e){return Be(this,e).delete(e)},Se.prototype.get=function(e){return Be(this,e).get(e)},Se.prototype.has=function(e){return Be(this,e).has(e)},Se.prototype.set=function(e,t){return Be(this,e).set(e,t),this},Ae.prototype.add=Ae.prototype.push=function(e){return this.__data__.set(e,a),this},Ae.prototype.has=function(e){return this.__data__.has(e)},Ne.prototype.clear=function(){this.__data__=new ke},Ne.prototype.delete=function(e){return this.__data__.delete(e)},Ne.prototype.get=function(e){return this.__data__.get(e)},Ne.prototype.has=function(e){return this.__data__.has(e)},Ne.prototype.set=function(e,t){var n=this.__data__;if(n instanceof ke){var o=n.__data__;if(!de||o.lengthl))return!1;var c=a.get(e);if(c&&a.get(t))return c==t;var d=-1,f=!0,h=o&s?new Ae:void 0;for(a.set(e,t),a.set(t,e);++d-1&&e%1==0&&e-1&&e%1==0&&e<=l}function it(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function ut(e){return!!e&&"object"==typeof e}function lt(e){return"symbol"==typeof e||ut(e)&&oe.call(e)==w}var pt=L?function(e){return function(t){return e(t)}}(L):function(e){return ut(e)&&st(e.length)&&!!I[oe.call(e)]};function ct(e){return ot(e)?Ve(e):Le(e)}function dt(e){return e}t.exports=function(e,t,n){var r=rt(e)?F:B,o=arguments.length<3;return r(e,ze(t),n,o,Ee)}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],6:[function(e,t,n){(function(e){var n=200,r="__lodash_hash_undefined__",o="[object Function]",a="[object GeneratorFunction]",s=/^\[object .+?Constructor\]$/,i="object"==typeof e&&e&&e.Object===Object&&e,u="object"==typeof self&&self&&self.Object===Object&&self,l=i||u||Function("return this")();function p(e,t){return!!(e?e.length:0)&&function(e,t,n){if(t!=t)return function(e,t,n,r){var o=e.length,a=n+(r?1:-1);for(;r?a--:++a-1}function c(e,t,n){for(var r=-1,o=e?e.length:0;++r-1},V.prototype.set=function(e,t){var n=this.__data__,r=I(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},T.prototype.clear=function(){this.__data__={hash:new N,map:new(k||V),string:new N}},T.prototype.delete=function(e){return C(this,e).delete(e)},T.prototype.get=function(e){return C(this,e).get(e)},T.prototype.has=function(e){return C(this,e).has(e)},T.prototype.set=function(e,t){return C(this,e).set(e,t),this},M.prototype.add=M.prototype.push=function(e){return this.__data__.set(e,r),this},M.prototype.has=function(e){return this.__data__.has(e)};var D=S&&1/h(new S([,-0]))[1]==1/0?function(e){return new S(e)}:function(){};function C(e,t){var n,r,o=e.__data__;return("string"==(r=typeof(n=t))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof t?"string":"hash"]:o.map}function R(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return E(n)?n:void 0}function J(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}t.exports=function(e){return e&&e.length?function(e,t,r){var o=-1,a=p,s=e.length,i=!0,u=[],l=u;if(r)i=!1,a=c;else if(s>=n){var d=t?null:D(e);if(d)return h(d);i=!1,a=f,l=new M}else l=t?[]:u;e:for(;++othis._exec(`java ${n.concat([`-file ${e.path}`]).join(" ")}`).then(e=>{const t=(e.stdout||e.stderr).match(/writing to (.*\.json)/)[1];return this._loadJSONFile(t)}))}}},{"child-process-promise":1,"load-json-file":1,"tmp-file":1}],8:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r,o=Object.assign||function(e){for(var t=1;t0===e.indexOf(`${a}.`)).map(e=>`${e.replace(`${a}.`,"")}=${encodeURI(n[e])}`).join("&")}`),this._makeRequest(i,u,t)}_makeRequest(e,t,n){const r={method:"POST",uri:`${e}?${t}`,headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"},body:n,json:!0};return this._username&&Object.assign(r,{auth:{user:this._username,pass:this._password}}),this._rp(r)}}},{"request-promise-native":11}],9:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.ConnectorServer=n.ConnectorCli=n.Service=n.Pipeline=n.Properties=void 0;var r=S(e("./simple/document")),o=S(e("./simple/sentence")),a=S(e("./simple/token")),s=S(e("./simple/expression")),i=S(e("./simple/annotable")),u=S(e("./simple/annotator")),l=S(e("./simple/annotator/tokenize")),p=S(e("./simple/annotator/natlog")),c=S(e("./simple/annotator/openie")),d=S(e("./simple/annotator/ssplit")),f=S(e("./simple/annotator/pos")),h=S(e("./simple/annotator/lemma")),g=S(e("./simple/annotator/ner")),m=S(e("./simple/annotator/parse")),_=S(e("./simple/annotator/depparse")),v=S(e("./simple/annotator/relation")),b=S(e("./simple/annotator/regexner")),y=S(e("./simple/annotator/coref")),x=S(e("./util/tree")),j=S(e("./properties")),w=S(e("./pipeline")),O=S(e("./service")),P=S(e("./connector/connector-cli")),k=S(e("./connector/connector-server"));function S(e){return e&&e.__esModule?e:{default:e}}n.Properties=j.default,n.Pipeline=w.default,n.Service=O.default,n.ConnectorCli=P.default,n.ConnectorServer=k.default;n.default={simple:{Annotable:i.default,Annotator:u.default,Document:r.default,Sentence:o.default,Token:a.default,Expression:s.default,annotator:{TokenizerAnnotator:l.default,WordsToSentenceAnnotator:d.default,POSTaggerAnnotator:f.default,MorphaAnnotator:h.default,NERClassifierCombiner:g.default,ParserAnnotator:m.default,DependencyParseAnnotator:_.default,RelationExtractorAnnotator:v.default,RegexNERAnnotator:b.default,CorefAnnotator:y.default,NaturalLogicAnnotator:p.default,OpenIEAnnotator:c.default}},util:{Tree:x.default}}},{"./connector/connector-cli":7,"./connector/connector-server":8,"./pipeline":10,"./properties":12,"./service":13,"./simple/annotable":14,"./simple/annotator":15,"./simple/annotator/coref":16,"./simple/annotator/depparse":17,"./simple/annotator/lemma":19,"./simple/annotator/natlog":20,"./simple/annotator/ner":21,"./simple/annotator/openie":22,"./simple/annotator/parse":23,"./simple/annotator/pos":26,"./simple/annotator/regexner":29,"./simple/annotator/relation":30,"./simple/annotator/ssplit":31,"./simple/annotator/tokenize":32,"./simple/document":35,"./simple/expression":38,"./simple/sentence":40,"./simple/token":41,"./util/tree":42}],10:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=Object.assign||function(e){for(var t=1;t(new e).toString()),this._getAnnotatorsKeys()).length>0)throw new Error(`Assert: ${e} requires ${t.join()} within the annotators list.`)}annotateTokensRegex(e,t=!1){var n=this;return j(function*(){return n.assert("TokensRegex",[i.default,p.default]),e.fromJSON(yield n._service.getTokensRegexData(e.text(),e.pattern(),n._getAnnotatorsKeys(),n._getAnnotatorsOptions())),e.setLanguageISO(O[n._language]),e.addAnnotator(y.TokensRegexAnnotator),t?n._annotateExpression(e):e})()}annotateSemgrex(e,t=!1){var n=this;return j(function*(){return n.assert("Semgrex",[i.default,p.default,g.default]),e.fromJSON(yield n._service.getSemgrexData(e.text(),e.pattern(),n._getAnnotatorsKeys(),n._getAnnotatorsOptions())),e.setLanguageISO(O[n._language]),e.addAnnotator(y.SemgrexAnnotator),t?n._annotateExpression(e):e})()}annotateTregex(e,t=!1){var n=this;return j(function*(){return n.assert("Tregex",[i.default,p.default,h.default]),e.fromJSON(yield n._service.getTregexData(e.text(),e.pattern(),n._getAnnotatorsKeys(),n._getAnnotatorsOptions())),e.setLanguageISO(O[n._language]),e.addAnnotator(y.TregexAnnotator),t?n._annotateExpression(e):e})()}_annotateExpression(e){var t=this;return j(function*(){const n=yield t.annotate(new b.default(e.text()));return n.setLanguageISO(O[t._language]),e.mergeTokensFromDocument(n),e})()}_semgrex(e,t){var n=this;return j(function*(){return yield n._service.getSemgrexData(e,t,n._getAnnotatorsKeys(),n._getAnnotatorsOptions())})()}_getAnnotatorsKeys(){return this._properties.getProperty("annotators","").split(",").map(e=>e.trim())}_getAnnotators(){return this._getAnnotatorsKeys().map(e=>w[e])}_getAnnotatorsOptions(){const e=this._properties.getProperties(),t=Object.keys(w);return Object.keys(e).filter(e=>t.includes(e.split(".")[0])).reduce((t,n)=>r({},t,{[n]:e[n]}),{})}}},{"./connector/connector-server":8,"./service":13,"./simple/annotator/coref":16,"./simple/annotator/depparse":17,"./simple/annotator/lemma":19,"./simple/annotator/natlog":20,"./simple/annotator/ner":21,"./simple/annotator/openie":22,"./simple/annotator/parse":23,"./simple/annotator/pos":26,"./simple/annotator/regexner":29,"./simple/annotator/relation":30,"./simple/annotator/ssplit":31,"./simple/annotator/tokenize":32,"./simple/document":35,"./simple/expression":38,"lodash.difference":2}],11:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=Object.assign||function(e){for(var t=1;tfetch(encodeURI(e.uri),r({},e,{withCredentials:!0})).then(e=>e.json()))},{}],12:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=Object.assign||function(e){for(var t=1;t`${e} = ${this._props[e]}`).join("\n")}}},{}],13:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r,o=Object.assign||function(e){for(var t=1;tthis.addAnnotator(e))}removeAnnotator(e){delete this._annotators[e.toString()]}hasAnnotator(e){return!!this._annotators[e.toString()]}hasAnyAnnotator(e){return e.some(e=>!!~Object.keys(this._annotators).indexOf(e.toString()))}}},{}],15:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=Object.assign||function(e){for(var t=1;te.pipeline())).concat([this.toString()]))}pipelineOptions(){return(0,s.default)(this.dependencies().map(e=>e.pipelineOptions()).concat(Object.keys(this.options()).map(e=>({[`${this}.${e}`]:this.option(e)}))),(e,t)=>r({},e,t),{})}}},{"lodash.flatten":3,"lodash.reduce":5,"lodash.uniq":6}],16:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=Object.assign||function(e){for(var t=1;te.isRepresentativeMention())}nonRepresentatives(){return this._mentions.filter(e=>!e.isRepresentativeMention())}document(e=null){return e&&(this._document=e),this._document}fromDocument(e){return this._mentions.forEach(t=>{const n=e.sentence(t.sentNum()-1),r=n.token(t.startIndex()-1);t.sentence(n),t.token(r)}),this}fromJSON(e){return this._mentions=e.map(e=>a.default.fromJSON(e)),this}toJSON(){return[...this._mentions]}static fromJSON(e){return(new this).fromJSON(e)}}},{"./coref-mention":34}],34:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=Object.assign||function(e){for(var t=1;te.toString()).join(". ")}sentences(){if(!this.hasAnnotator(o.default))throw new Error("Asked for sentences on Document, but there are unmet annotator dependencies.");return this._sentences}sentence(e){return this.sentences()[e]}corefs(){if(!this.hasAnnotator(i.default))throw new Error("Asked for corefs on Document, but there are unmet annotator dependencies.");return this._corefs}coref(e){return this.corefs()[e]}setLanguageISO(e){super.setLanguageISO(e),this._sentences.forEach(t=>t.setLanguageISO(e))}fromJSON(e){return e.sentences&&(this.addAnnotator(o.default),this._sentences=e.sentences.map(e=>a.default.fromJSON(e,!0))),e.corefs&&(this.addAnnotator(i.default),this._corefs=Object.keys(e.corefs).filter(e=>"length"!==e).map(t=>s.default.fromJSON(e.corefs[t]).fromDocument(this))),this}toJSON(){return{text:this._text,sentences:this._sentences}}static fromJSON(e){return(new this).fromJSON(e)}}},{"./annotable":14,"./annotator/coref":16,"./annotator/ssplit":31,"./coref-chain":33,"./sentence":40}],36:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=Object.assign||function(e){for(var t=1;tthis.group(e)))}group(e){return this._data[`$${e}`]}labels(){return Object.keys(this._data).filter(e=>/^\$/.test(e)).map(e=>e.substr(1))}fromJSON(e){return this._data=e,this}toJSON(){return r({},this._data)}static fromJSON(e){return(new this).fromJSON(e)}}},{}],37:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r,o=e("./expression-sentence-match"),a=(r=o)&&r.__esModule?r:{default:r};n.default=class{constructor(e){this._matches=e}matches(){return this._matches}match(e){return this._matches[e]}mergeTokensFromSentence(e){return this.matches().forEach(t=>t.groups().forEach(t=>{t.token=(t=>e.tokens().find(e=>e.index()===t.begin+1&&e.toString()===t.text))(t)||t.token})),this}fromJSON(e){return this._matches=Object.keys(e).filter(e=>"length"!==e).map(t=>a.default.fromJSON(e[t])),this}toJSON(){return[...this._matches]}static fromJSON(e){return(new this).fromJSON(e)}}},{"./expression-sentence-match":36}],38:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.TregexAnnotator=n.SemgrexAnnotator=n.TokensRegexAnnotator=void 0;var r=s(e("./annotable")),o=s(e("./annotator")),a=s(e("./expression-sentence"));function s(e){return e&&e.__esModule?e:{default:e}}n.TokensRegexAnnotator=class extends o.default{};n.SemgrexAnnotator=class extends o.default{};n.TregexAnnotator=class extends o.default{};n.default=class extends r.default{constructor(e,t){super(e),this._pattern=t,this._sentences=[]}toString(){return this._text}pattern(){return this._pattern}sentences(){return this._sentences}sentence(e){return this.sentences()[e]}mergeTokensFromDocument(e){return e.sentences().forEach((e,t)=>this.sentence(t).mergeTokensFromSentence(e)),this}fromJSON(e){return e.sentences&&(this._sentences=e.sentences.map(e=>a.default.fromJSON(e))),this}toJSON(){return{text:this._text,sentences:this._sentences}}static fromJSON(e){return(new this).fromJSON(e)}}},{"./annotable":14,"./annotator":15,"./expression-sentence":37}],39:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r,o=e("../service"),a=(r=o)&&r.__esModule?r:{default:r};n.default=class{constructor(e,t,n=null){this._dep=e,this._dependentToken=t,this._governorToken=n}toString(){return this._dep}governor(){return this._governorToken}governorGloss(){return this._governorToken?this._governorToken.word():""}dependent(){return this._dependentToken}dependentGloss(){return this._dependentToken.word()?this._dependentToken.word():""}dep(){return this._dep}depInfo(){return a.default.getGovernorDepInfo(this._dep)}toJSON(){return{dep:this._dep,governor:this._governorToken?this._governorToken.index():0,governorGloss:this._governorToken?this._governorToken.word():"ROOT",dependent:this._dependentToken.index(),dependentGloss:this._dependentToken.word()}}static fromJSON(){throw Error("Not implemented")}}},{"../service":13}],40:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=Object.assign||function(e){for(var t=1;te.toString()).join(" ")}index(){return this._index}parse(){return this._parse}words(){if(!this.hasAnnotator(s.default))throw new Error("Asked for words on Sentence, but there are unmet annotator dependencies.");return this._tokens.map(e=>e.word())}word(e){if(!this.hasAnnotator(s.default))throw new Error("Asked for a word on Sentence, but there are unmet annotator dependencies.");if(!this._tokens[e])throw new Error(`Sentence instance does not contain a token with index ${e}`);return this._tokens[e].word()}[Symbol.iterator](){return this._tokens.values()}posTags(){return this._tokens.map(e=>e.pos())}posTag(e){if(!this._tokens[e])throw new Error(`Sentence instance does not contain a token with index ${e}`);return this._tokens[e].pos()}lemmas(){return this._tokens.map(e=>e.lemma())}lemma(e){if(!this._tokens[e])throw new Error(`Sentence instance does not contain a token with index ${e}`);return this._tokens[e].lemma()}nerTags(){return this._tokens.map(e=>e.ner())}nerTag(e){if(!this._tokens[e])throw new Error(`Sentence instance does not contain a token with index ${e}`);return this._tokens[e].ner()}governors(){if(!this.hasAnnotator(l.default))throw new Error("Asked for governors on Sentence, but there are unmet annotator dependencies.");return this._governors}governor(e){if(!this.hasAnnotator(l.default))throw new Error("Asked for a governor on Sentence, but there are unmet annotator dependencies.");return this._governors[e]}incommingDependencyLabel(e){}natlogPolarities(){}natlogPolarity(e){}openie(){if(!this.hasAnnotator(u.default))throw new Error("Asked for a OpenIE-Annotation on Sentence, but there are unmet annotator dependencies.");return this._openie}openieTriples(e){}tokens(){if(!this.hasAnnotator(s.default))throw new Error("Asked for tokens on Sentence, but there are unmet annotator dependencies.");return this._tokens}token(e){if(!this.hasAnnotator(s.default))throw new Error("Asked for a token on Sentence, but there are unmet annotator dependencies.");return this._tokens[e]}algorithms(){}setLanguageISO(e){super.setLanguageISO(e),this._tokens.forEach(t=>t.setLanguageISO(e))}toJSON(){let e={index:this._index,tokens:this._tokens.map(e=>e.toJSON()),basicDependencies:this._governors.map(e=>e.toJSON()),enhancedDependencies:this._enhancedDependencies,enhancedPlusPlusDependencies:this._enhancedPlusPlusDependencies};return this._parse&&(e=r({},e,{parse:this._parse})),e}fromJSON(e,t=!1){const n=t?e:(0,o.default)(e.sentences);return this._index=e.index,n.tokens&&(this.addAnnotator(s.default),this._tokens=n.tokens.map(e=>p.default.fromJSON(e))),n.parse&&(this.addAnnotator(i.default),this._parse=n.parse),n.openie&&(this.addAnnotator(u.default),this._openie=n.openie),n.basicDependencies&&(this.addAnnotator(l.default),this._governors=n.basicDependencies.map(e=>new c.default(e.dep,this._tokens[e.dependent-1],this._tokens[e.governor-1])),this._basicDependencies=n.basicDependencies,this._enhancedDependencies=n.enhancedDependencies,this._enhancedPlusPlusDependencies=n.enhancedPlusPlusDependencies),this}static fromJSON(e,t=!1){return(new this).fromJSON(e,t)}}},{"./annotable":14,"./annotator/depparse":17,"./annotator/natlog":20,"./annotator/openie":22,"./annotator/parse":23,"./annotator/tokenize":32,"./governor":39,"./token":41,"lodash.head":4}],41:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=a(e("../service")),o=a(e("./annotable"));function a(e){return e&&e.__esModule?e:{default:e}}n.default=class extends o.default{constructor(e){super(e)}toString(){return this._text}index(){return this._index}word(){return this._text}originalText(){return this._originalText}characterOffsetBegin(){return this._characterOffsetBegin}characterOffsetEnd(){return this._characterOffsetEnd}before(){return this._before}after(){return this._after}lemma(){return this._lemma}pos(){return this._pos}posInfo(){return r.default.getTokenPosInfo(this._pos,this.getLanguageISO())}ner(){return this._ner}speaker(){return this._speaker}toJSON(){return{index:this._index,word:this._text,originalText:this._originalText,characterOffsetBegin:this._characterOffsetBegin,characterOffsetEnd:this._characterOffsetEnd,before:this._before,after:this._after,pos:this._pos,lemma:this._lemma,ner:this._ner,speaker:this._speaker}}static fromJSON(e){const t=new this;return t._index=e.index,t._text=e.word,t._originalText=e.originalText,t._characterOffsetBegin=e.characterOffsetBegin,t._characterOffsetEnd=e.characterOffsetEnd,t._before=e.before,t._after=e.after,t._pos=e.pos,t._lemma=e.lemma,t._ner=e.ner,t._speaker=e.speaker,t}}},{"../service":13,"./annotable":14}],42:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.Node=void 0;var r,o=e("../service"),a=(r=o)&&r.__esModule?r:{default:r};class s{constructor(e="",t="",n=[],r=null){this._pos=e,this._word=t,this._children=n,this._parent=r}pos(){return this._pos}posInfo(){return this._children.length?a.default.getSentenceParseInfo(this._pos,this.getLanguageISO()):a.default.getTokenPosInfo(this._pos,this.getLanguageISO())}token(e=null){return e&&(this._token=e),this._token}word(){return this._word}setLanguageISO(e){this._language=e}getLanguageISO(){return this._language}children(){return this._children}appendChild(e){this._children.push(e)}parent(e=null){return e&&(this._parent=e),this._parent}toJSON(){return{pos:this._pos,posInfo:this.posInfo(),word:this._word,token:this._token,children:this._children}}}n.Node=s;class i{constructor(e){this.rootNode=e}dump(){return JSON.stringify(this.rootNode,(e,t)=>t instanceof s?t.children().length?{pos:t.pos(),info:t.info(),children:t.children()}:{pos:t.pos(),info:t.info(),word:t.word(),token:t.token()}:t,2)}visitDeepFirst(e,t=this.rootNode){t.children().forEach(t=>{this.visitDeepFirst(e,t),e(t)}),e(t)}visitDeepFirstRight(e,t=this.rootNode){t.children().reverse().forEach(t=>{this.visitDeepFirstRight(e,t),e(t)}),e(t)}visitLeaves(e,t=this.rootNode){t.children().forEach(t=>{t.children().length?this.visitLeaves(e,t):e(t)}),t.children().length||e(t)}static fromSentence(e,t=!1){const n=e.parse();if(!n)throw new Error("Unable to create Tree from Sentence, did you run ParserAnnotator first?");const r=i.fromString(n,t);let o=0;r.visitLeaves(t=>t.token(e.token(o++)));const a=e.getLanguageISO();return a&&r.visitDeepFirst(e=>e.setLanguageISO(a)),r}static fromString(e,t=!1){return new i(this._transformTree(this._buildTree(e),t))}static _buildTree(e){let t={children:[]};const n=[t],r=e.length;for(let o=0;o-1?(e.pos=t.substr(0,n),e.word=t.substr(n+1)):e.pos=t}static _transformTree(e,t){if(t){const n=new s(e.pos,e.word);return e.children.forEach(e=>{const r=this._transformTree(e,t);r.parent(n),n.appendChild(r)}),n}return new s(e.pos,e.word,e.children.map(e=>this._transformTree(e)))}}n.default=i},{"../service":13}]},{},[9])(9)}); \ No newline at end of file diff --git a/package.json b/package.json index b3be48c..bb754b1 100644 --- a/package.json +++ b/package.json @@ -18,9 +18,9 @@ "build": "gulp build", "build:browser": "gulp build:browser", "prepublish": "npm run lint && npm run test && npm run compile", - "lint": "eslint 'src/**/*.js' 'test/*.js'", + "lint": "eslint \"src/**/*.js\" \"test/*.js\"", "lint:fix": "npm run lint -- --fix", - "test": "nyc --reporter=html --reporter=text mocha test/setup.js --sort 'src/**/*.spec.js' --compilers js:babel-core/register --timeout 30000", + "test": "nyc --reporter=html --reporter=text mocha test/setup.js --sort \"src/**/*.spec.js\" --compilers js:babel-core/register --timeout 30000", "test:watch": "npm run test -- --watch", "doc": "DEBUG=gulp-jsdoc3 gulp doc" }, diff --git a/src/index.js b/src/index.js index 0f0d0b8..9cbef47 100644 --- a/src/index.js +++ b/src/index.js @@ -14,6 +14,8 @@ import DependencyParseAnnotator from './simple/annotator/depparse'; import RelationExtractorAnnotator from './simple/annotator/relation'; import RegexNERAnnotator from './simple/annotator/regexner'; import CorefAnnotator from './simple/annotator/coref'; +import NaturalLogicAnnotator from './simple/annotator/natlog'; +import OpenIEAnnotator from './simple/annotator/openie'; import Tree from './util/tree'; import _Properties from './properties'; import _Pipeline from './pipeline'; @@ -58,6 +60,8 @@ export default { RelationExtractorAnnotator, RegexNERAnnotator, CorefAnnotator, + NaturalLogicAnnotator, + OpenIEAnnotator, }, }, /** diff --git a/src/index.spec.js b/src/index.spec.js index 7a4f6fc..5855bfa 100644 --- a/src/index.spec.js +++ b/src/index.spec.js @@ -10,7 +10,7 @@ import Token from './simple/token'; import Annotable from './simple/annotable'; import Annotator from './simple/annotator'; import TokenizerAnnotator from './simple/annotator/tokenize'; -import WordsToSentenceAnnotator from './simple/annotator/ssplit'; +import OpenIEAnnotator from './simple/annotator/openie'; import POSTaggerAnnotator from './simple/annotator/pos'; import MorphaAnnotator from './simple/annotator/lemma'; import NERClassifierCombiner from './simple/annotator/ner'; @@ -19,6 +19,8 @@ import DependencyParseAnnotator from './simple/annotator/depparse'; import RelationExtractorAnnotator from './simple/annotator/relation'; import RegexNERAnnotator from './simple/annotator/regexner'; import CorefAnnotator from './simple/annotator/coref'; +import NaturalLogicAnnotator from './simple/annotator/natlog'; +import WordsToSentenceAnnotator from './simple/annotator/ssplit'; import Tree from './util/tree'; describe('CoreNLP Library entry point', () => { @@ -73,6 +75,8 @@ describe('CoreNLP Library entry point', () => { RelationExtractorAnnotator, RegexNERAnnotator, CorefAnnotator, + NaturalLogicAnnotator, + OpenIEAnnotator, }); }); }); diff --git a/src/pipeline.js b/src/pipeline.js index 1d31123..ec41b36 100644 --- a/src/pipeline.js +++ b/src/pipeline.js @@ -11,6 +11,8 @@ import depparse from './simple/annotator/depparse'; import relation from './simple/annotator/relation'; import regexner from './simple/annotator/regexner'; import coref from './simple/annotator/coref'; +import natlog from './simple/annotator/natlog'; +import openie from './simple/annotator/openie'; import Document from './simple/document'; import { @@ -30,6 +32,8 @@ const ANNOTATORS_BY_KEY = { relation, regexner, coref, + natlog, + openie, }; const LANGUAGE_TO_ISO2 = { diff --git a/src/simple/annotator/natlog.js b/src/simple/annotator/natlog.js new file mode 100644 index 0000000..e08df17 --- /dev/null +++ b/src/simple/annotator/natlog.js @@ -0,0 +1,40 @@ +import Annotator from '../annotator'; +import TokenizerAnnotator from './tokenize'; +import WordsToSentenceAnnotator from './ssplit'; +import POSTaggerAnnotator from './pos'; +import MorphaAnnotator from './lemma'; +import DependencyParseAnnotator from './depparse'; + +/** + * @class + * @classdesc Class representing an Natural Logic Annotator. + * @extends Annotator + * @memberof CoreNLP/simple/annotator + * @requires tokenize, ssplit, pos, lemma, depparse (Can also use parse) + * @see {@link https://stanfordnlp.github.io/CoreNLP/natlog.html|NaturalLogicAnnotator} + */ +class NaturalLogicAnnotator extends Annotator { + /** + * Create an Annotator + * @param {Object} [options] a key-value map of options, without the annotator prefix + */ + constructor(options = {}) { + super( + 'natlog', + { + // dopolarity: True by default. If set to false, the annotator will only annotate + // quantifiers and quantifier scopes, and not annotate the polarity of each token + ...options, + }, + [ + new TokenizerAnnotator(), + new WordsToSentenceAnnotator(), + new POSTaggerAnnotator(), + new MorphaAnnotator(), + new DependencyParseAnnotator(), + ], + ); + } +} + +export default NaturalLogicAnnotator; diff --git a/src/simple/annotator/natlog.spec.js b/src/simple/annotator/natlog.spec.js new file mode 100644 index 0000000..bd100d9 --- /dev/null +++ b/src/simple/annotator/natlog.spec.js @@ -0,0 +1,20 @@ +import NaturalLogicAnnotator from './natlog'; + +describe('Annotator', () => { + let annotator; + + describe('NaturalLogicAnnotator', () => { + beforeEach(() => { + annotator = new NaturalLogicAnnotator(); + }); + + it('should have a proper pipeline', () => { + expect(annotator.pipeline()).to.deep.equal(['tokenize', 'ssplit', 'pos', 'lemma', 'depparse', 'natlog']); + }); + + it('should have the proper default options', () => { + expect(annotator.options()).to.deep.equal({ + }); + }); + }); +}); diff --git a/src/simple/annotator/openie.js b/src/simple/annotator/openie.js new file mode 100644 index 0000000..16d21d4 --- /dev/null +++ b/src/simple/annotator/openie.js @@ -0,0 +1,51 @@ +import Annotator from '../annotator'; +import NaturalLogicAnnotator from './natlog'; +import DependencyParseAnnotator from './depparse'; +import CorefAnnotator from './coref'; + +// TODO: Requirements are missing here https://stanfordnlp.github.io/CoreNLP/annotators.html, verify. + +/** + * @class + * @classdesc Class representing an OpenIE Annotator. + * @extends Annotator + * @memberof CoreNLP/simple/annotator + * @requires natlog + * @see {@link https://stanfordnlp.github.io/CoreNLP/openie.html|OpenIEAnnotator} + */ +class OpenIEAnnotator extends Annotator { + /** + * Create an Annotator + * @param {Object} [options] a key-value map of options, without the annotator prefix + */ + constructor(options = {}) { + super( + 'openie', + { + // format (Enum) default One of {reverb, ollie, default, qa_srl}. Changes the output form + // filelist (filepath) null A path to a file, which contains files to annotate. + // threads (integer) number of cores The number of threads to run on. + // max_entailments_per_clause (integer) 1000 The maximum number of entailments to prod + resolve_coref: false, // (boolean) false If true, run coreference (and consequently + // ignore_affinity (boolean) false Whether to ignore the affinity model for preposi + // affinity_probability_cap (double) 1 /3 The affinity value above which confidence + // triple.strict (boolean) true If true, extract triples only if they consume the e + triple: { all_nominals: false }, // If true, extract nominal relations always and not o + // splitter.model (filepath) You can override the default location of the clause + // splitter.nomodel (boolean) false Run without a clause splitting model – that is, + // splitter.disable (boolean) false Don’t split clauses at all, and only extract re + // affinity_models (filepath) + ...options, + }, + options.resolve_coref + ? [ + new CorefAnnotator(), + new DependencyParseAnnotator(), + new NaturalLogicAnnotator(), + ] + : [new NaturalLogicAnnotator()], + ); + } +} + +export default OpenIEAnnotator; diff --git a/src/simple/annotator/openie.spec.js b/src/simple/annotator/openie.spec.js new file mode 100644 index 0000000..aedf67d --- /dev/null +++ b/src/simple/annotator/openie.spec.js @@ -0,0 +1,32 @@ +import OpenIEAnnotator from './openie'; + +describe('Annotator', () => { + let annotator; + + describe('OpenIEAnnotator', () => { + beforeEach(() => { + annotator = new OpenIEAnnotator(); + }); + + it('should have a proper pipeline', () => { + expect(annotator.pipeline()).to.deep.equal([ + 'tokenize', + 'ssplit', + 'pos', + 'lemma', + 'depparse', + 'natlog', + 'openie', + ]); + }); + + it('should have the proper default options', () => { + expect(annotator.options()).to.deep.equal({ + resolve_coref: false, + triple: { + all_nominals: false, + }, + }); + }); + }); +}); diff --git a/src/simple/sentence.js b/src/simple/sentence.js index a1115e1..ccf9062 100644 --- a/src/simple/sentence.js +++ b/src/simple/sentence.js @@ -2,6 +2,7 @@ import head from 'lodash.head'; import Annotable from './annotable'; import TokenizerAnnotator from './annotator/tokenize'; import ParserAnnotator from './annotator/parse'; +import OpenIEAnnotator from './annotator/openie'; import DependencyParseAnnotator from './annotator/depparse'; import Token from './token'; import Governor from './governor'; @@ -30,6 +31,8 @@ class Sentence extends Annotable { super(text); this._tokens = []; this._governors = []; + this._openie = []; + this._natLogPolarities = []; } /** @@ -186,18 +189,45 @@ class Sentence extends Annotable { } // TODO - // eslint-disable-next-line class-methods-use-this + // eslint-disable-next-line class-methods-use-this, no-unused-vars natlogPolarities() { + // if (!this.hasAnnotator(NaturalLogicAnnotator)) { + // throw new Error( + // 'Asked for PolarityAnnotation on Sentence, but there are unmet annotator dependencies.' + // ); + // } + // return this._natLogPolarities; } // TODO // eslint-disable-next-line class-methods-use-this, no-unused-vars natlogPolarity(index) { + // if (!this.hasAnnotator(NaturalLogicAnnotator)) { + // throw new Error( + // 'Asked for a PolarityAnnotation on Sentence, but there are unmet annotator dependencies.' + // ); + // } + // return this._natLogPolarities[index]; } - // TODO - // eslint-disable-next-line class-methods-use-this + /** + * Extract open-domain relation triples. + * @requires {@link OpenIEAnnotator} + * @throws {Error} in case the require annotator was not applied to the sentence + * @returns {Array.} OpenIE-Triples + */ openie() { + // TODO: Create OpenIE-Triples: + // object:"Constantin Hütterer" + // objectSpan:Array(2) [3, 5] + // relation:"is" + // relationSpan:Array(2) [2, 3] + // subject:"My name" + // subjectSpan:Array(2) [0, 2] + if (!this.hasAnnotator(OpenIEAnnotator)) { + throw new Error('Asked for a OpenIE-Annotation on Sentence, but there are unmet annotator dependencies.'); + } + return this._openie; } // TODO @@ -287,6 +317,10 @@ class Sentence extends Annotable { this.addAnnotator(ParserAnnotator); this._parse = sentence.parse; } + if (sentence.openie) { + this.addAnnotator(OpenIEAnnotator); + this._openie = sentence.openie; + } if (sentence.basicDependencies) { this.addAnnotator(DependencyParseAnnotator); this._governors = sentence.basicDependencies.map(gov =>