nodejs-nomer 1.3.4 → 1.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/DEVELOPMENT.md ADDED
@@ -0,0 +1,26 @@
1
+ # DEVELOPMENT
2
+
3
+ Build:
4
+ `npm run build`
5
+
6
+ Link:
7
+
8
+ `npm link`
9
+
10
+ Use package for testing:
11
+ `npm link nodejs-nomer`
12
+
13
+ Run `script.js`
14
+ `node script.js`
15
+
16
+ # PUBLISH
17
+
18
+ Update minor version:
19
+ `npm version minor`
20
+
21
+ Publish
22
+ `npm publish`
23
+
24
+ Push to git
25
+ `npm push`
26
+
package/dist/index.js ADDED
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Nomer = void 0;
7
+ var _utils = require("./utils");
8
+ var _result = _interopRequireDefault(require("./result"));
9
+ var _propertiesFile = require("properties-file");
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
11
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
12
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
13
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
14
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
15
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
16
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
17
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
18
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
19
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
20
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
21
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
22
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
23
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
24
+ var Nomer = exports.Nomer = /*#__PURE__*/function () {
25
+ function Nomer() {
26
+ var propertiesPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
27
+ var echoOpt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
28
+ _classCallCheck(this, Nomer);
29
+ _defineProperty(this, "propertiesPath", null);
30
+ _defineProperty(this, "echoOpt", "");
31
+ this.propertiesPath = propertiesPath;
32
+ this.echoOpt = echoOpt;
33
+ }
34
+
35
+ /**
36
+ * Show version
37
+ * @returns string
38
+ */
39
+ return _createClass(Nomer, [{
40
+ key: "version",
41
+ value: function version() {
42
+ var res = (0, _utils.runNomer)((0, _utils.getNomerSimpleCmd)());
43
+ return res;
44
+ }
45
+ }, {
46
+ key: "clean",
47
+ value: function clean() {
48
+ var res = (0, _utils.runNomer)((0, _utils.getNomerSimpleCmd)("clean", false, this.getPropertiesPath()));
49
+ return res;
50
+ }
51
+ }, {
52
+ key: "inputSchema",
53
+ value: function inputSchema() {
54
+ var res = (0, _utils.runNomer)((0, _utils.getNomerSimpleCmd)("input-schema", false, this.getPropertiesPath()));
55
+ return res;
56
+ }
57
+ }, {
58
+ key: "outputSchema",
59
+ value: function outputSchema() {
60
+ var res = (0, _utils.runNomer)((0, _utils.getNomerSimpleCmd)("output-schema", false, this.getPropertiesPath()));
61
+ return res;
62
+ }
63
+ }, {
64
+ key: "properties",
65
+ value: function properties() {
66
+ var res = (0, _utils.runNomer)((0, _utils.getNomerSimpleCmd)("properties", false, this.getPropertiesPath()));
67
+ return res;
68
+ }
69
+ }, {
70
+ key: "matcher",
71
+ value: function matcher() {
72
+ var outputFormat = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "tsv";
73
+ var verbose = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
74
+ var res = (0, _utils.runNomer)((0, _utils.getNomerSimpleCmd)("matchers", verbose, null, outputFormat));
75
+ return res;
76
+ }
77
+ }, {
78
+ key: "validateTerm",
79
+ value: function validateTerm() {
80
+ var filepath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
81
+ var res = (0, _utils.runNomer)((0, _utils.getNomerValidateCmd)(filepath, "validate-term-link", this.getPropertiesPath()));
82
+ return res;
83
+ }
84
+ }, {
85
+ key: "replace",
86
+ value: function replace() {
87
+ var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
88
+ var matcher = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "globi-taxon-cache";
89
+ var res = (0, _utils.runNomer)((0, _utils.getNomerMatchCmd)(query, "replace", matcher, this.getPropertiesPath(), null, this.echoOpt));
90
+ return res;
91
+ }
92
+ }, {
93
+ key: "append",
94
+ value: function append() {
95
+ var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
96
+ var matcher = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "globi-taxon-cache";
97
+ var outputFormat = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "tsv";
98
+ var res = (0, _utils.runNomer)((0, _utils.getNomerMatchCmd)(query, "append", matcher, this.getPropertiesPath(), outputFormat, this.echoOpt), query);
99
+ return res;
100
+ }
101
+ }, {
102
+ key: "appendAsync",
103
+ value: function appendAsync() {
104
+ var matcher = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "globi-taxon-cache";
105
+ var outputFormat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "tsv";
106
+ return (0, _utils.runNomerAsync)("nomer append ".concat(matcher, " -o ").concat(outputFormat));
107
+ }
108
+ }, {
109
+ key: "getPropertiesPath",
110
+ value: function getPropertiesPath() {
111
+ return this.propertiesPath;
112
+ }
113
+ }, {
114
+ key: "toJson",
115
+ value: function toJson(result) {
116
+ return _result["default"].json(result);
117
+ }
118
+ }, {
119
+ key: "toArray",
120
+ value: function toArray(result) {
121
+ var columns = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
122
+ return _result["default"].tsv(result, columns);
123
+ }
124
+ }, {
125
+ key: "toObject",
126
+ value: function toObject(result) {
127
+ var content = this.properties(this.getPropertiesPath());
128
+ var properties = (0, _propertiesFile.getProperties)(content);
129
+ var schemaInput = JSON.parse(properties["nomer.schema.input"]).map(function (i) {
130
+ return i.type + 'Input';
131
+ });
132
+ var schemaAppend = JSON.parse(properties["nomer.append.schema.output"]).map(function (i) {
133
+ return i.type;
134
+ });
135
+ return _result["default"].tsv(result, [].concat(_toConsumableArray(schemaInput), ["matchType"], _toConsumableArray(schemaAppend)));
136
+ }
137
+ }]);
138
+ }();
package/dist/result.js ADDED
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
8
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
9
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
10
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
11
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
12
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
13
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
14
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
15
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
16
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
17
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
18
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
19
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
20
+ var Result = exports["default"] = /*#__PURE__*/function () {
21
+ function Result() {
22
+ _classCallCheck(this, Result);
23
+ }
24
+ return _createClass(Result, null, [{
25
+ key: "json",
26
+ value: function json(result) {
27
+ var arr = [];
28
+ result.split("\n").forEach(function (e) {
29
+ return arr.push(JSON.parse(e));
30
+ });
31
+ return arr;
32
+ }
33
+ }, {
34
+ key: "tsv",
35
+ value: function tsv(result) {
36
+ var columns = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
37
+ var arr = [];
38
+ result.split('\n').forEach(function (line) {
39
+ arr.push(line.split('\t'));
40
+ });
41
+ return columns ? arr.map(function (v) {
42
+ return Object.assign.apply(Object, _toConsumableArray(columns.map(function (k, i) {
43
+ return _defineProperty({}, k, v[i]);
44
+ })));
45
+ }) : arr;
46
+ }
47
+ }]);
48
+ }();
package/dist/utils.js ADDED
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.runNomerAsync = exports.runNomer = exports.getNomerValidateCmd = exports.getNomerSimpleCmd = exports.getNomerMatchCmd = void 0;
7
+ var _require = require('child_process'),
8
+ execSync = _require.execSync,
9
+ spawn = _require.spawn;
10
+ var getNomerValidateCmd = exports.getNomerValidateCmd = function getNomerValidateCmd() {
11
+ var filepath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
12
+ var cmd = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "validate-term";
13
+ var properties = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
14
+ if (filepath === "") {
15
+ throw new Exception("Filepath cannot be empty string");
16
+ }
17
+ var nomerCmd = "curl -L ".concat(filepath, " | nomer ").concat(cmd);
18
+ if (properties) {
19
+ nomerCmd = "".concat(nomerCmd, " -p ").concat(properties);
20
+ }
21
+ return nomerCmd;
22
+ };
23
+ var getNomerMatchCmd = exports.getNomerMatchCmd = function getNomerMatchCmd() {
24
+ var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
25
+ var cmd = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "append";
26
+ var matcher = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "globi-taxon-cache";
27
+ var properties = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
28
+ var outputFormat = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
29
+ var echoOpt = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : "-e";
30
+ var nomerCmd = "echo ".concat(echoOpt, " '").concat(query, "' | nomer ").concat(cmd, " ").concat(matcher);
31
+ if (properties) {
32
+ nomerCmd = "".concat(nomerCmd, " -p ").concat(properties);
33
+ }
34
+ if (outputFormat) {
35
+ nomerCmd = "".concat(nomerCmd, " -o ").concat(outputFormat);
36
+ }
37
+ return nomerCmd;
38
+ };
39
+ var getNomerSimpleCmd = exports.getNomerSimpleCmd = function getNomerSimpleCmd() {
40
+ var cmd = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "version";
41
+ var verbose = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
42
+ var properties = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
43
+ var outputFormat = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
44
+ var nomerCmd = "nomer ".concat(cmd);
45
+ if (properties) {
46
+ nomerCmd = "".concat(nomerCmd, " -p ").concat(properties);
47
+ }
48
+ if (outputFormat) {
49
+ nomerCmd = "".concat(nomerCmd, " -o ").concat(outputFormat);
50
+ }
51
+ if (verbose) {
52
+ nomerCmd = "".concat(nomerCmd, " -v");
53
+ }
54
+ return nomerCmd;
55
+ };
56
+ var runNomer = exports.runNomer = function runNomer(nomerCmd) {
57
+ try {
58
+ var result = execSync(nomerCmd, {
59
+ maxBuffer: 4096 * 4096
60
+ }).toString();
61
+ if (result) {
62
+ return result.trimEnd();
63
+ }
64
+ } catch (error) {
65
+ console.log("Error running nomer cmd: " + error.message);
66
+ return null;
67
+ }
68
+ };
69
+ var runNomerAsync = exports.runNomerAsync = function runNomerAsync(nomerCmd) {
70
+ var nomerCmdArr = nomerCmd.split(/\s+/);
71
+ var p = spawn(nomerCmdArr[0], nomerCmdArr.slice(1), {
72
+ // maxBuffer: 4096 * 4096
73
+ shell: true
74
+ });
75
+ return p;
76
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodejs-nomer",
3
- "version": "1.3.4",
3
+ "version": "1.3.7",
4
4
  "description": "NodeJS wrapper for nomer",
5
5
  "bin": {
6
6
  "nomer": "./bin/nomer"
package/src/index.js CHANGED
@@ -93,8 +93,8 @@ export class Nomer {
93
93
  return Result.json(result);
94
94
  }
95
95
 
96
- toArray(result) {
97
- return Result.tsv(result);
96
+ toArray(result, columns = null) {
97
+ return Result.tsv(result, columns);
98
98
  }
99
99
 
100
100
  toObject(result) {
package/test/script.js ADDED
@@ -0,0 +1,46 @@
1
+ const Nomer = require("nodejs-nomer")
2
+
3
+ const nomer = new Nomer.Nomer();
4
+
5
+ console.time("version")
6
+ console.log(nomer.version());
7
+ console.timeEnd("version")
8
+
9
+
10
+ console.time("append async")
11
+ const process = nomer.appendAsync("col")
12
+ const resultsAsync = []
13
+
14
+ const result = (stdout) => new Promise(resolve => {
15
+ stdout.on('data', async (data) => {
16
+ console.log(data.toString())
17
+ return nomer.toObject(data).filter((obj) => obj.matchType !== "NONE")
18
+
19
+ })
20
+ stdout.on('end', () => {
21
+ resolve('end')
22
+ })
23
+ })
24
+
25
+ p = result(process.stdout)
26
+ for (let index = 0; index < 1000; index++) {
27
+ process.stdin.write("\tBauhinia rufa\t\n")
28
+ }
29
+ process.stdin.end()
30
+
31
+ result.then((v) => console.log(v))
32
+
33
+
34
+ // console.time("append")
35
+ // const results = []
36
+ // for (let index = 0; index < 100; index++) {
37
+ // results.push(nomer.append("\tBauhinia rufa\t", "gbif"))
38
+ // }
39
+ // console.timeEnd("append")
40
+
41
+ // console.time("toObject")
42
+ // for (let index = 0; index < results.length; index++) {
43
+ // const element = results[index];
44
+ // nomer.toObject(element)
45
+ // }
46
+ // console.timeEnd("toObject")