Takes a {@link List} of something that extends {@link CoreMap} and prints
the likelihood of each possible label at each point.

@param document
A {@link List} of something that extends CoreMap.
505789
@Override
  public void printProbsDocument(List<IN> document) {

    Pair<int[][][], int[]> p = documentToDataAndLabels(document);
    int[][][] data = p.first();

    // FactorTable[] factorTables =
    // CRFLogConditionalObjectiveFunction.getCalibratedCliqueTree(weights, data,
    // labelIndices, classIndex.size());
    CRFCliqueTree cliqueTree = CRFCliqueTree.getCalibratedCliqueTree(weights, data, labelIndices, classIndex.size(),
        classIndex, flags.backgroundSymbol);

    // for (int i = 0; i < factorTables.length; i++) {
    for (int i = 0; i < cliqueTree.length(); i++) {
      IN wi = document.get(i);
      System.out.print(wi.get(CoreAnnotations.TextAnnotation.class) + '\t');
      for (Iterator<String> iter = classIndex.iterator(); iter.hasNext();) {
        String label = iter.next();
        int index = classIndex.indexOf(label);
        // double prob = Math.pow(Math.E, factorTables[i].logProbEnd(index));
        double prob = cliqueTree.prob(i, index);
        System.out.print(label + '=' + prob);
        if (iter.hasNext()) {
          System.out.print("\t");
        } else {
          System.out.print("\n");
        }
      }
    }
  }
1354706
protected void printFeatures(IN wi, Collection<String> features) {
    if (flags.printFeatures == null || writtenNum > flags.printFeaturesUpto) {
      return;
    }
    try {
      if (cliqueWriter == null) {
        cliqueWriter = new PrintWriter(new FileOutputStream("feats" + flags.printFeatures + ".txt"), true);
        writtenNum = 0;
      }
    } catch (Exception ioe) {
      throw new RuntimeException(ioe);
    }
    if (writtenNum >= flags.printFeaturesUpto) {
      return;
    }
    if (wi instanceof CoreLabel) {
      cliqueWriter.print(wi.get(TextAnnotation.class) + ' ' + wi.get(PartOfSpeechAnnotation.class) + ' '
          + wi.get(CoreAnnotations.GoldAnswerAnnotation.class) + '\t');
    } else {
      cliqueWriter.print(wi.get(CoreAnnotations.TextAnnotation.class)
          + wi.get(CoreAnnotations.GoldAnswerAnnotation.class) + '\t');
    }
    boolean first = true;
    for (Object feat : features) {
      if (first) {
        first = false;
      } else {
        cliqueWriter.print(" ");
      }
      cliqueWriter.print(feat);
    }
    cliqueWriter.println();
    writtenNum++;
  }
915256
public void setDocuments(java.util.Collection<DocumentMetadata> documents) {
        if (documents == null) {
            this.documents = null;
            return;
        }

        this.documents = new java.util.ArrayList<DocumentMetadata>(documents);
    }
1236705
def __isListOfTexts(self, docs):
        
        return isinstance(docs, list) and \
               all(isinstance(d, (basestring, Text)) for d in docs)
3171
public List<List<Word>> getSimpleSentenceList(Set<String> labelSet)
    {
        List<List<Word>> simpleList = new LinkedList<List<Word>>();
        for (Sentence sentence : sentenceList)
        {
            List<Word> wordList = new LinkedList<Word>();
            for (IWord word : sentence.wordList)
            {
                if (word instanceof CompoundWord)
                {
                    if (labelSet.contains(word.getLabel()))
                    {
                        for (Word inner : ((CompoundWord) word).innerList)
                        {
                            wordList.add(inner);
                        }
                    }
                    else
                    {
                        wordList.add(((CompoundWord) word).toWord());
                    }
                }
                else
                {
                    wordList.add((Word) word);
                }
            }
            simpleList.add(wordList);
        }

        return simpleList;
    }
726210
public String classify(final String[] document) {
        double[] outcomes = docClassifier.classifyProb(document);
        String category = docClassifier.getBestLabel(outcomes);
        return category;
    }
