指定位置合并Word文档

@param docMerges
待合并的文档
@param run
合并的位置
@return 合并后的文档
@throws Exception
@since 1.3.0
429386
public NiceXWPFDocument merge(List<NiceXWPFDocument> docMerges, XWPFRun run) throws Exception {
        if (null == docMerges || docMerges.isEmpty() || null == run) return this;
        // XWPFParagraph paragraph = insertNewParagraph(run);
        XWPFParagraph paragraph = (XWPFParagraph) run.getParent();
        CTP ctp = paragraph.getCTP();

        CTBody body = this.getDocument().getBody();
        String srcString = body.xmlText();
        String prefix = srcString.substring(0, srcString.indexOf(">") + 1);
        String sufix = srcString.substring(srcString.lastIndexOf("<"));
        List<String> addParts = new ArrayList<String>();
        for (NiceXWPFDocument docMerge : docMerges) {
            addParts.add(extractMergePart(docMerge));
        }

        CTP makeBody = CTP.Factory.parse(prefix + StringUtils.join(addParts, "") + sufix);
        ctp.set(makeBody);

        String xmlText = body.xmlText();
        xmlText = xmlText.replaceAll("<w:p><w:p>", "<w:p>").replaceAll("<w:p><w:p\\s", "<w:p ")
                .replaceAll("<w:p><w:tbl>", "<w:tbl>").replaceAll("<w:p><w:tbl\\s", "<w:tbl ");

        xmlText = xmlText.replaceAll("</w:sectPr></w:p>", "</w:sectPr>")
                .replaceAll("</w:p></w:p>", "</w:p>").replaceAll("</w:tbl></w:p>", "</w:tbl>")
                .replaceAll("<w:p(\\s[A-Za-z0-9:\\s=\"]*)?/></w:p>", "");

        // System.out.println(xmlText);
        body.set(CTBody.Factory.parse(xmlText));

        return generate();
    }
