"NLP.js" is a general natural language utilities for nodejs. Currently supporting:
Guess the language of a phrase
Fast levenshtein distance of two strings
Search the best substring of a string with less levenshtein distance to a given pattern.
Get stemmers and tokenizers for several languages.
Sentiment Analysis for phrases (with negation support).
Named Entity Recognition and management, multilanguage, and accepting similar strings, so the introduced text does not need to be exact.
Natural Language Processing Classifier, to classify utterance into intents.
Natural Language Generation Manager, so from intents and conditions it can generate an answer.
NLP Manager: a tool able to manage several languages, the Named Entities for each language, the utterance and intents for the training of the classifier, and for a given utterance return the entity extraction, the intent classification and the sentiment analysis. Also, it is able to maintain a Natural Language Generation Manager for the answers.
(function(){ var a = "1"; var f = function(){}; var b = "2"; var c = "3"; })();
变量a,f,b,c的声明会被提升到函数作用域的最前面,类似如下:
(function(){ var a,f,b,c; a = "1"; f = function(){}; b = "2"; c = "3"; })();
请注意函数表达式并没有被提升,这也是函数表达式与函数声明的区别。进一步看二者的区别:
(function(){ //var f1,function f2(){}; //hoisting, 被隐式提升的声明 f1(); //ReferenceError: f1 is not defined f2(); var f1 = function(){}; function f2(){} })();
f();//TypeError: f is not a function foo();//ReferenceError: foo is not defined var f = function foo(){console.log(typeof foo);}; f();//function foo();//ReferenceError: foo is not defined
var obj = {}; obj.__proto__ = Base.prototype; Base.call(obj);
第一行,我们创建了一个空对象 obj
第二行,我们将这个空对象的 __proto__ 成员指向了 Base 函数对象 prototype 成员对象
第三行,我们将 Base 函数对象的 this 指针替换成 obj,然后再调用 Base 函数,于是我们就给 obj 对象赋值了一个 id 成员变量,这个成员变量的值是”base”
2019-09-24 更新
最近看到一个专栏介绍 this 时,讲到为什么全局调用一个函数时,this 指向的是 window 对象呢?
因为全局调用时,并没有使用 call 方法绑定上下文,或是在一个对象中的方法调用 this ,而根据作用域链的规则,会从当前作用域范围向外找,找到全局作用域中的 window 对象。
var timestart = '2010-05-04'; var timeend = '2015-06-23'; var time1 = (timestart+' 00:00:00').toString(); var time2 = (timeend+' 23:59:59').toString(); timestart = new Date(time1); timeend = new Date(time2);
var time1 = (timestart+' 00:00:00').toString(); var time2 = (timeend+' 23:59:59').toString(); timestart = new Date(Date.parse(str.replace(/-/g,"/"))).getTime(); timeend = new Date(Date.parse(str.replace(/-/g,"/"))).getTime();
结论
2015-06-23 是无法被各个浏览器中,使用 new Date(str) 来正确生成日期对象的。 正确的用法是 2015/06/23.
<divonclick="outSideWork()"id="outSide"> <divonclick="inSideWork()"id="inSide"></div> </div> <scripttype="text/javascript"> functionoutSideWork() { alert('My name is outSide,I was working...'); } functioninSideWork() { alert('My name is inSide,I was working...'); } //因为下面程序自动激活单击事件,有些浏览器不允许,所以请单击灰色盒子,从这里开始下命令,这样因为冒泡的原因,黑色大盒子也会收到单击事件,并调用了自己的处理程序。如果还有更多盒子嵌套,一样道理。 /* function bossOrder() { document.getElmentById('inSide').click(); } bossOrder(); */ </script>
insertBefore
insertBefore 接收两个参数,第一个是插入的节点,第二个是参照节点,如 insertBefore(a,b),则 a 会插入在 b 的前面
//插入节点 var createNode =document.createElement("div"); var createTextNode =document.createTextNode("hello world"); createNode.appendChild(createTextNode); var div1 =document.getElementById("div1"); document.body.insertBefore(createNode,div1);
//文本片段 var fragment =document.createDocumentFragment(); var ul =document.getElementById("ul"); var li =null; for(var i =4; i >=0; i--){ li =document.createElement("li"); li.appendChild(document.createTextNode("item "+i)); fragment.appendChild(li); } ul.appendChild(fragment);
var addListener, removeListener, /* test element */ docEl =document.documentElement; // addListener if(docEl.addEventListener){ /* if `addEventListener` exists on test element, define function to use `addEventListener` */ addListener=function(element, eventName, handler){ element.addEventListener(eventName, handler,false); }; }elseif(docEl.attachEvent){ /* if `attachEvent` exists on test element, define function to use `attachEvent` */ addListener=function(element, eventName, handler){ element.attachEvent('on'+ eventName, handler); }; }else{ /* if neither methods exists on test element, define function to fallback strategy */ addListener=function(element, eventName, handler){ element['on'+ eventName]= handler; }; } // removeListener if(docEl.removeEventListener){ removeListener=function(element, eventName, handler){ element.removeEventListener(eventName, handler,false); }; }elseif(docEl.detachEvent){ removeListener=function(element, eventName, handler){ element.detachEvent('on'+ eventName, handler); }; }else{ removeListener=function(element, eventName, handler){ element['on'+ eventName]=null; }; }
Starting with JScript. 5.8, by default, the JScript. scripting engine supports the language feature set as it existed in version 5.7. This is to maintain compatibility with the earlier versions of the engine. To use the complete language feature set of version 5.8, the Windows Script. interface host has to invoke IActiveScriptProperty::SetProperty.
Internet Explorer 8 opts into the JScript. 5.8 language features when the document mode for Internet Explorer 8 is "Internet Explorer 8 Standards" mode. For other document modes, Internet Explorer uses the version 5.7 feature set.
JScript. 5.8 includes native JavaScript. Object Notation (JSON) support and the accessor methods for Document Object Model (DOM) prototypes.
Promise.prototype.then=function(onResolved, onRejected){ /* invoke handlers based upon state transition */ };
同时还需要两个方法来执行理从未完成到已完成和从未完成到拒绝的状态转变。
Promise.prototype.resolve=function(value){ /* move from unfulfilled to resolved */ }; Promise.prototype.reject=function(error){ /* move from unfulfilled to rejected */ };
Promise.when=function(){ /* handle promises arguments and queue each */ };
以刚才获取IE10和IE9两块内容的场景为例,我们可以这样来写代码:
var container, promise1, promise2; container =document.getElementById('container'); promise1 =searchTwitter('#IE10'); promise2 =searchTwitter('#IE9'); Promise.when(promise1, promise2).then(function(data1, data2){ /* Reshuffle due to date */ var totalResults =concatResults(data1.results, data2.results); totalResults.forEach(function(tweet){ var el =document.createElement('li'); el.innerText= tweet.text; container.appendChild(el); }); }, handleError);