169478
public void addAll(Iterable<? extends DOCUMENT> documents) {
      if (documents != null) {
         for (DOCUMENT doc : documents) {
            add(doc);
         }
      }
   }
849186
public static void parse(DocListener document, InputSource is, String tagmap) {
        XmlParser p = new XmlParser();
        p.go(document, is, tagmap);
    }
1277644
public void setFeaturesListLabels(Map<String, String> featuresListLabels) {
		this.featuresListLabels = featuresListLabels;
		controller.setFeaturesListLabels(featuresListLabels);
	}
623988
function(doc) {
        if (typeof doc == "string") { 
            doc = OpenLayers.Format.XML.prototype.read.apply(this, [doc]);
        }

        var nodes = this.getNodes(doc);
        var ways = this.getWays(doc);
        
        // Geoms will contain at least ways.length entries.
        var feat_list = new Array(ways.length);
        
        for (var i = 0; i < ways.length; i++) {
            // We know the minimal of this one ahead of time. (Could be -1
            // due to areas/polygons)
            var point_list = new Array(ways[i].nodes.length);
            
            var poly = this.isWayArea(ways[i]) ? 1 : 0; 
            for (var j = 0; j < ways[i].nodes.length; j++) {
               var node = nodes[ways[i].nodes[j]];
               
               var point = new OpenLayers.Geometry.Point(node.lon, node.lat);
               
               // Since OSM is topological, we stash the node ID internally. 
               point.osm_id = parseInt(ways[i].nodes[j]);
               point_list[j] = point;
               
               // We don't display nodes if they're used inside other 
               // elements.
               node.used = true; 
            }
            var geometry = null;
            if (poly) { 
                geometry = new OpenLayers.Geometry.Polygon(
                    new OpenLayers.Geometry.LinearRing(point_list));
            } else {    
                geometry = new OpenLayers.Geometry.LineString(point_list);
            }
            if (this.internalProjection && this.externalProjection) {
                geometry.transform(this.externalProjection, 
                    this.internalProjection);
            }        
            var feat = new OpenLayers.Feature.Vector(geometry,
                ways[i].tags);
            feat.osm_id = parseInt(ways[i].id);
            feat.fid = "way." + feat.osm_id;
            feat_list[i] = feat;
        } 
        for (var node_id in nodes) {
            var node = nodes[node_id];
            if (!node.used || this.checkTags) {
                var tags = null;
                
                if (this.checkTags) {
                    var result = this.getTags(node.node, true);
                    if (node.used && !result[1]) {
                        continue;
                    }
                    tags = result[0];
                } else { 
                    tags = this.getTags(node.node);
                }    
                
                var feat = new OpenLayers.Feature.Vector(
                    new OpenLayers.Geometry.Point(node['lon'], node['lat']),
                    tags);
                if (this.internalProjection && this.externalProjection) {
                    feat.geometry.transform(this.externalProjection, 
                        this.internalProjection);
                }        
                feat.osm_id = parseInt(node_id); 
                feat.fid = "node." + feat.osm_id;
                feat_list.push(feat);
            }   
            // Memory cleanup
            node.node = null;
        }        
        return feat_list;
    }
1208431
private static List<LabeledPoint> toLabeledPoint(List<DataSet> labeledPoints) {
        List<LabeledPoint> ret = new ArrayList<>();
        for (DataSet point : labeledPoints) {
            ret.add(toLabeledPoint(point));
        }
        return ret;
    }
