-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMorphParse.js
More file actions
190 lines (175 loc) · 4.76 KB
/
MorphParse.js
File metadata and controls
190 lines (175 loc) · 4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/**
* @fileOverview MorphParse is a parser for morphology codes,
* based on MorphCodes.js.
* @version 1.2
* @author David
*/
var MorphParse = function()
{
var language;
/**
* Parses the given code.
* @param {string} code A morph code
* @returns (string} The morphology
*/
this.Parse = function(code1)
{
language = code1.charAt(0);
code = code1.substr(1);
var parts = code.split('/');
var morph = parseCode(parts[0]);
if (!morph) { // Not starting with language character H/A
code = code1;
parts = code.split('/');
morph = parseCode(parts[0]);
if (!morph)
return 'Unknown part of speech in ' + code
}
for (var i = 1; i < parts.length; i++) {
morph += ', ' + parseCode(parts[i]);
}
return morph;
};
var parseCode = function(code)
{
var pos = code.charAt(0);
var morph = morphCodes.partOfSpeech[pos];
if (code.length > 1) {
switch (pos) {
case 'A':
morph += ' ' + parseAdjective(code);
break;
case 'C':
morph += ' ' + parseConjunction(code);
break;
case 'N':
morph += ' ' + parseNoun(code);
break;
case 'P':
morph += ' ' + parsePronoun(code);
break;
case 'S':
morph += ' ' + parseSuffix(code);
break;
case 'T':
morph += ' ' + parseParticle(code);
break;
case 'V':
morph += ' ' + parseVerb(code);
break;
default:
return false;
}
}
return morph;
};
var parseAdjective = function(code)
{
var morph = morphCodes.adjectiveType[code.charAt(1)];
if (code.length > 2) {
morph += ' ' + parseGender(code, 2);
}
return morph;
};
var parseConjunction = function(code)
{
var morph = morphCodes.conjunctionType[code.charAt(1)];
return morph;
};
var parseNoun = function(code)
{
var morph = morphCodes.nounType[code.charAt(1)];
if (code.length > 2) {
morph += ' ' + parseGender(code, 2);
}
return morph;
};
var parsePronoun = function(code)
{
var morph = morphCodes.pronounType[code.charAt(1)];
if (code.length > 2) {
morph += ' ' + parseCase(code);
}
return morph;
};
var parseSuffix = function(code)
{
var morph = morphCodes.suffixType[code.charAt(1)];
if (code.length > 2) {
morph += ' ' + parsePerson(code, 2);
}
return morph;
};
var parseParticle = function(code)
{
var morph = morphCodes.particleType[code.charAt(1)];
return morph;
};
var parseVerb = function(code)
{
var morph;
if (language === 'H') {
morph = morphCodes.verbStemHebrew[code.charAt(1)];
} else {
morph = morphCodes.verbStemAramaic[code.charAt(1)];
}
if (code.length > 2) {
morph += ' ' + parseAspect(code);
}
return morph;
};
var parseAspect = function(code)
{
var morph = morphCodes.verbAspect[code.charAt(2)];
if (code.length > 3) {
morph += ' ' + parsePerson(code, 3);
}
return morph;
};
var parseCase = function(code)
{
var morph = morphCodes.adjCase[code.charAt(2)];
if ( morph === undefined ) {
morph = parsePerson(code, 2);
} else if (code.length > 3) {
morph += ' ' + parsePerson(code, 3);
}
return morph;
};
var parsePerson = function(code, pos)
{
var morph = morphCodes.person[code.charAt(pos)];
if ( morph === undefined ) {
morph = parseGender(code, pos);
} else {
pos++;
if (code.length > pos) {
morph += ' ' +parseGender(code, pos);
}
}
return morph;
};
var parseGender = function(code, pos)
{
var morph = morphCodes.gender[code.charAt(pos)];
pos++;
if (code.length > pos) {
morph += ' ' + parseNumber(code, pos);
}
return morph;
};
var parseNumber = function(code, pos)
{
var morph = morphCodes.number[code.charAt(pos)];
pos++;
if (code.length > pos) {
morph += ' ' + parseState(code, pos);
}
return morph;
};
var parseState = function(code, pos)
{
var morph = morphCodes.state[code.charAt(pos)];
return morph;
};
};