UNPKG

image-classifier-ts

Version:

Command line tool to auto-classify images, renaming them with appropriate labels. Uses Node and Google Vision API.

72 lines 3.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ImageLocation = void 0; var LocationNameGenerator_1 = require("../geoCode/LocationNameGenerator"); var StringUtils_1 = require("../utils/StringUtils"); // immutable object! var ImageLocation = /** @class */ (function () { function ImageLocation(country, addressLevel1, addressLevel2, subLocality, locationFormat, // overrides the other params (from manual CSV file) givenLocation) { if (givenLocation === void 0) { givenLocation = null; } this.country = country; this.addressLevel1 = addressLevel1; this.addressLevel2 = addressLevel2; this.subLocality = subLocality; this.locationFormat = locationFormat; this.givenLocation = givenLocation; } ImageLocation.fromGivenLocation = function (givenLocation, options) { return new ImageLocation("", "", "", "", options.locationFormat, givenLocation); }; Object.defineProperty(ImageLocation.prototype, "completionScore", { get: function () { return [ { value: this.givenLocation, score: 10 }, { value: this.country, score: 10 }, { value: this.addressLevel1, score: 5 }, { value: this.addressLevel2, score: 3 }, { value: this.subLocality, score: 1 } ] .map(function (entry) { return entry.value && entry.value.length > 0 ? entry.score : 0; }) .reduce(function (previous, current) { return previous + current; }, 0); }, enumerable: false, configurable: true }); ImageLocation.prototype.toString = function (locationFormat) { if (locationFormat === void 0) { locationFormat = this.locationFormat; } if (this.givenLocation) { return this.givenLocation.trim(); } var tokens = new Map(); tokens.set(LocationNameGenerator_1.LocationFormatToken.Country, this.cleanValue(this.country)); tokens.set(LocationNameGenerator_1.LocationFormatToken.Area1, this.cleanValue(this.addressLevel1)); tokens.set(LocationNameGenerator_1.LocationFormatToken.Area2, this.cleanValue(this.addressLevel2)); tokens.set(LocationNameGenerator_1.LocationFormatToken.Area3, this.cleanValue(this.subLocality)); return LocationNameGenerator_1.LocationNameGenerator.generate(tokens, locationFormat); }; ImageLocation.prototype.cleanValue = function (value) { return StringUtils_1.StringUtils.replaceAll(value.trim(), " ", "_"); }; return ImageLocation; }()); exports.ImageLocation = ImageLocation; //# sourceMappingURL=ImageLocation.js.map