658478
public static Element[] toElementArray(Document doc, Object o) throws PageException {
	// Node[]
	if (o instanceof Node[]) {
	    Node[] nodes = (Node[]) o;
	    if (_isAllOfSameType(nodes, Node.ELEMENT_NODE)) return (Element[]) nodes;

	    Element[] elements = new Element[nodes.length];
	    for (int i = 0; i < nodes.length; i++) {
		elements[i] = toElement(doc, nodes[i]);
	    }
	    return elements;
	}
	// Collection
	else if (o instanceof Collection) {
	    Collection coll = (Collection) o;
	    Iterator<Object> it = coll.valueIterator();
	    List<Element> elements = new ArrayList<Element>();
	    while (it.hasNext()) {
		elements.add(toElement(doc, it.next()));
	    }
	    return elements.toArray(new Element[elements.size()]);
	}
	// Node Map and List
	Node[] nodes = _toNodeArray(doc, o);
	if (nodes != null) return toElementArray(doc, nodes);
	// Single Text Node
	try {
	    return new Element[] { toElement(doc, o) };
	}
	catch (ExpressionException e) {
	    throw new XMLException("can't cast Object of type " + Caster.toClassName(o) + " to a XML Element Array");
	}
    }
629840
@Override
  public List<IN> classify(List<IN> document) {
    if (flags.useSequences) {
      classifySeq(document);
    } else {
      classifyNoSeq(document);
    }
    return document;
  }
543533
private List<Facet> buildFacetsFromObject(@NotNull Object document) {
        List<Facet> facets = new ArrayList<>();

        for (Field field : document.getClass().getDeclaredFields()) {
            if (isFacetField(field)) {
                Object fieldValue = getFieldValue(document, field);

                if (fieldValue != null) {
                    List<Serializable> values = transformValue(fieldValue);

                    values.forEach(value -> {
                        Facet key = new Facet(new FacetType(field.getName(), value.getClass()), value);

                        facets.add(key);
                    });
                }
            }
        }

        return facets;
    }
110027
public void printFirstOrderProbsDocument(List<IN> document) {

    CRFCliqueTree cliqueTree = getCliqueTree(document);

    // for (int i = 0; i < factorTables.length; i++) {
    for (int i = 0; i < cliqueTree.length(); i++) {
      IN wi = document.get(i);
      System.out.print(wi.get(CoreAnnotations.TextAnnotation.class) + '\t');
      for (Iterator<String> iter = classIndex.iterator(); iter.hasNext();) {
        String label = iter.next();
        int index = classIndex.indexOf(label);
        if (i == 0) {
          // double prob = Math.pow(Math.E, factorTables[i].logProbEnd(index));
          double prob = cliqueTree.prob(i, index);
          System.out.print(label + '=' + prob);
          if (iter.hasNext()) {
            System.out.print("\t");
          } else {
            System.out.print("\n");
          }
        } else {
          for (Iterator<String> iter1 = classIndex.iterator(); iter1.hasNext();) {
            String label1 = iter1.next();
            int index1 = classIndex.indexOf(label1);
            // double prob = Math.pow(Math.E, factorTables[i].logProbEnd(new
            // int[]{index1, index}));
            double prob = cliqueTree.prob(i, new int[] { index1, index });
            System.out.print(label1 + '_' + label + '=' + prob);
            if (iter.hasNext() || iter1.hasNext()) {
              System.out.print("\t");
            } else {
              System.out.print("\n");
            }
          }
        }
      }
    }
  }
1201714
void printMap(PrintWriter out, Map<String, Map<String, List<TagsMetricsPair>>> map) {
    for (Map.Entry<String, Map<String, List<TagsMetricsPair>>> context : map.entrySet()) {
      out.println(context.getKey());
      for (Map.Entry<String, List<TagsMetricsPair>> record : context.getValue().entrySet()) {
        indent(out, 1);
        out.println(record.getKey());
        for (TagsMetricsPair pair : record.getValue()) {
          indent(out, 2);
          // Prints tag values in the form "{key=value,key=value}:"
          out.print("{");
          boolean first = true;
          for (Map.Entry<String, Object> tagValue : pair.tagMap.entrySet()) {
            if (first) {
              first = false;
            } else {
              out.print(",");
            }
            out.print(tagValue.getKey());
            out.print("=");
            out.print(tagValue.getValue().toString());
          }
          out.println("}:");
          
          // Now print metric values, one per line
          for (Map.Entry<String, Number> metricValue : 
              pair.metricMap.entrySet()) {
            indent(out, 3);
            out.print(metricValue.getKey());
            out.print("=");
            out.println(metricValue.getValue().toString());
          }
        }
      }
    }    
  }
