<commit_before>/**
 * @file xsdwebformparsertags.js
 * XSD Schema to HTML5 Web Form
 * @author <NAME> <<EMAIL>>
 * @copyright Copyright (C) 2017 Eworx, <NAME>. All rights reserved.
 */


/**
 * Class XSDWebFormParserTags
 * Parser for XSD Schema Tags
 * Static
 */
class XSDWebFormParserHTMLTags
{

    /**
     * Class constructor
     */
    constructor(){
        
        this.HTML_TYPES = {
            "form": this.parseForm,
            "group": this.parseGroup,
            "input": this.parseInput,
            "text": this.parseText,
            "number": this.parseNumber,
            "date": this.parseDate,
            "select": this.parseSelect
        };

        this.HTMLObjects = [];
        // this.isGroupSwitch = false;
        this.showLog = false;
        this.verbose = false;
    }

    /**
     * htmlParse - Parse inner XML Document
     * @param htmlItem
     * @param xsdItem
     */
    htmlParse(htmlItem, xsdItem) 
    {
        // Loop through Tag's childNodes
        for (let i = 0, l = htmlItem.children.length; i < l; i++) {

            if (htmlItem.children[i].type === "element") {
                // console.log("-----------" + htmlItem.children[i].name);
                if (this.showLog) {
                    process.stdout.write(`\x1b[0m\x1b[31mHTML => \x1b[0m\x1b[33m${htmlItem.children[i].name}`);
                    
                    if (htmlItem.children[i].attr.name) {
                        process.stdout.write(` :: \x1b[1m\x1b[33m${htmlItem.children[i].attr.name} \x1b[0m`);
                    }

                    if (htmlItem.children[i].attr.element) {

                            // if (htmlItem.children[i].attr.element ==="AcquiringMemberState") {
                            //     htmlItem.children[i].attr.test ="ASDASDASASDAS";
                            //     console.log("SSSSS"+htmlItem.children[i]);
                            // }

                        process.stdout.write(` :: \x1b[1m\x1b[33m${htmlItem.children[i].attr.element} \x1b[0m`);
                    }
                    console.log("");
                }

                this.parseHTMLItem(htmlItem.children[i], xsdItem);
                
                // if (htmlItem.children[i].name !== "group") {
                //     // this.isGroupSwitch = true;
                //     this.htmlParse(htmlItem.children[i], xsdItem);
                // }

                this.htmlParse(htmlItem.children[i], xsdItem);

            }
        };

    }

    /**
     * parseHTMLItem - Parse HTML Tag
     * @param item
     * @param xsdItem
     */
    parseHTMLItem(item, xsdItem) 
    {

        if ((item.name in this.HTML_TYPES)) {
            (this.HTML_TYPES[item.name])(item, xsdItem, this);
        } else {
            console.log(`\n************* Unknown HTML Tag {${item.name}} *************\n`);
            process.stdout.write('\x07');
        }

    }

    /**
     * getXSDComplexByGroupTag - Find and get XSD complexType Type filtered by Group Tag name
     * @param xsdItemName
     * @param xsdItem
     */
    getXSDComplexByGroupTag(xsdItemName, xsdItem) 
    {

        var XSDWFormComplexItems = xsdItem.childWithAttribute("name", xsdItemName).childNamed("xs:sequence");
        if (!XSDWFormComplexItems) return "";
        
        return XSDWFormComplexItems;

    }

    /**
     * parseForm- Parse Form Tag
     * @param item
     * @param xsdItem
     * @param sender
     */
    parseForm(item, xsdItem, sender) 
    {

        sender.logTag(item.name);  

    }

    /**
     * parseGroup- Parse Group Tag
     * @param item
     * @param xsdItem
     * @param sender
     */
    parseGroup(item, xsdItem, sender)  
    {

        sender.logTag(item.name);  
        // this.isGroupSwitch = true;
        var groupObject = {
                    name : item.attr.element,
                    htmlXML : item,
                    xsdXML :  sender.getXSDComplexByGroupTag(item.attr.element, xsdItem)
                }
        sender.HTMLObjects.push({ type : "group", itemObject : groupObject });

    } 

