/// <summary>Creates an EnglishGrammaticalRelation AddDep edit.</summary>
        /// <param name="newNode">String representation of new dependent IndexedFeatureNode map.</param>
        public static Edu.Stanford.Nlp.Semgraph.Semgrex.Ssurgeon.AddDep CreateEngAddDep(string govNodeName, string engRelation, string newNode)
        {
            GrammaticalRelation relation = EnglishGrammaticalRelations.ValueOf(engRelation);
            //  IndexedWord newNodeObj = new IndexedWord(CoreLabel.fromAbstractMapLabel(IndexedFeatureLabel.valueOf(newNode, MapFactory.HASH_MAP_FACTORY)));
            IndexedWord newNodeObj = FromCheapString(newNode);

            return(new Edu.Stanford.Nlp.Semgraph.Semgrex.Ssurgeon.AddDep(govNodeName, relation, newNodeObj));
        }
        /// <summary>
        /// Convert from a string representation of a GrammaticalRelation to a
        /// GrammaticalRelation.  Where possible, you should avoid using this
        /// method and simply work with true GrammaticalRelations rather than
        /// string representations.  Correct behavior of this method depends
        /// on the underlying data structure resources used being kept in sync
        /// with the ToString() and Equals() methods.  However, there is really
        /// no choice but to use this method when storing GrammaticalRelations
        /// to text files and then reading them back in, so this method is not deprecated.
        /// </summary>
        /// <param name="s">The string representation of a GrammaticalRelation</param>
        /// <returns>The grammatical relation represented by this String</returns>
        public static GrammaticalRelation ValueOf(Language language, string s)
        {
            GrammaticalRelation reln = (StringsToRelations[language] != null
                ? ValueOf(s, StringsToRelations[language].Values)
                : null);

            if (reln == null)
            {
                // TODO this breaks the hierarchical structure of the classes,
                //      but it makes English relations that much likelier to work.
                reln = EnglishGrammaticalRelations.ValueOf(s);
            }
            if (reln == null)
            {
                // the block below fails when 'specific' includes underscores.
                // this is possible on weird web text, which generates relations such as prep______

                /*
                 * string[] names = s.split("_");
                 * string specific = names.length > 1? names[1] : null;
                 * reln = new GrammaticalRelation(language, names[0], null, null, null, specific);
                 */
                string name;
                string specific;
                int    underscorePosition = s.IndexOf('_');
                if (underscorePosition > 0)
                {
                    name     = s.Substring(0, underscorePosition);
                    specific = s.Substring(underscorePosition + 1);
                }
                else
                {
                    name     = s;
                    specific = null;
                }
                reln = new GrammaticalRelation(language, name, null, null, specific);
            }
            return(reln);
        }
Exemple #3
0
        public static Edu.Stanford.Nlp.Semgraph.Semgrex.Ssurgeon.AddEdge CreateEngAddEdge(string govName, string depName, string engRelnName, double weight)
        {
            GrammaticalRelation reln = EnglishGrammaticalRelations.ValueOf(engRelnName);

            return(new Edu.Stanford.Nlp.Semgraph.Semgrex.Ssurgeon.AddEdge(govName, depName, reln, weight));
        }
Exemple #4
0
        /// <summary>
        /// When deserializing a GrammaticalRelation, it needs to be matched
        /// up with the existing singleton relation of the same type.
        /// </summary>
        /// <remarks>
        /// When deserializing a GrammaticalRelation, it needs to be matched
        /// up with the existing singleton relation of the same type.
        /// TODO: there are a bunch of things wrong with this.  For one
        /// thing, it's crazy slow, since it goes through all the existing
        /// relations in an array.  For another, it would be cleaner to have
        /// subclasses for the English and Chinese relations
        /// </remarks>
        /// <exception cref="Java.IO.ObjectStreamException"/>
        protected internal virtual object ReadResolve()
        {
            switch (language)
            {
            case Language.Any:
            {
                if (shortName.Equals(Governor.shortName))
                {
                    return(Governor);
                }
                else
                {
                    if (shortName.Equals(Dependent.shortName))
                    {
                        return(Dependent);
                    }
                    else
                    {
                        if (shortName.Equals(Root.shortName))
                        {
                            return(Root);
                        }
                        else
                        {
                            if (shortName.Equals(Kill.shortName))
                            {
                                return(Kill);
                            }
                            else
                            {
                                throw new Exception("Unknown general relation " + shortName);
                            }
                        }
                    }
                }
                goto case Language.English;
            }

            case Language.English:
            {
                Edu.Stanford.Nlp.Trees.GrammaticalRelation rel = EnglishGrammaticalRelations.ValueOf(ToString());
                if (rel == null)
                {
                    switch (shortName)
                    {
                    case "conj":
                    {
                        return(EnglishGrammaticalRelations.GetConj(specific));
                    }

                    case "prep":
                    {
                        return(EnglishGrammaticalRelations.GetPrep(specific));
                    }

                    case "prepc":
                    {
                        return(EnglishGrammaticalRelations.GetPrepC(specific));
                    }

                    default:
                    {
                        // TODO: we need to figure out what to do with relations
                        // which were serialized and then deprecated.  Perhaps there
                        // is a good way to make them singletons
                        return(this);
                    }
                    }
                }
                else
                {
                    //throw new RuntimeException("Unknown English relation " + this);
                    return(rel);
                }
                goto case Language.Chinese;
            }

            case Language.Chinese:
            {
                Edu.Stanford.Nlp.Trees.GrammaticalRelation rel = ChineseGrammaticalRelations.ValueOf(ToString());
                if (rel == null)
                {
                    // TODO: we need to figure out what to do with relations
                    // which were serialized and then deprecated.  Perhaps there
                    // is a good way to make them singletons
                    return(this);
                }
                //throw new RuntimeException("Unknown Chinese relation " + this);
                return(rel);
            }

            case Language.UniversalEnglish:
            {
                Edu.Stanford.Nlp.Trees.GrammaticalRelation rel_1 = UniversalEnglishGrammaticalRelations.ValueOf(ToString());
                if (rel_1 == null)
                {
                    switch (shortName)
                    {
                    case "conj":
                    {
                        return(UniversalEnglishGrammaticalRelations.GetConj(specific));
                    }

                    case "nmod":
                    {
                        return(UniversalEnglishGrammaticalRelations.GetNmod(specific));
                    }

                    case "acl":
                    {
                        return(UniversalEnglishGrammaticalRelations.GetAcl(specific));
                    }

                    case "advcl":
                    {
                        return(UniversalEnglishGrammaticalRelations.GetAdvcl(specific));
                    }

                    default:
                    {
                        // TODO: we need to figure out what to do with relations
                        // which were serialized and then deprecated.  Perhaps there
                        // is a good way to make them singletons
                        return(this);
                    }
                    }
                }
                else
                {
                    //throw new RuntimeException("Unknown English relation " + this);
                    return(rel_1);
                }
                goto default;
            }

            default:
            {
                throw new Exception("Unknown language " + language);
            }
            }
        }