501083
@Override
  public void train(Collection<List<IN>> docs, DocumentReaderAndWriter<IN> readerAndWriter) {
    Timing timer = new Timing();
    timer.start();
    makeAnswerArraysAndTagIndex(docs);
    long elapsedMs = timer.stop();
    System.err.println("Time to convert docs to feature indices: " + Timing.toSecondsString(elapsedMs) + " seconds");
    if (flags.exportFeatures != null) {
      timer.start();
      CRFFeatureExporter<IN> featureExporter = new CRFFeatureExporter<IN>(this);
      featureExporter.printFeatures(flags.exportFeatures, docs);
      elapsedMs = timer.stop();
      System.err.println("Time to export features: " + Timing.toSecondsString(elapsedMs) + " seconds");
    }
    for (int i = 0; i <= flags.numTimesPruneFeatures; i++) {
      timer.start();
      Pair<int[][][][], int[][]> dataAndLabels = documentsToDataAndLabels(docs);
      elapsedMs = timer.stop();
      System.err.println("Time to convert docs to data/labels: " + Timing.toSecondsString(elapsedMs) + " seconds");

      Evaluator[] evaluators = null;
      if (flags.evaluateIters > 0) {
        List<Evaluator> evaluatorList = new ArrayList<Evaluator>();
        evaluatorList.add(new MemoryEvaluator());
        if (flags.evaluateTrain) {
          CRFClassifierEvaluator<IN> crfEvaluator = new CRFClassifierEvaluator<IN>("Train set", this);
          List<Pair<int[][][], int[]>> trainDataAndLabels = new ArrayList<Pair<int[][][], int[]>>();
          for (int j = 0; j < dataAndLabels.first().length; j++) {
            Pair<int[][][], int[]> p = new Pair<int[][][], int[]>(dataAndLabels.first()[j], dataAndLabels.second()[j]);
            trainDataAndLabels.add(p);
          }
          crfEvaluator.setTestData(docs, trainDataAndLabels);
          crfEvaluator.setEvalCmd(flags.evalCmd);
          evaluatorList.add(crfEvaluator);
        }
        if (flags.testFile != null) {
          CRFClassifierEvaluator<IN> crfEvaluator = new CRFClassifierEvaluator<IN>("Test set (" + flags.testFile + ")",
              this);
          ObjectBank<List<IN>> testObjBank = makeObjectBankFromFile(flags.testFile, readerAndWriter);
          List<Pair<int[][][], int[]>> testDataAndLabels = documentsToDataAndLabelsList(testObjBank);
          crfEvaluator.setTestData(testObjBank, testDataAndLabels);
          crfEvaluator.setEvalCmd(flags.evalCmd);
          evaluatorList.add(crfEvaluator);
        }
        if (flags.testFiles != null) {
          String[] testFiles = flags.testFiles.split(",");
          for (String testFile : testFiles) {
            CRFClassifierEvaluator<IN> crfEvaluator = new CRFClassifierEvaluator<IN>("Test set ("
                + testFile + ")", this);
            ObjectBank<List<IN>> testObjBank = makeObjectBankFromFile(testFile, readerAndWriter);
            List<Pair<int[][][], int[]>> testDataAndLabels = documentsToDataAndLabelsList(testObjBank);
            crfEvaluator.setTestData(testObjBank, testDataAndLabels);
            crfEvaluator.setEvalCmd(flags.evalCmd);
            evaluatorList.add(crfEvaluator);
          }
        }
        evaluators = new Evaluator[evaluatorList.size()];
        evaluatorList.toArray(evaluators);
      }

      if (flags.numTimesPruneFeatures == i) {
        docs = null; // hopefully saves memory
      }
      // save feature index to disk and read in later
      File featIndexFile = null;

      if (flags.saveFeatureIndexToDisk) {
        try {
          System.err.println("Writing feature index to temporary file.");
          featIndexFile = IOUtils.writeObjectToTempFile(featureIndex, "featIndex" + i + ".tmp");
          featureIndex = null;
        } catch (IOException e) {
          throw new RuntimeException("Could not open temporary feature index file for writing.");
        }
      }

      // first index is the number of the document
      // second index is position in the document also the index of the
      // clique/factor table
      // third index is the number of elements in the clique/window thase
      // features are for (starting with last element)
      // fourth index is position of the feature in the array that holds them
      // element in data[i][j][k][m] is the index of the mth feature occurring
      // in position k of the jth clique of the ith document
      int[][][][] data = dataAndLabels.first();
      // first index is the number of the document
      // second index is the position in the document
      // element in labels[i][j] is the index of the correct label (if it
      // exists) at position j in document i
      int[][] labels = dataAndLabels.second();

      if (flags.loadProcessedData != null) {
        List processedData = loadProcessedData(flags.loadProcessedData);
        if (processedData != null) {
          // enlarge the data and labels array
          int[][][][] allData = new int[data.length + processedData.size()][][][];
          int[][] allLabels = new int[labels.length + processedData.size()][];
          System.arraycopy(data, 0, allData, 0, data.length);
          System.arraycopy(labels, 0, allLabels, 0, labels.length);
          // add to the data and labels array
          addProcessedData(processedData, allData, allLabels, data.length);
          data = allData;
          labels = allLabels;
        }
      }

      if (flags.useFloat) {
        CRFLogConditionalObjectiveFloatFunction func = new CRFLogConditionalObjectiveFloatFunction(data, labels,
            featureIndex, windowSize, classIndex, labelIndices, map, flags.backgroundSymbol, flags.sigma);
        func.crfType = flags.crfType;

        QNMinimizer minimizer;
        if (flags.interimOutputFreq != 0) {
          FloatFunction monitor = new ResultStoringFloatMonitor(flags.interimOutputFreq, flags.serializeTo);
          minimizer = new QNMinimizer(monitor);
        } else {
          minimizer = new QNMinimizer();
        }

        if (i == 0) {
          minimizer.setM(flags.QNsize);
        } else {
          minimizer.setM(flags.QNsize2);
        }

        float[] initialWeights;
        if (flags.initialWeights == null) {
          initialWeights = func.initial();
        } else {
          try {
            System.err.println("Reading initial weights from file " + flags.initialWeights);
            DataInputStream dis = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(
                flags.initialWeights))));
            initialWeights = Convert.readFloatArr(dis);
          } catch (IOException e) {
            throw new RuntimeException("Could not read from float initial weight file " + flags.initialWeights);
          }
        }
        System.err.println("numWeights: " + initialWeights.length);
        float[] weights = minimizer.minimize(func, (float) flags.tolerance, initialWeights);
        this.weights = ArrayMath.floatArrayToDoubleArray(func.to2D(weights));

      } else {

        /*double[] estimate = null;

        if(flags.estimateInitial){
          int[][][][] approxData = new int[data.length/100][][][];
          int[][] approxLabels = new int[data.length/100][];

          Random generator = new Random(1);
          for(int k=0;k<approxData.length; k++){
            int thisInd = generator.nextInt(data.length);
            approxData[k] = data[ thisInd];
            approxLabels[k] = labels[ thisInd];
          }

          CRFLogConditionalObjectiveFunction approxFunc = new CRFLogConditionalObjectiveFunction(approxData, approxLabels, featureIndex, windowSize, classIndex, labelIndices, map, flags.backgroundSymbol, flags.sigma);
          approxFunc.crfType = flags.crfType;
          minimizer = new QNMinimizer(10);

          if (flags.initialWeights == null) {
            estimate = approxFunc.initial();
          } else {
            try {
              System.err.println("Reading initial weights from file " + flags.initialWeights);
              DataInputStream dis = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(flags.initialWeights))));
              estimate = Convert.readDoubleArr(dis);
            } catch (IOException e) {
              throw new RuntimeException("Could not read from double initial weight file " + flags.initialWeights);
            }
          }

          estimate = minimizer.minimize(approxFunc, 1e-2, estimate);

        }
        */
        CRFLogConditionalObjectiveFunction func = new CRFLogConditionalObjectiveFunction(data, labels, featureIndex,
            windowSize, classIndex, labelIndices, map, flags.backgroundSymbol, flags.sigma);
        func.crfType = flags.crfType;
        if (evaluators != null) {
          for (Evaluator eval : evaluators) {
            if (eval instanceof CRFClassifierEvaluator) {
              ((CRFClassifierEvaluator) eval).setHelperFunction(func);
            }
          }
        }
        Minimizer minimizer = getMinimizer(i, evaluators);

        double[] initialWeights;
        if (flags.initialWeights == null) {
          initialWeights = func.initial();
        } else {
          try {
            System.err.println("Reading initial weights from file " + flags.initialWeights);
            DataInputStream dis = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(
                flags.initialWeights))));
            initialWeights = Convert.readDoubleArr(dis);
          } catch (IOException e) {
            throw new RuntimeException("Could not read from double initial weight file " + flags.initialWeights);
          }
        }
        System.err.println("numWeights: " + initialWeights.length);

        if (flags.testObjFunction) {
          StochasticDiffFunctionTester tester = new StochasticDiffFunctionTester(func);
          if (tester.testSumOfBatches(initialWeights, 1e-4)) {
            System.err.println("Testing complete... exiting");
            System.exit(1);
          } else {
            System.err.println("Testing failed....exiting");
            System.exit(1);
          }

        }
        double[] weights = minimizer.minimize(func, flags.tolerance, initialWeights);
        this.weights = func.to2D(weights);
      }

      // save feature index to disk and read in later
      if (flags.saveFeatureIndexToDisk) {
        try {
          System.err.println("Reading temporary feature index file.");
          featureIndex = (Index<String>) IOUtils.readObjectFromFile(featIndexFile);
        } catch (Exception e) {
          throw new RuntimeException("Could not open temporary feature index file for reading.");
        }
      }

      if (i != flags.numTimesPruneFeatures) {
        dropFeaturesBelowThreshold(flags.featureDiffThresh);
        System.err.println("Removing features with weight below " + flags.featureDiffThresh + " and retraining...");
      }

    }
  }
