UNPKG

image-classifier-ts

Version:

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

40 lines 2.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GeoCodeResponseParser = void 0; var ImageLocation_1 = require("../model/ImageLocation"); var ImageProperties_1 = require("../model/ImageProperties"); var GeoCodeResponseParser; (function (GeoCodeResponseParser) { // exported so can unit test function parseResponse(properties, responseJson, options, outputter) { if (!responseJson) { outputter.error("no response from geo coding service"); return properties; } var bestLocation = properties; for (var index in responseJson.results) { var result = responseJson.results[index]; var newProperties = ImageProperties_1.ImageProperties.withLocation(properties, new ImageLocation_1.ImageLocation(extractAddressComponent(result, "country", false), extractAddressComponent(result, "administrative_area_level_1"), extractAddressComponent(result, "administrative_area_level_2"), extractAddressComponent(result, "sublocality_level_1"), options.locationFormat)); if (!bestLocation.location || (newProperties.location && newProperties.location.completionScore > bestLocation.location.completionScore)) { bestLocation = newProperties; } } return bestLocation; } GeoCodeResponseParser.parseResponse = parseResponse; function extractAddressComponent(json, type, isLong) { if (isLong === void 0) { isLong = true; } var components = json.address_components .filter(function (r) { return r.types.some(function (t) { return t === type; }); }) .map(function (r) { return (isLong ? r.long_name : r.short_name); }) .filter(function (n) { return n && n.length > 0; }); var component = ""; if (components.length > 0) { component = components[0]; } return component; } })(GeoCodeResponseParser = exports.GeoCodeResponseParser || (exports.GeoCodeResponseParser = {})); //# sourceMappingURL=GeoCodeResponseParser.js.map