nl_tokens: Factory to gather parents and patch them based on their childrens directionality .
pl_tokens: function concatenateFactory ( ) { var queue = [ ] concatenate . done = done return concatenate // Gather a parent if not already gathered. function concatenate ( node , index , parent ) { if ( parent && parent . type !== 'WordNode' && <mask> . indexOf ( parent ) === - 1 ) { queue . push ( parent ) } } // Patch all words in `parent`. function one ( node ) { var children = node . children var length = children . length var polarity = 0 var index = - 1 var child var hasNegation while ( ++ index < length ) { child = children [ index ] if ( child . data && child . data . polarity ) { polarity += ( hasNegation ? - 1 : 1 ) * child . data . polarity } // If the value is a word, remove any present negation.  Otherwise, add // negation if the node contains it. if ( child . type === 'WordNode' ) { if ( hasNegation ) { hasNegation = false } else if ( isNegation ( child ) ) { hasNegation = true } } } patch ( node , polarity ) } // Patch all parents. function done ( ) { var length = queue . length var index = - 1 queue . reverse ( ) while ( ++ index < length ) { one ( queue [ index ] ) } } }