604905
public void write() throws Exception {
    PrintWriter out;
    String output = output();

    if (outFile != null) {
      out = new PrintWriter(Files.newBufferedWriter(outFile.toPath(), UTF_8));
    } else if (inPlace) {
      assert docFile != null
          : "@AssumeAssertion(nullness): dependent: docFile is non-null if inPlace is true";
      out = new PrintWriter(Files.newBufferedWriter(docFile.toPath(), UTF_8));
    } else {
      out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out, UTF_8)));
    }

    out.println(output);
    out.flush();
    out.close();
  }
151038
private boolean goToNextDoc() throws IOException {
    if (docId == NO_MORE_DOCS) {
      return true;
    } else {
      docId = spans1.spans.nextDoc();
      if (docId == NO_MORE_DOCS) {
        return true;
      } else {
        int spans2DocId = spans2.spans.docID();
        if (spans2DocId < docId) {
          spans2DocId = spans2.spans.advance(docId);
        }
        if (docId != spans2DocId) {
          return spans1.spans.nextStartPosition() != NO_MORE_POSITIONS;
        } else if (goToNextStartPosition()) {
          return true;
        } else {
          reset();
          return false;
        }
      }
    }
  }
830369
static <INN extends CoreMap & HasWord> void mergeTwoDocuments(List<INN> mainDocument, List<INN> auxDocument, Set<String> auxLabels, String background) {		
		boolean insideAuxTag = false;
		boolean auxTagValid = true;
		String prevAnswer = background;
		Collection<INN> constituents = new ArrayList<INN>();

		Iterator<INN> auxIterator = auxDocument.listIterator();

		for (INN wMain : mainDocument) {
			String mainAnswer = wMain.get(AnswerAnnotation.class);
			INN wAux = auxIterator.next();
			String auxAnswer = wAux.get(AnswerAnnotation.class);
			boolean insideMainTag = !mainAnswer.equals(background);

			/* if the auxiliary classifier gave it one of the labels unique to
				 auxClassifier, we might set the mainLabel to that. */
			if (auxLabels.contains(auxAnswer) && !auxAnswer.equals(background)) { //AZ not equal background symbol (it is background symbol not strong class)
				if ( ! prevAnswer.equals(auxAnswer) && ! prevAnswer.equals(background)) {
					if (auxTagValid){
						for (INN wi : constituents) {
							wi.set(AnswerAnnotation.class, prevAnswer);
						}
					}
					constituents = new ArrayList<INN>();
				}
				insideAuxTag = true;
				if (insideMainTag) { auxTagValid = false; }
				prevAnswer = auxAnswer;
				constituents.add(wMain);
			} else {
				if (insideAuxTag) {
					if (auxTagValid){
						for (INN wi : constituents) {
							wi.set(AnswerAnnotation.class, prevAnswer);
						}
					}
					constituents = new ArrayList<INN>();
				}
				insideAuxTag=false;
				auxTagValid = true;
				prevAnswer = background;
			}
		}
		// deal with a sequence final auxLabel
		if (auxTagValid){
			for (INN wi : constituents) {
				wi.set(AnswerAnnotation.class, prevAnswer);
			}
		}
	}
