<commit_before>(function() {
    angular
        .module("resourceFactory", [])
        .factory("Resource", ["PredObject", "Namespace", ResourceFactory]);

    function ResourceFactory(PredObject, Namespace) {
        function Resource(id, tmpl) {
            this._id = id;
            this._template = tmpl;
            this._type = (typeof tmpl !== "undefined" && tmpl !== null) ? tmpl.getClassID() : null;
            this._properties = {};
            this._pristine = {};
        }

        /**
         * @@@ add a utility function to load a resource from the
         *     triple-store
         */
        Resource.fromGraph = function(store, uri) {
            var query = "SELECT *  FROM { <" + uri + "> ?p ?o }", r;
            r = new Resource(uri, null);
            store.execute(query, function(success, results) {
                if (success) {
                    console.log(results);
                }
            });
            return r;
        };

        /**
         * Return resource URI.
         */
        Resource.prototype.getID = function() {
                return this._id;
        };

        /**
         * Return resource URI.
         */
        Resource.prototype.getType = function() {
            return this._type;
        };

        Resource.prototype.setTemplate = function(tmpl) {
            this._template = tmpl;
            this._type = tmpl.getClassID();
        };
        
        /**
         * Initialize hash for new property in resource.
         */
        Resource.prototype.initializeProperty = function(property, flags) {
            var prop, constraint, defaultVal;
            prop = property.getProperty().getID();
            if (typeof this._properties[prop] === "undefined") {
                this._properties[prop] = [];
                this._pristine[prop] = [];
            }
            if (property.hasConstraint()) {
                constraint = property.getConstraint();
                if (constraint.hasDefaultURI()) {
                    if (constraint.hasDefaultLiteral()) {
                        defaultVal = new PredObject(constraint.getDefaultLiteral(), constraint.getDefaultURI(), property.getType(), false);
                    } else {
                        defaultVal = new PredObject(constraint.getDefaultURI(), constraint.getDefaultURI(), property.getType(), false);
                    }
                    this._properties[prop].push(defaultVal);
                    this._pristine[prop].push(defaultVal);
                } else if (property.getConstraint().hasDefaultLiteral()) {
                    defaultVal = new PredObject(constraint.getDefaultLiteral(), null, property.getType(), false);
                    this._properties[prop].push(defaultVal);
                    this._pristine[prop].push(defaultVal);
                }
            }
            if (!flags.hasRequired && property.isRequired()) {
                flags.hasRequired = true;
            }
            flags.loading[prop] = false;
        };

        /**
         * Return property values based on the property URI.
         */
        Resource.prototype.getPropertyValues = function(property) {
            if (typeof this._properties[property] !== "undefined") {
                return this._properties[property];
            } else {
                return null;
            }
        }
        
        /**
         * Set work's value of property to String or Date value.
         * Returns true if it makes a change in the model, false if not.
         */
        Resource.prototype.addPropertyValue = function(property, value) {
            var propID, seen, val, isDirty, textValue;
            isDirty = false;
            if (typeof property === "string") {
                propID = property;
            } else {
                propID = property.getProperty().getID();
            }
            objType = property.getType();
            seen = false;
            if (typeof value === "object" && typeof value.toISOString !== "undefined") {
                textValue = value.toISOString().split("T")[0];
            } else {
                textValue = value;
            }
            angular.forEach(this._properties[propID], function(val) {
                if (val.getValue() === textValue) {
                    seen = true;
                }
            });
            if (!seen && textValue !== "") {
                isDirty = true;
                val = new PredObject(textValue, textValue, objType, true);
                if (property.hasConstraint() && property.getConstraint().hasComplexType()) {
                    val.setDatatype(property.getConstraint().getComplexTypeID());
                };
                this._properties[propID].push(val);
            }
            return isDirty;
        };
        
        /**
         * Delete a value for a work's property, return whether a change
         * in the model occurred or not.
         */
        Resource.prototype.removePropertyValue = function(property, value) {
            var prop, empty, objs, rmIdx, objVal;
            removed = false;<commit_msg>remove add property by string, is a property template and needs access to all helper functions<commit_after>(function() {
    angular
        .module("resourceFactory", [])
        .factory("Resource", ["PredObject", "Namespace", ResourceFactory]);

    function ResourceFactory(PredObject, Namespace) {
        function Resource(id, tmpl) {
            this._id = id;
            this._template = tmpl;
            this._type = (typeof tmpl !== "undefined" && tmpl !== null) ? tmpl.getClassID() : null;
            this._properties = {};
            this._pristine = {};
        }

        /**
         * @@@ add a utility function to load a resource from the
         *     triple-store
         */
        Resource.fromGraph = function(store, uri) {
            var query = "SELECT *  FROM { <" + uri + "> ?p ?o }", r;
            r = new Resource(uri, null);
            store.execute(query, function(success, results) {
                if (success) {
                    console.log(results);
                }
            });
            return r;
        };

        /**
         * Return resource URI.
         */
        Resource.prototype.getID = function() {
                return this._id;
        };

        /**
         * Return resource URI.
         */
        Resource.prototype.getType = function() {
            return this._type;
        };

        Resource.prototype.setTemplate = function(tmpl) {
            this._template = tmpl;
            this._type = tmpl.getClassID();
        };
        
        /**
         * Initialize hash for new property in resource.
         */
        Resource.prototype.initializeProperty = function(property, flags) {
            var prop, constraint, defaultVal;
            prop = property.getProperty().getID();
            if (typeof this._properties[prop] === "undefined") {
                this._properties[prop] = [];
                this._pristine[prop] = [];
            }
            if (property.hasConstraint()) {
                constraint = property.getConstraint();
                if (constraint.hasDefaultURI()) {
                    if (constraint.hasDefaultLiteral()) {
                        defaultVal = new PredObject(constraint.getDefaultLiteral(), constraint.getDefaultURI(), property.getType(), false);
                    } else {
                        defaultVal = new PredObject(constraint.getDefaultURI(), constraint.getDefaultURI(), property.getType(), false);
                    }
                    this._properties[prop].push(defaultVal);
                    this._pristine[prop].push(defaultVal);
                } else if (property.getConstraint().hasDefaultLiteral()) {
                    defaultVal = new PredObject(constraint.getDefaultLiteral(), null, property.getType(), false);
                    this._properties[prop].push(defaultVal);
                    this._pristine[prop].push(defaultVal);
                }
            }
            if (!flags.hasRequired && property.isRequired()) {
                flags.hasRequired = true;
            }
            flags.loading[prop] = false;
        };

        /**
         * Return property values based on the property URI.
         */
        Resource.prototype.getPropertyValues = function(property) {
            if (typeof this._properties[property] !== "undefined") {
                return this._properties[property];
            } else {
                return null;
            }
        }
        
        /**
         * Set work's value of property to String or Date value.
         * Returns true if it makes a change in the model, false if not.
         */
        Resource.prototype.addPropertyValue = function(property, value) {
            var propID, seen, val, isDirty, textValue;
            isDirty = false;
            propID = property.getProperty().getID();
            objType = property.getType();
            seen = false;
            if (typeof value === "object" && typeof value.toISOString !== "undefined") {
                textValue = value.toISOString().split("T")[0];
            } else {
                textValue = value;
            }
            angular.forEach(this._properties[propID], function(val) {
                if (val.getValue() === textValue) {
                    seen = true;
                }
            });
            if (!seen && textValue !== "") {
                isDirty = true;
                val = new PredObject(textValue, textValue, objType, true);
                if (property.hasConstraint() && property.getConstraint().hasComplexType()) {
                    val.setDatatype(property.getConstraint().getComplexTypeID());
                };
                this._properties[propID].push(val);
            }
            return isDirty;
        };
        
        /**
         * Delete a value for a work's property, return whether a change
         * in the model occurred or not.
         */
        Resource.prototype.removePropertyValue = function(property, value) {
            var prop, empty, objs, rmIdx, objVal;
            removed = false;
{'fraction_non_alphanumeric': 0.11511639328160299, 'fraction_numerical': 0.00019644435713584126, 'mean_word_length': 1.4900953778429935, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2118879', 'n_tokens_mistral': 2445, 'n_tokens_neox': 2381, 'n_words': 557}