示例#1
0
 /// <summary>Remove attached pronouns from a strippable Spanish verb form.</summary>
 /// <remarks>
 /// Remove attached pronouns from a strippable Spanish verb form. (Use
 /// <see cref="IsStrippable(string)"/>
 /// to determine if a word is a
 /// strippable verb.)
 /// Converts, e.g.,
 /// <ul>
 /// <li> decírmelo -&gt; decir
 /// <li> mudarse -&gt; mudar
 /// <li> contándolos -&gt; contando
 /// <li> hazlo -&gt; haz
 /// </ul>
 /// </remarks>
 /// <returns>
 /// A verb form stripped of attached pronouns, or <tt>null</tt>
 /// if no pronouns were located / stripped.
 /// </returns>
 public string StripVerb(string verb)
 {
     SpanishVerbStripper.StrippedVerb separated = SeparatePronouns(verb);
     if (separated != null)
     {
         return(separated.GetStem());
     }
     return(null);
 }
示例#2
0
        /// <summary>Validate and normalize the given verb stripper result.</summary>
        /// <remarks>
        /// Validate and normalize the given verb stripper result.
        /// Returns <tt>true</tt> if the given data is a valid pairing of verb form
        /// and clitic pronoun(s).
        /// May modify <tt>pair</tt> in place in order to make the pair valid.
        /// For example, if the pair <tt>(senta, os)</tt> is provided, this
        /// method will return <tt>true</tt> and modify the pair to be
        /// <tt>(sentad, os)</tt>.
        /// </remarks>
        private bool NormalizeStrippedVerb(SpanishVerbStripper.StrippedVerb verb)
        {
            string normalized = RemoveAccents(verb.GetOriginalStem());
            string firstPron  = verb.GetPronouns()[0].ToLower();
            // Look up verb in dictionary.
            string verbKey = normalized.ToLower();
            string pos     = dict[verbKey];
            bool   valid   = false;

            // System.out.println(verbKey + " " + dict.containsKey(verbKey + 's'));
            // Validate resulting split verb and normalize the new form at the same
            // time.
            if (pos != null)
            {
                // Check not invalid combination of verb root and pronoun.
                // (If we combine a second-person plural imperative and the
                // second person plural object pronoun, we expect to see an
                // elided verb root, not the normal one that's in the
                // dictionary.)
                valid = !(pos.Equals("VMM02P0") && Sharpen.Runtime.EqualsIgnoreCase(firstPron, "os"));
            }
            else
            {
                if (Sharpen.Runtime.EqualsIgnoreCase(firstPron, "os") && dict.Contains(verbKey + 'd'))
                {
                    // Special case: de-elide elided verb root in the case of a second
                    // person plural imperative + second person object pronoun
                    //
                    // (e.g., given (senta, os), return (sentad, os))
                    normalized = normalized + GetCase(normalized, 'd');
                    valid      = true;
                }
                else
                {
                    if (nosse.Matcher(firstPron).Matches() && dict.Contains(verbKey + 's'))
                    {
                        // Special case: de-elide elided verb root in the case of a first
                        // person plural imperative + object pronoun
                        //
                        // (vámo, nos) -> (vámos, nos)
                        normalized = normalized + GetCase(normalized, 's');
                        valid      = true;
                    }
                }
            }
            if (valid)
            {
                // Update normalized form.
                verb.SetStem(normalized);
                return(true);
            }
            return(false);
        }