95126
private boolean goToNextDoc() throws IOException {
    if (docId == NO_MORE_DOCS) {
      return true;
    } else {
      // try to find docId with match for all items from sequence
      Integer spanDocId;
      Integer newDocId = null;
      Integer minOptionalDocId = null;
      boolean allItemsOptional = true;
      for (QueueItem item : queueSpans) {
        if (!item.sequenceSpans.optional) {
          allItemsOptional = false;
        }
        if (!item.noMoreDocs) {
          if (item.sequenceSpans.spans == null) {
            spanDocId = NO_MORE_DOCS;
          } else if (newDocId == null) {
            spanDocId = item.sequenceSpans.spans.nextDoc();
          } else {
            if (!item.sequenceSpans.optional) {
              spanDocId = item.sequenceSpans.spans.advance(newDocId);
            } else {
              if (item.sequenceSpans.spans.docID() == -1
                  || newDocId > item.sequenceSpans.spans.docID()) {
                spanDocId = item.sequenceSpans.spans.advance(newDocId);
              } else {
                spanDocId = item.sequenceSpans.spans.docID();
              }
            }
          }
          if (spanDocId.equals(NO_MORE_DOCS)) {
            item.noMoreDocs = true;
            if (!item.sequenceSpans.optional) {
              // a not optional span has NO_MORE_DOCS: stop
              docId = NO_MORE_DOCS;
              return true;
            }
          } else if (!spanDocId.equals(newDocId)) {
            // last found spanDocId not equal to potential new docId
            if (newDocId != null) {
              if (!item.sequenceSpans.optional) {
                // move also previous spans to at least spanDocId
                advance(spanDocId);
                return true;
              }
              // define potential new docId
            } else {
              if (!item.sequenceSpans.optional) {
                // previous optional span with lower docId
                if ((minOptionalDocId != null)
                    && (minOptionalDocId < spanDocId)) {
                  advance(spanDocId);
                  return true;
                } else {
                  // use spanDocId as potential newDocId
                  newDocId = spanDocId;
                }
              } else {
                // remember minimum docId optional spans
                minOptionalDocId = (minOptionalDocId == null) ? spanDocId
                    : Math.min(minOptionalDocId, spanDocId);
              }
            }
          }
        }
      }
      // if all items are optional
      if (allItemsOptional && newDocId == null && minOptionalDocId != null) {
        newDocId = minOptionalDocId;
      }
      // nothing found
      if (newDocId == null) {
        docId = NO_MORE_DOCS;
        return true;
      } else {
        docId = newDocId;
        ignoreItem.advanceToDoc(docId);
        // try and glue together
        if (findMatches()) {
          return true;
          // no matches
        } else {
          resetQueue();
          return false;
        }
      }
    }
  }