272705
static <INN extends CoreMap & HasWord> void mergeTwoDocumentsByLongestSequence(
			List<INN> mainDocument, 
			List<INN> auxDocument, 
			Set<String> auxLabels, 
			String background ) {
		
		class Sequence {
			String type;
			int start;
			int len;
			Sequence (String type, int start, int len) {
				this.type = type;
				this.start = start;
				this.len = len;
			}
			public String toString() {
				return String.format("%s:%d:%d", type, start, len);
			}
		}
		
		List<Sequence> mainSeq = new ArrayList<>();
		List<Sequence> auxSeq = new ArrayList<>();
		
		String prevAnswer = "O";
		int len = 0;
		int id = -1;
		for (INN l : mainDocument) {
			id++;
			String answer = l.get(AnswerAnnotation.class);
			if (!answer.equals(prevAnswer)) {
				if (!prevAnswer.equals(background)) {
					mainSeq.add(new Sequence(prevAnswer, id-len, len));
				}
				if (!answer.equals(background)) {
					len = 1;
				}
				prevAnswer = answer;
			} else {
				len++;
			}			
		}
		if (!prevAnswer.equals(background)) mainSeq.add(new Sequence(prevAnswer, id-len+1, len));
		
		prevAnswer = "O";
		len = 0;
		id = -1;
		for (INN l : auxDocument) {
			id++;
			String answer = l.get(AnswerAnnotation.class);
			if (!answer.equals(prevAnswer)) {
				if (!prevAnswer.equals(background)) {
					auxSeq.add(new Sequence(prevAnswer, id-len, len));
				}
				if (!answer.equals(background)) {
					len = 1;
				}
				prevAnswer = answer;
			} else {
				len++;
			}			
		}
		if (!prevAnswer.equals(background)) auxSeq.add(new Sequence(prevAnswer, id-len+1, len));
		
		List<Sequence> resSeq = new ArrayList<>();
		Iterator<Sequence> mainSeqIt = mainSeq.iterator();
		Iterator<Sequence> auxSeqIt = auxSeq.iterator();
		Sequence main = null, aux = null, s = null;
		id = -1;
		if (mainSeqIt.hasNext()) main = mainSeqIt.next();
		if (auxSeqIt.hasNext()) aux = auxSeqIt.next();
		while(main != null || aux != null) {
			while (main != null && main.start < id) {
				if (mainSeqIt.hasNext()) main = mainSeqIt.next();
				else main = null;
			}
			
			while (aux != null && aux.start < id) {
				if (auxSeqIt.hasNext()) aux = auxSeqIt.next();
				else aux = null;
			}
			
			s = main;
			if (s == null 
					|| aux != null && (aux.start + aux.len - 1 < s.start
							|| s.len < aux.len
							&& (aux.start >= s.start && aux.start < s.start + s.len || s.start >= aux.start && s.start < aux.start + aux.len))) {
				s = aux;
			}
			if (s != null) {
				resSeq.add(s);
				id = s.start + s.len;
			}
		}
		
//		for (Sequence seq: mainSeq) System.err.print(seq + " ");
//		System.err.println();
//		for (Sequence seq: auxSeq) System.err.print(seq + " ");
//		System.err.println();
//		for (Sequence seq: resSeq) System.err.print(seq + " ");
//		System.err.println();
//		for (Sequence seq: resSeq) {
//			for (int i = seq.start; i < seq.start + seq.len; i++) {
//				System.err.printf("%s[%s/%s] ", mainDocument.get(i).word(), mainDocument.get(i).get(AnswerAnnotation.class), auxDocument.get(i).get(AnswerAnnotation.class));
//			}
//		}		
		for (INN l : mainDocument) l.set(AnswerAnnotation.class, background);
		for (Sequence seq : resSeq) {
			for (int i = seq.start; i < seq.start + seq.len; i++) {
				mainDocument.get(i).set(AnswerAnnotation.class, seq.type);
			}
		}
	}