<commit_before>#include "include/XyLatinStr.hpp"
#include "include/XyUTF8Str.hpp"
#include "Diff_DeltaConstructor.hpp"

#include "CommonSubSequenceAlgorithms.hpp"
#include "Tools.hpp"
#include "include/XID_map.hpp"
#include "Diff_NodesManager.hpp"
#include "include/XyStrDiff.hpp"
#include "DeltaException.hpp"

#include "xercesc/dom/DOMNode.hpp"
#include "xercesc/dom/DOMNodeList.hpp"
#include "xercesc/dom/DOMElement.hpp"
#include "xercesc/dom/DOMNamedNodeMap.hpp"
#include "xercesc/dom/DOMAttr.hpp"
#include "xercesc/util/XMLString.hpp"

//#define SKIP_UNIMPORTANT_MOVE 1

#include <stdio.h>
#include <map>
#include <queue>
#include <list>
#include <math.h>
#include <fstream>
#include "infra/general/hash_map.hpp"

unsigned long long int   clocksCDDinitDomDelta      ;
unsigned long long int   clocksCDDprepareVectors    ;
unsigned long long int   clocksCDDsaveXidMap        ;
unsigned long long int   clocksCDDcomputeWeakMove   ;
unsigned long long int   clocksCDDdetectUpdate      ;
unsigned long long int   clocksCDDaddAttributeOps   ;
unsigned long long int   clocksConstructDOMDelta    ;

bool _XyDiff_DontSaveXidmapToFile = false;

XERCES_CPP_NAMESPACE_USE

XID_DOMDocument *DeltaConstructor::getDeltaDocument(void) {
	return deltaDoc ;
	}

DeltaConstructor::DeltaConstructor(
		class NodesManager *incMappings,
		const char *from,
		XID_DOMDocument* fromXDD,
		const char *to,
		XID_DOMDocument* toXDD,
		bool IncIgnoreUnimportantData) {

	v0XML        = fromXDD ;
	v1XML        = toXDD ;
	v0filename   = from ;
	v1filename   = to ;
	nodesManager = incMappings ;
	
	moveCount    = 0 ;
	updateCount  = 0 ;
	
	ignoreUnimportantData = IncIgnoreUnimportantData ;
	XMLCh tempStrA[100];
	XMLCh tempStrB[100];
	XMLString::transcode("urn:schemas-xydiff:unit-delta", xyDiffNS_ch, 99);
	deltaDoc     = XID_DOMDocument::createDocument() ;

	XMLString::transcode("unit_delta", tempStrA, 99);
	DOMElement* deltaRoot = deltaDoc->createElement(tempStrA);
	XMLCh *xmlnsURI_ch = XMLString::transcode("http://www.w3.org/2000/xmlns/");
	XMLCh *xmlns_ch = XMLString::transcode("xmlns");
	deltaRoot->setAttributeNS(xmlnsURI_ch, xmlns_ch, xyDiffNS_ch);
	XMLString::release(&xmlnsURI_ch);
	XMLString::release(&xmlns_ch);
	deltaDoc->appendChild( (DOMNode*) deltaRoot );

	XMLString::transcode("t", tempStrA, 99);
	DOMElement* tElem = deltaDoc->createElement(tempStrA);

	if (ignoreUnimportantData) {
		XMLString::transcode("IgnoreBlankTexts", tempStrA, 99);
		XMLString::transcode("yes", tempStrB, 99);
		tElem->setAttribute(tempStrA, tempStrB);
	}
	deltaRoot->appendChild( tElem );

	scriptRoot = tElem ;
	
	}

/*****************************************************
 *         ++++ Construct Delete Script ++++         *
 *****************************************************/

