Skip to content

Commit

Permalink
optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
kariminf committed Aug 24, 2017
1 parent f8a5ee7 commit bc2b57f
Show file tree
Hide file tree
Showing 20 changed files with 292 additions and 320 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This will break the projects developed on precedent versions.
## Version current

* ADD: Japanese Morpho -> jslinguaJpnStemmer
* ADD: normalization to Japanese Morpho

## Version 0.5.0 (2017-08-13)

Expand Down
2 changes: 1 addition & 1 deletion ara/ara.info.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function(){

var Info = {};
let Info = {};
if ( typeof module === "object" && module && typeof module.exports === "object" ) {
Info = require("../info.js");
module.exports = AraInfo;
Expand Down
60 changes: 27 additions & 33 deletions ara/ara.lang.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function(){

var Lang = {};
let Lang = {};
if ( typeof module === "object" && module && typeof module.exports === "object" ) {
Lang = require("../lang.js");
module.exports = AraLang;
Expand Down Expand Up @@ -32,30 +32,27 @@
}

AraLang.prototype = Object.create(Lang.prototype);
var Me = AraLang.prototype;
let Me = AraLang.prototype;
Me.constructor = AraLang;

//https://ar.wikipedia.org/wiki/قائمة_الأعداد
var lookup = {
const lookup = {
0: "صفر", 1:"واحد", 2:"اثنان", 3:"ثلاث", 4:"أربع", 5:"خمس",
6:"ست", 7:"سبع", 8:"ثمان", 9:"تسع", 10:"عشر",
100:"مائة", 1000:"ألف", 1000000:"مليون", 1000000000:"مليار"
}

var bigNbr = [
},
bigNbr = [
100, 1000, 1000000, 1000000000
//1000000000, 1000000, 1000, 100, 10
]

var lookup2 = {
],
lookup2 = {
100: "مائتان",
1000: "ألفان",
1000000: "مليونان",
1000000000: "ملياران"
//1000000000, 1000000, 1000, 100, 10
}

var lookupPl = {
},
lookupPl = {
100: "مائة",
1000: "آلاف",
1000000: "ملايين",
Expand Down Expand Up @@ -97,8 +94,8 @@
return lookup[num] + "ة";

if (num < 100 ){
var div = ~~(num/10);
var rem = ~~(num % 10);
let div = ~~(num/10);
let rem = ~~(num % 10);

if (div == 1){
if (rem == 0)
Expand All @@ -110,29 +107,28 @@
return toArabicLetters(rem) + " " + lookup[10];
}

var tenth = lookup[div] + "ون";
let tenth = lookup[div] + "ون";
if (div == 2)
tenth = lookup[10] + "ون";

if (rem == 0)
return tenth;

var suff = " و";
let suff = " و";

return toArabicLetters(rem) + suff + tenth;

}

for (var i = 1; i < bigNbr.length; i++) {
var big = bigNbr[i];
var lessBig = bigNbr[i-1];
for (let i = 1; i < bigNbr.length; i++) {
let big = bigNbr[i],
lessBig = bigNbr[i-1];
if (num < big ){
var div = ~~(num/lessBig);
var rem = ~~(num % lessBig);

var pron = lookup[lessBig];
var pref = "";
var suff = "";
let div = ~~(num/lessBig),
rem = ~~(num % lessBig),
pron = lookup[lessBig],
pref = "",
suff = "";

if (div < 3){
if (div == 2)
Expand Down Expand Up @@ -165,14 +161,12 @@
}
}

var lessBig = bigNbr[bigNbr.length-1];

var div = ~~(num/lessBig);
var rem = ~~(num % lessBig);

var pron = lookup[lessBig];
var pref = "";
var suff = "";
let lessBig = bigNbr[bigNbr.length-1],
div = ~~(num/lessBig),
rem = ~~(num % lessBig),
pron = lookup[lessBig],
pref = "",
suff = "";

if (div < 3){
if (div == 2)
Expand Down
56 changes: 27 additions & 29 deletions ara/ara.morpho.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(function () {

var Morpho = {};
let Morpho = {};
if ( typeof module === "object" && module && typeof module.exports === "object" ) {
Morpho = require("../morpho.js");
module.exports = AraMorpho;
Expand All @@ -10,14 +10,14 @@
}

//Different global features
var F = Morpho.Feature;
var Tense = F.Tense;
var Mood = F.Mood;
var Voice = F.Voice;
var GNumber = F.Number;
var Aspect = F.Aspect;
var Gender = F.Gender;
var Person = F.Person;
let F = Morpho.Feature,
Tense = F.Tense,
Mood = F.Mood,
Voice = F.Voice,
GNumber = F.Number,
Aspect = F.Aspect,
Gender = F.Gender,
Person = F.Person;

var g;
function AraMorpho() {
Expand All @@ -27,7 +27,7 @@
}

AraMorpho.prototype = Object.create(Morpho.prototype);
var Me = AraMorpho.prototype;
let Me = AraMorpho.prototype;

Me.constructor = AraMorpho;

Expand Down Expand Up @@ -76,32 +76,32 @@
Me.conjugate = function(verb, opts){
//delete diacretics
verb = verb.trim();
var noDiac = verb.replace(/\u064E\u064F\u0650\u0651\u0652/gi, "");//fat,dam,kas,shad,sukun
let noDiac = verb.replace(/\u064E\u064F\u0650\u0651\u0652/gi, "");//fat,dam,kas,shad,sukun

var len = noDiac.length;
let len = noDiac.length;

//detect if the verb with weak begining
var weekBegin = /^[اأو]/.test(noDiac);
let weekBegin = /^[اأو]/.test(noDiac);

//detect if the verb has a week ending
var weekEnd = /[يى]$/.test(noDiac);
let weekEnd = /[يى]$/.test(noDiac);

//detect if the verb has a week middle
var weekMiddle = false;
let weekMiddle = false;

var begin = "";
var end = "";
var endDiac = "ُ";//Dhamma for present
var notAllowed = false;
let begin = "",
end = "",
endDiac = "ُ",//Dhamma for present
notAllowed = false;

//Future is prefix + present
var future = 0;
let future = 0;
if (opts.tense === Tense.Fu){
future = 1;
opts.tense = Tense.Pr;
}

var befLast = "ِ";//kasra for the char before last
let befLast = "ِ";//kasra for the char before last


if (len === 3){
Expand Down Expand Up @@ -132,7 +132,7 @@
case GNumber.S:
if (opts.gender === Gender.F){
end = "ينَ";
var endDiac = "ِ";//Kasra
endDiac = "ِ";//Kasra
}
break;

Expand All @@ -146,7 +146,7 @@
case GNumber.P:
if (opts.gender === Gender.F){
end = "نَ";
var endDiac = "ْ";//Sukuun
endDiac = "ْ";//Sukuun
}
else end = "ونَ";
break;
Expand Down Expand Up @@ -250,7 +250,7 @@

}//swich(tense)

var result = verb;
let result = verb;

if(befLast){
if(befLast === "X") befLast = "";
Expand Down Expand Up @@ -331,11 +331,11 @@
* @return {string} normalized word
**/
Me.normalize = function(word, opts){
var norm = word.trim();
let norm = word.trim();

//If no options are afforded, do all
if (! opts || opts.length < 1){
var opts = "voc,alef,yeh,teh,_";
opts = "voc,alef,yeh,teh,_";
}

//Delete vocals: fathah, kasrah, etc.
Expand Down Expand Up @@ -380,9 +380,7 @@
* @return {[type]} [description]
*/
function jslinguaAraStemmer(word){
var stem = word;


let stem = word;
return stem;
}

Expand Down

0 comments on commit bc2b57f

Please sign in to comment.