83490
def merge_join_docs(self, keys):
        

        join = defaultdict(list)

        for key in keys:
            join[key] = self.generate_join_docs_list(
                self.collections_data['left'].get(key, []), self.collections_data['right'].get(key, []))
        return join
1077457
private void printMergedCopy(String output) throws IOException, ParserConfigurationException, TransformerConfigurationException, TransformerException {
        tc = "printMergedCopy - ";
        if (debug)
            Tr.info(traceComponent, tc + "Output File: " + output);
        cleanPlugins();
        FileOutputStream fos = new FileOutputStream(output);
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder parser = dbf.newDocumentBuilder();
        Document mergeDoc = parser.newDocument();
        final Comment comment = mergeDoc.createComment(" This config file was generated by plugin's merge tool v1.0.0.2 on " +
                                                       new SimpleDateFormat("yyyy.MM.dd 'at' HH:mm:ss z").format(new Date()) + " ");
        mergeDoc.appendChild(comment);

        mergeDoc.appendChild(mergeDoc.importNode(mergeConfigNode, true));
        mergeConfigNode = mergeDoc.getDocumentElement();
        removeComments(parser, mergeDoc);

        mergeConfigNode.appendChild(mergeDoc.importNode(mergeDoc.createComment(" Server Clusters "), true));

        Node[] sc = null;
        sharedPlugins.trimToSize();
        Iterator<PluginInfo> itrSharedPlugins = sharedPlugins.iterator();
        while (itrSharedPlugins.hasNext()) {
            if (failOver)
                sc = (itrSharedPlugins.next()).getFailOverServerClusters();
            else
                sc = (itrSharedPlugins.next()).getSharedServerClusters();

            for (int i = 0; i < sc.length; i++)
                mergeConfigNode.appendChild(mergeDoc.importNode(sc[i], true));
        }

        for (int i = 0; i < plugins.length - paramCnt; i++) {
            if (!plugins[i].getUniquePluginRep().isEmpty()) {
                sc = plugins[i].getUnsharedServerClusters();
                for (int j = 0; j < sc.length; j++)
                    mergeConfigNode.appendChild(mergeDoc.importNode(sc[j], true));
            }
        }

        mergeConfigNode.appendChild(mergeDoc.createComment(" Virtual Host Groups "));

        Node[] vhgs = null;
        itrSharedPlugins = sharedPlugins.iterator();
        while (itrSharedPlugins.hasNext()) {
            vhgs = (itrSharedPlugins.next()).getSharedVHostGrps();
            for (int i = 0; i < vhgs.length; i++) {
                mergeConfigNode.appendChild(mergeDoc.importNode(vhgs[i], true));
            }
        }

        vhgs = null;
        for (int i = 0; i < plugins.length - paramCnt; i++) {
            vhgs = plugins[i].getUnsharedVHostGrp();
            for (int j = 0; j < vhgs.length; j++)
                mergeConfigNode.appendChild(mergeDoc.importNode(vhgs[j], true));
        }

        mergeConfigNode.appendChild(mergeDoc.createComment(" URI Groups "));

        Node[] uriGrps = null;
        itrSharedPlugins = sharedPlugins.iterator();
        while (itrSharedPlugins.hasNext()) {
            uriGrps = (itrSharedPlugins.next()).getUriGrps();
            for (int i = 0; i < uriGrps.length; i++)
                mergeConfigNode.appendChild(mergeDoc.importNode(uriGrps[i], true));
        }

        for (int i = 0; i < plugins.length - paramCnt; i++) {
            uriGrps = plugins[i].getUriGrps();
            for (int j = 0; j < uriGrps.length; j++)
                mergeConfigNode.appendChild(mergeDoc.importNode(uriGrps[j], true));

            //output unqiueUriGrps needed due to vhost def
            uriGrps = plugins[i].getUniqueUriGrps();
            for (int j = 0; j < uriGrps.length; j++)
                mergeConfigNode.appendChild(mergeDoc.importNode(uriGrps[j], true));
        }

        mergeConfigNode.appendChild(mergeDoc.createComment(" Routes "));

        Node[] routes = null;
        itrSharedPlugins = sharedPlugins.iterator();
        while (itrSharedPlugins.hasNext()) {
            routes = (itrSharedPlugins.next()).getRoutes();
            for (int i = 0; i < routes.length; i++)
                mergeConfigNode.appendChild(mergeDoc.importNode(routes[i], true));
        }

        for (int i = 0; i < plugins.length - paramCnt; i++) {
            routes = plugins[i].getRoutes();
            for (int j = 0; j < routes.length; j++)
                mergeConfigNode.appendChild(mergeDoc.importNode(routes[j], true));
        }

        TransformerFactory transfac = TransformerFactory.newInstance();

        Transformer trans = transfac.newTransformer();
        trans.setOutputProperty(OutputKeys.INDENT, "yes");
        trans.setOutputProperty(OutputKeys.METHOD, "xml");
        trans.setOutputProperty(OutputKeys.ENCODING, encoding);
        trans.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
        //create string from xml tree
        StreamResult result = new StreamResult(fos);
        DOMSource source = new DOMSource(mergeDoc);
        trans.transform(source, result);

        fos.flush();
        fos.close();

        Tr.info(traceComponent, "Merged plugin config file written to " + output);
    }
