sap-leonardo
Advanced tools
Comparing version 0.5.0 to 0.5.1
@@ -1,7 +0,7 @@ | ||
import { Promise } from 'es6-promise'; | ||
import { Promise } from "es6-promise"; | ||
export declare class DocumentFeatureExtraction { | ||
private _apiKey; | ||
private _baseUrl; | ||
private apiKey; | ||
private baseUrl; | ||
constructor(apiKey: any, baseUrl?: string); | ||
inferenceSync(files: any, texts: any): Promise<any>; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const assert = require("assert"); | ||
const es6_promise_1 = require("es6-promise"); | ||
const fs = require("fs"); | ||
const request = require("request"); | ||
const fs = require("fs"); | ||
const es6_promise_1 = require("es6-promise"); | ||
const assert = require("assert"); | ||
class DocumentFeatureExtraction { | ||
constructor(apiKey, baseUrl = "https://sandbox.api.sap.com") { | ||
assert(apiKey, "apiKey is required"); | ||
this._apiKey = apiKey; | ||
this._baseUrl = baseUrl; | ||
this.apiKey = apiKey; | ||
this.baseUrl = baseUrl; | ||
} | ||
inferenceSync(files, texts) { | ||
return new es6_promise_1.Promise((resolve, reject) => { | ||
var headers = { | ||
"Content-Type": 'application/json', | ||
Accept: 'application/json', | ||
APIKey: this._apiKey | ||
const headers = { | ||
"APIKey": this.apiKey, | ||
"Accept": "application/json", | ||
"Content-Type": "application/json", | ||
}; | ||
var formData; | ||
let formData; | ||
if (files) { | ||
var data = fs.readFileSync(files, {}); | ||
const data = fs.readFileSync(files, {}); | ||
formData = { | ||
files: { value: data, options: files } | ||
files: { value: data, options: files }, | ||
}; | ||
@@ -29,7 +29,7 @@ } | ||
formData = { | ||
texts: texts | ||
texts, | ||
}; | ||
} | ||
var url = this._baseUrl + "/ml/docfeatureextraction/inference_sync"; | ||
request.post({ url: url, formData: formData, headers: headers }, (err, response, body) => { | ||
const url = this.baseUrl + "/ml/docfeatureextraction/inference_sync"; | ||
request.post({ url, formData, headers }, (err, response, body) => { | ||
if (err) { | ||
@@ -36,0 +36,0 @@ return reject(err); |
@@ -1,7 +0,7 @@ | ||
import { Promise } from 'es6-promise'; | ||
import { Promise } from "es6-promise"; | ||
export declare class FaceDetection { | ||
private _apiKey; | ||
private _baseUrl; | ||
private apiKey; | ||
private baseUrl; | ||
constructor(apiKey: any, baseUrl?: string); | ||
faceDetection(files: string): Promise<any>; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const assert = require("assert"); | ||
const es6_promise_1 = require("es6-promise"); | ||
const fs = require("fs"); | ||
const request = require("request"); | ||
const fs = require("fs"); | ||
const es6_promise_1 = require("es6-promise"); | ||
const assert = require("assert"); | ||
class FaceDetection { | ||
constructor(apiKey, baseUrl = "https://sandbox.api.sap.com") { | ||
assert(apiKey, "apiKey is required"); | ||
this._apiKey = apiKey; | ||
this._baseUrl = baseUrl; | ||
this.apiKey = apiKey; | ||
this.baseUrl = baseUrl; | ||
} | ||
faceDetection(files) { | ||
return new es6_promise_1.Promise((resolve, reject) => { | ||
fs.readFile(files, {}, (err, data) => { | ||
if (err) { | ||
return reject(err); | ||
fs.readFile(files, {}, (fileErr, fileData) => { | ||
if (fileErr) { | ||
return reject(fileErr); | ||
} | ||
var formData = { | ||
files: { value: data, options: files } | ||
const formData = { | ||
files: { value: fileData, options: files }, | ||
}; | ||
var headers = { | ||
Accept: 'application/json', | ||
APIKey: this._apiKey | ||
const headers = { | ||
APIKey: this.apiKey, | ||
Accept: "application/json", | ||
}; | ||
var url = this._baseUrl + "/ml/facedetection/face-detection"; | ||
request.post({ url: url, formData: formData, headers: headers }, (err, response, body) => { | ||
const url = this.baseUrl + "/ml/facedetection/face-detection"; | ||
request.post({ url, formData, headers }, (err, response, body) => { | ||
if (err) { | ||
@@ -29,0 +29,0 @@ return reject(err); |
@@ -1,5 +0,5 @@ | ||
import { Promise } from 'es6-promise'; | ||
import { Promise } from "es6-promise"; | ||
export declare class HumanDetection { | ||
private _apiKey; | ||
private _baseUrl; | ||
private apiKey; | ||
private baseUrl; | ||
constructor(apiKey: any, baseUrl?: string); | ||
@@ -6,0 +6,0 @@ humanDetection(files: string): Promise<any>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const assert = require("assert"); | ||
const es6_promise_1 = require("es6-promise"); | ||
const fs = require("fs"); | ||
const request = require("request"); | ||
const fs = require("fs"); | ||
const es6_promise_1 = require("es6-promise"); | ||
const assert = require("assert"); | ||
class HumanDetection { | ||
constructor(apiKey, baseUrl = "https://sandbox.api.sap.com") { | ||
assert(apiKey, "apiKey is required"); | ||
this._apiKey = apiKey; | ||
this._baseUrl = baseUrl; | ||
this.apiKey = apiKey; | ||
this.baseUrl = baseUrl; | ||
} | ||
humanDetection(files) { | ||
return new es6_promise_1.Promise((resolve, reject) => { | ||
fs.readFile(files, {}, (err, data) => { | ||
if (err) { | ||
return reject(err); | ||
fs.readFile(files, {}, (fileErr, fileData) => { | ||
if (fileErr) { | ||
return reject(fileErr); | ||
} | ||
var formData = { | ||
file: { value: data, options: files } | ||
const formData = { | ||
file: { value: fileData, options: files }, | ||
}; | ||
var headers = { | ||
Accept: 'application/json', | ||
APIKey: this._apiKey | ||
const headers = { | ||
APIKey: this.apiKey, | ||
Accept: "application/json", | ||
}; | ||
var url = this._baseUrl + "/ml/humandetection/human-detection/"; | ||
request.post({ url: url, formData: formData, headers: headers }, (err, response, body) => { | ||
const url = this.baseUrl + "/ml/humandetection/human-detection/"; | ||
request.post({ url, formData, headers }, (err, response, body) => { | ||
if (err) { | ||
@@ -38,20 +38,20 @@ return reject(err); | ||
return new es6_promise_1.Promise((resolve, reject) => { | ||
fs.readFile(files, {}, (err, data) => { | ||
if (err) { | ||
return reject(err); | ||
fs.readFile(files, {}, (fileErr, fileData) => { | ||
if (fileErr) { | ||
return reject(fileErr); | ||
} | ||
var formData = { | ||
file: { value: data, options: files } | ||
const formData = { | ||
file: { value: fileData, options: files }, | ||
}; | ||
var headers = { | ||
APIKey: this._apiKey | ||
const headers = { | ||
APIKey: this.apiKey, | ||
}; | ||
var url = this._baseUrl + "/ml/humandetection/human-detection/format:image"; | ||
var imageData = []; | ||
const url = this.baseUrl + "/ml/humandetection/human-detection/format:image"; | ||
const imageData = []; | ||
request | ||
.post({ url: url, formData: formData, headers: headers }) | ||
.on('data', (data) => { | ||
.post({ url, formData, headers }) | ||
.on("data", (data) => { | ||
imageData.push(data); | ||
}) | ||
.on('end', () => { | ||
.on("end", () => { | ||
resolve(Buffer.concat(imageData)); | ||
@@ -58,0 +58,0 @@ }); |
@@ -1,7 +0,7 @@ | ||
import { Promise } from 'es6-promise'; | ||
import { Promise } from "es6-promise"; | ||
export declare class ImageFeatureExtraction { | ||
private _apiKey; | ||
private _baseUrl; | ||
private apiKey; | ||
private baseUrl; | ||
constructor(apiKey: any, baseUrl?: string); | ||
featureExtraction(files: string, authorization?: any): Promise<any>; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const assert = require("assert"); | ||
const es6_promise_1 = require("es6-promise"); | ||
const fs = require("fs"); | ||
const request = require("request"); | ||
const fs = require("fs"); | ||
const es6_promise_1 = require("es6-promise"); | ||
const assert = require("assert"); | ||
class ImageFeatureExtraction { | ||
constructor(apiKey, baseUrl = "https://sandbox.api.sap.com") { | ||
assert(apiKey, "apiKey is required"); | ||
this._apiKey = apiKey; | ||
this._baseUrl = baseUrl; | ||
this.apiKey = apiKey; | ||
this.baseUrl = baseUrl; | ||
} | ||
featureExtraction(files, authorization = null) { | ||
return new es6_promise_1.Promise((resolve, reject) => { | ||
fs.readFile(files, {}, (err, data) => { | ||
if (err) { | ||
return reject(err); | ||
fs.readFile(files, {}, (fileErr, fileData) => { | ||
if (fileErr) { | ||
return reject(fileErr); | ||
} | ||
var formData = { | ||
files: { value: data, options: files }, | ||
const formData = { | ||
files: { value: fileData, options: files }, | ||
}; | ||
var headers = { | ||
Accept: 'application/json', | ||
APIKey: this._apiKey | ||
const headers = { | ||
APIKey: this.apiKey, | ||
Accept: "application/json", | ||
}; | ||
var url = this._baseUrl + "/ml/imagefeatureextraction/feature-extraction"; | ||
request.post({ url: url, formData: formData, headers: headers }, (err, response, body) => { | ||
const url = this.baseUrl + "/ml/imagefeatureextraction/feature-extraction"; | ||
request.post({ url, formData, headers }, (err, response, body) => { | ||
if (err) { | ||
@@ -29,0 +29,0 @@ return reject(err); |
@@ -1,5 +0,5 @@ | ||
import { Promise } from 'es6-promise'; | ||
import { Promise } from "es6-promise"; | ||
export declare class Imageclassification { | ||
private _apiKey; | ||
private _baseUrl; | ||
private apiKey; | ||
private baseUrl; | ||
constructor(apiKey: any, baseUrl?: string); | ||
@@ -6,0 +6,0 @@ classification(files: string): Promise<any>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const assert = require("assert"); | ||
const es6_promise_1 = require("es6-promise"); | ||
const fs = require("fs"); | ||
const request = require("request"); | ||
const fs = require("fs"); | ||
const es6_promise_1 = require("es6-promise"); | ||
const assert = require("assert"); | ||
class Imageclassification { | ||
constructor(apiKey, baseUrl = "https://sandbox.api.sap.com") { | ||
assert(apiKey, "apiKey is required"); | ||
this._apiKey = apiKey; | ||
this._baseUrl = baseUrl; | ||
this.apiKey = apiKey; | ||
this.baseUrl = baseUrl; | ||
} | ||
classification(files) { | ||
return new es6_promise_1.Promise((resolve, reject) => { | ||
fs.readFile(files, {}, (err, data) => { | ||
if (err) { | ||
return reject(err); | ||
fs.readFile(files, {}, (fileErr, fileData) => { | ||
if (fileErr) { | ||
return reject(fileErr); | ||
} | ||
var formData = { | ||
files: { value: data, options: files } | ||
const formData = { | ||
files: { value: fileData, options: files }, | ||
}; | ||
var headers = { | ||
Accept: 'application/json', | ||
APIKey: this._apiKey | ||
const headers = { | ||
APIKey: this.apiKey, | ||
Accept: "application/json", | ||
}; | ||
var url = this._baseUrl + "/ml/imageclassification/classification"; | ||
request.post({ url: url, formData: formData, headers: headers }, (err, response, body) => { | ||
const url = this.baseUrl + "/ml/imageclassification/classification"; | ||
request.post({ url, formData, headers }, (err, response, body) => { | ||
if (err) { | ||
@@ -36,6 +36,6 @@ return reject(err); | ||
} | ||
/*eslint no-unused-vars: ["off", { "args": "all" }]*/ | ||
/*eslint no-unused-vars ["off", { "args": "all" }]*/ | ||
customizable(modelName, version, files) { | ||
return new es6_promise_1.Promise((resolve, reject) => { | ||
//var url = "/ml/imageclassification/models/" + modelName + "/versions/" + version; | ||
// const url = "/ml/imageclassification/models/" + modelName + "/versions/" + version; | ||
reject("not implemented"); | ||
@@ -42,0 +42,0 @@ }); |
@@ -13,1 +13,2 @@ export * from "./imageclassification"; | ||
export * from "./image_feature_extraction"; | ||
export * from "./face_feature_extraction"; |
@@ -18,1 +18,2 @@ "use strict"; | ||
__export(require("./image_feature_extraction")); | ||
__export(require("./face_feature_extraction")); |
@@ -1,5 +0,5 @@ | ||
import { Promise } from 'es6-promise'; | ||
import { Promise } from "es6-promise"; | ||
export declare class LanguageDetection { | ||
private _apiKey; | ||
private _baseUrl; | ||
private apiKey; | ||
private baseUrl; | ||
constructor(apiKey: any, baseUrl?: string); | ||
@@ -6,0 +6,0 @@ language(message: string): Promise<any>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const assert = require("assert"); | ||
const es6_promise_1 = require("es6-promise"); | ||
const request = require("request"); | ||
const es6_promise_1 = require("es6-promise"); | ||
const assert = require("assert"); | ||
class LanguageDetection { | ||
constructor(apiKey, baseUrl = "https://sandbox.api.sap.com") { | ||
assert(apiKey, "apiKey is required"); | ||
this._apiKey = apiKey; | ||
this._baseUrl = baseUrl; | ||
this.apiKey = apiKey; | ||
this.baseUrl = baseUrl; | ||
} | ||
language(message) { | ||
return new es6_promise_1.Promise((resolve, reject) => { | ||
var headers = { | ||
"Content-Type": 'application/json', | ||
Accept: 'application/json', | ||
APIKey: this._apiKey | ||
const headers = { | ||
"APIKey": this.apiKey, | ||
"Accept": "application/json", | ||
"Content-Type": "application/json", | ||
}; | ||
var url = this._baseUrl + "/ml/languagedetection/language"; | ||
var data = JSON.stringify({ message: message }); | ||
request.post({ url: url, body: data, headers: headers }, (err, response, body) => { | ||
const url = this.baseUrl + "/ml/languagedetection/language"; | ||
const data = JSON.stringify({ message }); | ||
request.post({ url, body: data, headers }, (err, response, body) => { | ||
if (err) { | ||
@@ -31,9 +31,9 @@ return reject(err); | ||
return new es6_promise_1.Promise((resolve, reject) => { | ||
var headers = { | ||
"Content-Type": 'application/json', | ||
Accept: 'application/json', | ||
APIKey: this._apiKey | ||
const headers = { | ||
"APIKey": this.apiKey, | ||
"Accept": "application/json", | ||
"Content-Type": "application/json", | ||
}; | ||
var url = this._baseUrl + "/ml/languagedetection/version"; | ||
request.get({ url: url, headers: headers }, (err, response, body) => { | ||
const url = this.baseUrl + "/ml/languagedetection/version"; | ||
request.get({ url, headers }, (err, response, body) => { | ||
if (err) { | ||
@@ -40,0 +40,0 @@ return reject(err); |
@@ -1,7 +0,7 @@ | ||
import { Promise } from 'es6-promise'; | ||
import { Promise } from "es6-promise"; | ||
export declare class MultiInstanceImageSegmentation { | ||
private _apiKey; | ||
private _baseUrl; | ||
private apiKey; | ||
private baseUrl; | ||
constructor(apiKey: any, baseUrl?: string); | ||
instanceSegmentor(files: string, format?: any): Promise<any>; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const assert = require("assert"); | ||
const es6_promise_1 = require("es6-promise"); | ||
const fs = require("fs"); | ||
const request = require("request"); | ||
const fs = require("fs"); | ||
const es6_promise_1 = require("es6-promise"); | ||
const assert = require("assert"); | ||
class MultiInstanceImageSegmentation { | ||
constructor(apiKey, baseUrl = "https://sandbox.api.sap.com") { | ||
assert(apiKey, "apiKey is required"); | ||
this._apiKey = apiKey; | ||
this._baseUrl = baseUrl; | ||
this.apiKey = apiKey; | ||
this.baseUrl = baseUrl; | ||
} | ||
instanceSegmentor(files, format = null) { | ||
return new es6_promise_1.Promise((resolve, reject) => { | ||
fs.readFile(files, {}, (err, data) => { | ||
if (err) { | ||
return reject(err); | ||
fs.readFile(files, {}, (fileErr, fileData) => { | ||
if (fileErr) { | ||
return reject(fileErr); | ||
} | ||
var formData = { | ||
files: { value: data, options: files } | ||
const formData = { | ||
files: { value: fileData, options: files }, | ||
}; | ||
var headers = { | ||
Accept: 'application/json', | ||
APIKey: this._apiKey | ||
const headers = { | ||
APIKey: this.apiKey, | ||
Accept: "application/json", | ||
}; | ||
var url = this._baseUrl + "/ml/instancesegmentor/instance-segmentor"; | ||
let url = this.baseUrl + "/ml/instancesegmentor/instance-segmentor"; | ||
if (format) { | ||
url += "/format:jpg"; | ||
} | ||
request.post({ url: url, formData: formData, headers: headers }, (err, response, body) => { | ||
request.post({ url, formData, headers }, (err, response, body) => { | ||
if (err) { | ||
@@ -32,0 +32,0 @@ return reject(err); |
@@ -1,9 +0,9 @@ | ||
import { Promise } from 'es6-promise'; | ||
import { Promise } from "es6-promise"; | ||
export declare class OCR { | ||
private _apiKey; | ||
private _baseUrl; | ||
private apiKey; | ||
private baseUrl; | ||
constructor(apiKey: any, baseUrl?: string); | ||
ocr(files: string, options?: any, asJobs?: Boolean): Promise<any>; | ||
ocr(files: string, options?: any, asJobs?: boolean): Promise<any>; | ||
jobs(files: string, options?: any): Promise<any>; | ||
jobsId(id: string): Promise<any>; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const assert = require("assert"); | ||
const es6_promise_1 = require("es6-promise"); | ||
const fs = require("fs"); | ||
const request = require("request"); | ||
const fs = require("fs"); | ||
const es6_promise_1 = require("es6-promise"); | ||
const assert = require("assert"); | ||
class OCR { | ||
constructor(apiKey, baseUrl = "https://sandbox.api.sap.com") { | ||
assert(apiKey, "apiKey is required"); | ||
this._apiKey = apiKey; | ||
this._baseUrl = baseUrl; | ||
this.apiKey = apiKey; | ||
this.baseUrl = baseUrl; | ||
} | ||
ocr(files, options = null, asJobs = false) { | ||
return new es6_promise_1.Promise((resolve, reject) => { | ||
fs.readFile(files, {}, (err, data) => { | ||
if (err) { | ||
return reject(err); | ||
fs.readFile(files, {}, (fileErr, fileData) => { | ||
if (fileErr) { | ||
return reject(fileErr); | ||
} | ||
var formData; | ||
let formData; | ||
if (options) { | ||
formData = { | ||
files: { value: data, options: files }, | ||
options: JSON.stringify(options) | ||
files: { value: fileData, options: files }, | ||
options: JSON.stringify(options), | ||
}; | ||
@@ -28,11 +28,11 @@ } | ||
formData = { | ||
files: { value: data, options: files } | ||
files: { value: fileData, options: files }, | ||
}; | ||
} | ||
var headers = { | ||
Accept: 'application/json', | ||
APIKey: this._apiKey | ||
const headers = { | ||
APIKey: this.apiKey, | ||
Accept: "application/json", | ||
}; | ||
var url = this._baseUrl + "/ml/ocr/ocr" + (asJobs ? "/jobs" : ""); | ||
request.post({ url: url, formData: formData, headers: headers }, (err, response, body) => { | ||
const url = this.baseUrl + "/ml/ocr/ocr" + (asJobs ? "/jobs" : ""); | ||
request.post({ url, formData, headers }, (err, response, body) => { | ||
if (err) { | ||
@@ -51,8 +51,8 @@ return reject(err); | ||
return new es6_promise_1.Promise((resolve, reject) => { | ||
var headers = { | ||
Accept: 'application/json', | ||
APIKey: this._apiKey | ||
const headers = { | ||
APIKey: this.apiKey, | ||
Accept: "application/json", | ||
}; | ||
var url = this._baseUrl + "/ml/ocr/ocr/jobs/" + id; | ||
request.get({ url: url, headers: headers }, (err, response, body) => { | ||
const url = this.baseUrl + "/ml/ocr/ocr/jobs/" + id; | ||
request.get({ url, headers }, (err, response, body) => { | ||
if (err) { | ||
@@ -59,0 +59,0 @@ return reject(err); |
@@ -1,7 +0,7 @@ | ||
import { Promise } from 'es6-promise'; | ||
import { Promise } from "es6-promise"; | ||
export declare class ProductTextClassification { | ||
private _apiKey; | ||
private _baseUrl; | ||
private apiKey; | ||
private baseUrl; | ||
constructor(apiKey: any, baseUrl?: string); | ||
inferenceSync(files: any, texts: any): Promise<any>; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const assert = require("assert"); | ||
const es6_promise_1 = require("es6-promise"); | ||
const fs = require("fs"); | ||
const request = require("request"); | ||
const fs = require("fs"); | ||
const es6_promise_1 = require("es6-promise"); | ||
const assert = require("assert"); | ||
class ProductTextClassification { | ||
constructor(apiKey, baseUrl = "https://sandbox.api.sap.com") { | ||
assert(apiKey, "apiKey is required"); | ||
this._apiKey = apiKey; | ||
this._baseUrl = baseUrl; | ||
this.apiKey = apiKey; | ||
this.baseUrl = baseUrl; | ||
} | ||
inferenceSync(files, texts) { | ||
return new es6_promise_1.Promise((resolve, reject) => { | ||
var headers = { | ||
"Content-Type": 'application/json', | ||
Accept: 'application/json', | ||
APIKey: this._apiKey | ||
const headers = { | ||
"APIKey": this.apiKey, | ||
"Accept": "application/json", | ||
"Content-Type": "application/json", | ||
}; | ||
var formData; | ||
let formData; | ||
if (files) { | ||
var data = fs.readFileSync(files, {}); | ||
const data = fs.readFileSync(files, {}); | ||
formData = { | ||
files: { value: data, options: files } | ||
files: { value: data, options: files }, | ||
}; | ||
@@ -29,7 +29,7 @@ } | ||
formData = { | ||
texts: texts | ||
texts, | ||
}; | ||
} | ||
var url = this._baseUrl + "/ml/producttextclassifier/inference_sync"; | ||
request.post({ url: url, formData: formData, headers: headers }, (err, response, body) => { | ||
const url = this.baseUrl + "/ml/producttextclassifier/inference_sync"; | ||
request.post({ url, formData, headers }, (err, response, body) => { | ||
if (err) { | ||
@@ -36,0 +36,0 @@ return reject(err); |
@@ -1,7 +0,7 @@ | ||
import { Promise } from 'es6-promise'; | ||
import { Promise } from "es6-promise"; | ||
export declare class SceneTextRecognition { | ||
private _apiKey; | ||
private _baseUrl; | ||
private apiKey; | ||
private baseUrl; | ||
constructor(apiKey: any, baseUrl?: string); | ||
sceneTextRecognition(files: string): Promise<any>; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const assert = require("assert"); | ||
const es6_promise_1 = require("es6-promise"); | ||
const fs = require("fs"); | ||
const request = require("request"); | ||
const fs = require("fs"); | ||
const es6_promise_1 = require("es6-promise"); | ||
const assert = require("assert"); | ||
class SceneTextRecognition { | ||
constructor(apiKey, baseUrl = "https://sandbox.api.sap.com") { | ||
assert(apiKey, "apiKey is required"); | ||
this._apiKey = apiKey; | ||
this._baseUrl = baseUrl; | ||
this.apiKey = apiKey; | ||
this.baseUrl = baseUrl; | ||
} | ||
sceneTextRecognition(files) { | ||
return new es6_promise_1.Promise((resolve, reject) => { | ||
fs.readFile(files, {}, (err, data) => { | ||
if (err) { | ||
return reject(err); | ||
fs.readFile(files, {}, (fileErr, fileData) => { | ||
if (fileErr) { | ||
return reject(fileErr); | ||
} | ||
var formData = { | ||
files: { value: data, options: files } | ||
const formData = { | ||
files: { value: fileData, options: files }, | ||
}; | ||
var headers = { | ||
Accept: 'application/json', | ||
APIKey: this._apiKey | ||
const headers = { | ||
APIKey: this.apiKey, | ||
Accept: "application/json", | ||
}; | ||
var url = this._baseUrl + "/ml/scenetextrecognition/scene-text-recognition"; | ||
request.post({ url: url, formData: formData, headers: headers }, (err, response, body) => { | ||
const url = this.baseUrl + "/ml/scenetextrecognition/scene-text-recognition"; | ||
request.post({ url, formData, headers }, (err, response, body) => { | ||
if (err) { | ||
@@ -29,0 +29,0 @@ return reject(err); |
@@ -1,7 +0,7 @@ | ||
import { Promise } from 'es6-promise'; | ||
import { Promise } from "es6-promise"; | ||
export declare class SimilarityScoring { | ||
private _apiKey; | ||
private _baseUrl; | ||
private apiKey; | ||
private baseUrl; | ||
constructor(apiKey: any, baseUrl?: string); | ||
similarityScoring(files: any, texts: any, options: string): Promise<any>; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const assert = require("assert"); | ||
const es6_promise_1 = require("es6-promise"); | ||
const fs = require("fs"); | ||
const request = require("request"); | ||
const fs = require("fs"); | ||
const es6_promise_1 = require("es6-promise"); | ||
const assert = require("assert"); | ||
class SimilarityScoring { | ||
constructor(apiKey, baseUrl = "https://sandbox.api.sap.com") { | ||
assert(apiKey, "apiKey is required"); | ||
this._apiKey = apiKey; | ||
this._baseUrl = baseUrl; | ||
this.apiKey = apiKey; | ||
this.baseUrl = baseUrl; | ||
} | ||
similarityScoring(files, texts, options) { | ||
return new es6_promise_1.Promise((resolve, reject) => { | ||
var headers = { | ||
"Content-Type": 'application/json', | ||
Accept: 'application/json', | ||
APIKey: this._apiKey | ||
const headers = { | ||
"APIKey": this.apiKey, | ||
"Accept": "application/json", | ||
"Content-Type": "application/json", | ||
}; | ||
var formData; | ||
let formData; | ||
if (files) { | ||
var data = fs.readFileSync(files, {}); | ||
const data = fs.readFileSync(files, {}); | ||
formData = { | ||
files: { value: data, options: files }, | ||
options: options | ||
options, | ||
}; | ||
@@ -30,8 +30,8 @@ } | ||
formData = { | ||
texts: texts, | ||
options: options | ||
options, | ||
texts, | ||
}; | ||
} | ||
var url = this._baseUrl + "/ml/similarityscoring/similarity-scoring"; | ||
request.post({ url: url, formData: formData, headers: headers }, (err, response, body) => { | ||
const url = this.baseUrl + "/ml/similarityscoring/similarity-scoring"; | ||
request.post({ url, formData, headers }, (err, response, body) => { | ||
if (err) { | ||
@@ -38,0 +38,0 @@ return reject(err); |
@@ -5,49 +5,53 @@ "use strict"; | ||
const index_1 = require("../index"); | ||
describe('document feature extraction', () => { | ||
var documentFeatureExtraction = new index_1.DocumentFeatureExtraction(process.env.API_KEY); | ||
describe('texts', () => { | ||
describe("document feature extraction", () => { | ||
const documentFeatureExtraction = new index_1.DocumentFeatureExtraction(process.env.API_KEY); | ||
describe("texts", () => { | ||
// tslint:disable-next-line:max-line-length | ||
const productText = "Get the clarity of 4K UHD in an old-fashioned smart TV design that's mind controllable. Ultra HD makes everything smooth and sharp. Magic power gives you instant access to your favourite content and the movie night is just a smile away."; // note: is this an adjusted description for a Smart TV | ||
it('should detect features', (done) => { | ||
documentFeatureExtraction.inferenceSync(null, productText).then(body => { | ||
chai_1.expect(body).to.have.property('_id'); | ||
chai_1.expect(body).to.have.property('doc_vectors').to.be.an('array').with.length(1); | ||
chai_1.expect(body).to.have.property('processed_time'); | ||
chai_1.expect(body).to.have.property('request'); | ||
chai_1.expect(body).to.have.property('status').to.be.equal('DONE'); | ||
chai_1.expect(body).to.have.property('tenantName'); | ||
chai_1.expect(body.doc_vectors[0]).to.have.property('embedding').to.be.an('array').with.length(200).is.eql(embedding); | ||
chai_1.expect(body.doc_vectors[0]).to.have.property('id').to.be.equal('0'); | ||
it("should detect features", (done) => { | ||
documentFeatureExtraction.inferenceSync(null, productText).then((body) => { | ||
chai_1.expect(body).to.have.property("_id"); | ||
chai_1.expect(body).to.have.property("doc_vectors").to.be.an("array").with.length(1); | ||
chai_1.expect(body).to.have.property("processed_time"); | ||
chai_1.expect(body).to.have.property("request"); | ||
chai_1.expect(body).to.have.property("status").to.be.equal("DONE"); | ||
chai_1.expect(body).to.have.property("tenantName"); | ||
chai_1.expect(body.doc_vectors[0]).to.have.property("embedding").to.be.an("array").with.length(200).is.eql(embedding); | ||
chai_1.expect(body.doc_vectors[0]).to.have.property("id").to.be.equal("0"); | ||
}).then(done, done); | ||
}); | ||
}); | ||
describe('files', () => { | ||
it('should detect features', (done) => { | ||
documentFeatureExtraction.inferenceSync("./testdata/product_text.zip", null).then(body => { | ||
chai_1.expect(body).to.have.property('_id'); | ||
chai_1.expect(body).to.have.property('doc_vectors').to.be.an('array').with.length(1); | ||
chai_1.expect(body).to.have.property('processed_time'); | ||
chai_1.expect(body).to.have.property('request'); | ||
chai_1.expect(body).to.have.property('status').to.be.equal('DONE'); | ||
chai_1.expect(body).to.have.property('tenantName'); | ||
chai_1.expect(body.doc_vectors[0]).to.have.property('embedding').to.be.an('array').with.length(200).is.eql(embedding); | ||
chai_1.expect(body.doc_vectors[0]).to.have.property('id').to.be.equal('product_text.txt'); | ||
describe("files", () => { | ||
it("should detect features", (done) => { | ||
documentFeatureExtraction.inferenceSync("./testdata/product_text.zip", null).then((body) => { | ||
chai_1.expect(body).to.have.property("_id"); | ||
chai_1.expect(body).to.have.property("doc_vectors").to.be.an("array").with.length(1); | ||
chai_1.expect(body).to.have.property("processed_time"); | ||
chai_1.expect(body).to.have.property("request"); | ||
chai_1.expect(body).to.have.property("status").to.be.equal("DONE"); | ||
chai_1.expect(body).to.have.property("tenantName"); | ||
chai_1.expect(body.doc_vectors[0]).to.have.property("embedding").to.be.an("array").with.length(200).is.eql(embedding); | ||
chai_1.expect(body.doc_vectors[0]).to.have.property("id").to.be.equal("product_text.txt"); | ||
}).then(done, done); | ||
}); | ||
}); | ||
describe('error coverage', () => { | ||
it('should return a file not found error', (done) => { | ||
documentFeatureExtraction.inferenceSync("file_does_not_exist", null).then(body => { }, err => { | ||
chai_1.expect(err).to.have.property('errno').to.be.equal(-2); | ||
chai_1.expect(err).to.have.property('code').to.be.equal('ENOENT'); | ||
describe("error coverage", () => { | ||
it("should return a file not found error", (done) => { | ||
documentFeatureExtraction.inferenceSync("file_does_not_exist", null).then(() => { chai_1.expect.fail(); }, (err) => { | ||
chai_1.expect(err).to.have.property("errno").to.be.equal(-2); | ||
chai_1.expect(err).to.have.property("code").to.be.equal("ENOENT"); | ||
}).then(done, done); | ||
}); | ||
var documentFeatureExtraction = new index_1.DocumentFeatureExtraction(process.env.API_KEY, 'http://localhost:11111'); | ||
it('should return connection refused error', (done) => { | ||
documentFeatureExtraction.inferenceSync("./testdata/product_text.zip", null).then(body => { }, err => { | ||
chai_1.expect(err).to.have.property('errno').to.be.equal('ECONNREFUSED'); | ||
chai_1.expect(err).to.have.property('code').to.be.equal('ECONNREFUSED'); | ||
const documentFeatureExtractionErr = new index_1.DocumentFeatureExtraction(process.env.API_KEY, "http://localhost:11111"); | ||
it("should return connection refused error", (done) => { | ||
documentFeatureExtractionErr.inferenceSync("./testdata/product_text.zip", null).then(() => { chai_1.expect.fail(); }, (err) => { | ||
chai_1.expect(err).to.have.property("errno").to.be.equal("ECONNREFUSED"); | ||
chai_1.expect(err).to.have.property("code").to.be.equal("ECONNREFUSED"); | ||
}).then(done, done); | ||
}); | ||
}); | ||
var embedding = [ | ||
// tslint:disable:object-literal-key-quotes | ||
// tslint:disable:max-line-length | ||
// tslint:disable:trailing-comma | ||
const embedding = [ | ||
0.1563027948141098, | ||
@@ -54,0 +58,0 @@ 0.004084547515958548, |
@@ -5,45 +5,19 @@ "use strict"; | ||
const index_1 = require("../index"); | ||
describe('face detection', () => { | ||
var faceDetection = new index_1.FaceDetection(process.env.API_KEY); | ||
describe('four people', () => { | ||
it('should predict four faces', (done) => { | ||
faceDetection.faceDetection("./testdata/man-3365368_640.jpg").then(body => { | ||
chai_1.expect(body).to.have.property('id'); | ||
chai_1.expect(body).to.have.property('predictions'); | ||
chai_1.expect(body).to.have.property('processedTime'); | ||
chai_1.expect(body).to.have.property('status').to.be.equal('DONE'); | ||
chai_1.expect(body.predictions).to.be.an('array').have.lengthOf(1); | ||
chai_1.expect(body.predictions[0]).to.have.property('faces').to.be.an('array').have.lengthOf(4); | ||
chai_1.expect(body.predictions[0]).to.have.property('numberOfFaces').to.be.equal(4); | ||
let expected_results = [ | ||
{ | ||
"bottom": 260, | ||
"left": 73, | ||
"right": 135, | ||
"top": 198 | ||
}, | ||
{ | ||
"bottom": 301, | ||
"left": 377, | ||
"right": 439, | ||
"top": 239 | ||
}, | ||
{ | ||
"bottom": 287, | ||
"left": 245, | ||
"right": 320, | ||
"top": 213 | ||
}, | ||
{ | ||
"bottom": 322, | ||
"left": 522, | ||
"right": 584, | ||
"top": 260 | ||
} | ||
]; | ||
for (var i = 0; i < expected_results.length; i++) { | ||
chai_1.expect(body.predictions[0].faces[i].bottom).to.be.equal(expected_results[i].bottom); | ||
chai_1.expect(body.predictions[0].faces[i].left).to.be.equal(expected_results[i].left); | ||
chai_1.expect(body.predictions[0].faces[i].right).to.be.equal(expected_results[i].right); | ||
chai_1.expect(body.predictions[0].faces[i].top).to.be.equal(expected_results[i].top); | ||
describe("face detection", () => { | ||
const faceDetection = new index_1.FaceDetection(process.env.API_KEY); | ||
describe("four people", () => { | ||
it("should predict four faces", (done) => { | ||
faceDetection.faceDetection("./testdata/man-3365368_640.jpg").then((body) => { | ||
chai_1.expect(body).to.have.property("id"); | ||
chai_1.expect(body).to.have.property("predictions"); | ||
chai_1.expect(body).to.have.property("processedTime"); | ||
chai_1.expect(body).to.have.property("status").to.be.equal("DONE"); | ||
chai_1.expect(body.predictions).to.be.an("array").have.lengthOf(1); | ||
chai_1.expect(body.predictions[0]).to.have.property("faces").to.be.an("array").have.lengthOf(4); | ||
chai_1.expect(body.predictions[0]).to.have.property("numberOfFaces").to.be.equal(4); | ||
for (let i = 0; i < expectedResults.length; i++) { | ||
chai_1.expect(body.predictions[0].faces[i].bottom).to.be.equal(expectedResults[i].bottom); | ||
chai_1.expect(body.predictions[0].faces[i].left).to.be.equal(expectedResults[i].left); | ||
chai_1.expect(body.predictions[0].faces[i].right).to.be.equal(expectedResults[i].right); | ||
chai_1.expect(body.predictions[0].faces[i].top).to.be.equal(expectedResults[i].top); | ||
} | ||
@@ -53,17 +27,46 @@ }).then(done, done); | ||
}); | ||
describe('error coverage', () => { | ||
it('should return a file not found error', (done) => { | ||
faceDetection.faceDetection("file_does_not_exist").then(body => { }, err => { | ||
chai_1.expect(err).to.have.property('errno').to.be.equal(-2); | ||
chai_1.expect(err).to.have.property('code').to.be.equal('ENOENT'); | ||
describe("error coverage", () => { | ||
it("should return a file not found error", (done) => { | ||
faceDetection.faceDetection("file_does_not_exist").then(() => { chai_1.expect.fail(); }, (err) => { | ||
chai_1.expect(err).to.have.property("errno").to.be.equal(-2); | ||
chai_1.expect(err).to.have.property("code").to.be.equal("ENOENT"); | ||
}).then(done, done); | ||
}); | ||
it('should return connection refused error', (done) => { | ||
var faceDetection = new index_1.FaceDetection(process.env.API_KEY, 'http://localhost:11111'); | ||
faceDetection.faceDetection("./testdata/man-3365368_640.jpg").then(body => { }, err => { | ||
chai_1.expect(err).to.have.property('errno').to.be.equal('ECONNREFUSED'); | ||
chai_1.expect(err).to.have.property('code').to.be.equal('ECONNREFUSED'); | ||
it("should return connection refused error", (done) => { | ||
const faceDetectionErr = new index_1.FaceDetection(process.env.API_KEY, "http://localhost:11111"); | ||
faceDetectionErr.faceDetection("./testdata/man-3365368_640.jpg").then(() => { chai_1.expect.fail(); }, (err) => { | ||
chai_1.expect(err).to.have.property("errno").to.be.equal("ECONNREFUSED"); | ||
chai_1.expect(err).to.have.property("code").to.be.equal("ECONNREFUSED"); | ||
}).then(done, done); | ||
}); | ||
}); | ||
// tslint:disable:object-literal-key-quotes | ||
// tslint:disable:max-line-length | ||
// tslint:disable:trailing-comma | ||
const expectedResults = [ | ||
{ | ||
"bottom": 260, | ||
"left": 73, | ||
"right": 135, | ||
"top": 198 | ||
}, | ||
{ | ||
"bottom": 301, | ||
"left": 377, | ||
"right": 439, | ||
"top": 239 | ||
}, | ||
{ | ||
"bottom": 287, | ||
"left": 245, | ||
"right": 320, | ||
"top": 213 | ||
}, | ||
{ | ||
"bottom": 322, | ||
"left": 522, | ||
"right": 584, | ||
"top": 260 | ||
} | ||
]; | ||
}); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const chai_1 = require("chai"); | ||
//import * as fs from 'fs'; | ||
// import * as fs from "fs"; | ||
const index_1 = require("../index"); | ||
describe('human detection', () => { | ||
var humanDetection = new index_1.HumanDetection(process.env.API_KEY); | ||
describe('four people', () => { | ||
it('should predict four people', (done) => { | ||
humanDetection.humanDetection("./testdata/man-3365368_640.jpg").then(body => { | ||
chai_1.expect(body).to.have.property('detection_boxes').to.be.an('array').have.lengthOf(4); | ||
chai_1.expect(body).to.have.property('detection_classes').to.be.an('array').have.lengthOf(4); | ||
chai_1.expect(body).to.have.property('detection_scores').to.be.an('array').have.lengthOf(4); | ||
chai_1.expect(body).to.have.property('num_detections').to.be.equal(4); | ||
let expected_results = { | ||
describe("human detection", () => { | ||
const humanDetection = new index_1.HumanDetection(process.env.API_KEY); | ||
describe("four people", () => { | ||
it("should predict four people", (done) => { | ||
humanDetection.humanDetection("./testdata/man-3365368_640.jpg").then((body) => { | ||
chai_1.expect(body).to.have.property("detection_boxes").to.be.an("array").have.lengthOf(4); | ||
chai_1.expect(body).to.have.property("detection_classes").to.be.an("array").have.lengthOf(4); | ||
chai_1.expect(body).to.have.property("detection_scores").to.be.an("array").have.lengthOf(4); | ||
chai_1.expect(body).to.have.property("num_detections").to.be.equal(4); | ||
const expectedResults = { | ||
detection_boxes: [[0.13377800583839417, | ||
@@ -32,3 +32,3 @@ 0.485458105802536, | ||
0.9987258911132812]], | ||
detection_classes: ['human', 'human', 'human', 'human'], | ||
detection_classes: ["human", "human", "human", "human"], | ||
detection_scores: [0.9962896108627319, | ||
@@ -38,12 +38,12 @@ 0.9920268654823303, | ||
0.9902926683425903], | ||
num_detections: 4 | ||
num_detections: 4, | ||
}; | ||
for (var i = 0; i < expected_results.detection_boxes[0].length; i++) { | ||
chai_1.expect(body.detection_boxes[0][i]).to.be.equal(expected_results.detection_boxes[0][i]); | ||
for (let i = 0; i < expectedResults.detection_boxes[0].length; i++) { | ||
chai_1.expect(body.detection_boxes[0][i]).to.be.equal(expectedResults.detection_boxes[0][i]); | ||
} | ||
for (var i = 0; i < expected_results.detection_classes.length; i++) { | ||
chai_1.expect(body.detection_classes[i]).to.be.equal(expected_results.detection_classes[i]); | ||
for (let i = 0; i < expectedResults.detection_classes.length; i++) { | ||
chai_1.expect(body.detection_classes[i]).to.be.equal(expectedResults.detection_classes[i]); | ||
} | ||
for (var i = 0; i < expected_results.detection_scores.length; i++) { | ||
chai_1.expect(body.detection_scores[i]).to.be.equal(expected_results.detection_scores[i]); | ||
for (let i = 0; i < expectedResults.detection_scores.length; i++) { | ||
chai_1.expect(body.detection_scores[i]).to.be.equal(expectedResults.detection_scores[i]); | ||
} | ||
@@ -53,9 +53,9 @@ }).then(done, done); | ||
}); | ||
describe('human detection image', () => { | ||
var humanDetection = new index_1.HumanDetection(process.env.API_KEY); | ||
describe('four people', () => { | ||
it('should predict four people', (done) => { | ||
humanDetection.humanDetectionImage("./testdata/man-3365368_640.jpg").then(body => { | ||
describe("human detection image", () => { | ||
const humanDetectionImage = new index_1.HumanDetection(process.env.API_KEY); | ||
describe("four people", () => { | ||
it("should predict four people", (done) => { | ||
humanDetectionImage.humanDetectionImage("./testdata/man-3365368_640.jpg").then((body) => { | ||
chai_1.expect(body.length).to.be.equal(393486); | ||
//fs.writeFileSync("human-detection-image.png", body); | ||
// fs.writeFileSync("human-detection-image.png", body); | ||
}).then(done, done); | ||
@@ -65,20 +65,20 @@ }); | ||
}); | ||
describe('error coverage', () => { | ||
it('should return a file not found error', (done) => { | ||
humanDetection.humanDetection("file_does_not_exist").then(body => { }, err => { | ||
chai_1.expect(err).to.have.property('errno').to.be.equal(-2); | ||
chai_1.expect(err).to.have.property('code').to.be.equal('ENOENT'); | ||
describe("error coverage", () => { | ||
it("should return a file not found error", (done) => { | ||
humanDetection.humanDetection("file_does_not_exist").then(() => { chai_1.expect.fail(); }, (err) => { | ||
chai_1.expect(err).to.have.property("errno").to.be.equal(-2); | ||
chai_1.expect(err).to.have.property("code").to.be.equal("ENOENT"); | ||
}).then(done, done); | ||
}); | ||
it('should return a file not found (image) error', (done) => { | ||
humanDetection.humanDetectionImage("file_does_not_exist").then(body => { }, err => { | ||
chai_1.expect(err).to.have.property('errno').to.be.equal(-2); | ||
chai_1.expect(err).to.have.property('code').to.be.equal('ENOENT'); | ||
it("should return a file not found (image) error", (done) => { | ||
humanDetection.humanDetectionImage("file_does_not_exist").then(() => { chai_1.expect.fail(); }, (err) => { | ||
chai_1.expect(err).to.have.property("errno").to.be.equal(-2); | ||
chai_1.expect(err).to.have.property("code").to.be.equal("ENOENT"); | ||
}).then(done, done); | ||
}); | ||
it('should return connection refused error', (done) => { | ||
var humanDetection = new index_1.HumanDetection(process.env.API_KEY, 'http://localhost:11111'); | ||
humanDetection.humanDetection("./testdata/man-3365368_640.jpg").then(body => { }, err => { | ||
chai_1.expect(err).to.have.property('errno').to.be.equal('ECONNREFUSED'); | ||
chai_1.expect(err).to.have.property('code').to.be.equal('ECONNREFUSED'); | ||
it("should return connection refused error", (done) => { | ||
const humanDetectionErr = new index_1.HumanDetection(process.env.API_KEY, "http://localhost:11111"); | ||
humanDetectionErr.humanDetection("./testdata/man-3365368_640.jpg").then(() => { chai_1.expect.fail(); }, (err) => { | ||
chai_1.expect(err).to.have.property("errno").to.be.equal("ECONNREFUSED"); | ||
chai_1.expect(err).to.have.property("code").to.be.equal("ECONNREFUSED"); | ||
}).then(done, done); | ||
@@ -85,0 +85,0 @@ }); |
@@ -5,15 +5,14 @@ "use strict"; | ||
const index_1 = require("../index"); | ||
describe('image feature extraction', () => { | ||
var imageFeatureExtraction = new index_1.ImageFeatureExtraction(process.env.API_KEY); | ||
describe('shoe', () => { | ||
it('should return a vector', (done) => { | ||
imageFeatureExtraction.featureExtraction("./testdata/chucks-153310_640.png").then(body => { | ||
console.log(JSON.stringify(body, null, " ")); | ||
chai_1.expect(body).to.have.property('id'); | ||
chai_1.expect(body).to.have.property('predictions'); | ||
chai_1.expect(body).to.have.property('processedTime'); | ||
chai_1.expect(body).to.have.property('status').to.be.equal('DONE'); | ||
chai_1.expect(body.predictions).to.be.an('array').have.lengthOf(1); | ||
chai_1.expect(body.predictions[0]).to.have.property('featureVectors'); | ||
chai_1.expect(body.predictions[0].featureVectors).to.be.an('array').have.lengthOf(2048); | ||
describe("image feature extraction", () => { | ||
const imageFeatureExtraction = new index_1.ImageFeatureExtraction(process.env.API_KEY); | ||
describe("shoe", () => { | ||
it("should return a vector", (done) => { | ||
imageFeatureExtraction.featureExtraction("./testdata/chucks-153310_640.png").then((body) => { | ||
chai_1.expect(body).to.have.property("id"); | ||
chai_1.expect(body).to.have.property("predictions"); | ||
chai_1.expect(body).to.have.property("processedTime"); | ||
chai_1.expect(body).to.have.property("status").to.be.equal("DONE"); | ||
chai_1.expect(body.predictions).to.be.an("array").have.lengthOf(1); | ||
chai_1.expect(body.predictions[0]).to.have.property("featureVectors"); | ||
chai_1.expect(body.predictions[0].featureVectors).to.be.an("array").have.lengthOf(2048); | ||
chai_1.expect(body.predictions[0].featureVectors).to.be.eql(featureVectors); | ||
@@ -23,18 +22,18 @@ }).then(done, done); | ||
}); | ||
describe('error coverage', () => { | ||
it('should return a file not found error', (done) => { | ||
imageFeatureExtraction.featureExtraction("file_does_not_exist").then(body => { }, err => { | ||
chai_1.expect(err).to.have.property('errno').to.be.equal(-2); | ||
chai_1.expect(err).to.have.property('code').to.be.equal('ENOENT'); | ||
describe("error coverage", () => { | ||
it("should return a file not found error", (done) => { | ||
imageFeatureExtraction.featureExtraction("file_does_not_exist").then((body) => { newFunction(); }, (err) => { | ||
chai_1.expect(err).to.have.property("errno").to.be.equal(-2); | ||
chai_1.expect(err).to.have.property("code").to.be.equal("ENOENT"); | ||
}).then(done, done); | ||
}); | ||
it('should return connection refused error', (done) => { | ||
var imageFeatureExtraction = new index_1.ImageFeatureExtraction(process.env.API_KEY, 'http://localhost:11111'); | ||
imageFeatureExtraction.featureExtraction("./testdata/chucks-153310_640.png").then(body => { }, err => { | ||
chai_1.expect(err).to.have.property('errno').to.be.equal('ECONNREFUSED'); | ||
chai_1.expect(err).to.have.property('code').to.be.equal('ECONNREFUSED'); | ||
it("should return connection refused error", (done) => { | ||
const imageFeatureExtractionErr = new index_1.ImageFeatureExtraction(process.env.API_KEY, "http://localhost:11111"); | ||
imageFeatureExtractionErr.featureExtraction("./testdata/chucks-153310_640.png").then(() => { chai_1.expect.fail(); }, (err) => { | ||
chai_1.expect(err).to.have.property("errno").to.be.equal("ECONNREFUSED"); | ||
chai_1.expect(err).to.have.property("code").to.be.equal("ECONNREFUSED"); | ||
}).then(done, done); | ||
}); | ||
xit('should return method not implemented error', (done) => { | ||
imageFeatureExtraction.featureExtraction("").then(body => { }, err => { | ||
xit("should return method not implemented error", (done) => { | ||
imageFeatureExtraction.featureExtraction("").then(() => { chai_1.expect.fail(); }, (err) => { | ||
chai_1.expect(err).is.equal("not implemented"); | ||
@@ -44,3 +43,6 @@ }).then(done, done); | ||
}); | ||
var featureVectors = [ | ||
// tslint:disable:object-literal-key-quotes | ||
// tslint:disable:max-line-length | ||
// tslint:disable:trailing-comma | ||
const featureVectors = [ | ||
0.04334653913974762, | ||
@@ -2096,1 +2098,4 @@ 0.10124225914478302, | ||
}); | ||
function newFunction() { | ||
chai_1.expect.fail(); | ||
} |
@@ -5,24 +5,24 @@ "use strict"; | ||
const index_1 = require("../index"); | ||
describe('imageclassification', () => { | ||
var imageclassification = new index_1.Imageclassification(process.env.API_KEY); | ||
describe('elephant', () => { | ||
it('should predict a tusker and an elephant', (done) => { | ||
imageclassification.classification("./testdata/elephant-114543_640.jpg").then(body => { | ||
chai_1.expect(body).to.have.property('id'); | ||
chai_1.expect(body).to.have.property('predictions'); | ||
chai_1.expect(body).to.have.property('processedTime'); | ||
chai_1.expect(body).to.have.property('status').to.be.equal('DONE'); | ||
chai_1.expect(body.predictions).to.be.an('array').have.lengthOf(1); | ||
chai_1.expect(body.predictions[0]).to.have.property('results'); | ||
chai_1.expect(body.predictions[0].results).to.be.an('array').have.lengthOf(5); | ||
let expected_results = [ | ||
{ label: 'tusker', score: 0.7052137851715088 }, | ||
{ label: 'African elephant, Loxodonta africana', score: 0.14608600735664368 }, | ||
{ label: 'Indian elephant, Elephas maximus', score: 0.08779436349868774 }, | ||
{ label: 'toaster', score: 0.0002799317880999297 }, | ||
{ label: 'combination lock', score: 0.0002534814993850887 } | ||
describe("imageclassification", () => { | ||
const imageclassification = new index_1.Imageclassification(process.env.API_KEY); | ||
describe("elephant", () => { | ||
it("should predict a tusker and an elephant", (done) => { | ||
imageclassification.classification("./testdata/elephant-114543_640.jpg").then((body) => { | ||
chai_1.expect(body).to.have.property("id"); | ||
chai_1.expect(body).to.have.property("predictions"); | ||
chai_1.expect(body).to.have.property("processedTime"); | ||
chai_1.expect(body).to.have.property("status").to.be.equal("DONE"); | ||
chai_1.expect(body.predictions).to.be.an("array").have.lengthOf(1); | ||
chai_1.expect(body.predictions[0]).to.have.property("results"); | ||
chai_1.expect(body.predictions[0].results).to.be.an("array").have.lengthOf(5); | ||
const expectedResults = [ | ||
{ label: "tusker", score: 0.7052137851715088 }, | ||
{ label: "African elephant, Loxodonta africana", score: 0.14608600735664368 }, | ||
{ label: "Indian elephant, Elephas maximus", score: 0.08779436349868774 }, | ||
{ label: "toaster", score: 0.0002799317880999297 }, | ||
{ label: "combination lock", score: 0.0002534814993850887 }, | ||
]; | ||
for (var i = 0; i < 5; i++) { | ||
chai_1.expect(body.predictions[0].results[i].label).to.be.equal(expected_results[i].label); | ||
chai_1.expect(body.predictions[0].results[i].score).to.be.equal(expected_results[i].score); | ||
for (let i = 0; i < 5; i++) { | ||
chai_1.expect(body.predictions[0].results[i].label).to.be.equal(expectedResults[i].label); | ||
chai_1.expect(body.predictions[0].results[i].score).to.be.equal(expectedResults[i].score); | ||
} | ||
@@ -32,22 +32,23 @@ }).then(done, done); | ||
}); | ||
describe('some image classification errors', () => { | ||
it('should throw an error for wrong file type (text)', (done) => { | ||
imageclassification.classification("./LICENSE").then(body => { | ||
chai_1.expect(body).to.have.property('error'); | ||
chai_1.expect(body.error).to.have.property('message'); | ||
describe("some image classification errors", () => { | ||
it("should throw an error for wrong file type (text)", (done) => { | ||
imageclassification.classification("./LICENSE").then((body) => { | ||
chai_1.expect(body).to.have.property("error"); | ||
chai_1.expect(body.error).to.have.property("message"); | ||
chai_1.expect(body.error.message).to.be.equal("Error when uploading files:: Invalid file type"); | ||
}).then(done, done); | ||
}); | ||
it('should throw an error for zip with hierarchy', (done) => { | ||
imageclassification.classification("./testdata/Archive.zip").then(body => { | ||
chai_1.expect(body).to.have.property('error'); | ||
chai_1.expect(body.error).to.have.property('message'); | ||
it("should throw an error for zip with hierarchy", (done) => { | ||
imageclassification.classification("./testdata/Archive.zip").then((body) => { | ||
chai_1.expect(body).to.have.property("error"); | ||
chai_1.expect(body.error).to.have.property("message"); | ||
// tslint:disable-next-line:max-line-length | ||
chai_1.expect(body.error.message).to.be.equal("Invalid request: Absolute path, or hierarchy in archive file is not allowed"); | ||
}).then(done, done); | ||
}); | ||
it('should throw an error for wrong API Key', (done) => { | ||
var imageclassificationWithWrongApiKey = new index_1.Imageclassification("WRONG"); | ||
imageclassificationWithWrongApiKey.classification("./testdata/elephant-114543_640.jpg").then(body => { | ||
chai_1.expect(body).to.have.property('fault'); | ||
chai_1.expect(body.fault).to.have.property('faultstring'); | ||
it("should throw an error for wrong API Key", (done) => { | ||
const imageclassificationWithWrongApiKey = new index_1.Imageclassification("WRONG"); | ||
imageclassificationWithWrongApiKey.classification("./testdata/elephant-114543_640.jpg").then((body) => { | ||
chai_1.expect(body).to.have.property("fault"); | ||
chai_1.expect(body.fault).to.have.property("faultstring"); | ||
chai_1.expect(body.fault.faultstring).to.be.equal("Invalid ApiKey"); | ||
@@ -57,18 +58,18 @@ }).then(done, done); | ||
}); | ||
describe('error coverage', () => { | ||
it('should return a file not found error', (done) => { | ||
imageclassification.classification("file_does_not_exist").then(body => { }, err => { | ||
chai_1.expect(err).to.have.property('errno').to.be.equal(-2); | ||
chai_1.expect(err).to.have.property('code').to.be.equal('ENOENT'); | ||
describe("error coverage", () => { | ||
it("should return a file not found error", (done) => { | ||
imageclassification.classification("file_does_not_exist").then(() => { chai_1.expect.fail(); }, (err) => { | ||
chai_1.expect(err).to.have.property("errno").to.be.equal(-2); | ||
chai_1.expect(err).to.have.property("code").to.be.equal("ENOENT"); | ||
}).then(done, done); | ||
}); | ||
it('should return connection refused error', (done) => { | ||
var imageclassification = new index_1.Imageclassification(process.env.API_KEY, 'http://localhost:11111'); | ||
imageclassification.classification("./testdata/elephant-114543_640.jpg").then(body => { }, err => { | ||
chai_1.expect(err).to.have.property('errno').to.be.equal('ECONNREFUSED'); | ||
chai_1.expect(err).to.have.property('code').to.be.equal('ECONNREFUSED'); | ||
it("should return connection refused error", (done) => { | ||
const imageclassificationErr = new index_1.Imageclassification(process.env.API_KEY, "http://localhost:11111"); | ||
imageclassificationErr.classification("./testdata/elephant-114543_640.jpg").then(() => { chai_1.expect.fail(); }, (err) => { | ||
chai_1.expect(err).to.have.property("errno").to.be.equal("ECONNREFUSED"); | ||
chai_1.expect(err).to.have.property("code").to.be.equal("ECONNREFUSED"); | ||
}).then(done, done); | ||
}); | ||
it('should return method not implemented error', (done) => { | ||
imageclassification.customizable("", "", "").then(body => { }, err => { | ||
it("should return method not implemented error", (done) => { | ||
imageclassification.customizable("", "", "").then(() => { chai_1.expect.fail(); }, (err) => { | ||
chai_1.expect(err).is.equal("not implemented"); | ||
@@ -75,0 +76,0 @@ }).then(done, done); |
@@ -5,49 +5,49 @@ "use strict"; | ||
const index_1 = require("../index"); | ||
describe('language detection', () => { | ||
var languageDetection = new index_1.LanguageDetection(process.env.API_KEY); | ||
describe('detect the language', () => { | ||
const text_english = "This service translates text from a source language into several target languages."; | ||
const text_deutsch = "Dieser Service übersetzt Text aus einer Quellsprache in mehrere Zielsprachen."; | ||
const text_español = "Este servicio convierte texto de un idioma fuente en varios idiomas de destino."; | ||
it('should detect English', (done) => { | ||
languageDetection.language(text_english).then(body => { | ||
chai_1.expect(body).to.have.property('langCode').to.be.equal('en'); | ||
chai_1.expect(body).to.have.property('confidence').to.be.equal(1); | ||
chai_1.expect(body).to.have.property('langStr').to.be.equal('English'); | ||
describe("language detection", () => { | ||
const languageDetection = new index_1.LanguageDetection(process.env.API_KEY); | ||
describe("detect the language", () => { | ||
const textEnglish = "This service translates text from a source language into several target languages."; | ||
const textDeutsch = "Dieser Service übersetzt Text aus einer Quellsprache in mehrere Zielsprachen."; | ||
const textEspañol = "Este servicio convierte texto de un idioma fuente en constios idiomas de destino."; | ||
it("should detect English", (done) => { | ||
languageDetection.language(textEnglish).then((body) => { | ||
chai_1.expect(body).to.have.property("langCode").to.be.equal("en"); | ||
chai_1.expect(body).to.have.property("confidence").to.be.equal(1); | ||
chai_1.expect(body).to.have.property("langStr").to.be.equal("English"); | ||
}).then(done, done); | ||
}); | ||
it('should detect German', (done) => { | ||
languageDetection.language(text_deutsch).then(body => { | ||
chai_1.expect(body).to.have.property('langCode').to.be.equal('de'); | ||
chai_1.expect(body).to.have.property('confidence').to.be.equal(1); | ||
chai_1.expect(body).to.have.property('langStr').to.be.equal('German'); | ||
it("should detect German", (done) => { | ||
languageDetection.language(textDeutsch).then((body) => { | ||
chai_1.expect(body).to.have.property("langCode").to.be.equal("de"); | ||
chai_1.expect(body).to.have.property("confidence").to.be.equal(1); | ||
chai_1.expect(body).to.have.property("langStr").to.be.equal("German"); | ||
}).then(done, done); | ||
}); | ||
it('should detect Spanish', (done) => { | ||
languageDetection.language(text_español).then(body => { | ||
chai_1.expect(body).to.have.property('langCode').to.be.equal('es'); | ||
chai_1.expect(body).to.have.property('confidence').to.be.equal(1); | ||
chai_1.expect(body).to.have.property('langStr').to.be.equal('Spanish'); | ||
it("should detect Spanish", (done) => { | ||
languageDetection.language(textEspañol).then((body) => { | ||
chai_1.expect(body).to.have.property("langCode").to.be.equal("es"); | ||
chai_1.expect(body).to.have.property("confidence").to.be.equal(1); | ||
chai_1.expect(body).to.have.property("langStr").to.be.equal("Spanish"); | ||
}).then(done, done); | ||
}); | ||
}); | ||
describe('provide version', () => { | ||
it('should provide version', (done) => { | ||
languageDetection.version().then(body => { | ||
chai_1.expect(body).to.have.property('version').to.be.equal('1.0-SNAPSHOT'); | ||
describe("provide version", () => { | ||
it("should provide version", (done) => { | ||
languageDetection.version().then((body) => { | ||
chai_1.expect(body).to.have.property("version").to.be.equal("1.0-SNAPSHOT"); | ||
}).then(done, done); | ||
}); | ||
}); | ||
describe('error coverage', () => { | ||
var languageDetection = new index_1.LanguageDetection(process.env.API_KEY, 'http://localhost:11111'); | ||
it('should return connection refused error', (done) => { | ||
languageDetection.language("").then(body => { }, err => { | ||
chai_1.expect(err).to.have.property('errno').to.be.equal('ECONNREFUSED'); | ||
chai_1.expect(err).to.have.property('code').to.be.equal('ECONNREFUSED'); | ||
describe("error coverage", () => { | ||
const languageDetectionErr = new index_1.LanguageDetection(process.env.API_KEY, "http://localhost:11111"); | ||
it("should return connection refused error", (done) => { | ||
languageDetectionErr.language("").then((body) => { newFunction(); }, (err) => { | ||
chai_1.expect(err).to.have.property("errno").to.be.equal("ECONNREFUSED"); | ||
chai_1.expect(err).to.have.property("code").to.be.equal("ECONNREFUSED"); | ||
}).then(done, done); | ||
}); | ||
it('should return connection refused (version) error', (done) => { | ||
languageDetection.version().then(body => { }, err => { | ||
chai_1.expect(err).to.have.property('errno').to.be.equal('ECONNREFUSED'); | ||
chai_1.expect(err).to.have.property('code').to.be.equal('ECONNREFUSED'); | ||
it("should return connection refused (version) error", (done) => { | ||
languageDetectionErr.version().then((body) => { newFunction_1(); }, (err) => { | ||
chai_1.expect(err).to.have.property("errno").to.be.equal("ECONNREFUSED"); | ||
chai_1.expect(err).to.have.property("code").to.be.equal("ECONNREFUSED"); | ||
}).then(done, done); | ||
@@ -57,1 +57,7 @@ }); | ||
}); | ||
function newFunction_1() { | ||
chai_1.expect.fail(); | ||
} | ||
function newFunction() { | ||
chai_1.expect.fail(); | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const chai_1 = require("chai"); | ||
//import * as fs from 'fs'; | ||
// import * as fs from "fs"; | ||
const index_1 = require("../index"); | ||
var fileName = "juice-1271881_640.jpg"; | ||
describe('multi-instance image segmentation', () => { | ||
var multiInstanceImageSegmentation = new index_1.MultiInstanceImageSegmentation(process.env.API_KEY); | ||
describe('four items', () => { | ||
it('should predict three bottles and a can', (done) => { | ||
multiInstanceImageSegmentation.instanceSegmentor("./testdata/" + fileName).then(body => { | ||
chai_1.expect(body).to.have.property('id'); | ||
chai_1.expect(body).to.have.property('predictions').is.an('array').with.length(1); | ||
chai_1.expect(body).to.have.property('processedTime'); | ||
chai_1.expect(body).to.have.property('status').to.be.equal('DONE'); | ||
chai_1.expect(body.predictions[0]).to.have.property('imageName').which.is.equal(fileName); | ||
chai_1.expect(body.predictions[0]).to.have.property('results').is.an('array').with.length(4); | ||
// for (var i = 0; i < body.predictions[0].results.length; i++) { | ||
// body.predictions[0].results[i].mask = "..."; | ||
// } | ||
// console.log(JSON.stringify(body, null, ' ')); | ||
var expected_results = [ | ||
{ | ||
"bbox": { | ||
"x1": 366, | ||
"x2": 577, | ||
"y1": 143, | ||
"y2": 575 | ||
}, | ||
"classId": 5, | ||
"className": "Glass Bottle", | ||
"mask": "...", | ||
"score": 1 | ||
}, | ||
{ | ||
"bbox": { | ||
"x1": 49, | ||
"x2": 266, | ||
"y1": 321, | ||
"y2": 579 | ||
}, | ||
"classId": 1, | ||
"className": "Can", | ||
"mask": "...", | ||
"score": 1 | ||
}, | ||
{ | ||
"bbox": { | ||
"x1": 244, | ||
"x2": 356, | ||
"y1": 92, | ||
"y2": 489 | ||
}, | ||
"classId": 4, | ||
"className": "Pet Bottle", | ||
"mask": "...", | ||
"score": 0.98 | ||
}, | ||
{ | ||
"bbox": { | ||
"x1": 289, | ||
"x2": 421, | ||
"y1": 149, | ||
"y2": 536 | ||
}, | ||
"classId": 5, | ||
"className": "Glass Bottle", | ||
"mask": "...", | ||
"score": 0.94 | ||
} | ||
]; | ||
for (var i = 0; i < expected_results.length; i++) { | ||
chai_1.expect(body.predictions[0].results[i].bbox).to.be.eql(expected_results[i].bbox); | ||
chai_1.expect(body.predictions[0].results[i].classId).to.be.equal(expected_results[i].classId); | ||
chai_1.expect(body.predictions[0].results[i].className).to.be.equal(expected_results[i].className); | ||
chai_1.expect(body.predictions[0].results[i].score).to.be.equal(expected_results[i].score); | ||
const fileName = "juice-1271881_640.jpg"; | ||
describe("multi-instance image segmentation", () => { | ||
const multiInstanceImageSegmentation = new index_1.MultiInstanceImageSegmentation(process.env.API_KEY); | ||
describe("four items", () => { | ||
it("should predict three bottles and a can", (done) => { | ||
multiInstanceImageSegmentation.instanceSegmentor("./testdata/" + fileName).then((body) => { | ||
chai_1.expect(body).to.have.property("id"); | ||
chai_1.expect(body).to.have.property("predictions").which.is.an("array").with.length(1); | ||
chai_1.expect(body).to.have.property("processedTime"); | ||
chai_1.expect(body).to.have.property("status").to.be.equal("DONE"); | ||
chai_1.expect(body.predictions[0]).to.have.property("imageName").which.is.equal(fileName); | ||
chai_1.expect(body.predictions[0]).to.have.property("results").is.an("array").with.length(4); | ||
for (let i = 0; i < expectedResults.length; i++) { | ||
chai_1.expect(body.predictions[0].results[i].bbox).to.be.eql(expectedResults[i].bbox); | ||
chai_1.expect(body.predictions[0].results[i].classId).to.be.equal(expectedResults[i].classId); | ||
chai_1.expect(body.predictions[0].results[i].className).to.be.equal(expectedResults[i].className); | ||
chai_1.expect(body.predictions[0].results[i].score).to.be.equal(expectedResults[i].score); | ||
// encoded mask data should have the size of bbox width * height | ||
var encodedMaskData = Buffer.from(body.predictions[0].results[i].mask, 'base64'); | ||
var bbox = body.predictions[0].results[i].bbox; | ||
var bboxWidth = Math.abs(bbox.x2 - bbox.x1); | ||
var bboxHeight = Math.abs(bbox.y2 - bbox.y1); | ||
const encodedMaskData = Buffer.from(body.predictions[0].results[i].mask, "base64"); | ||
const bbox = body.predictions[0].results[i].bbox; | ||
const bboxWidth = Math.abs(bbox.x2 - bbox.x1); | ||
const bboxHeight = Math.abs(bbox.y2 - bbox.y1); | ||
chai_1.expect(encodedMaskData.length).to.be.equal(bboxWidth * bboxHeight); | ||
@@ -87,18 +33,20 @@ } | ||
}); | ||
describe('multi-instance image segmentation image:jpg', () => { | ||
var multiInstanceImageSegmentation = new index_1.MultiInstanceImageSegmentation(process.env.API_KEY); | ||
describe('return image', () => { | ||
it('should return a png image', (done) => { | ||
multiInstanceImageSegmentation.instanceSegmentor("./testdata/" + fileName, true).then(body => { | ||
chai_1.expect(body).to.have.property('id'); | ||
chai_1.expect(body).to.have.property('predictions').is.an('array').with.length(1); | ||
chai_1.expect(body).to.have.property('processedTime'); | ||
chai_1.expect(body).to.have.property('status').to.be.equal('DONE'); | ||
chai_1.expect(body.predictions[0]).to.have.property('imageName').is.equal(fileName); | ||
//fs.writeFileSync("MultiInstanceImageSegmentation.png", Buffer.from(body.predictions[0].imageString, 'base64')); | ||
var encodedImageData = Buffer.from(body.predictions[0].imageString, 'base64'); | ||
var isJPG = encodedImageData[0] === 0xFF && | ||
describe("multi-instance image segmentation image:jpg", () => { | ||
const multiInstanceImageSegmentationImage = new index_1.MultiInstanceImageSegmentation(process.env.API_KEY); | ||
describe("return image", () => { | ||
it("should return a png image", (done) => { | ||
multiInstanceImageSegmentationImage.instanceSegmentor("./testdata/" + fileName, true).then((body) => { | ||
chai_1.expect(body).to.have.property("id"); | ||
chai_1.expect(body).to.have.property("predictions").is.an("array").with.length(1); | ||
chai_1.expect(body).to.have.property("processedTime"); | ||
chai_1.expect(body).to.have.property("status").to.be.equal("DONE"); | ||
chai_1.expect(body.predictions[0]).to.have.property("imageName").is.equal(fileName); | ||
// fs.writeFileSync( | ||
// "MultiInstanceImageSegmentation.png", | ||
// Buffer.from(body.predictions[0].imageString, "base64")); | ||
const encodedImageData = Buffer.from(body.predictions[0].imageString, "base64"); | ||
const isJPG = encodedImageData[0] === 0xFF && | ||
encodedImageData[1] === 0xD8 && | ||
encodedImageData[2] === 0xFF; | ||
var isPNG = encodedImageData[0] === 0x89 && | ||
const isPNG = encodedImageData[0] === 0x89 && | ||
encodedImageData[1] === 0x50 && | ||
@@ -111,3 +59,5 @@ encodedImageData[2] === 0x4E && | ||
encodedImageData[7] === 0x0A; | ||
// tslint:disable-next-line:no-unused-expression | ||
chai_1.expect(isJPG).is.false; | ||
// tslint:disable-next-line:no-unused-expression | ||
chai_1.expect(isPNG).is.true; | ||
@@ -118,17 +68,70 @@ }).then(done, done); | ||
}); | ||
describe('error coverage', () => { | ||
it('should return a file not found error', (done) => { | ||
multiInstanceImageSegmentation.instanceSegmentor("file_does_not_exist").then(body => { }, err => { | ||
chai_1.expect(err).to.have.property('errno').to.be.equal(-2); | ||
chai_1.expect(err).to.have.property('code').to.be.equal('ENOENT'); | ||
describe("error coverage", () => { | ||
it("should return a file not found error", (done) => { | ||
multiInstanceImageSegmentation.instanceSegmentor("file_does_not_exist").then(() => { chai_1.expect.fail(); }, (err) => { | ||
chai_1.expect(err).to.have.property("errno").to.be.equal(-2); | ||
chai_1.expect(err).to.have.property("code").to.be.equal("ENOENT"); | ||
}).then(done, done); | ||
}); | ||
it('should return connection refused error', (done) => { | ||
var multiInstanceImageSegmentation = new index_1.MultiInstanceImageSegmentation(process.env.API_KEY, 'http://localhost:11111'); | ||
multiInstanceImageSegmentation.instanceSegmentor("./testdata/" + fileName).then(body => { }, err => { | ||
chai_1.expect(err).to.have.property('errno').to.be.equal('ECONNREFUSED'); | ||
chai_1.expect(err).to.have.property('code').to.be.equal('ECONNREFUSED'); | ||
it("should return connection refused error", (done) => { | ||
const multiInstanceImageSegmentationErr = new index_1.MultiInstanceImageSegmentation(process.env.API_KEY, "http://localhost:11111"); | ||
multiInstanceImageSegmentationErr.instanceSegmentor("./testdata/" + fileName).then(() => { chai_1.expect.fail(); }, (err) => { | ||
chai_1.expect(err).to.have.property("errno").to.be.equal("ECONNREFUSED"); | ||
chai_1.expect(err).to.have.property("code").to.be.equal("ECONNREFUSED"); | ||
}).then(done, done); | ||
}); | ||
}); | ||
// tslint:disable:object-literal-key-quotes | ||
// tslint:disable:max-line-length | ||
// tslint:disable:trailing-comma | ||
const expectedResults = [ | ||
{ | ||
"bbox": { | ||
"x1": 366, | ||
"x2": 577, | ||
"y1": 143, | ||
"y2": 575 | ||
}, | ||
"classId": 5, | ||
"className": "Glass Bottle", | ||
"mask": "...", | ||
"score": 1 | ||
}, | ||
{ | ||
"bbox": { | ||
"x1": 49, | ||
"x2": 266, | ||
"y1": 321, | ||
"y2": 579 | ||
}, | ||
"classId": 1, | ||
"className": "Can", | ||
"mask": "...", | ||
"score": 1 | ||
}, | ||
{ | ||
"bbox": { | ||
"x1": 244, | ||
"x2": 356, | ||
"y1": 92, | ||
"y2": 489 | ||
}, | ||
"classId": 4, | ||
"className": "Pet Bottle", | ||
"mask": "...", | ||
"score": 0.98 | ||
}, | ||
{ | ||
"bbox": { | ||
"x1": 289, | ||
"x2": 421, | ||
"y1": 149, | ||
"y2": 536 | ||
}, | ||
"classId": 5, | ||
"className": "Glass Bottle", | ||
"mask": "...", | ||
"score": 0.94 | ||
} | ||
]; | ||
}); |
@@ -5,37 +5,38 @@ "use strict"; | ||
const index_1 = require("../index"); | ||
describe('ocr', () => { | ||
var ocr = new index_1.OCR(process.env.API_KEY); | ||
describe('image to text', () => { | ||
it('should return an English text', (done) => { | ||
ocr.ocr("./testdata/ocr/english_1000.png").then(body => { | ||
chai_1.expect(body).to.have.property('id'); | ||
chai_1.expect(body).to.have.property('predictions'); | ||
chai_1.expect(body).to.have.property('processedTime'); | ||
chai_1.expect(body).to.have.property('status').to.be.equal('DONE'); | ||
chai_1.expect(body.predictions).to.be.an('array').have.lengthOf(1); | ||
const english_text = "Training Service for Optical Character\nRecognition\n\nThe Optical Character Recognition (OCR) service recognizes typewritten text from scanned or digital documents. The service accepts pdf,\njpg and png files types as input and returns detected texts within the file in either text or hROCR format. The service supports two modes of\noperation: synchronous (blocking) and asynchronous (non-blocking).\nUse Cases\n\n+ Supported languages are English, German, French, Spanish, Russian, Arabic, Chinese Simplified and Chinese Traditional.\n\n» The OCR service works best with well-scanned documents, i.e. the FS OCR is not intended for use with arbitrary textual\n\n \n\np For other text use-cases. such as recognizing text in natural images, please refer to the ML foundation\nScene Text Recognition service.\n\n« The OCR service only returns text, no assumptions are done as to its organization (e.g. table layouts) or semantics (e.g. table header\nor totals line)\n\n« Image preprocessing to ensure a good contrast and straight frontal scan can improve the recognition results.\n« Aright choice of processing options (model type. languages) can improve the recognition results\n« The API Business Hub sandbox service instance only allows documents of up to 2MB, whereas productive instances up to 10MB.\n\n« For heavy load, the asynchronous part should be used as the synchronous part times out with too many queries.\n\f"; | ||
chai_1.expect(body.predictions[0]).to.be.equal(english_text); | ||
describe("ocr", () => { | ||
const ocr = new index_1.OCR(process.env.API_KEY); | ||
describe("image to text", () => { | ||
it("should return an English text", (done) => { | ||
ocr.ocr("./testdata/ocr/english_1000.png").then((body) => { | ||
chai_1.expect(body).to.have.property("id"); | ||
chai_1.expect(body).to.have.property("predictions"); | ||
chai_1.expect(body).to.have.property("processedTime"); | ||
chai_1.expect(body).to.have.property("status").to.be.equal("DONE"); | ||
chai_1.expect(body.predictions).to.be.an("array").have.lengthOf(1); | ||
// tslint:disable-next-line:max-line-length | ||
const englishText = "Training Service for Optical Character\nRecognition\n\nThe Optical Character Recognition (OCR) service recognizes typewritten text from scanned or digital documents. The service accepts pdf,\njpg and png files types as input and returns detected texts within the file in either text or hROCR format. The service supports two modes of\noperation: synchronous (blocking) and asynchronous (non-blocking).\nUse Cases\n\n+ Supported languages are English, German, French, Spanish, Russian, Arabic, Chinese Simplified and Chinese Traditional.\n\n» The OCR service works best with well-scanned documents, i.e. the FS OCR is not intended for use with arbitrary textual\n\n \n\np For other text use-cases. such as recognizing text in natural images, please refer to the ML foundation\nScene Text Recognition service.\n\n« The OCR service only returns text, no assumptions are done as to its organization (e.g. table layouts) or semantics (e.g. table header\nor totals line)\n\n« Image preprocessing to ensure a good contrast and straight frontal scan can improve the recognition results.\n« Aright choice of processing options (model type. languages) can improve the recognition results\n« The API Business Hub sandbox service instance only allows documents of up to 2MB, whereas productive instances up to 10MB.\n\n« For heavy load, the asynchronous part should be used as the synchronous part times out with too many queries.\n\f"; | ||
chai_1.expect(body.predictions[0]).to.be.equal(englishText); | ||
}).then(done, done); | ||
}); | ||
}); | ||
describe('image to text with options', () => { | ||
it('should return XML', (done) => { | ||
let options = { "lang": "en", "outputType": "xml", "pageSegMode": "1", "modelType": "lstmStandard" }; | ||
ocr.ocr("./testdata/ocr/english_1000.png", options).then(body => { | ||
chai_1.expect(body).to.have.property('id'); | ||
chai_1.expect(body).to.have.property('predictions'); | ||
chai_1.expect(body).to.have.property('processedTime'); | ||
chai_1.expect(body).to.have.property('status').to.be.equal('DONE'); | ||
chai_1.expect(body.predictions).to.be.an('array').have.lengthOf(1); | ||
describe("image to text with options", () => { | ||
it("should return XML", (done) => { | ||
const options = { lang: "en", outputType: "xml", pageSegMode: "1", modelType: "lstmStandard" }; | ||
ocr.ocr("./testdata/ocr/english_1000.png", options).then((body) => { | ||
chai_1.expect(body).to.have.property("id"); | ||
chai_1.expect(body).to.have.property("predictions"); | ||
chai_1.expect(body).to.have.property("processedTime"); | ||
chai_1.expect(body).to.have.property("status").to.be.equal("DONE"); | ||
chai_1.expect(body.predictions).to.be.an("array").have.lengthOf(1); | ||
chai_1.expect(body.predictions[0]).to.match(/^<html:html/); | ||
}).then(done, done); | ||
}); | ||
it('should return a German text', (done) => { | ||
let options = { "lang": "de", "outputType": "txt", "pageSegMode": "1", "modelType": "lstmStandard" }; | ||
ocr.ocr("./testdata/ocr/deutsch.png", options).then(body => { | ||
chai_1.expect(body).to.have.property('id'); | ||
chai_1.expect(body).to.have.property('predictions'); | ||
chai_1.expect(body).to.have.property('processedTime'); | ||
chai_1.expect(body).to.have.property('status').to.be.equal('DONE'); | ||
chai_1.expect(body.predictions).to.be.an('array').have.lengthOf(1); | ||
it("should return a German text", (done) => { | ||
const options = { lang: "de", outputType: "txt", pageSegMode: "1", modelType: "lstmStandard" }; | ||
ocr.ocr("./testdata/ocr/deutsch.png", options).then((body) => { | ||
chai_1.expect(body).to.have.property("id"); | ||
chai_1.expect(body).to.have.property("predictions"); | ||
chai_1.expect(body).to.have.property("processedTime"); | ||
chai_1.expect(body).to.have.property("status").to.be.equal("DONE"); | ||
chai_1.expect(body.predictions).to.be.an("array").have.lengthOf(1); | ||
chai_1.expect(body.predictions[0]).to.match(/Stückchen/); | ||
@@ -45,44 +46,42 @@ }).then(done, done); | ||
}); | ||
describe('image to text (via job)', () => { | ||
var jobid; | ||
it('should return a job id', (done) => { | ||
ocr.jobs("./testdata/ocr/english_1000.png").then(body => { | ||
chai_1.expect(body).to.have.property('id'); | ||
chai_1.expect(body).to.have.property('status').to.be.equal("PENDING"); | ||
describe("image to text (via job)", () => { | ||
let jobid; | ||
it("should return a job id", (done) => { | ||
ocr.jobs("./testdata/ocr/english_1000.png").then((body) => { | ||
chai_1.expect(body).to.have.property("id"); | ||
chai_1.expect(body).to.have.property("status").to.be.equal("PENDING"); | ||
jobid = body.id; | ||
}).then(done, done); | ||
}); | ||
it('should return no error for the job id', (done) => { | ||
ocr.jobsId(jobid).then(body => { | ||
chai_1.expect(body).to.have.property('id').to.be.equal(jobid); | ||
chai_1.expect(body).to.have.property('status'); | ||
it("should return no error for the job id", (done) => { | ||
ocr.jobsId(jobid).then((body) => { | ||
chai_1.expect(body).to.have.property("id").to.be.equal(jobid); | ||
chai_1.expect(body).to.have.property("status"); | ||
}).then(done, done); | ||
}); | ||
}); | ||
describe('error coverage', () => { | ||
it('should return a file not found error', (done) => { | ||
ocr.ocr("file_does_not_exist").then(body => { }, err => { | ||
chai_1.expect(err).to.have.property('errno').to.be.equal(-2); | ||
chai_1.expect(err).to.have.property('code').to.be.equal('ENOENT'); | ||
describe("error coverage", () => { | ||
it("should return a file not found error", (done) => { | ||
ocr.ocr("file_does_not_exist").then(() => { chai_1.expect.fail(); }, (err) => { | ||
chai_1.expect(err).to.have.property("errno").to.be.equal(-2); | ||
chai_1.expect(err).to.have.property("code").to.be.equal("ENOENT"); | ||
}).then(done, done); | ||
}); | ||
it('should return connection refused error', (done) => { | ||
var ocr = new index_1.OCR(process.env.API_KEY, 'http://localhost:11111'); | ||
ocr.ocr("./testdata/ocr/english_1000.png").then(body => { }, err => { | ||
chai_1.expect(err).to.have.property('errno').to.be.equal('ECONNREFUSED'); | ||
chai_1.expect(err).to.have.property('code').to.be.equal('ECONNREFUSED'); | ||
const ocrErr = new index_1.OCR(process.env.API_KEY, "http://localhost:11111"); | ||
it("should return connection refused error", (done) => { | ||
ocrErr.ocr("./testdata/ocr/english_1000.png").then(() => { chai_1.expect.fail(); }, (err) => { | ||
chai_1.expect(err).to.have.property("errno").to.be.equal("ECONNREFUSED"); | ||
chai_1.expect(err).to.have.property("code").to.be.equal("ECONNREFUSED"); | ||
}).then(done, done); | ||
}); | ||
it('should return connection refused (jobs) error', (done) => { | ||
var ocr = new index_1.OCR(process.env.API_KEY, 'http://localhost:11111'); | ||
ocr.jobs("./testdata/ocr/english_1000.png", null).then(body => { }, err => { | ||
chai_1.expect(err).to.have.property('errno').to.be.equal('ECONNREFUSED'); | ||
chai_1.expect(err).to.have.property('code').to.be.equal('ECONNREFUSED'); | ||
it("should return connection refused (jobs) error", (done) => { | ||
ocrErr.jobs("./testdata/ocr/english_1000.png", null).then(() => { chai_1.expect.fail(); }, (err) => { | ||
chai_1.expect(err).to.have.property("errno").to.be.equal("ECONNREFUSED"); | ||
chai_1.expect(err).to.have.property("code").to.be.equal("ECONNREFUSED"); | ||
}).then(done, done); | ||
}); | ||
it('should return connection refused (jobId) error', (done) => { | ||
var ocr = new index_1.OCR(process.env.API_KEY, 'http://localhost:11111'); | ||
ocr.jobsId("").then(body => { }, err => { | ||
chai_1.expect(err).to.have.property('errno').to.be.equal('ECONNREFUSED'); | ||
chai_1.expect(err).to.have.property('code').to.be.equal('ECONNREFUSED'); | ||
it("should return connection refused (jobId) error", (done) => { | ||
ocrErr.jobsId("").then(() => { chai_1.expect.fail(); }, (err) => { | ||
chai_1.expect(err).to.have.property("errno").to.be.equal("ECONNREFUSED"); | ||
chai_1.expect(err).to.have.property("code").to.be.equal("ECONNREFUSED"); | ||
}).then(done, done); | ||
@@ -89,0 +88,0 @@ }); |
@@ -5,41 +5,20 @@ "use strict"; | ||
const index_1 = require("../index"); | ||
describe('product text classification', () => { | ||
var productTextClassification = new index_1.ProductTextClassification(process.env.API_KEY); | ||
describe('texts', () => { | ||
const productText = "Get the clarity of 4K UHD in an old-fashioned smart TV design that's mind controllable. Ultra HD makes everything smooth and sharp. Magic power gives you instant access to your favourite content and the movie night is just a smile away."; // note: is this an adjusted description for a Smart TV | ||
it('should detect a LCD TV', (done) => { | ||
productTextClassification.inferenceSync(null, productText).then(body => { | ||
chai_1.expect(body).to.have.property('_id'); | ||
chai_1.expect(body).to.have.property('predictions').to.be.an('array').with.length(1); | ||
chai_1.expect(body).to.have.property('processed_time'); | ||
chai_1.expect(body).to.have.property('request'); | ||
chai_1.expect(body).to.have.property('status').to.be.equal('DONE'); | ||
chai_1.expect(body).to.have.property('tenantName'); | ||
chai_1.expect(body.predictions[0]).to.have.property('description').to.be.equal(productText); | ||
chai_1.expect(body.predictions[0]).to.have.property('results').to.be.an('array').with.length(5); | ||
var expected_results = [ | ||
{ | ||
"category": "LED TVs", | ||
"confidence": 0.913253 | ||
}, | ||
{ | ||
"category": "digital cameras", | ||
"confidence": 0.040222 | ||
}, | ||
{ | ||
"category": "other", | ||
"confidence": 0.03803 | ||
}, | ||
{ | ||
"category": "smartphones", | ||
"confidence": 0.004975 | ||
}, | ||
{ | ||
"category": "computer monitors", | ||
"confidence": 0.001214 | ||
} | ||
]; | ||
for (var i = 0; i < expected_results.length; i++) { | ||
chai_1.expect(body.predictions[0].results[i].category).to.be.equal(expected_results[i].category); | ||
chai_1.expect(body.predictions[0].results[i].confidence).to.be.equal(expected_results[i].confidence); | ||
describe("product text classification", () => { | ||
const productTextClassification = new index_1.ProductTextClassification(process.env.API_KEY); | ||
describe("texts", () => { | ||
// tslint:disable-next-line:max-line-length | ||
const productText = "Get the clarity of 4K UHD in an old-fashioned smart TV design that's mind controllable. Ultra HD makes everything smooth and sharp. Magic power gives you instant access to your favourite content and the movie night is just a smile away."; // note: this is an adjusted description for a Smart TV | ||
it("should detect a LCD TV", (done) => { | ||
productTextClassification.inferenceSync(null, productText).then((body) => { | ||
chai_1.expect(body).to.have.property("_id"); | ||
chai_1.expect(body).to.have.property("predictions").to.be.an("array").with.length(1); | ||
chai_1.expect(body).to.have.property("processed_time"); | ||
chai_1.expect(body).to.have.property("request"); | ||
chai_1.expect(body).to.have.property("status").to.be.equal("DONE"); | ||
chai_1.expect(body).to.have.property("tenantName"); | ||
chai_1.expect(body.predictions[0]).to.have.property("description").to.be.equal(productText); | ||
chai_1.expect(body.predictions[0]).to.have.property("results").to.be.an("array").with.length(5); | ||
for (let i = 0; i < expectedResults.length; i++) { | ||
chai_1.expect(body.predictions[0].results[i].category).to.be.equal(expectedResults[i].category); | ||
chai_1.expect(body.predictions[0].results[i].confidence).to.be.equal(expectedResults[i].confidence); | ||
} | ||
@@ -49,38 +28,16 @@ }).then(done, done); | ||
}); | ||
describe('files', () => { | ||
it('should detect a LCD TV', (done) => { | ||
productTextClassification.inferenceSync("./testdata/product_text.zip", null).then(body => { | ||
chai_1.expect(body).to.have.property('_id'); | ||
chai_1.expect(body).to.have.property('predictions').to.be.an('array').with.length(1); | ||
chai_1.expect(body).to.have.property('processed_time'); | ||
chai_1.expect(body).to.have.property('request'); | ||
chai_1.expect(body).to.have.property('status').to.be.equal('DONE'); | ||
chai_1.expect(body).to.have.property('tenantName'); | ||
chai_1.expect(body.predictions[0]).to.have.property('file').to.be.equal('product_text.txt'); | ||
chai_1.expect(body.predictions[0]).to.have.property('results').to.be.an('array').with.length(5); | ||
var expected_results = [ | ||
{ | ||
"category": "LED TVs", | ||
"confidence": 0.913253 | ||
}, | ||
{ | ||
"category": "digital cameras", | ||
"confidence": 0.040222 | ||
}, | ||
{ | ||
"category": "other", | ||
"confidence": 0.03803 | ||
}, | ||
{ | ||
"category": "smartphones", | ||
"confidence": 0.004975 | ||
}, | ||
{ | ||
"category": "computer monitors", | ||
"confidence": 0.001214 | ||
} | ||
]; | ||
for (var i = 0; i < expected_results.length; i++) { | ||
chai_1.expect(body.predictions[0].results[i].category).to.be.equal(expected_results[i].category); | ||
chai_1.expect(body.predictions[0].results[i].confidence).to.be.equal(expected_results[i].confidence); | ||
describe("files", () => { | ||
it("should detect a LCD TV", (done) => { | ||
productTextClassification.inferenceSync("./testdata/product_text.zip", null).then((body) => { | ||
chai_1.expect(body).to.have.property("_id"); | ||
chai_1.expect(body).to.have.property("predictions").to.be.an("array").with.length(1); | ||
chai_1.expect(body).to.have.property("processed_time"); | ||
chai_1.expect(body).to.have.property("request"); | ||
chai_1.expect(body).to.have.property("status").to.be.equal("DONE"); | ||
chai_1.expect(body).to.have.property("tenantName"); | ||
chai_1.expect(body.predictions[0]).to.have.property("file").to.be.equal("product_text.txt"); | ||
chai_1.expect(body.predictions[0]).to.have.property("results").to.be.an("array").with.length(5); | ||
for (let i = 0; i < expectedResults.length; i++) { | ||
chai_1.expect(body.predictions[0].results[i].category).to.be.equal(expectedResults[i].category); | ||
chai_1.expect(body.predictions[0].results[i].confidence).to.be.equal(expectedResults[i].confidence); | ||
} | ||
@@ -90,17 +47,42 @@ }).then(done, done); | ||
}); | ||
describe('error coverage', () => { | ||
it('should return a file not found error', (done) => { | ||
productTextClassification.inferenceSync("file_does_not_exist", null).then(body => { }, err => { | ||
chai_1.expect(err).to.have.property('errno').to.be.equal(-2); | ||
chai_1.expect(err).to.have.property('code').to.be.equal('ENOENT'); | ||
describe("error coverage", () => { | ||
it("should return a file not found error", (done) => { | ||
productTextClassification.inferenceSync("file_does_not_exist", null).then(() => { chai_1.expect.fail(); }, (err) => { | ||
chai_1.expect(err).to.have.property("errno").to.be.equal(-2); | ||
chai_1.expect(err).to.have.property("code").to.be.equal("ENOENT"); | ||
}).then(done, done); | ||
}); | ||
var productTextClassification = new index_1.ProductTextClassification(process.env.API_KEY, 'http://localhost:11111'); | ||
it('should return connection refused error', (done) => { | ||
productTextClassification.inferenceSync("./testdata/product_text.zip", null).then(body => { }, err => { | ||
chai_1.expect(err).to.have.property('errno').to.be.equal('ECONNREFUSED'); | ||
chai_1.expect(err).to.have.property('code').to.be.equal('ECONNREFUSED'); | ||
it("should return connection refused error", (done) => { | ||
const productTextClassificationErr = new index_1.ProductTextClassification(process.env.API_KEY, "http://localhost:11111"); | ||
productTextClassificationErr.inferenceSync("./testdata/product_text.zip", null).then(() => { chai_1.expect.fail(); }, (err) => { | ||
chai_1.expect(err).to.have.property("errno").to.be.equal("ECONNREFUSED"); | ||
chai_1.expect(err).to.have.property("code").to.be.equal("ECONNREFUSED"); | ||
}).then(done, done); | ||
}); | ||
}); | ||
// tslint:disable:object-literal-key-quotes | ||
// tslint:disable:max-line-length | ||
// tslint:disable:trailing-comma | ||
const expectedResults = [ | ||
{ | ||
"category": "LED TVs", | ||
"confidence": 0.913253 | ||
}, | ||
{ | ||
"category": "digital cameras", | ||
"confidence": 0.040222 | ||
}, | ||
{ | ||
"category": "other", | ||
"confidence": 0.03803 | ||
}, | ||
{ | ||
"category": "smartphones", | ||
"confidence": 0.004975 | ||
}, | ||
{ | ||
"category": "computer monitors", | ||
"confidence": 0.001214 | ||
} | ||
]; | ||
}); |
@@ -5,48 +5,51 @@ "use strict"; | ||
const index_1 = require("../index"); | ||
describe('SceneTextRecognition', () => { | ||
var sceneTextRecognition = new index_1.SceneTextRecognition(process.env.API_KEY); | ||
describe('scene text', () => { | ||
it('should return a text', (done) => { | ||
sceneTextRecognition.sceneTextRecognition("./testdata/stop-634941_640.jpg").then(body => { | ||
chai_1.expect(body).to.have.property('id'); | ||
chai_1.expect(body).to.have.property('predictions'); | ||
chai_1.expect(body).to.have.property('processedTime'); | ||
chai_1.expect(body).to.have.property('status').to.be.equal('DONE'); | ||
chai_1.expect(body.predictions).to.be.an('array').have.lengthOf(1); | ||
chai_1.expect(body.predictions[0]).to.have.property('results').to.be.an('array').with.lengthOf(1); | ||
var results = [ | ||
{ | ||
"bboxAccuracy": 0.955111026763916, | ||
"boundingBox": { | ||
"x1": 395, | ||
"x2": 525, | ||
"x3": 525, | ||
"x4": 395, | ||
"y1": 139, | ||
"y2": 139, | ||
"y3": 197, | ||
"y4": 197 | ||
}, | ||
"text": "stoP" | ||
} | ||
]; | ||
chai_1.expect(body.predictions[0].results[0]).to.be.eql(results[0]); | ||
describe("SceneTextRecognition", () => { | ||
const sceneTextRecognition = new index_1.SceneTextRecognition(process.env.API_KEY); | ||
describe("scene text", () => { | ||
it("should return a text", (done) => { | ||
sceneTextRecognition.sceneTextRecognition("./testdata/stop-634941_640.jpg").then((body) => { | ||
chai_1.expect(body).to.have.property("id"); | ||
chai_1.expect(body).to.have.property("predictions"); | ||
chai_1.expect(body).to.have.property("processedTime"); | ||
chai_1.expect(body).to.have.property("status").to.be.equal("DONE"); | ||
chai_1.expect(body.predictions).to.be.an("array").have.lengthOf(1); | ||
chai_1.expect(body.predictions[0]).to.have.property("results").to.be.an("array").with.lengthOf(1); | ||
chai_1.expect(body.predictions[0].results[0]).to.be.eql(expectedResults[0]); | ||
}).then(done, done); | ||
}); | ||
}); | ||
describe('error coverage', () => { | ||
it('should return a file not found error', (done) => { | ||
sceneTextRecognition.sceneTextRecognition("file_does_not_exist").then(body => { }, err => { | ||
chai_1.expect(err).to.have.property('errno').to.be.equal(-2); | ||
chai_1.expect(err).to.have.property('code').to.be.equal('ENOENT'); | ||
describe("error coverage", () => { | ||
it("should return a file not found error", (done) => { | ||
sceneTextRecognition.sceneTextRecognition("file_does_not_exist").then(() => { chai_1.expect.fail(); }, (err) => { | ||
chai_1.expect(err).to.have.property("errno").to.be.equal(-2); | ||
chai_1.expect(err).to.have.property("code").to.be.equal("ENOENT"); | ||
}).then(done, done); | ||
}); | ||
it('should return connection refused error', (done) => { | ||
var sceneTextRecognition = new index_1.SceneTextRecognition(process.env.API_KEY, 'http://localhost:11111'); | ||
sceneTextRecognition.sceneTextRecognition("./testdata/stop-634941_640.jpg").then(body => { }, err => { | ||
chai_1.expect(err).to.have.property('errno').to.be.equal('ECONNREFUSED'); | ||
chai_1.expect(err).to.have.property('code').to.be.equal('ECONNREFUSED'); | ||
it("should return connection refused error", (done) => { | ||
const sceneTextRecognitionErr = new index_1.SceneTextRecognition(process.env.API_KEY, "http://localhost:11111"); | ||
sceneTextRecognitionErr.sceneTextRecognition("./testdata/stop-634941_640.jpg").then(() => { chai_1.expect.fail(); }, (err) => { | ||
chai_1.expect(err).to.have.property("errno").to.be.equal("ECONNREFUSED"); | ||
chai_1.expect(err).to.have.property("code").to.be.equal("ECONNREFUSED"); | ||
}).then(done, done); | ||
}); | ||
}); | ||
// tslint:disable:object-literal-key-quotes | ||
// tslint:disable:max-line-length | ||
// tslint:disable:trailing-comma | ||
const expectedResults = [ | ||
{ | ||
"bboxAccuracy": 0.955111026763916, | ||
"boundingBox": { | ||
"x1": 395, | ||
"x2": 525, | ||
"x3": 525, | ||
"x4": 395, | ||
"y1": 139, | ||
"y2": 139, | ||
"y3": 197, | ||
"y4": 197 | ||
}, | ||
"text": "stoP" | ||
} | ||
]; | ||
}); |
@@ -5,39 +5,39 @@ "use strict"; | ||
const index_1 = require("../index"); | ||
describe('similarity scoring', () => { | ||
var similarityScoring = new index_1.SimilarityScoring(process.env.API_KEY); | ||
const options = JSON.stringify({ "numSimilarVectors": 2 }); | ||
describe('texts', () => { | ||
it('should detect similarity scores', (done) => { | ||
similarityScoring.similarityScoring(null, JSON.stringify(data), options).then(body => { | ||
chai_1.expect(body).to.have.property('id'); | ||
chai_1.expect(body).to.have.property('predictions'); | ||
chai_1.expect(body).to.have.property('processedTime'); | ||
chai_1.expect(body).to.have.property('status').to.be.equal('DONE'); | ||
chai_1.expect(body.predictions).to.be.an('array').have.lengthOf(3).is.eql(predictions); | ||
describe("similarity scoring", () => { | ||
const similarityScoring = new index_1.SimilarityScoring(process.env.API_KEY); | ||
const options = JSON.stringify({ numSimilarVectors: 2 }); | ||
describe("texts", () => { | ||
it("should detect similarity scores", (done) => { | ||
similarityScoring.similarityScoring(null, JSON.stringify(data), options).then((body) => { | ||
chai_1.expect(body).to.have.property("id"); | ||
chai_1.expect(body).to.have.property("predictions"); | ||
chai_1.expect(body).to.have.property("processedTime"); | ||
chai_1.expect(body).to.have.property("status").to.be.equal("DONE"); | ||
chai_1.expect(body.predictions).to.be.an("array").have.lengthOf(3).is.eql(predictions); | ||
}).then(done, done); | ||
}); | ||
}); | ||
describe('files', () => { | ||
it('should detect similarity scores', (done) => { | ||
similarityScoring.similarityScoring("./testdata/vector.zip", null, options).then(body => { | ||
chai_1.expect(body).to.have.property('id'); | ||
chai_1.expect(body).to.have.property('predictions'); | ||
chai_1.expect(body).to.have.property('processedTime'); | ||
chai_1.expect(body).to.have.property('status').to.be.equal('DONE'); | ||
chai_1.expect(body.predictions).to.be.an('array').have.lengthOf(3).is.eql(predictions); | ||
describe("files", () => { | ||
it("should detect similarity scores", (done) => { | ||
similarityScoring.similarityScoring("./testdata/vector.zip", null, options).then((body) => { | ||
chai_1.expect(body).to.have.property("id"); | ||
chai_1.expect(body).to.have.property("predictions"); | ||
chai_1.expect(body).to.have.property("processedTime"); | ||
chai_1.expect(body).to.have.property("status").to.be.equal("DONE"); | ||
chai_1.expect(body.predictions).to.be.an("array").have.lengthOf(3).is.eql(predictions); | ||
}).then(done, done); | ||
}); | ||
}); | ||
describe('similarity scoring with different options', () => { | ||
var similarityScoring = new index_1.SimilarityScoring(process.env.API_KEY); | ||
describe('texts', () => { | ||
it('should detect similarity scores for 1 similar vector', (done) => { | ||
const options = JSON.stringify({ "numSimilarVectors": 1 }); | ||
similarityScoring.similarityScoring(null, JSON.stringify(data), options).then(body => { | ||
chai_1.expect(body).to.have.property('id'); | ||
chai_1.expect(body).to.have.property('predictions'); | ||
chai_1.expect(body).to.have.property('processedTime'); | ||
chai_1.expect(body).to.have.property('status').to.be.equal('DONE'); | ||
chai_1.expect(body.predictions).to.be.an('array').have.lengthOf(3); | ||
for (var i = 0; i < 3; i++) { | ||
describe("similarity scoring with different options", () => { | ||
const similarityScoringWithOptions = new index_1.SimilarityScoring(process.env.API_KEY); | ||
describe("texts", () => { | ||
it("should detect similarity scores for 1 similar vector", (done) => { | ||
const optionsOne = JSON.stringify({ numSimilarVectors: 1 }); | ||
similarityScoringWithOptions.similarityScoring(null, JSON.stringify(data), optionsOne).then((body) => { | ||
chai_1.expect(body).to.have.property("id"); | ||
chai_1.expect(body).to.have.property("predictions"); | ||
chai_1.expect(body).to.have.property("processedTime"); | ||
chai_1.expect(body).to.have.property("status").to.be.equal("DONE"); | ||
chai_1.expect(body.predictions).to.be.an("array").have.lengthOf(3); | ||
for (let i = 0; i < 3; i++) { | ||
chai_1.expect(body.predictions[i].similarVectors[0].score).to.be.equal(predictions[i].similarVectors[0].score); | ||
@@ -49,18 +49,21 @@ } | ||
}); | ||
describe('error coverage', () => { | ||
it('should return a file not found error', (done) => { | ||
similarityScoring.similarityScoring("file_does_not_exist", null, "").then(body => { }, err => { | ||
chai_1.expect(err).to.have.property('errno').to.be.equal(-2); | ||
chai_1.expect(err).to.have.property('code').to.be.equal('ENOENT'); | ||
describe("error coverage", () => { | ||
it("should return a file not found error", (done) => { | ||
similarityScoringErr.similarityScoring("file_does_not_exist", null, "").then(() => { chai_1.expect.fail(); }, (err) => { | ||
chai_1.expect(err).to.have.property("errno").to.be.equal(-2); | ||
chai_1.expect(err).to.have.property("code").to.be.equal("ENOENT"); | ||
}).then(done, done); | ||
}); | ||
var similarityScoring = new index_1.SimilarityScoring(process.env.API_KEY, 'http://localhost:11111'); | ||
it('should return connection refused error', (done) => { | ||
similarityScoring.similarityScoring("./testdata/product_text.zip", null, "").then(body => { }, err => { | ||
chai_1.expect(err).to.have.property('errno').to.be.equal('ECONNREFUSED'); | ||
chai_1.expect(err).to.have.property('code').to.be.equal('ECONNREFUSED'); | ||
const similarityScoringErr = new index_1.SimilarityScoring(process.env.API_KEY, "http://localhost:11111"); | ||
it("should return connection refused error", (done) => { | ||
similarityScoringErr.similarityScoring("./testdata/product_text.zip", null, "").then(() => { chai_1.expect.fail(); }, (err) => { | ||
chai_1.expect(err).to.have.property("errno").to.be.equal("ECONNREFUSED"); | ||
chai_1.expect(err).to.have.property("code").to.be.equal("ECONNREFUSED"); | ||
}).then(done, done); | ||
}); | ||
}); | ||
var data = { | ||
// tslint:disable:object-literal-key-quotes | ||
// tslint:disable:max-line-length | ||
// tslint:disable:trailing-comma | ||
const data = { | ||
"0": [ | ||
@@ -81,3 +84,3 @@ { | ||
}; | ||
var predictions = [ | ||
const predictions = [ | ||
{ | ||
@@ -113,12 +116,12 @@ "id": "vector_0", | ||
{ | ||
"id": "vector_1", | ||
"score": 0.853805753175138 | ||
id: "vector_1", | ||
score: 0.853805753175138 | ||
}, | ||
{ | ||
"id": "vector_0", | ||
"score": 0.849864721937753 | ||
id: "vector_0", | ||
score: 0.849864721937753 | ||
} | ||
] | ||
} | ||
}, | ||
]; | ||
}); |
@@ -5,10 +5,10 @@ "use strict"; | ||
const index_1 = require("../index"); | ||
describe('translation', () => { | ||
var translation = new index_1.Translation(process.env.API_KEY); | ||
describe('translate text', () => { | ||
const text_english = "This service translates text from a source language into several target languages."; | ||
const text_deutsch = "Dieser Service übersetzt Text aus einer Quellsprache in mehrere Zielsprachen."; | ||
const text_español = "Este servicio convierte texto de un idioma fuente en varios idiomas de destino."; | ||
it('should translate English to German', (done) => { | ||
let request = { | ||
describe("translation", () => { | ||
const translation = new index_1.Translation(process.env.API_KEY); | ||
describe("translate text", () => { | ||
const textEnglish = "This service translates text from a source language into several target languages."; | ||
const textDeutsch = "Dieser Service übersetzt Text aus einer Quellsprache in mehrere Zielsprachen."; | ||
const textEspañol = "Este servicio convierte texto de un idioma fuente en varios idiomas de destino."; | ||
it("should translate English to German", (done) => { | ||
const request = { | ||
sourceLanguage: "en", | ||
@@ -18,17 +18,17 @@ targetLanguages: ["de"], | ||
{ | ||
value: text_english, | ||
key: "TEXT_ENGLISH" | ||
} | ||
] | ||
key: "TEXT_ENGLISH", | ||
value: textEnglish, | ||
}, | ||
], | ||
}; | ||
translation.translation(request).then(body => { | ||
chai_1.expect(body).to.have.property('units').to.be.an('array').have.lengthOf(1); | ||
chai_1.expect(body.units[0]).to.have.property('value').to.be.equal(text_english); | ||
chai_1.expect(body.units[0]).to.have.property('translations').to.be.an('array').have.lengthOf(1); | ||
chai_1.expect(body.units[0].translations[0]).to.have.property('language').to.be.equal('de'); | ||
chai_1.expect(body.units[0].translations[0]).to.have.property('value').to.be.equal(text_deutsch); | ||
translation.translation(request).then((body) => { | ||
chai_1.expect(body).to.have.property("units").to.be.an("array").have.lengthOf(1); | ||
chai_1.expect(body.units[0]).to.have.property("value").to.be.equal(textEnglish); | ||
chai_1.expect(body.units[0]).to.have.property("translations").to.be.an("array").have.lengthOf(1); | ||
chai_1.expect(body.units[0].translations[0]).to.have.property("language").to.be.equal("de"); | ||
chai_1.expect(body.units[0].translations[0]).to.have.property("value").to.be.equal(textDeutsch); | ||
}).then(done, done); | ||
}); | ||
it('should translate German to English', (done) => { | ||
let body = { | ||
it("should translate German to English", (done) => { | ||
const translationRequest = { | ||
sourceLanguage: "de", | ||
@@ -38,17 +38,17 @@ targetLanguages: ["en"], | ||
{ | ||
value: text_deutsch, | ||
key: "TEXT_DEUTSCH" | ||
} | ||
] | ||
key: "TEXT_DEUTSCH", | ||
value: textDeutsch, | ||
}, | ||
], | ||
}; | ||
translation.translation(body).then(body => { | ||
chai_1.expect(body).to.have.property('units').to.be.an('array').have.lengthOf(1); | ||
chai_1.expect(body.units[0]).to.have.property('value').to.be.equal(text_deutsch); | ||
chai_1.expect(body.units[0]).to.have.property('translations').to.be.an('array').have.lengthOf(1); | ||
chai_1.expect(body.units[0].translations[0]).to.have.property('language').to.be.equal('en'); | ||
chai_1.expect(body.units[0].translations[0]).to.have.property('value').to.be.equal(text_english); | ||
translation.translation(translationRequest).then((body) => { | ||
chai_1.expect(body).to.have.property("units").to.be.an("array").have.lengthOf(1); | ||
chai_1.expect(body.units[0]).to.have.property("value").to.be.equal(textDeutsch); | ||
chai_1.expect(body.units[0]).to.have.property("translations").to.be.an("array").have.lengthOf(1); | ||
chai_1.expect(body.units[0].translations[0]).to.have.property("language").to.be.equal("en"); | ||
chai_1.expect(body.units[0].translations[0]).to.have.property("value").to.be.equal(textEnglish); | ||
}).then(done, done); | ||
}); | ||
it('should translate English to German and Spanish', (done) => { | ||
let body = { | ||
it("should translate English to German and Spanish", (done) => { | ||
const translationRequest = { | ||
sourceLanguage: "en", | ||
@@ -58,19 +58,19 @@ targetLanguages: ["de", "es"], | ||
{ | ||
value: text_english, | ||
key: "TEXT_ENGLISH" | ||
} | ||
] | ||
key: "TEXT_ENGLISH", | ||
value: textEnglish, | ||
}, | ||
], | ||
}; | ||
translation.translation(body).then(body => { | ||
chai_1.expect(body).to.have.property('units').to.be.an('array').have.lengthOf(1); | ||
chai_1.expect(body.units[0]).to.have.property('value').to.be.equal(text_english); | ||
chai_1.expect(body.units[0]).to.have.property('translations').to.be.an('array').have.lengthOf(2); | ||
chai_1.expect(body.units[0].translations[0]).to.have.property('language').to.be.equal('de'); | ||
chai_1.expect(body.units[0].translations[0]).to.have.property('value').to.be.equal(text_deutsch); | ||
chai_1.expect(body.units[0].translations[1]).to.have.property('language').to.be.equal('es'); | ||
chai_1.expect(body.units[0].translations[1]).to.have.property('value').to.be.equal(text_español); | ||
translation.translation(translationRequest).then((body) => { | ||
chai_1.expect(body).to.have.property("units").to.be.an("array").have.lengthOf(1); | ||
chai_1.expect(body.units[0]).to.have.property("value").to.be.equal(textEnglish); | ||
chai_1.expect(body.units[0]).to.have.property("translations").to.be.an("array").have.lengthOf(2); | ||
chai_1.expect(body.units[0].translations[0]).to.have.property("language").to.be.equal("de"); | ||
chai_1.expect(body.units[0].translations[0]).to.have.property("value").to.be.equal(textDeutsch); | ||
chai_1.expect(body.units[0].translations[1]).to.have.property("language").to.be.equal("es"); | ||
chai_1.expect(body.units[0].translations[1]).to.have.property("value").to.be.equal(textEspañol); | ||
}).then(done, done); | ||
}); | ||
it('should translate Spanish to English, but Spanish to German is not available', (done) => { | ||
let body = { | ||
it("should translate Spanish to English, but Spanish to German is not available", (done) => { | ||
const translationRequest = { | ||
sourceLanguage: "es", | ||
@@ -80,22 +80,24 @@ targetLanguages: ["en", "de"], | ||
{ | ||
value: text_español, | ||
key: "TEXT_ESPAÑOL" | ||
} | ||
] | ||
key: "TEXT_ESPAÑOL", | ||
value: textEspañol, | ||
}, | ||
], | ||
}; | ||
translation.translation(body).then(body => { | ||
chai_1.expect(body).to.have.property('units').to.be.an('array').have.lengthOf(1); | ||
chai_1.expect(body.units[0]).to.have.property('value').to.be.equal(text_español); | ||
chai_1.expect(body.units[0]).to.have.property('translations').to.be.an('array').have.lengthOf(2); | ||
chai_1.expect(body.units[0].translations[0]).to.have.property('language').to.be.equal('en'); | ||
chai_1.expect(body.units[0].translations[0]).to.have.property('value').to.be.not.null; | ||
chai_1.expect(body.units[0].translations[1]).to.have.property('language').to.be.equal('de'); | ||
chai_1.expect(body.units[0].translations[1]).to.have.property('value').to.be.null; | ||
translation.translation(translationRequest).then((body) => { | ||
chai_1.expect(body).to.have.property("units").to.be.an("array").have.lengthOf(1); | ||
chai_1.expect(body.units[0]).to.have.property("value").to.be.equal(textEspañol); | ||
chai_1.expect(body.units[0]).to.have.property("translations").to.be.an("array").have.lengthOf(2); | ||
chai_1.expect(body.units[0].translations[0]).to.have.property("language").to.be.equal("en"); | ||
// tslint:disable-next-line:no-unused-expression | ||
chai_1.expect(body.units[0].translations[0]).to.have.property("value").to.be.not.null; | ||
chai_1.expect(body.units[0].translations[1]).to.have.property("language").to.be.equal("de"); | ||
// tslint:disable-next-line:no-unused-expression | ||
chai_1.expect(body.units[0].translations[1]).to.have.property("value").to.be.null; | ||
}).then(done, done); | ||
}); | ||
}); | ||
describe('error coverage', () => { | ||
var translation = new index_1.Translation(process.env.API_KEY, 'http://localhost:11111'); | ||
it('should return connection refused error', (done) => { | ||
let body = { | ||
describe("error coverage", () => { | ||
const translationErr = new index_1.Translation(process.env.API_KEY, "http://localhost:11111"); | ||
it("should return connection refused error", (done) => { | ||
const body = { | ||
sourceLanguage: "es", | ||
@@ -105,10 +107,10 @@ targetLanguages: ["en", "de"], | ||
{ | ||
key: "TEXT_ESPAÑOL", | ||
value: "", | ||
key: "TEXT_ESPAÑOL" | ||
} | ||
] | ||
}, | ||
], | ||
}; | ||
translation.translation(body).then(body => { }, err => { | ||
chai_1.expect(err).to.have.property('errno').to.be.equal('ECONNREFUSED'); | ||
chai_1.expect(err).to.have.property('code').to.be.equal('ECONNREFUSED'); | ||
translationErr.translation(body).then(() => { chai_1.expect.fail(); }, (err) => { | ||
chai_1.expect(err).to.have.property("errno").to.be.equal("ECONNREFUSED"); | ||
chai_1.expect(err).to.have.property("code").to.be.equal("ECONNREFUSED"); | ||
}).then(done, done); | ||
@@ -115,0 +117,0 @@ }); |
@@ -1,8 +0,8 @@ | ||
import { Promise } from 'es6-promise'; | ||
export interface TranslationRequest { | ||
import { Promise } from "es6-promise"; | ||
export interface ITranslationRequest { | ||
sourceLanguage: string; | ||
targetLanguages: string[]; | ||
units: TextTranslationRequest[]; | ||
units: ITextTranslationRequest[]; | ||
} | ||
export interface TextTranslationRequest { | ||
export interface ITextTranslationRequest { | ||
value: string; | ||
@@ -12,6 +12,6 @@ key: string; | ||
export declare class Translation { | ||
private _apiKey; | ||
private _baseUrl; | ||
private apiKey; | ||
private baseUrl; | ||
constructor(apiKey: any, baseUrl?: string); | ||
translation(body: TranslationRequest): Promise<any>; | ||
translation(translationRequest: ITranslationRequest): Promise<any>; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const assert = require("assert"); | ||
const es6_promise_1 = require("es6-promise"); | ||
const request = require("request"); | ||
const es6_promise_1 = require("es6-promise"); | ||
const assert = require("assert"); | ||
class Translation { | ||
constructor(apiKey, baseUrl = "https://sandbox.api.sap.com") { | ||
assert(apiKey, "apiKey is required"); | ||
this._apiKey = apiKey; | ||
this._baseUrl = baseUrl; | ||
this.apiKey = apiKey; | ||
this.baseUrl = baseUrl; | ||
} | ||
translation(body) { | ||
translation(translationRequest) { | ||
return new es6_promise_1.Promise((resolve, reject) => { | ||
var headers = { | ||
"Content-Type": 'application/json', | ||
Accept: 'application/json', | ||
APIKey: this._apiKey | ||
const headers = { | ||
"APIKey": this.apiKey, | ||
"Accept": "application/json", | ||
"Content-Type": "application/json", | ||
}; | ||
var url = this._baseUrl + "/ml/translation/translation"; | ||
var data = JSON.stringify(body); | ||
request.post({ url: url, body: data, headers: headers }, (err, response, body) => { | ||
const url = this.baseUrl + "/ml/translation/translation"; | ||
const data = JSON.stringify(translationRequest); | ||
request.post({ url, body: data, headers }, (err, response, body) => { | ||
if (err) { | ||
@@ -23,0 +23,0 @@ return reject(err); |
{ | ||
"name": "sap-leonardo", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "NPM module for SAP Leonardo Machine Learning Foundation - Functional Services https://api.sap.com/package/SAPLeonardoMLFunctionalServices", | ||
@@ -9,3 +9,3 @@ "main": "dist/index.js", | ||
"test": "npm run build && ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha --report lcovonly -- -s 30000 -t 30000 dist/test/test_*.js && cat ./coverage/lcov.info | ./node_modules/.bin/coveralls", | ||
"lint": "npm run build && ./node_modules/.bin/eslint dist/*.js" | ||
"lint": "./node_modules/.bin/tslint src/**/*.ts && ./node_modules/.bin/eslint examples/*.js" | ||
}, | ||
@@ -20,4 +20,3 @@ "author": "Lars Gregori <github@larsgregori.de>", | ||
"dist/", | ||
"README.md", | ||
"LICENSE" | ||
"README.md" | ||
], | ||
@@ -43,3 +42,3 @@ "keywords": [ | ||
"devDependencies": { | ||
"@types/chai": "^4.1.5", | ||
"@types/chai": "^4.1.6", | ||
"@types/mocha": "^5.2.5", | ||
@@ -49,8 +48,9 @@ "@types/request": "^2.47.1", | ||
"coveralls": "^3.0.2", | ||
"eslint": "^5.6.0", | ||
"eslint": "^5.6.1", | ||
"istanbul": "^0.4.5", | ||
"mocha": "^5.2.0", | ||
"ts-node": "^7.0.1", | ||
"tslint": "^5.11.0", | ||
"typescript": "^3.1.1" | ||
} | ||
} |
@@ -17,4 +17,2 @@ # SAP Leonardo Machine Learning Foundation - Functional Services | ||
Sign up a free account at [SAP API Business Hub](https://api.sap.com/). | ||
Install the npm package: | ||
@@ -25,2 +23,4 @@ ```sh | ||
Sign up a free account at [SAP API Business Hub](https://api.sap.com/) and get your API key. | ||
Use e.g. the image classification service with your API key: | ||
@@ -30,12 +30,10 @@ ```javascript | ||
var imageclassification = new leonardo.Imageclassification("apiKey3x4mpleUs3y0ur0wnKey123abc"); | ||
var imageclassification = new leonardo.Imageclassification("apiKey"); | ||
imageclassification.classification("./elephant-114543_640.jpg") | ||
.then(body => { | ||
console.log(JSON.stringify(body, null, " ")); | ||
.then((body) => { | ||
var firstResult = body.predictions[0].results[0]; | ||
console.log("RESULT:", firstResult.label, firstResult.score) | ||
// RESULT: tusker 0.7052137851715088 | ||
console.log("result:", firstResult.label, firstResult.score); | ||
// result: tusker 0.7052137851715088 | ||
}) | ||
.catch(err => { console.error(err) }); | ||
.catch((err) => { console.error(err); }); | ||
``` | ||
@@ -47,17 +45,36 @@ More examples can be found in the examples and src/test folder. | ||
Following services are implemented (unordered; the way I've added them): | ||
Following services (with a link) are implemented: | ||
- [Inference Service for Customizable Image Classification](https://api.sap.com/api/image_classification_api/resource) | ||
- [Inference Service for Optical Character Recognition (OCR)](https://api.sap.com/api/ocr_api/resource) | ||
- [Inference Service for Machine Translation](https://api.sap.com/api/translation_api/resource) | ||
- [Inference Service for Language Detection](https://api.sap.com/api/language_detection_api/resource) | ||
- [Inference Service for Face Detection](https://api.sap.com/api/face_detection_api/resource) | ||
- [Inference Service for Human Detection](https://api.sap.com/api/human_detection_api/resource) | ||
- [Inference Service For Customizable Image Feature Extraction](https://api.sap.com/api/img_feature_extraction_api/resource) | ||
- [Product Text Classification API](https://api.sap.com/api/product_text_classification_api/resource) | ||
- [Inference Service for Multi-Instance Image Segmentation](https://api.sap.com/api/instance_segmentor_api/resource) | ||
- [Inference Service for Scene Text Recognition](https://api.sap.com/api/scene_text_recognition_api/resource) | ||
- [Inference Service for Document Feature Extraction](https://api.sap.com/api/document_feature_extraction_api/resource) | ||
- [Inference Service for Multi-Instance Image Segmentation](https://api.sap.com/api/instance_segmentor_api/resource) | ||
- [Inference Service for Face Feature Extraction](https://api.sap.com/api/face_feature_extraction_api/resource) | ||
- [Inference Service for Machine Translation](https://api.sap.com/api/translation_api/resource) | ||
- ~~Training Service for Customizable Object Detection~~ | ||
- [Inference Service for Similarity Scoring](https://api.sap.com/api/similarity_scoring_api/resource) | ||
- [Inference Service For Customizable Image Feature Extraction](https://api.sap.com/api/img_feature_extraction_api/resource) | ||
- [Inference Service for Customizable Image Classification](https://api.sap.com/api/image_classification_api/resource) | ||
- ~~Time Series Changepoint Detection API~~ | ||
- ~~Product Image Classification API~~ | ||
- ~~Training Service for Customizable Similarity Search~~ | ||
- ~~Inference Service for Customizable Similarity Search~~ | ||
- ~~Inference Service for Topic Detection~~ | ||
- [Inference Service for Human Detection](https://api.sap.com/api/human_detection_api/resource) | ||
- [Inference Service for Face Detection](https://api.sap.com/api/face_detection_api/resource) | ||
- [Inference Service for Language Detection](https://api.sap.com/api/language_detection_api/resource) | ||
- ~~Training Service for Customizable Text Classification~~ | ||
- ~~Inference Service for Customizable Object Detection~~~~ | ||
- [Inference Service for Optical Character Recognition (OCR)](https://api.sap.com/api/ocr_api/resource) | ||
- ~~Inference Service for Customizable Text Classification~~ | ||
- ~~Training Service For Customizable Image Classification and Feature Extraction~~ | ||
## Build | ||
@@ -88,2 +105,6 @@ | ||
## Blog Posts | ||
- [NPM Module for SAP Leonardo Machine Learning](https://blogs.sap.com/2018/10/04/npm-module-for-sap-leonardo-machine-learning/) | ||
## Image Sources | ||
@@ -98,3 +119,6 @@ | ||
- [testdata/chucks-153310_640.png](https://pixabay.com/en/chucks-converse-shoes-footwear-153310/) | ||
- [hiking-shoes-3074971_640.png](https://pixabay.com/en/hiking-shoes-boots-leather-3074971/) | ||
- [converse-2069209_640.jpg](https://pixabay.com/en/converse-shoes-grass-outdoors-2069209/) | ||
## License | ||
@@ -101,0 +125,0 @@ |
196367
4680
126
44
11
60