👬Comparison Functions

A set of functions for comparing and matching Arabic words based on vocalization, patterns (wazn), and shadda positioning, designed for efficient Arabic text analysis and processing.

Table of Contents

vocalizedlike

Checks if two words are vocalized similar based on their vocalized similarity score.

Parameters

  • word1 (String): The first word to compare.

  • word2 (String): The second word to compare.

Returns

  • Boolean: true if the words are vocalized similar, false otherwise.

Example

const word1 = "سَلَام";
const word2 = "سَلِيم";
console.log(vocalizedlike(word1, word2)); // Output: false

waznlike

Checks if a given word matches a specified pattern (wazn) and optionally extracts the root.

Parameters

  • word1 (String): The word to be checked against the wazn.

  • wazn (String): The pattern to be matched.

  • extractRoot (Boolean, optional): If true, the function returns the extracted root instead of a boolean value. Defaults to false.

Returns

  • Boolean or String: If extractRoot is false, returns true if the word matches the wazn and false otherwise. If extractRoot is true, returns the extracted root if the word matches the wazn, and false otherwise.

Example

const word = "فَعَلَ";
const pattern = "فَعَلَ";
console.log(waznlike(word, pattern)); // Output: true
console.log(waznlike(word, pattern, true)); // Output: "فعل"

shaddalike

Checks if two words are similar based on the position of shadda and their characters.

Parameters

  • partial (String): The first word to compare.

  • fully (String): The second word to compare.

Returns

  • Boolean: true if the words are similar based on the position of shadda and their characters, false otherwise.

Example

const partialWord = "مُتَحَدَّث";
const fullyWord = "مُتَحَدَّث";
console.log(shaddalike(partialWord, fullyWord)); // Output: true

Last updated