Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for sr-SR #40

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
45 changes: 45 additions & 0 deletions inflection/resources/org/unicode/inflection/features/grammar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2314,6 +2314,51 @@
</category>
</grammar>
</language>
<language id="sr">
<grammar>
<category name="case">
<restrictions>
<restriction name="pos" value="noun"/>
<restriction name="pos" value="proper-noun"/>
</restrictions>
<grammeme name="nominative"/>
<grammeme name="genitive"/>
<grammeme name="dative"/>
<grammeme name="accusative"/>
<grammeme name="vocative"/>
<grammeme name="locative"/>
<grammeme name="instrumental"/>
</category>
<category name="count">
<grammeme name="singular"/>
<grammeme name="plural"/>
</category>
<category name="emphasis">
<restrictions>
<restriction name="pos" value="pronoun"/>
</restrictions>
<grammeme name="stressed"/>
<grammeme name="unstressed"/>
</category>
<category name="gender">
<grammeme name="masculine"/>
<grammeme name="feminine"/>
<grammeme name="neuter"/>
</category>
<category name="person">
<grammeme name="first"/>
<grammeme name="second"/>
<grammeme name="third"/>
</category>
<category name="pronounType">
<restrictions>
<restriction name="pos" value="pronoun"/>
</restrictions>
<grammeme name="personal"/>
<grammeme name="reflexive"/>
</category>
</grammar>
</language>
<language id="sv">
<grammar>
<category name="case">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
оно,third,singular,nominative,neuter
он,third,singular,nominative,masculine
она,third,singular,nominative,feminine
она,third,plural,nominative,neuter
оне,third,plural,nominative,masculine
они,third,plural,nominative,feminine
ти,second,singular,nominative
ви,second,plural,nominative
ја,first,singular,nominative
ми,first,plural,nominative
њега,third,singular,accusative,neuter,stressed
га,third,singular,accusative,neuter,unstressed
њега,third,singular,accusative,masculine,stressed
га,third,singular,accusative,masculine,unstressed
њу,third,singular,accusative,feminine,stressed
ју,third,singular,accusative,feminine,unstressed
њих,third,plural,accusative,gender,stressed
их,third,plural,accusative,gender,unstressed
тебе,second,singular,accusative,stressed
те,second,singular,accusative,unstressed
вас,second,plural,accusative
мене,first,singular,accusative,stressed
ме,first,singular,accusative,unstressed
нас,first,plural,accusative
њему,third,singular,dative,neuter,stressed
му,third,singular,dative,neuter,unstressed
њему,third,singular,dative,masculine,stressed
му,third,singular,dative,masculine,unstressed
њој,third,singular,dative,feminine,stressed
јој,third,singular,dative,feminine,unstressed
њима,third,plural,dative,gender,stressed
им,third,plural,dative,gender,unstressed
теби,second,singular,dative,stressed
ти,second,singular,dative,unstressed
вама,second,plural,dative,stressed
вам,second,plural,dative,unstressed
мени,first,singular,dative,stressed
ми,first,singular,dative,unstressed
нама,first,plural,dative,stressed
нам,first,plural,dative,unstressed
њему,third,singular,locative,neuter
њему,third,singular,locative,masculine
њој,third,singular,locative,feminine
њима,third,plural,locative,gender
теби,second,singular,locative
вама,second,plural,locative
мени,first,singular,locative
нама,first,plural,locative
њим,third,singular,instrumental,neuter
њим,third,singular,instrumental,masculine
њом,third,singular,instrumental,feminine
њима,third,plural,instrumental,gender
тобом,second,singular,instrumental
вама,second,plural,instrumental
мном,first,singular,instrumental
нама,first,plural,instrumental
њега,third,singular,genitive,neuter,stressed
га,third,singular,genitive,neuter,unstressed
њега,third,singular,genitive,masculine,stressed
га,third,singular,genitive,masculine,unstressed
ње,third,singular,genitive,feminine,stressed
је,third,singular,genitive,feminine,unstressed
њих,third,plural,genitive,gender,stressed
их,third,plural,genitive,gender,unstressed
тебе,second,singular,genitive,stressed
те,second,singular,genitive,unstressed
вас,second,plural,genitive
мене,first,singular,genitive,stressed
ме,first,singular,genitive,unstressed
нас,first,plural,genitive
себе,person,count,gender,accusative,reflexive,stressed
се,person,count,gender,accusative,reflexive,unstressed
себи,person,count,gender,dative,reflexive,stressed
си,person,count,gender,dative,reflexive,unstressed
себе,person,count,gender,locative,reflexive
собом,person,count,gender,instrumental,reflexive
себи,person,count,gender,genitive,reflexive,stressed
се,person,count,gender,genitive,reflexive,unstressed
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Copyright 2024-2024 Apple Inc. All rights reserved.
#
# The first in each group is the primary language and is loaded first.
# These are languages that are advertised. Don't list a language if you want it to be a secret.
locale.group.ar=ar_SA
locale.group.da=da_DK
locale.group.de=de_DE,de_AT,de_CH
Expand All @@ -20,6 +19,7 @@ locale.group.nb=nb_NO
locale.group.nl=nl_NL,nl_BE
locale.group.pt=pt_BR,pt_PT
locale.group.ru=ru_RU
locale.group.sr=sr_RS
locale.group.sv=sv_SE
locale.group.th=th_TH
locale.group.tr=tr_TR
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#
# Copyright 2024 and later: Unicode, Inc. and others.
# License & terms of use: http://www.unicode.org/copyright.html
#
tokenizer.implementation.class=DefaultTokenizer
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <inflection/dialog/language/NlCommonConceptFactory.hpp>
#include <inflection/dialog/language/PtCommonConceptFactory.hpp>
#include <inflection/dialog/language/RuCommonConceptFactory.hpp>
#include <inflection/dialog/language/SrCommonConceptFactory.hpp>
#include <inflection/dialog/language/SvCommonConceptFactory.hpp>
#include <inflection/dialog/language/ThCommonConceptFactory.hpp>
#include <inflection/dialog/language/TrCommonConceptFactory.hpp>
Expand Down Expand Up @@ -81,6 +82,7 @@ static CommonConceptFactory* constructCommonConceptFactory(const ::inflection::u
{"nl", &constructor<language::NlCommonConceptFactory>},
{"pt", &constructor<language::PtCommonConceptFactory>},
{"ru", &constructor<language::RuCommonConceptFactory>},
{"sr", &constructor<language::SrCommonConceptFactory>},
{"sv", &constructor<language::SvCommonConceptFactory>},
{"th", &constructor<language::ThCommonConceptFactory>},
{"tr", &constructor<language::TrCommonConceptFactory>},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2024 and later: Unicode, Inc. and others.
* License & terms of use: http://www.unicode.org/copyright.html
*/
#include <inflection/dialog/language/SrCommonConceptFactory.hpp>

#include <inflection/grammar/synthesis/GrammemeConstants.hpp>

namespace inflection::dialog::language {

SrCommonConceptFactory::SrCommonConceptFactory(const ::inflection::util::ULocale& language)
: super(language, ::inflection::grammar::synthesis::GrammemeConstants::GENDER, {
{::inflection::grammar::synthesis::GrammemeConstants::GENDER_MASCULINE(), u"cardinal-masculine"},
{::inflection::grammar::synthesis::GrammemeConstants::GENDER_FEMININE(), u"cardinal-feminine"},
{::inflection::grammar::synthesis::GrammemeConstants::GENDER_NEUTER(), u"cardinal-neuter"}})
{
}

SrCommonConceptFactory::~SrCommonConceptFactory()
{
}

} // namespace inflection::dialog::language
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2024 and later: Unicode, Inc. and others.
* License & terms of use: http://www.unicode.org/copyright.html
*/
#pragma once

#include <inflection/dialog/language/fwd.hpp>
#include <inflection/dialog/CommonConceptFactoryImpl.hpp>

class inflection::dialog::language::SrCommonConceptFactory
: public CommonConceptFactoryImpl
{
public:
typedef CommonConceptFactoryImpl super;
public:

explicit SrCommonConceptFactory(const ::inflection::util::ULocale& language);
~SrCommonConceptFactory() override;
};
1 change: 1 addition & 0 deletions inflection/src/inflection/dialog/language/fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ namespace inflection
class NlCommonConceptFactory;
class PtCommonConceptFactory;
class RuCommonConceptFactory;
class SrCommonConceptFactory;
class SvCommonConceptFactory;
class ThCommonConceptFactory;
class TrCommonConceptFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <inflection/grammar/synthesis/NlGrammarSynthesizer.hpp>
#include <inflection/grammar/synthesis/PtGrammarSynthesizer.hpp>
#include <inflection/grammar/synthesis/RuGrammarSynthesizer.hpp>
#include <inflection/grammar/synthesis/SrGrammarSynthesizer.hpp>
#include <inflection/grammar/synthesis/SvGrammarSynthesizer.hpp>
#include <inflection/grammar/synthesis/TrGrammarSynthesizer.hpp>
#include <inflection/util/LocaleUtils.hpp>
Expand Down Expand Up @@ -44,6 +45,7 @@ static const ::std::map<::inflection::util::ULocale, addSemanticFeatures>& GRAMM
{::inflection::util::LocaleUtils::DUTCH(), &NlGrammarSynthesizer::addSemanticFeatures},
{::inflection::util::LocaleUtils::PORTUGUESE(), &PtGrammarSynthesizer::addSemanticFeatures},
{::inflection::util::LocaleUtils::RUSSIAN(), &RuGrammarSynthesizer::addSemanticFeatures},
{::inflection::util::LocaleUtils::SERBIAN(), &SrGrammarSynthesizer::addSemanticFeatures},
{::inflection::util::LocaleUtils::SWEDISH(), &SvGrammarSynthesizer::addSemanticFeatures},
{::inflection::util::LocaleUtils::TURKISH(), &TrGrammarSynthesizer::addSemanticFeatures},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2024 and later: Unicode, Inc. and others.
* License & terms of use: http://www.unicode.org/copyright.html
*/
#include <inflection/grammar/synthesis/SrGrammarSynthesizer.hpp>

#include <inflection/dialog/DictionaryLookupFunction.hpp>
#include <inflection/dialog/SemanticFeatureModel.hpp>
#include <inflection/grammar/synthesis/GrammemeConstants.hpp>
#include <inflection/grammar/synthesis/SrGrammarSynthesizer_SrDisplayFunction.hpp>
#include <inflection/util/LocaleUtils.hpp>
#include <inflection/npc.hpp>

namespace inflection::grammar::synthesis {

void SrGrammarSynthesizer::addSemanticFeatures(::inflection::dialog::SemanticFeatureModel& featureModel)
{
featureModel.putDefaultFeatureFunctionByName(GrammemeConstants::GENDER, new ::inflection::dialog::DictionaryLookupFunction(::inflection::util::LocaleUtils::SERBIAN(), {GrammemeConstants::GENDER_MASCULINE(), GrammemeConstants::GENDER_FEMININE(), GrammemeConstants::GENDER_NEUTER()}));
featureModel.putDefaultFeatureFunctionByName(GrammemeConstants::NUMBER, new ::inflection::dialog::DictionaryLookupFunction(::inflection::util::LocaleUtils::SERBIAN(), {GrammemeConstants::NUMBER_SINGULAR(), GrammemeConstants::NUMBER_PLURAL()}));

featureModel.setDefaultDisplayFunction(new SrGrammarSynthesizer_SrDisplayFunction(featureModel));
}

} // namespace inflection::grammar::synthesis
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2024 and later: Unicode, Inc. and others.
* License & terms of use: http://www.unicode.org/copyright.html
*/
#pragma once

#include <inflection/dialog/fwd.hpp>
#include <inflection/grammar/synthesis/fwd.hpp>
#include <string>
#include <set>

class inflection::grammar::synthesis::SrGrammarSynthesizer final
{
public:
static void addSemanticFeatures(::inflection::dialog::SemanticFeatureModel& featureModel);

private:
SrGrammarSynthesizer() = delete;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2024 and later: Unicode, Inc. and others.
* License & terms of use: http://www.unicode.org/copyright.html
*/
#include <inflection/grammar/synthesis/SrGrammarSynthesizer_SrDisplayFunction.hpp>

#include <inflection/dialog/SemanticFeature.hpp>
#include <inflection/dialog/SemanticFeatureModel_DisplayData.hpp>
#include <inflection/dialog/SemanticFeatureModel_DisplayValue.hpp>
#include <inflection/dialog/SemanticFeatureModel.hpp>
#include <inflection/dictionary/DictionaryMetaData.hpp>
#include <inflection/grammar/synthesis/GrammarSynthesizerUtil.hpp>
#include <inflection/grammar/synthesis/GrammemeConstants.hpp>
#include <inflection/tokenizer/TokenChain.hpp>
#include <inflection/tokenizer/TokenizerFactory.hpp>
#include <inflection/util/LocaleUtils.hpp>
#include <inflection/npc.hpp>
#include <memory>

namespace inflection::grammar::synthesis {

SrGrammarSynthesizer_SrDisplayFunction::SrGrammarSynthesizer_SrDisplayFunction(const ::inflection::dialog::SemanticFeatureModel& model)
: super()
, dictionary(*npc(::inflection::dictionary::DictionaryMetaData::createDictionary(::inflection::util::LocaleUtils::FRENCH())))
, countFeature(model.getFeature(GrammemeConstants::NUMBER))
, genderFeature(model.getFeature(GrammemeConstants::GENDER))
, partOfSpeechFeature(model.getFeature(GrammemeConstants::POS))
, tokenizer(::inflection::tokenizer::TokenizerFactory::createTokenizer(::inflection::util::LocaleUtils::FRENCH()))
, dictionaryInflector(::inflection::util::LocaleUtils::SERBIAN(),{
{GrammemeConstants::POS_NOUN(), GrammemeConstants::POS_ADJECTIVE(), GrammemeConstants::POS_VERB()},
{GrammemeConstants::PERSON_THIRD(), GrammemeConstants::PERSON_FIRST(), GrammemeConstants::PERSON_SECOND()},
{GrammemeConstants::NUMBER_SINGULAR(), GrammemeConstants::NUMBER_PLURAL()},
{GrammemeConstants::GENDER_MASCULINE(), GrammemeConstants::GENDER_FEMININE(), GrammemeConstants::GENDER_NEUTER()}
}, {}, true)
{
}

SrGrammarSynthesizer_SrDisplayFunction::~SrGrammarSynthesizer_SrDisplayFunction()
{
}

::inflection::dialog::SemanticFeatureModel_DisplayValue * SrGrammarSynthesizer_SrDisplayFunction::getDisplayValue(const dialog::SemanticFeatureModel_DisplayData &displayData, const ::std::map<::inflection::dialog::SemanticFeature, ::std::u16string> &constraints, bool enableInflectionGuess) const
{
const auto displayValue = GrammarSynthesizerUtil::getTheBestDisplayValue(displayData, constraints);
if (displayValue == nullptr) {
return nullptr;
}
::std::u16string displayString = displayValue->getDisplayString();
if (displayString.empty()) {
return nullptr;
}

// TODO Implement the rest
}

} // namespace inflection::grammar::synthesis
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2024 and later: Unicode, Inc. and others.
* License & terms of use: http://www.unicode.org/copyright.html
*/
#pragma once

#include <inflection/dialog/DefaultDisplayFunction.hpp>
#include <inflection/dialog/DictionaryLookupInflector.hpp>
#include <inflection/dictionary/fwd.hpp>
#include <inflection/dictionary/Inflector.hpp>
#include <inflection/grammar/synthesis/fwd.hpp>
#include <inflection/tokenizer/Tokenizer.hpp>
#include <string>
#include <set>
#include <vector>

class inflection::grammar::synthesis::SrGrammarSynthesizer_SrDisplayFunction
: public virtual ::inflection::dialog::DefaultDisplayFunction
{

public:
typedef ::inflection::dialog::DefaultDisplayFunction super;

private:
const ::inflection::dictionary::DictionaryMetaData& dictionary;
const ::inflection::dialog::SemanticFeature* countFeature { };
const ::inflection::dialog::SemanticFeature* genderFeature { };
const ::inflection::dialog::SemanticFeature* partOfSpeechFeature { };
const ::std::unique_ptr<::inflection::tokenizer::Tokenizer> tokenizer;
const ::inflection::dialog::DictionaryLookupInflector dictionaryInflector;

public:
::inflection::dialog::SemanticFeatureModel_DisplayValue * getDisplayValue(const dialog::SemanticFeatureModel_DisplayData &displayData, const ::std::map<::inflection::dialog::SemanticFeature, ::std::u16string> &constraints, bool enableInflectionGuess) const override;

public:
explicit SrGrammarSynthesizer_SrDisplayFunction(const ::inflection::dialog::SemanticFeatureModel& model);
~SrGrammarSynthesizer_SrDisplayFunction() override;

public:
SrGrammarSynthesizer_SrDisplayFunction(SrGrammarSynthesizer_SrDisplayFunction&) = delete;
SrGrammarSynthesizer_SrDisplayFunction& operator=(const SrGrammarSynthesizer_SrDisplayFunction&) = delete;
};
2 changes: 2 additions & 0 deletions inflection/src/inflection/grammar/synthesis/fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ namespace inflection
class RuGrammarSynthesizer_RuDisplayFunction;
class RuGrammarSynthesizer_ToPrepositionLookupFunction;
class RuGrammarSynthesizer_WithPrepositionLookupFunction;
class SrGrammarSynthesizer;
class SrGrammarSynthesizer_SrDisplayFunction;
class SvGrammarSynthesizer;
class SvGrammarSynthesizer_ArticleLookupFunction;
class SvGrammarSynthesizer_GenderLookupFunction;
Expand Down
Loading