cry-sloimena 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/izlusci.mjs +8 -3
- package/dist/test/imena.test.mjs +19 -0
- package/dist/urediImePriimek.mjs +16 -0
- package/package.json +1 -1
package/dist/izlusci.mjs
CHANGED
|
@@ -210,18 +210,23 @@ export function izlusci(vhodnoIme, opcije) {
|
|
|
210
210
|
// Check if there's at least one word after surname(s) that is a name but not a surname
|
|
211
211
|
let surnameEndIndex = 0;
|
|
212
212
|
for (let i = 0; i < classifications.length; i++) {
|
|
213
|
-
if
|
|
213
|
+
// Stop counting a leading word as surname if it's also recognized as
|
|
214
|
+
// a given name. This ensures inputs like "Voglar Dejan" are treated
|
|
215
|
+
// as surname + given name rather than two surnames.
|
|
216
|
+
if (classifications[i].isSurname && !(classifications[i].isMale || classifications[i].isFemale)) {
|
|
214
217
|
surnameEndIndex = i + 1;
|
|
215
218
|
}
|
|
216
219
|
else {
|
|
217
220
|
break;
|
|
218
221
|
}
|
|
219
222
|
}
|
|
220
|
-
// Check if remaining words are names
|
|
223
|
+
// Check if remaining words are names. If a token is both a name and a
|
|
224
|
+
// surname (ambiguous), still allow it to count as a name for the
|
|
225
|
+
// purposes of detecting surname-first input like "Voglar Dejan".
|
|
221
226
|
let hasNameOnlyAfterSurnames = false;
|
|
222
227
|
for (let i = surnameEndIndex; i < classifications.length; i++) {
|
|
223
228
|
const c = classifications[i];
|
|
224
|
-
if (
|
|
229
|
+
if (c.isMale || c.isFemale) {
|
|
225
230
|
hasNameOnlyAfterSurnames = true;
|
|
226
231
|
break;
|
|
227
232
|
}
|
package/dist/test/imena.test.mjs
CHANGED
|
@@ -181,4 +181,23 @@ describe('Lastna imena', () => {
|
|
|
181
181
|
});
|
|
182
182
|
});
|
|
183
183
|
});
|
|
184
|
+
describe('Voglar Dejan variants', () => {
|
|
185
|
+
const testCases = [
|
|
186
|
+
{ text: 'VOGLAR DEJAN', expectedPriimek: 'Voglar', expectedIme: 'Dejan', expectedSpol: 'm' },
|
|
187
|
+
{ text: 'voglar dejan', expectedPriimek: 'Voglar', expectedIme: 'Dejan', expectedSpol: 'm' },
|
|
188
|
+
{ text: 'dejan voglar', expectedIme: 'Dejan', expectedPriimek: 'Voglar', expectedSpol: 'm' },
|
|
189
|
+
{ text: 'Dejan Voglar', expectedIme: 'Dejan', expectedPriimek: 'Voglar', expectedSpol: 'm' }
|
|
190
|
+
];
|
|
191
|
+
testCases.forEach(({ text, expectedIme, expectedPriimek, expectedSpol }) => {
|
|
192
|
+
it(`should recognize: ${text}`, () => {
|
|
193
|
+
const result = urediImePriimek(text);
|
|
194
|
+
expect(typeof result).to.not.equal('string');
|
|
195
|
+
if (typeof result !== 'string') {
|
|
196
|
+
expect(result.ime).to.equal(expectedIme);
|
|
197
|
+
expect(result.priimek).to.equal(expectedPriimek);
|
|
198
|
+
expect(result.spol).to.equal(expectedSpol);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
});
|
|
184
203
|
});
|
package/dist/urediImePriimek.mjs
CHANGED
|
@@ -495,6 +495,22 @@ export function urediImePriimek(vhodnoIme, correctCase = true) {
|
|
|
495
495
|
};
|
|
496
496
|
}
|
|
497
497
|
// If no pattern matches, return input as-is
|
|
498
|
+
// Fallback: try surname-first parsing (e.g., "Voglar Dejan" or "voglar dejan")
|
|
499
|
+
if (wordInfo.length >= 2) {
|
|
500
|
+
const lastWord = wordInfo[wordInfo.length - 1].word;
|
|
501
|
+
const lastIsMale = isMaleName(lastWord);
|
|
502
|
+
const lastIsFemale = isFemaleName(lastWord);
|
|
503
|
+
if (lastIsMale || lastIsFemale) {
|
|
504
|
+
const surnameParts = wordInfo.slice(0, wordInfo.length - 1).map(i => i.word);
|
|
505
|
+
const allSurnameParts = surnameParts.every(part => isSurname(part));
|
|
506
|
+
if (allSurnameParts || !isMaleName(surnameParts[0]) && !isFemaleName(surnameParts[0])) {
|
|
507
|
+
const ime = formatNames([lastWord]);
|
|
508
|
+
const priimek = formatNames(surnameParts);
|
|
509
|
+
const spol = lastIsFemale && !lastIsMale ? 'f' : 'm';
|
|
510
|
+
return { ime, priimek, spol };
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|
|
498
514
|
return trimmed;
|
|
499
515
|
}
|
|
500
516
|
/**
|