/// <summary>Emits a parseable instruction string.</summary>
        public override string ToEditString()
        {
            StringWriter buf = new StringWriter();

            buf.Write(Label);
            buf.Write("\t");
            buf.Write(Edu.Stanford.Nlp.Semgraph.Semgrex.Ssurgeon.Ssurgeon.GovNodenameArg);
            buf.Write(" ");
            buf.Write(govNodeName);
            buf.Write("\t");
            buf.Write(Edu.Stanford.Nlp.Semgraph.Semgrex.Ssurgeon.Ssurgeon.RelnArg);
            buf.Write(" ");
            buf.Write(relation.ToString());
            buf.Write("\t");
            buf.Write(Edu.Stanford.Nlp.Semgraph.Semgrex.Ssurgeon.Ssurgeon.NodeProtoArg);
            buf.Write(" ");
            buf.Write("\"");
            //  buf.write(newNodePrototype.toString("map")); buf.write("\"\t")
            buf.Write(CheapWordToString(newNodePrototype));
            buf.Write("\"\t");
            buf.Write(Edu.Stanford.Nlp.Semgraph.Semgrex.Ssurgeon.Ssurgeon.WeightArg);
            buf.Write(" ");
            buf.Write(weight.ToString());
            return(buf.ToString());
        }
Exemple #2
0
        public override string ToEditString()
        {
            StringWriter buf = new StringWriter();

            buf.Write(Label);
            buf.Write("\t");
            buf.Write(Edu.Stanford.Nlp.Semgraph.Semgrex.Ssurgeon.Ssurgeon.RelnArg);
            buf.Write(" ");
            buf.Write(relation.ToString());
            buf.Write("\t");
            buf.Write(Edu.Stanford.Nlp.Semgraph.Semgrex.Ssurgeon.Ssurgeon.GovNodenameArg);
            buf.Write(" ");
            buf.Write(govName);
            buf.Write("\t");
            buf.Write(Edu.Stanford.Nlp.Semgraph.Semgrex.Ssurgeon.Ssurgeon.DepNodenameArg);
            buf.Write(" ");
            buf.Write(depName);
            return(buf.ToString());
        }
        internal static bool CheckIfSatisfiesRelConstrains(SemanticGraph g, IndexedWord curr, IndexedWord child, IList <string> allCutOffRels, GrammaticalRelation rel)
        {
            string relName         = rel.GetShortName();
            string relSpecificName = rel.ToString();
            string relFullName     = rel.GetLongName();

            if (allCutOffRels != null)
            {
                foreach (string check in allCutOffRels)
                {
                    if (relName.Matches(check) || (relSpecificName != null && relSpecificName.Matches(check)) || (relFullName != null && relFullName.Matches(check)))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #4
0
        public virtual string PrintSemanticGraph(SemanticGraph sg, bool unescapeParenthesis)
        {
            bool          isTree = SemanticGraphUtils.IsTree(sg);
            StringBuilder sb     = new StringBuilder();

            /* Print comments. */
            foreach (string comment in sg.GetComments())
            {
                sb.Append(comment).Append("\n");
            }
            foreach (IndexedWord token in sg.VertexListSorted())
            {
                /* Check for multiword tokens. */
                if (token.ContainsKey(typeof(CoreAnnotations.CoNLLUTokenSpanAnnotation)))
                {
                    IntPair tokenSpan = token.Get(typeof(CoreAnnotations.CoNLLUTokenSpanAnnotation));
                    if (tokenSpan.GetSource() == token.Index())
                    {
                        string range = string.Format("%d-%d", tokenSpan.GetSource(), tokenSpan.GetTarget());
                        sb.Append(string.Format("%s\t%s\t_\t_\t_\t_\t_\t_\t_\t_%n", range, token.OriginalText()));
                    }
                }
                /* Try to find main governor and additional dependencies. */
                string govIdx = null;
                GrammaticalRelation         reln = null;
                Dictionary <string, string> enhancedDependencies = new Dictionary <string, string>();
                foreach (IndexedWord parent in sg.GetParents(token))
                {
                    SemanticGraphEdge edge = sg.GetEdge(parent, token);
                    if (govIdx == null && !edge.IsExtra())
                    {
                        govIdx = parent.ToCopyIndex();
                        reln   = edge.GetRelation();
                    }
                    enhancedDependencies[parent.ToCopyIndex()] = edge.GetRelation().ToString();
                }
                string additionalDepsString = isTree ? "_" : CoNLLUUtils.ToExtraDepsString(enhancedDependencies);
                string word           = token.Word();
                string featuresString = CoNLLUUtils.ToFeatureString(token.Get(typeof(CoreAnnotations.CoNLLUFeats)));
                string pos            = token.GetString <CoreAnnotations.PartOfSpeechAnnotation>("_");
                string upos           = token.GetString <CoreAnnotations.CoarseTagAnnotation>("_");
                string misc           = token.GetString <CoreAnnotations.CoNLLUMisc>("_");
                string lemma          = token.GetString <CoreAnnotations.LemmaAnnotation>("_");
                string relnName       = reln == null ? "_" : reln.ToString();
                /* Root. */
                if (govIdx == null && sg.GetRoots().Contains(token))
                {
                    govIdx               = "0";
                    relnName             = GrammaticalRelation.Root.ToString();
                    additionalDepsString = isTree ? "_" : "0:" + relnName;
                }
                else
                {
                    if (govIdx == null)
                    {
                        govIdx   = "_";
                        relnName = "_";
                    }
                }
                if (unescapeParenthesis)
                {
                    word  = word.ReplaceAll(LrbPattern, "(");
                    word  = word.ReplaceAll(RrbPattern, ")");
                    lemma = lemma.ReplaceAll(LrbPattern, "(");
                    lemma = lemma.ReplaceAll(RrbPattern, ")");
                }
                sb.Append(string.Format("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s%n", token.ToCopyIndex(), word, lemma, upos, pos, featuresString, govIdx, relnName, additionalDepsString, misc));
            }
            sb.Append("\n");
            return(sb.ToString());
        }