299143
def merge_annotations(system, document):
        
        if not Path(document).exists():
            return
        meta = FileSystem.load_yaml(document)
        click.secho('merge: {0}'.format(document.name), fg='blue')
        for identifier, data in meta.items():
            symbol = system.lookup(identifier)
            if symbol:
                merge(symbol.tags, data)
27004
public long getNumDocs() {
        Log.debug("Getting num docs");
        try {
            IndexSearcher searcher = searcherManager.acquire();
            try {
                return searcher.getIndexReader().numDocs();
            } finally {
                searcherManager.release(searcher);
            }
        } catch (IOException e) {
            Log.error(e, "Error while getting num docs");
            throw new RuntimeException(e);
        }

    }
594082
function merge(docset, customTags) {
  doc_ast.linenr = docset["linenr"];

  // useful for applying global NS items to the proper NS
  docset["original_name"] = docset["code"].name;
  docset["comment"] = doc_ast.detect(docset["tagname"], docset["comment"], customTags);
  
  return Merger.merge(docset);
}
896104
def merge(args):
    
    p = OptionParser(merge.__doc__)
    p.set_outfile(outfile="merged_results.delta")
    opts, args = p.parse_args(args)

    if len(args) < 3:
        sys.exit(not p.print_help())

    ref, query = args[:2]
    deltafiles = args[2:]
    outfile = opts.outfile

    ref = get_abs_path(ref)
    query = get_abs_path(query)
    fw = must_open(outfile, "w")
    print(" ".join((ref, query)), file=fw)
    print("NUCMER", file=fw)
    fw.close()

    for d in deltafiles:
        cmd = "awk 'NR > 2 {{print $0}}' {0}".format(d)
        sh(cmd, outfile=outfile, append=True)
1062824
@Override
    public synchronized void run() {

        try {
            // do the rename operation
            m_mergePages.actionMerge(getReport());
        } catch (Exception e) {
            getReport().println(e);
            if (LOG.isErrorEnabled()) {
                LOG.error(e.getLocalizedMessage());
            }
        }
    }
726394
public void mergeXfaData(Node n) throws IOException, DocumentException {
        XfaForm.Xml2SomDatasets data = new XfaForm.Xml2SomDatasets(n);
        for (Iterator it = data.getOrder().iterator(); it.hasNext();) {
            String name = (String)it.next();
            String text = XfaForm.getNodeText((Node)data.getName2Node().get(name));
            setField(name, text);
        }
    }
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);
			}
		}
	}
158396
private Document toXML(Collection<ArchiveEntry> files) throws Exception
    {
        Document doc = new DOMDocument();

        Element packageElement = new DOMElement("package");
        doc.setRootElement(packageElement);

        Element infoElement = new DOMElement("infos");
        packageElement.add(infoElement);
        addInfoElements(infoElement);

        Element filesElement = new DOMElement(FILES_TAG);
        packageElement.add(filesElement);
        addFileElements(files, filesElement);

        return doc;
    }
509128
public static ObjectStream<DocSample> getDocumentStream(
      final String inputData, String clearFeatures) throws IOException {
    final ObjectStream<String> docStream = IOUtils
        .readFileIntoMarkableStreamFactory(inputData);
    ObjectStream<DocSample> sampleStream = new DocSampleStream(clearFeatures,
        docStream);
    return sampleStream;
  }