oxford-text-checker
Version:
OxfordTextChecker wrapper - analyzes vocabulary in your text
159 lines • 7.89 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
to[j] = from[i];
return to;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TextChecker = exports.DictionaryTypeEnum = void 0;
/* tslint:disable */
var Main_1 = require("./oxford-text-checker-source/Main");
var text_1 = require("./oxford-text-checker-source/text");
var DictionaryTypeEnum;
(function (DictionaryTypeEnum) {
DictionaryTypeEnum["OX3K"] = "ox3k";
DictionaryTypeEnum["OX5K"] = "ox5k";
DictionaryTypeEnum["OX5K_ONLY"] = "ox5k_only";
DictionaryTypeEnum["OPAL"] = "opal";
})(DictionaryTypeEnum = exports.DictionaryTypeEnum || (exports.DictionaryTypeEnum = {}));
var ComplexityTypeEnum;
(function (ComplexityTypeEnum) {
ComplexityTypeEnum["A1"] = "a1";
ComplexityTypeEnum["A2"] = "a2";
ComplexityTypeEnum["B1"] = "b1";
ComplexityTypeEnum["B2"] = "b2";
ComplexityTypeEnum["C1"] = "c1";
ComplexityTypeEnum["Unclassified"] = "uncl";
/** Oxford Phrasal Academic Lexicon. */
ComplexityTypeEnum["OPAL"] = "opal";
})(ComplexityTypeEnum || (ComplexityTypeEnum = {}));
/**
* OxfordTextChecker wrapper - analyzes vocabulary in your text.
*/
var TextChecker = /** @class */ (function (_super) {
__extends(TextChecker, _super);
// @ts-ignore:disable-next-line
function TextChecker(props) {
var _a, _b, _c, _d;
var _this = this;
var text = (_a = props === null || props === void 0 ? void 0 : props.text) !== null && _a !== void 0 ? _a : '';
var ignoreCase = (_b = !(props === null || props === void 0 ? void 0 : props.isIgnoreCase)) !== null && _b !== void 0 ? _b : false;
var ignoreNumbers = (_c = !(props === null || props === void 0 ? void 0 : props.isIgnoreNumbers)) !== null && _c !== void 0 ? _c : false;
var texttobeIgnored = __spreadArray([], ((_d = props === null || props === void 0 ? void 0 : props.ignoredText) !== null && _d !== void 0 ? _d : []));
_this = _super.call(this, { text: text, ignoreCase: ignoreCase, ignoreNumbers: ignoreNumbers, texttobeIgnored: texttobeIgnored }) || this;
_this.computeData = function (list) {
var oOpalWordsRef = _this.getOpalWordsObj();
var aProps = _this.findText(), nLen = aProps ? aProps.length : 0, i, oTypes = { a1: 0, a2: 0, b1: 0, b2: 0, c1: 0, uncl: 0, opal: 0 }, oTable = {
a1: { name: 'A1', number: undefined },
a2: { name: 'A2', number: undefined },
b1: { name: 'B1', number: undefined },
b2: { name: 'B2', number: undefined },
c1: { name: 'C1', number: undefined },
uncl: { name: 'Unclassified', number: undefined },
opal: { name: 'OPAL written', number: undefined },
}, nTotal = 0, aSelected = text_1.dougnutData.doughList[list], j, nSelected = aSelected.length, aTemp = [], oTemp = {};
for (i = 0; i < nLen; i++) {
var sWord = aProps[i].word;
if (sWord) {
++nTotal;
var oPos = aProps[i].position;
if (oPos) {
if ((list === 'ox3k' || list === 'ox5k') && oPos['Ox3K/5K'].search(list) > -1) {
var stype = aProps[i].position.Style.split('_')[0];
oTypes[stype] += 1;
// @ts-ignore
oTable[stype].number = (oTable[stype].number || 0) + 1;
}
else if (list === 'ox5k_only' && _this.checkIfOnly5k(oPos['Ox3K/5K'])) {
var stype = aProps[i].position.Style.split('_')[0];
oTypes[stype] += 1;
// @ts-ignore
oTable[stype]['number'] = (oTable[stype]['number'] || 0) + 1;
// @ts-ignore
}
else if (list === 'opal' && oOpalWordsRef[sWord]) {
oTypes.opal += 1;
// @ts-ignore
oTable.opal['number'] = (oTable.opal['number'] || 0) + 1;
}
// @ts-ignore
}
else if (list === 'opal' && oOpalWordsRef[sWord]) {
oTypes.opal += 1;
// @ts-ignore
oTable.opal['number'] = (oTable.opal['number'] || 0) + 1;
}
else if (!oPos && ['‐', '‑', '‒', '–', '—', '―', '-'].indexOf(aProps[i].word) === -1) {
oTypes.uncl += 1;
// @ts-ignore
oTable.uncl['number'] = (oTable.uncl['number'] || 0) + 1;
}
}
}
var aLables = [], aColors = [], nTotalCount = 0;
for (j = 0; j < nSelected; j++) {
var sSlect = aSelected[j].name, sLabel = aSelected[j].label, sBg = aSelected[j].bg;
// @ts-ignore
aTemp.push(oTypes[sSlect]);
// @ts-ignore
nTotalCount += oTypes[sSlect];
aLables.push(sLabel);
aColors.push(sBg);
// @ts-ignore
oTemp[sSlect] = oTable[sSlect];
}
// @ts-ignore
oTable = oTemp;
var cefrData = {};
var nUnclassifiedWordsCount = {};
var aTableData = [];
for (var o in oTable) {
// @ts-ignore
var nInt = oTable[o].number ? oTable[o].number : 0, nPer = nTotal ? nInt / nTotal : 0,
// @ts-ignore
aTemp_1 = [oTable[o].name, nInt, Math.round(nPer * 100)];
aTableData.push(aTemp_1);
}
cefrData.data = aTableData;
cefrData.bg = aColors;
nUnclassifiedWordsCount = oTypes.uncl;
return {
cefrData: cefrData,
nUnclassifiedWordsCount: nUnclassifiedWordsCount,
};
};
_this.getOpalWordsObj = function () {
var _a;
var i, aOpalWordList = (_a = _this.wordsWithDelimitersOpal) !== null && _a !== void 0 ? _a : [], nLen = aOpalWordList.length, oOpal = {};
for (i = 0; i < nLen; i++) {
if (aOpalWordList[i].position) {
var sWord = aOpalWordList[i].word;
// @ts-ignore
oOpal[sWord] = true;
}
}
return oOpal;
};
_this.findText();
return _this;
}
return TextChecker;
}(Main_1.default));
exports.TextChecker = TextChecker;
exports.default = TextChecker;
//# sourceMappingURL=index.js.map