AnantLabs / simplenlg

Automatically exported from code.google.com/p/simplenlg
0 stars 0 forks source link

Recognise plurals in strings #15

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Simplenlg should recognise plurals in strings, and indeed other inflected 
forms.  For example, realising the result of

  createClause("my dog", "like", "bones")

should result in "My dog likes bones", not "My dog likes bone".

Because of the internal architecture of simplenlg, this is not a 
straightforward fix

Original issue reported on code.google.com by ehud.rei...@gmail.com on 9 Jun 2011 at 10:59

GoogleCodeExporter commented 9 years ago
A solution to this would be to create a copy of the word, and apply the plural, 
when creating the lexicon variants. This is from the Actionscript version I'm 
working on:

private function IndexWord(word:WordElement):void
{
    ...
    // now index by variant
    var variants:Dictionary = getVariants(word);
    for (var variant:String in variants)
    {
        updateIndex(variants[variant], variant, indexByVariant);
    }
}

private function getVariants(word:WordElement):Dictionary
{
    var variants:Dictionary = new Dictionary();
    variants[word.getBaseForm()] = word;
    var category:ElementCategory = word.getCategory();
    if (category is LexicalCategory)
    {
        var clone:WordElement;
        switch (category)
        {
            case LexicalCategory.NOUN:
                clone = word.clone() as WordElement;
                clone.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);
                variants[getVariant(word, LexicalFeature.PLURAL, "s")] = clone;
                break;

            case LexicalCategory.ADJECTIVE:
                variants[getVariant(word, LexicalFeature.COMPARATIVE, "er")] = word;
                variants[getVariant(word, LexicalFeature.SUPERLATIVE, "est")] = word;
                break;

            case LexicalCategory.VERB:
                variants[getVariant(word, LexicalFeature.PRESENT3S, "s")] = word;
                variants[getVariant(word, LexicalFeature.PAST, "ed")] = word;
                variants[getVariant(word, LexicalFeature.PAST_PARTICIPLE, "ed")] = word;
                variants[getVariant(word, LexicalFeature.PRESENT_PARTICIPLE, "ing")] = word;
                break;

            default:
                // only base needed for other forms
        }
    }
    return variants;
}

Original comment by o...@steamshift.net on 28 Feb 2012 at 6:25

GoogleCodeExporter commented 9 years ago
Sorry, should've mentioned those were from the XMLLexicon class.

Original comment by o...@steamshift.net on 28 Feb 2012 at 6:48