wordmap
Version:
Multi-Lingual Word Alignment Prediction
34 lines (33 loc) • 1.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const Algorithm_1 = require("../Algorithm");
/**
* Determines the likely hood that an n-gram is a phrase.
*/
class CharacterLength extends Algorithm_1.default {
constructor() {
super(...arguments);
this.name = "character length";
}
execute(prediction) {
let weight = 0;
// TRICKY: do not score null alignments
if (!prediction.target.isNull()) {
// sentence lengths
const sourceSentenceLength = prediction.source.sentenceCharacterLength;
const targetSentenceLength = prediction.target.sentenceCharacterLength;
// n-gram lengths
const sourceLength = prediction.source.characterLength;
const targetLength = prediction.target.characterLength;
const primaryLengthRatio = sourceLength / sourceSentenceLength;
const secondaryLengthRatio = targetLength / targetSentenceLength;
// length affinity
const delta = Math.abs(primaryLengthRatio - secondaryLengthRatio);
// TRICKY: the power of 5 improves the curve
weight = Math.pow(1 - delta, 5);
}
prediction.setScore("characterLength", weight);
return prediction;
}
}
exports.default = CharacterLength;