我正在为法语构造一个共轭表的模型。有名词变体、副词变体和19个动词连词。我试图对数据进行建模,以便可以以与遍历以下XML树(摘自我的XML字典文件)相同的方式访问每一块数据:
<Word word="être" aspirate="false">
<GrammaticalForms>
<GrammaticalForm form="nm" definition="A being (e.g. animal, insect)."></GrammaticalForm>
<GrammaticalForm form="vi" definition="The be (a state of existence)."></GrammaticalForm>
</GrammaticalForms>
<ConjugationTables>
<NounTable ms="être" fs="" mpl="êtres" fpl="" gender="m"></NounTable>
<AdjectiveTable ms="" fs="" mpl="" fpl="" na=""></AdjectiveTable>
<VerbTable group="e" auxillary="a" prepositions="à, de, des, en" transitive="false" pronominal="false">
<Indicative>
<Present fps="suis" sps="es" tps="est" fpp="sommes" spp="êtes" tpp="sont"></Present>
<SimplePast fps="fus" sps="fus" tps="fut" fpp="fûmes" spp="fûtes" tpp="furent"></SimplePast>
<PresentPerfect fps="ai été" sps="as été" tps="a été" fpp="avons été" spp="avez été" tpp="ont été"></PresentPerfect>
<PastPerfect fps="eus été" sps="eus été" tps="eut été" fpp="eûmes été" spp="eûtes été" tpp="eurent été"></PastPerfect>
<Imperfect fps="étais" sps="étais" tps="était" fpp="étions" spp="étiez" tpp="étaient"></Imperfect>
<Pluperfect fps="avais été" sps="avais été" tps="avait été" fpp="avions été" spp="aviez été" tpp="avaient été"></Pluperfect>
<Future fps="serai" sps="seras" tps="sera" fpp="serons" spp="serez" tpp="seront"></Future>
<PastFuture fps="aurai été" sps="auras été" tps="aura été" fpp="aurons été" spp="aurez été" tpp="auront été"></PastFuture>
</Indicative>
<Subjunctive>
<Present fps="sois" sps="sois" tps="soit" fpp="soyons" spp="soyez" tpp="soient"></Present>
<Past fps="aie été" sps="aies été" tps="ait été" fpp="ayons été" spp="ayez été" tpp="aient été"></Past>
<Imperfect fps="fusse" sps="fusses" tps="fût" fpp="fussions" spp="fussiez" tpp="fussent"></Imperfect>
<Pluperfect fps="eusse été" sps="eusses été" tps="eût été" fpp="eussions été" spp="eussiez été" tpp="eussent été"></Pluperfect>
</Subjunctive>
<Conditional>
<Present fps="serais" sps="serais" tps="serait" fpp="serions" spp="seriez" tpp="seraient"></Present>
<FirstPast fps="aurais été" sps="aurais été" tps="aurait été" fpp="aurions été" spp="auriez été" tpp="auraient été"></FirstPast>
<SecondPast fps="eusse été" sps="eusses été" tps="eût été" fpp="eussions été" spp="eussiez été" tpp="eussent été"></SecondPast>
</Conditional>
<Imperative>
<Present sps="sois" fpp="soyons" spp="soyez"></Present>
<Past sps="aie été" fpp="ayons été" spp="ayez été"></Past>
</Imperative>
<Infinitive present="être" past="avoir été"></Infinitive>
<Participle present="étant" past="été"></Participle>
</VerbTable>
</ConjugationTables>
</Word>下面是我发现的对数据建模的方法。这只是一种存储机制。基本上,有必要在内存中保存整个字典(可能不包括标准的动词共轭,但这只会使事情变得更复杂--我可以在以后对此进行优化)。这将允许即时查找应用程序中的一个单词。Words将作为另一个类的数据成员存储在SortedDictionary中。还将有一个单独的拼写检查器的实现。
特定于语法的数据不应该是此架构的一部分。简单地说,特殊的异常,如bel (在以元音开头的单词之前出现的beau的拐点)将在应用程序的语法接口中单独处理。这种设计是为了在词典中的所有单词之间存储共同的属性,例如名词/形容词的变化,动词的接合,以及其他一些小的数据,如定义(S),单词的语法形式等等。
以下是我所拥有的,并将在这里提到的其他答案的基础上加以改进(至少尽我所能):
class Word
{
// the infinitive Word in the Dictionary
public string word { get; set; }
// Whether or not the Word is aspirate - adjective forms and phonetics change.
public bool aspirate { get; set; }
/*
* The list of grammatical forms that this Word can have. For example, 'être':
* 'être' --> vi (verb intransitive) "to be".
* '(un) être' --> nm (noun masculin) "(a) being".
*/
public List<GrammaticalForm> forms { get; set; }
public struct GrammaticalForm
{
// The grammatical identifier of the form (e.g., 'vi' or 'nm'). --> ENUM LATER
public string form { get; set; }
// The definition (meaning) of the Word in a particular form.
public string definition { get; set; }
}
// The table of noun INFLECTIONS, if the Word has a grammatical form of a noun.
public NounTable nounTable { get; set; }
// The table of adjective INFLECTIONS, if the Word has a grammatical form of an adjective.
public AdjectiveTable adjectiveTable { get; set; }
// The table of verb conjugations, if the Word has a grammatical form of a verb.
public VerbTable verbTable { get; set; }
}
abstract class ConjugationTable
{
// If there are any properties that would eventually be shared among all conjugation
// types, they would go here.
}
class NounTable : ConjugationTable
{
/*
* The gender of the noun:
* 'ms' (masculin singular)
* 'fs' (feminin singular)
* 'mpl' (masculin plural)
* 'fpl' (feminin plural)
*/
public string gender { get; set; }
public string ms { get; set; }
public string fs { get; set; }
public string mpl { get; set; }
public string fpl { get; set; }
}
class AdjectiveTable : ConjugationTable
{
/*
* The gender of the adjective:
* 'ms' (masculin singular)
* 'fs' (feminin singular)
* 'mpl' (masculin plural)
* 'fpl' (feminin plural)
* 'na' (non-aspirate)
*/
public string ms { get; set; }
public string fs { get; set; }
public string mpl { get; set; }
public string fpl { get; set; }
public string na { get; set; }
/*
* The location of the adjective around the noun:
* 'b' (before)
* 'a' (after)
* 'n' (neutral) --> the adjective can come before OR after the noun.
*/
public char location { get; set; }
}
class VerbTable : ConjugationTable
{
/*
* The group the verb belongs to:
* 'f' (first) --> er.
* 's' (second) --> ir.
* 't' (third) --> ir, oir, re.
* 'e' (exception) --> être, avoir, etc.
*/
public char group { get; set; }
/*
* The auxillary verb the verb takes:
* 'e' (être).
* 'a' (avoir).
*/
public char auxillary { get; set; }
// A list of grammatically-valid prepositions the verb can take.
public string[] prepositions { get; set; }
// Whether or not the verb is transitive.
public bool transitive { get; set; }
/*
* Whether or not the verb has a pronominal form. If true, a function will later
* conjugate the pronominal infinitive of the verb for lookup in the Dictionary.
* This saves space over allocating a string of the conjugated pronominal infinitive.
*/
public bool pronominal { get; set; }
/*
* The subject of the verb determined by the markers:
* 'fps' (first person singular)
* 'sps' (second person singular)
* 'tps' (third person singular)
* 'fpp' (first person plural)
* 'spp' (second person plural)
* 'tpp' (third person plural)
* 'present' (present tense)
* 'past' (past tense)
* and their accompanying conjugations.
*/
// All of the different conjugation types are instantiated
// when a VerbTable is instantiated.
public IndicativePresent indicativePresent = new IndicativePresent();
public IndicativeSimplePast indicativeSimplePast = new IndicativeSimplePast();
public IndicativePresentPerfect indicativePresentPerfect = new IndicativePresentPerfect();
public IndicativePastPerfect indicativePastPerfect = new IndicativePastPerfect();
public IndicativeImperfect indicativeImperfect = new IndicativeImperfect();
public IndicativePluperfect indicativePluperfect = new IndicativePluperfect();
public IndicativeFuture indicativeFuture = new IndicativeFuture();
public IndicativePastFuture indicativePastFuture = new IndicativePastFuture();
public SubjunctivePresent subjunctivePresent = new SubjunctivePresent();
public SubjunctivePast subjunctivePast = new SubjunctivePast();
public SubjunctiveImperfect subjunctiveImperfect = new SubjunctiveImperfect();
public SubjunctivePluperfect subjunctivePluperfect = new SubjunctivePluperfect();
public ConditionalPresent conditionalPresent = new ConditionalPresent();
public ConditionalFirstPast conditionalFirstPast = new ConditionalFirstPast();
public ConditionalSecondPast conditionalSecondPast = new ConditionalSecondPast();
public ImperativePresent imperativePresent = new ImperativePresent();
public ImperativePast imperativePast = new ImperativePast();
public Infinitive infinitive = new Infinitive();
public Participle participle = new Participle();
}
abstract class Indicative
{
// Any common elements that indicative tenses share.
public abstract string fps { get; set; }
public abstract string sps { get; set; }
public abstract string tps { get; set; }
public abstract string fpp { get; set; }
public abstract string spp { get; set; }
public abstract string tpp { get; set; }
}
abstract class Subjunctive
{
// Any common elements that subjunctive tenses share.
public abstract string fps { get; set; }
public abstract string sps { get; set; }
public abstract string tps { get; set; }
public abstract string fpp { get; set; }
public abstract string spp { get; set; }
public abstract string tpp { get; set; }
}
abstract class Conditional
{
// Any common elements that conditional tenses share.
public abstract string fps { get; set; }
public abstract string sps { get; set; }
public abstract string tps { get; set; }
public abstract string fpp { get; set; }
public abstract string spp { get; set; }
public abstract string tpp { get; set; }
}
abstract class Imperative
{
// Any common elements that imperative tenses share.
public abstract string sps { get; set; }
public abstract string fpp { get; set; }
public abstract string spp { get; set; }
}
class IndicativePresent : Indicative
{
public override string fps { get; set; }
public override string sps { get; set; }
public override string tps { get; set; }
public override string fpp { get; set; }
public override string spp { get; set; }
public override string tpp { get; set; }
}
class IndicativeSimplePast : Indicative
{
public override string fps { get; set; }
public override string sps { get; set; }
public override string tps { get; set; }
public override string fpp { get; set; }
public override string spp { get; set; }
public override string tpp { get; set; }
}
class IndicativePresentPerfect : Indicative
{
public override string fps { get; set; }
public override string sps { get; set; }
public override string tps { get; set; }
public override string fpp { get; set; }
public override string spp { get; set; }
public override string tpp { get; set; }
}
class IndicativePastPerfect : Indicative
{
public override string fps { get; set; }
public override string sps { get; set; }
public override string tps { get; set; }
public override string fpp { get; set; }
public override string spp { get; set; }
public override string tpp { get; set; }
}
class IndicativeImperfect : Indicative
{
public override string fps { get; set; }
public override string sps { get; set; }
public override string tps { get; set; }
public override string fpp { get; set; }
public override string spp { get; set; }
public override string tpp { get; set; }
}
class IndicativePluperfect : Indicative
{
public override string fps { get; set; }
public override string sps { get; set; }
public override string tps { get; set; }
public override string fpp { get; set; }
public override string spp { get; set; }
public override string tpp { get; set; }
}
class IndicativeFuture : Indicative
{
public override string fps { get; set; }
public override string sps { get; set; }
public override string tps { get; set; }
public override string fpp { get; set; }
public override string spp { get; set; }
public override string tpp { get; set; }
}
class IndicativePastFuture : Indicative
{
public override string fps { get; set; }
public override string sps { get; set; }
public override string tps { get; set; }
public override string fpp { get; set; }
public override string spp { get; set; }
public override string tpp { get; set; }
}
class SubjunctivePresent : Subjunctive
{
public override string fps { get; set; }
public override string sps { get; set; }
public override string tps { get; set; }
public override string fpp { get; set; }
public override string spp { get; set; }
public override string tpp { get; set; }
}
class SubjunctivePast : Subjunctive
{
public override string fps { get; set; }
public override string sps { get; set; }
public override string tps { get; set; }
public override string fpp { get; set; }
public override string spp { get; set; }
public override string tpp { get; set; }
}
class SubjunctiveImperfect : Subjunctive
{
public override string fps { get; set; }
public override string sps { get; set; }
public override string tps { get; set; }
public override string fpp { get; set; }
public override string spp { get; set; }
public override string tpp { get; set; }
}
class SubjunctivePluperfect : Subjunctive
{
public override string fps { get; set; }
public override string sps { get; set; }
public override string tps { get; set; }
public override string fpp { get; set; }
public override string spp { get; set; }
public override string tpp { get; set; }
}
class ConditionalPresent : Conditional
{
public override string fps { get; set; }
public override string sps { get; set; }
public override string tps { get; set; }
public override string fpp { get; set; }
public override string spp { get; set; }
public override string tpp { get; set; }
}
class ConditionalFirstPast : Conditional
{
public override string fps { get; set; }
public override string sps { get; set; }
public override string tps { get; set; }
public override string fpp { get; set; }
public override string spp { get; set; }
public override string tpp { get; set; }
}
class ConditionalSecondPast : Conditional
{
public override string fps { get; set; }
public override string sps { get; set; }
public override string tps { get; set; }
public override string fpp { get; set; }
public override string spp { get; set; }
public override string tpp { get; set; }
}
class ImperativePresent : Imperative
{
public override string sps { get; set; }
public override string fpp { get; set; }
public override string spp { get; set; }
}
class ImperativePast : Imperative
{
public override string sps { get; set; }
public override string fpp { get; set; }
public override string spp { get; set; }
}
class Infinitive
{
public string present { get; set; }
public string past { get; set; }
}
class Participle
{
public string present { get; set; }
public string past { get; set; }
}发布于 2014-02-05 13:30:41
我将主要评论查询界面,因为对于如何存储所有这些单词表单,我没有很好的想法。
你有一个小的组合爆炸问题,你应该承认。在法语中,名词和形容词的变化主要取决于性别和数字,因此您应该公开一个接受两个独立参数的Inflect()方法,而不是四个无参数获取器。当涉及动词时,带有独立论点的界面变得更为明显,动词也取决于人、时态和情绪。
正如人类语言中常见的情况一样,有些特殊的情况你可能会考虑。例如,形容词博乌以形式出现。
然而,在以元音或静音h开头的单词之前,阳性单数就变成了美语。此外,下面的单词不一定是被修改的名词(例如un et vaste沙龙)。可能还有其他的例子和论据来保持接口的灵活性,以处理这种语言缺陷。
动词组可能应该是第一、第二、第三、不规范(例如:存在)和缺陷(例如,falloir)。
https://codereview.stackexchange.com/questions/40868
复制相似问题