Esempio n. 1
0
        // public method --------------------------------------------------------------
        /// <summary>
        /// Returns a pretty-printed string representation of the given semantic graph,
        /// on one or more lines.
        /// </summary>
        public virtual string FormatSemanticGraph(SemanticGraph sg)
        {
            if (sg.VertexSet().IsEmpty())
            {
                return("[]");
            }
            @out = new StringBuilder();
            // not thread-safe!!!
            used = Generics.NewHashSet();
            if (sg.GetRoots().Count == 1)
            {
                FormatSGNode(sg, sg.GetFirstRoot(), 1);
            }
            else
            {
                int index = 0;
                foreach (IndexedWord root in sg.GetRoots())
                {
                    index += 1;
                    @out.Append("root_").Append(index).Append("> ");
                    FormatSGNode(sg, root, 9);
                    @out.Append("\n");
                }
            }
            string result = @out.ToString();

            if (!result.StartsWith("["))
            {
                result = "[" + result + "]";
            }
            return(result);
        }
        public virtual void TestEnv()
        {
            SemanticGraph h = SemanticGraph.ValueOf("[married/VBN nsubjpass>Hughes/NNP auxpass>was/VBD nmod:to>Gracia/NNP]");

            h.GetFirstRoot().Set(typeof(PatternsAnnotations.PatternLabel1), "YES");
            //SemanticGraph t = SemanticGraph
            //  .valueOf("[loved/VBD\nnsubj:Hughes/NNP\ndobj:[wife/NN poss:his/PRP$ appos:Gracia/NNP]\nconj_and:[obsessed/JJ\ncop:was/VBD\nadvmod:absolutely/RB\nprep_with:[Elicia/NN poss:his/PRP$ amod:little/JJ nn:daughter/NN]]]");
            string macro = "macro WORD = married";
            Env    env   = new Env();

            env.Bind("pattern1", typeof(PatternsAnnotations.PatternLabel1));
            string pattern = "({pattern1:YES}=parent >>nsubjpass {}=node)";
            IList <SemgrexPattern> pats = SemgrexBatchParser.CompileStream(new ByteArrayInputStream(Sharpen.Runtime.GetBytesForString((macro + "\n" + pattern), StandardCharsets.Utf8)), env);
            SemgrexPattern         pat3 = pats[0];
            bool           ignoreCase   = true;
            SemgrexMatcher mat3         = pat3.Matcher(h, ignoreCase);

            if (mat3.Find())
            {
                string parent = mat3.GetNode("parent").Word();
                string node   = mat3.GetNode("node").Word();
                System.Console.Out.WriteLine("Result: parent is " + parent + " and node is " + node);
                NUnit.Framework.Assert.AreEqual(parent, "married");
                NUnit.Framework.Assert.AreEqual(node, "Hughes");
            }
            else
            {
                throw new Exception("failed!");
            }
        }
Esempio n. 3
0
 public virtual SemgrexMatcher Matcher(SemanticGraph hypGraph, Alignment alignment, SemanticGraph txtGraph, bool ignoreCase)
 {
     return(Matcher(hypGraph, alignment, txtGraph, true, hypGraph.GetFirstRoot(), Generics.NewHashMap(), Generics.NewHashMap(), new VariableStrings(), ignoreCase));
 }
Esempio n. 4
0
 /// <summary>
 /// Get a
 /// <see cref="SemgrexMatcher"/>
 /// for this pattern in this graph.
 /// </summary>
 /// <param name="sg">the SemanticGraph to match on</param>
 /// <param name="ignoreCase">
 /// will ignore case for matching a pattern with a node; not
 /// implemented by Coordination Pattern
 /// </param>
 /// <returns>a SemgrexMatcher</returns>
 public virtual SemgrexMatcher Matcher(SemanticGraph sg, bool ignoreCase)
 {
     return(Matcher(sg, sg.GetFirstRoot(), Generics.NewHashMap(), Generics.NewHashMap(), new VariableStrings(), ignoreCase));
 }
Esempio n. 5
0
 /// <summary>
 /// Get a
 /// <see cref="SemgrexMatcher"/>
 /// for this pattern in this graph, with some
 /// initial conditions on the variable assignments
 /// </summary>
 public virtual SemgrexMatcher Matcher(SemanticGraph sg, IDictionary <string, IndexedWord> variables)
 {
     return(Matcher(sg, sg.GetFirstRoot(), variables, Generics.NewHashMap(), new VariableStrings(), false));
 }
 internal override SemgrexMatcher Matcher(SemanticGraph sg, Alignment alignment, SemanticGraph sg_align, bool hyp, IndexedWord node, IDictionary <string, IndexedWord> namesToNodes, IDictionary <string, string> namesToRelations, VariableStrings
                                          variableStrings, bool ignoreCase)
 {
     // log.info("making matcher: " +
     // ((reln.equals(GraphRelation.ALIGNED_ROOT)) ? false : hyp));
     return(new NodePattern.NodeMatcher(this, sg, alignment, sg_align, (reln.Equals(GraphRelation.AlignedRoot)) ? false : hyp, (reln.Equals(GraphRelation.AlignedRoot)) ? sg_align.GetFirstRoot() : node, namesToNodes, namesToRelations, variableStrings
                                        , ignoreCase));
 }