dist/multilabel/BinarySegmentation.js
function(words, accumulatedClasses, explain, explanations) {

		//for (var start=0; start<=words.length; ++start) {
		//	for (var end=start+1; end<=words.length; ++end) {
		//		var segment = words.slice(start,end).join(" ");

		//		var bestClassAndProbability = this.bestClassOfSegment(segment, explain);
		//		if (bestClassAndProbability[1] != Infinity)
		//		{
		//			var bestClass = bestClassAndProbability[0];
		//			var bestClassProbability = bestClassAndProbability[1];
			//		digraph.add(start, end, -bestClassProbability);
		//		}
		//	}
		//}

		var cheapest_paths = require("graph-paths").cheapest_paths;

                var mini = Infinity
                _(words.length).times(function(nn){
                   cheapestSegmentClassificationCosts = cheapest_paths(segmentClassificationCosts, nn);
                       _.each(cheapestSegmentClassificationCosts, function(value, key, list){
                             if (value.cost<mini)
                               {
                                mini = value.cost
	                            cheapestSentenceClassificationCost = value
                                 }
                         }, this)
                 }, this)
                   
     cheapestSegmentClassificationCosts = cheapest_paths(segmentClassificationCosts, 0);
     cheapestSentenceClassificationCost = cheapestSegmentClassificationCosts[words.length];


        var path = cheapestSentenceClassificationCost.path;


		for (var i=0; i<path.length-1; ++i) {
			// var segment = words.slice(cheapestClassificationPath[i],cheapestClassificationPath[i+1]).join(" ");
			var segment = words.slice(path[i],path[i+1]).join(" ");
			//HERE
			var segmentClassesWithExplain = this.classifySegment(segment, explain);
			var segmentClasses = (segmentClassesWithExplain.classes? segmentClassesWithExplain.classes: segmentClassesWithExplain);
			
			if (segmentClasses.length>0)
				accumulatedClasses[segmentClasses[0]] = true;

			// explanations = []
			if (explain>0) {
					if (segmentClasses.length>0)
						explanations.push([segmentClasses[0], segment, [path[i], path[i+1]],segmentClassesWithExplain['explanation']['positive']])

			};
			
		}
	}
function(words, accumulatedClasses, explain, explanations) {

		//for (var start=0; start<=words.length; ++start) {
		//	for (var end=start+1; end<=words.length; ++end) {
		//		var segment = words.slice(start,end).join(" ");

		//		var bestClassAndProbability = this.bestClassOfSegment(segment, explain);
		//		if (bestClassAndProbability[1] != Infinity)
		//		{
		//			var bestClass = bestClassAndProbability[0];
		//			var bestClassProbability = bestClassAndProbability[1];
			//		digraph.add(start, end, -bestClassProbability);
		//		}
		//	}
		//}

		var cheapest_paths = require("graph-paths").cheapest_paths;

                var mini = Infinity
                _(words.length).times(function(nn){
                   cheapestSegmentClassificationCosts = cheapest_paths(segmentClassificationCosts, nn);
                       _.each(cheapestSegmentClassificationCosts, function(value, key, list){
                             if (value.cost<mini)
                               {
                                mini = value.cost
	                            cheapestSentenceClassificationCost = value
                                 }
                         }, this)
                 }, this)
                   
     cheapestSegmentClassificationCosts = cheapest_paths(segmentClassificationCosts, 0);
     cheapestSentenceClassificationCost = cheapestSegmentClassificationCosts[words.length];


        var path = cheapestSentenceClassificationCost.path;


		for (var i=0; i<path.length-1; ++i) {
			// var segment = words.slice(cheapestClassificationPath[i],cheapestClassificationPath[i+1]).join(" ");
			var segment = words.slice(path[i],path[i+1]).join(" ");
			//HERE
			var segmentClassesWithExplain = this.classifySegment(segment, explain);
			var segmentClasses = (segmentClassesWithExplain.classes? segmentClassesWithExplain.classes: segmentClassesWithExplain);
			
			if (segmentClasses.length>0)
				accumulatedClasses[segmentClasses[0]] = true;

			// explanations = []
			if (explain>0) {
					if (segmentClasses.length>0)
						explanations.push([segmentClasses[0], segment, [path[i], path[i+1]],segmentClassesWithExplain['explanation']['positive']])

			};
			
		}
	}
protected function:
Strategy of finding the cheapest segmentation (- most probable segmentation), using a dynamic programming algorithm.
Based on:
Morbini Fabrizio, Sagae Kenji. Joint Identification and Segmentation of Domain-Specific Dialogue Acts for Conversational Dialogue Systems. ACL-HLT 2011
http://www.citeulike.org/user/erelsegal-halevi/article/10259046