<commit_before>'use strict';

angular.module('angularApp')
    .factory('Entity', function (Uris, $q, $http, Request, GraphHelper, Expression, $filter, toaster, $cacheFactory) {
        // Service logic
        // ...

        var getName = function (entity) {
            if (entity[Uris.FOAF_FIRST_NAME] || entity[Uris.FOAF_LAST_NAME]) {
                var personName = entity[Uris.FOAF_FIRST_NAME] + ' ' + entity[Uris.FOAF_LAST_NAME];
                if (entity[Uris.QA_PREF_LABEL]) {
                    personName += ' (' + entity[Uris.QA_PREF_LABEL] + ')';
                }
                return personName;
            } else {
                return entity[Uris.QA_CITATION] || entity[Uris.QA_TOPIC_HEADING] || entity[Uris.QA_EVENT_TITLE] || entity[Uris.QA_AWARD_TITLE] || 
                				entity[Uris.QA_FIRM_NAME] || entity[Uris.FOAF_NAME] || entity[Uris.QA_LABEL] || 'Unknown';
            }
        };

        /*
"<NAME>, Ronchamps, France"
1: "<NAME>, Ronchamp, France"

 */
        var setupNames = function (entities) {
            // Array or object
            angular.forEach(entities, function (entity) {

                // Make the entities auto-complete compatible (for select2)
                entity.name = getName(entity);
                entity.text = entity.name;
                entity.id = entity.uri;
                // if (angular.isArray(entity.name)) {
                //     console.log('an array?', entity.name);
                //     entity.name = entity.name[0];
                // }
                entity.encodedUri = GraphHelper.encodeUriString(entity.uri);
            });
            return entities;
        };

        var setupPicturesAndTypes = function (entities) {

            // Setup the types on these entities
            GraphHelper.setupTypes(entities);

            // Get all the preferred images
            // var imageUris = GraphHelper.getAttributeValuesUnique(entities, Uris.QA_PREFERRED_IMAGE);

            // Set the default picture
            angular.forEach(entities, function (entity) {
                entity.picture = {
                    file: 'images/icon.png',
                    thumb: 'images/icon.png',
                };
            });

            // Overwrite the pictures if we have them
            // @todo: remove kludge
            // This is a complete kludge because the server is not automatically setting 
            // the preferred image of an entity to be a file
            // 
            return Expression.loadAllFull('qldarch:Photograph').then(function (expressions) {
                console.log('expressions', expressions);
                // return Expression.loadList(imageUris, 'qldarch:Photograph').then(function (expressions) {
                angular.forEach(expressions, function (expression) {
                    // this.QA_DEPICTS_BUILDING = this.QA_NS + 'depictsBuilding';
                    // this.QA_DEPICTS_ARCHITECT = this.QA_NS + 'depictsArchitect';
                    var depictsUri = expression[Uris.QA_DEPICTS_BUILDING] || expression[Uris.QA_DEPICTS_ARCHITECT]
                    	|| expression[Uris.QA_DEPICTS_FIRM];
                    if (depictsUri) {
                        // console.log('expression depicts someone or something', depictsUri);
                        if (depictsUri === 'http://qldarch.net/users/patriciadowling/Architect#63377814877') {
                            console.log('MATCH');
                        }
                        // its a photo of an architect or building
                        angular.forEach(entities, function (entity) {
                            if (entity.uri === depictsUri && angular.isDefined(expression.file)) {
                                entity.picture = expression.file;
                            }
                        });
                    }
                });
                
                angular.forEach(entities, function (entity) {
                    // Add images
                    // Add preferred images
                    if (angular.isDefined(entity[Uris.QA_PREFERRED_IMAGE])) {
                        // Add in the expression we got back
                        var imageUri = entity[Uris.QA_PREFERRED_IMAGE];
                        if (angular.isArray(imageUri)) {
                            imageUri = imageUri[0];
                        }
                        var expression = expressions[imageUri];
                        if (angular.isDefined(expression.file)) {
                            entity.picture = expression.file;
                        }
                    }
                });
                
                return entities;
            });
        };

        var clearEntityCaches = function () {
            $cacheFactory.get('$http').remove('/ws/rest/entity/detail/qldarch%3ANonDigitalThing?INCSUBCLASS=true&');
            $cacheFactory.get('$http').remove('/ws/rest/entity/detail/qldarch%3AArchitect?INCSUBCLASS=false&');
            $cacheFactory.get('$http').remove('/ws/rest/entity/detail/qldarch%3AFirm?INCSUBCLASS=false&');
            $cacheFactory.get('$http').remove('/ws/rest/entity/detail/qldarch%3AStructure?INCSUBCLASS=false&');
            // http://127.0.0.1:9000/ws/rest/entity/detail/qldarch%3ANonDigitalThing?INCSUBCLASS=true&
        };


        // Public API here
        var entity = {
        	clearAll: function() {
            	$cacheFactory.get('$http').removeAll();
        	},
        		
            update: function (uri, data) {
                var payload = angular.copy(data);
                // Remove any extra information
                // This causes the web server to die
                delete payload.encodedUri;<commit_msg>fix(entity-class): fix entities faulty preferred images<commit_after>'use strict';

angular.module('angularApp')
    .factory('Entity', function (Uris, $q, $http, Request, GraphHelper, Expression, $filter, toaster, $cacheFactory) {
        // Service logic
        // ...

        var getName = function (entity) {
            if (entity[Uris.FOAF_FIRST_NAME] || entity[Uris.FOAF_LAST_NAME]) {
                var personName = entity[Uris.FOAF_FIRST_NAME] + ' ' + entity[Uris.FOAF_LAST_NAME];
                if (entity[Uris.QA_PREF_LABEL]) {
                    personName += ' (' + entity[Uris.QA_PREF_LABEL] + ')';
                }
                return personName;
            } else {
                return entity[Uris.QA_CITATION] || entity[Uris.QA_TOPIC_HEADING] || entity[Uris.QA_EVENT_TITLE] || entity[Uris.QA_AWARD_TITLE] || 
                				entity[Uris.QA_FIRM_NAME] || entity[Uris.FOAF_NAME] || entity[Uris.QA_LABEL] || 'Unknown';
            }
        };

        /*
"<NAME>, Ronchamps, France"
1: "<NAME>, Ronchamp, France"

 */
        var setupNames = function (entities) {
            // Array or object
            angular.forEach(entities, function (entity) {

                // Make the entities auto-complete compatible (for select2)
                entity.name = getName(entity);
                entity.text = entity.name;
                entity.id = entity.uri;
                // if (angular.isArray(entity.name)) {
                //     console.log('an array?', entity.name);
                //     entity.name = entity.name[0];
                // }
                entity.encodedUri = GraphHelper.encodeUriString(entity.uri);
            });
            return entities;
        };

        var setupPicturesAndTypes = function (entities) {

            // Setup the types on these entities
            GraphHelper.setupTypes(entities);

            // Get all the preferred images
            // var imageUris = GraphHelper.getAttributeValuesUnique(entities, Uris.QA_PREFERRED_IMAGE);

            // Set the default picture
            angular.forEach(entities, function (entity) {
                entity.picture = {
                    file: 'images/icon.png',
                    thumb: 'images/icon.png',
                };
            });

            // Overwrite the pictures if we have them
            // @todo: remove kludge
            // This is a complete kludge because the server is not automatically setting 
            // the preferred image of an entity to be a file
            // 
            return Expression.loadAllFull('qldarch:Photograph').then(function (expressions) {
                console.log('expressions', expressions);
                // return Expression.loadList(imageUris, 'qldarch:Photograph').then(function (expressions) {
                angular.forEach(expressions, function (expression) {
                    // this.QA_DEPICTS_BUILDING = this.QA_NS + 'depictsBuilding';
                    // this.QA_DEPICTS_ARCHITECT = this.QA_NS + 'depictsArchitect';
                    var depictsUri = expression[Uris.QA_DEPICTS_BUILDING] || expression[Uris.QA_DEPICTS_ARCHITECT]
                    	|| expression[Uris.QA_DEPICTS_FIRM];
                    if (depictsUri) {
                        // console.log('expression depicts someone or something', depictsUri);
                        if (depictsUri === 'http://qldarch.net/users/patriciadowling/Architect#63377814877') {
                            console.log('MATCH');
                        }
                        // its a photo of an architect or building
                        angular.forEach(entities, function (entity) {
                            if (entity.uri === depictsUri && angular.isDefined(expression.file)) {
                                entity.picture = expression.file;
                            }
                        });
                    }
                });
                
                angular.forEach(entities, function (entity) {
                    // Add images
                    // Add preferred images
                    if (angular.isDefined(entity[Uris.QA_PREFERRED_IMAGE])) {
                        // Add in the expression we got back
                        var imageUri = entity[Uris.QA_PREFERRED_IMAGE];
                        if (angular.isArray(imageUri)) {
                            imageUri = imageUri[0];
                        }
                        var expression = expressions[imageUri];
                        if (expression && angular.isDefined(expression.file)) {
                            entity.picture = expression.file;
                        }
                    }
                });
                
                return entities;
            });
        };

        var clearEntityCaches = function () {
            $cacheFactory.get('$http').remove('/ws/rest/entity/detail/qldarch%3ANonDigitalThing?INCSUBCLASS=true&');
            $cacheFactory.get('$http').remove('/ws/rest/entity/detail/qldarch%3AArchitect?INCSUBCLASS=false&');
            $cacheFactory.get('$http').remove('/ws/rest/entity/detail/qldarch%3AFirm?INCSUBCLASS=false&');
            $cacheFactory.get('$http').remove('/ws/rest/entity/detail/qldarch%3AStructure?INCSUBCLASS=false&');
            // http://127.0.0.1:9000/ws/rest/entity/detail/qldarch%3ANonDigitalThing?INCSUBCLASS=true&
        };


        // Public API here
        var entity = {
        	clearAll: function() {
            	$cacheFactory.get('$http').removeAll();
        	},
        		
            update: function (uri, data) {
                var payload = angular.copy(data);
                // Remove any extra information
                // This causes the web server to die
                delete payload.encodedUri;
{'fraction_non_alphanumeric': 0.11043583955547838, 'fraction_numerical': 0.005209237714881056, 'mean_word_length': 1.4916720744105558, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '4026245', 'n_tokens_mistral': 3144, 'n_tokens_neox': 2941, 'n_words': 543}