    /**
     * parseInput- Parse Input Tag
     * @param item
     * @param xsdItem
     * @param sender
     */
    parseInput(item, xsdItem, sender)
    {<commit_msg>Parsing html data<commit_after>/**
 * @file xsdwebformparsertags.js
 * XSD Schema to HTML5 Web Form
 * @author <NAME> <<EMAIL>>
 * @copyright Copyright (C) 2017 Eworx, <NAME>. All rights reserved.
 */


/**
 * Class XSDWebFormParserTags
 * Parser for XSD Schema Tags
 * Static
 */
class XSDWebFormParserHTMLTags
{

    /**
     * Class constructor
     */
    constructor(){
        
        this.HTML_TYPES = {
            "form": {
                        fn : this.parseForm,
                    },
            "group": {
                        fn : this.parseGroup,
                    },
            "input": {
                        fn : this.parseInput,
                    },
            "text": {
                        fn : this.parseText,
                    },
            "number": {
                        fn : this.parseNumber,
                    },
            "date": {
                        fn : this.parseDate,
                    },
            "select": {
                        fn : this.parseSelect
                    }
        };

        this.HTMLObjects = [];
        this.showLog = false;
        this.verbose = false;
    }

    /**
     * htmlParse - Parse inner XML Document
     * @param htmlItem
     * @param xsdItem
     */
    htmlParse(htmlItem, xsdItem) 
    {
        // Loop through Tag's childNodes
        for (let i = 0, l = htmlItem.children.length; i < l; i++) {

            if (htmlItem.children[i].type === "element") {
                // console.log("-----------" + htmlItem.children[i].name);
                if (this.showLog) {
                    process.stdout.write(`\x1b[0m\x1b[31mHTML => \x1b[0m\x1b[33m${htmlItem.children[i].name}`);
                    
                    if (htmlItem.children[i].attr.name) {
                        process.stdout.write(` :: \x1b[1m\x1b[33m${htmlItem.children[i].attr.name} \x1b[0m`);
                    }

                    if (htmlItem.children[i].attr.element) {

                            // if (htmlItem.children[i].attr.element ==="AcquiringMemberState") {
                            //     htmlItem.children[i].attr.test ="ASDASDASASDAS";
                            //     console.log("SSSSS"+htmlItem.children[i]);
                            // }

                        process.stdout.write(` :: \x1b[1m\x1b[33m${htmlItem.children[i].attr.element} \x1b[0m`);
                    }
                    console.log("");
                }

                this.parseHTMLItem(htmlItem.children[i], xsdItem);
                
                // if (htmlItem.children[i].name !== "group") {
                //     this.htmlParse(htmlItem.children[i], xsdItem);
                // }

                this.htmlParse(htmlItem.children[i], xsdItem);

            }
        };

    }

    /**
     * parseHTMLItem - Parse HTML Tag
     * @param item
     * @param xsdItem
     */
    parseHTMLItem(item, xsdItem) 
    {

        if ((item.name in this.HTML_TYPES)) {
            (this.HTML_TYPES[item.name].fn)(item, xsdItem, this);
        } else {
            console.log(`\n************* Unknown HTML Tag {${item.name}} *************\n`);
            process.stdout.write('\x07');
        }

    }

    /**
     * getXSDComplexByGroupTag - Find and get XSD complexType Type filtered by Group Tag name
     * @param xsdItemName
     * @param xsdItem
     */
    getXSDComplexByGroupTag(xsdItemName, xsdItem) 
    {

        var XSDWFormComplexItems = xsdItem.childWithAttribute("name", xsdItemName).childNamed("xs:sequence");
        if (!XSDWFormComplexItems) return "";
        
        return XSDWFormComplexItems;

    }

    /**
     * parseForm- Parse Form Tag
     * @param item
     * @param xsdItem
     * @param sender
     */
    parseForm(item, xsdItem, sender) 
    {

        sender.logTag(item.name);  

    }

    /**
     * parseGroup- Parse Group Tag
     * @param item
     * @param xsdItem
     * @param sender
     */
    parseGroup(item, xsdItem, sender)  
    {

        sender.logTag(item.name);  
        var groupObject = {
                    name : item.attr.element,
                    htmlXML : item,
                    xsdXML :  sender.getXSDComplexByGroupTag(item.attr.element, xsdItem)
                }
        sender.HTMLObjects.push({ type : "group", itemObject : groupObject });

    } 

    /**
     * parseInput- Parse Input Tag
     * @param item
     * @param xsdItem
     * @param sender
     */
    parseInput(item, xsdItem, sender)
    {
{'fraction_non_alphanumeric': 0.13518772893772893, 'fraction_numerical': 0.007326007326007326, 'mean_word_length': 1.4042377545404512, 'pattern_counts': {'":': 14, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4715858', 'n_tokens_mistral': 2685, 'n_tokens_neox': 2555, 'n_words': 455}