void DeltaConstructor::ConstructDeleteScript( int v0nodeID, bool ancestorDeleted ) {

	class AtomicInfo & myAtomicInfo = nodesManager->v0node[ v0nodeID ] ;
	DOMNode* node = nodesManager->v0nodeByDID[ v0nodeID ] ;
<commit_msg>XyDiff: Fixed issue with namespaces causing warnings with delta creation<commit_after>#include "include/XyLatinStr.hpp"
#include "include/XyUTF8Str.hpp"
#include "Diff_DeltaConstructor.hpp"

#include "CommonSubSequenceAlgorithms.hpp"
#include "Tools.hpp"
#include "include/XID_map.hpp"
#include "Diff_NodesManager.hpp"
#include "include/XyStrDiff.hpp"
#include "DeltaException.hpp"

#include "xercesc/dom/DOMNode.hpp"
#include "xercesc/dom/DOMNodeList.hpp"
#include "xercesc/dom/DOMElement.hpp"
#include "xercesc/dom/DOMNamedNodeMap.hpp"
#include "xercesc/dom/DOMAttr.hpp"
#include "xercesc/util/XMLString.hpp"

//#define SKIP_UNIMPORTANT_MOVE 1

#include <stdio.h>
#include <map>
#include <queue>
#include <list>
#include <math.h>
#include <fstream>
#include "infra/general/hash_map.hpp"

unsigned long long int   clocksCDDinitDomDelta      ;
unsigned long long int   clocksCDDprepareVectors    ;
unsigned long long int   clocksCDDsaveXidMap        ;
unsigned long long int   clocksCDDcomputeWeakMove   ;
unsigned long long int   clocksCDDdetectUpdate      ;
unsigned long long int   clocksCDDaddAttributeOps   ;
unsigned long long int   clocksConstructDOMDelta    ;

bool _XyDiff_DontSaveXidmapToFile = false;

XERCES_CPP_NAMESPACE_USE

XID_DOMDocument *DeltaConstructor::getDeltaDocument(void) {
	return deltaDoc ;
	}

DeltaConstructor::DeltaConstructor(
		class NodesManager *incMappings,
		const char *from,
		XID_DOMDocument* fromXDD,
		const char *to,
		XID_DOMDocument* toXDD,
		bool IncIgnoreUnimportantData) {

	v0XML        = fromXDD ;
	v1XML        = toXDD ;
	v0filename   = from ;
	v1filename   = to ;
	nodesManager = incMappings ;
	
	moveCount    = 0 ;
	updateCount  = 0 ;
	
	ignoreUnimportantData = IncIgnoreUnimportantData ;
	XMLCh tempStrA[100];
	XMLCh tempStrB[100];

	XMLCh *xmlnsURI_ch = XMLString::transcode("http://www.w3.org/2000/xmlns/");
	XMLCh *xmlns_ch = XMLString::transcode("xmlns");

	XMLString::transcode("urn:schemas-xydiff:unit-delta", xyDiffNS_ch, 99);
	deltaDoc     = XID_DOMDocument::createDocument() ;


	XMLString::transcode("unit_delta", tempStrA, 99);
	DOMElement* deltaRoot = deltaDoc->createElement(tempStrA);
	deltaRoot->setAttributeNS(xmlnsURI_ch, xmlns_ch, xyDiffNS_ch);
	deltaDoc->appendChild( (DOMNode*) deltaRoot );

	XMLString::transcode("t", tempStrA, 99);
	DOMElement* tElem = deltaDoc->createElement(tempStrA);

	if (ignoreUnimportantData) {
		XMLString::transcode("IgnoreBlankTexts", tempStrA, 99);
		XMLString::transcode("yes", tempStrB, 99);
		tElem->setAttribute(tempStrA, tempStrB);
	}
	deltaRoot->appendChild( tElem );

	// Copy namespaces from root element
	DOMNamedNodeMap *v1XMLAttrs = v1XML->getDocumentElement()->getAttributes();
	for (int i = 0; i < v1XMLAttrs->getLength(); i++) {
		DOMAttr *attr = (DOMAttr *) v1XMLAttrs->item(i);
		// If it is in the xmlns namespace
		if (XMLString::compareString(attr->getNamespaceURI(), xmlnsURI_ch) != 0) {
			DOMNamedNodeMap *deltaAttrs = deltaRoot->getAttributes();
			if (deltaAttrs->getNamedItem( attr->getNodeName()) == NULL) {
				deltaRoot->setAttributeNS(xmlnsURI_ch, attr->getName(), attr->getValue());
			}
		}
	}
	
	
	scriptRoot = tElem ;

	XMLString::release(&xmlnsURI_ch);
	XMLString::release(&xmlns_ch);

	}

/*****************************************************
 *         ++++ Construct Delete Script ++++         *
 *****************************************************/

void DeltaConstructor::ConstructDeleteScript( int v0nodeID, bool ancestorDeleted ) {

	class AtomicInfo & myAtomicInfo = nodesManager->v0node[ v0nodeID ] ;
	DOMNode* node = nodesManager->v0nodeByDID[ v0nodeID ] ;

{'fraction_non_alphanumeric': 0.1471658078205517, 'fraction_numerical': 0.011215519854501364, 'mean_word_length': 5.400581959262851, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 19}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '750822', 'n_tokens_mistral': 2376, 'n_tokens_neox': 2239, 'n_words': 427}