$nlp.inflect
Declines a Russian word into the required case.
Declination is performed using pymorphy2. Declinations are set in its format.
Syntax
- ECMAScript 5
- ECMAScript 6
$nlp.inflect("яблоко", "gent"); // => "яблока"
In the ECMAScript 6 runtime, the method is asynchronous:
await $nlp.inflect("яблоко", "gent"); // => "яблока"
How to use
In the example below, gent
is the genitive case.
- ECMAScript 5
- ECMAScript 6
require: city/city.sc
module = sys.zb-common
theme: /
state: WhatCityAreYouFrom
# What city are you from?
a: Из какого вы города?
state: GetCity
q: * $City *
if: $parseTree._City.name === "Санкт-Петербург" # St. Petersburg
# Wow, I’m from St. Petersburg, too!
a: Ух ты, я тоже из Питера!
else:
# You’re from $parseTree._City.name, great! And I’m from St. Petersburg.
a: Из {{capitalize($nlp.inflect($parseTree._City.name, "gent"))}}, здорово! А я из Питера.
require: city/city.sc
module = sys.zb-common
theme: /
state: WhatCityAreYouFrom
# What city are you from?
a: Из какого вы города?
state: GetCity
q: * $City *
if: $parseTree._City.name === "Санкт-Петербург" # St. Petersburg
# Wow, I’m from St. Petersburg, too!
a: Ух ты, я тоже из Питера!
else:
scriptEs6:
# You’re from $parseTree._City.name, great! And I’m from St. Petersburg.
$reactions.answer("Из " + (capitalize(await $nlp.inflect($parseTree._City.name, "gent"))) + ", здорово! А я из Питера.");