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);
        }
コード例 #2
0
        private void ExtractNPorPRPFromDependency(ICoreMap s, IList <Mention> mentions, ICollection <IntPair> mentionSpanSet, ICollection <IntPair> namedEntitySpanSet)
        {
            IList <CoreLabel>   sent       = s.Get(typeof(CoreAnnotations.TokensAnnotation));
            SemanticGraph       basic      = s.Get(typeof(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation));
            IList <IndexedWord> nounsOrPrp = basic.GetAllNodesByPartOfSpeechPattern("N.*|PRP.*|DT");
            // DT is for "this, these, etc"
            Tree tree = s.Get(typeof(TreeCoreAnnotations.TreeAnnotation));

            foreach (IndexedWord w in nounsOrPrp)
            {
                SemanticGraphEdge   edge = basic.GetEdge(basic.GetParent(w), w);
                GrammaticalRelation rel  = null;
                string shortname         = "root";
                // if edge is null, it's root
                if (edge != null)
                {
                    rel       = edge.GetRelation();
                    shortname = rel.GetShortName();
                }
                // TODO: what to remove? remove more?
                if (shortname.Matches("det|compound"))
                {
                    //        // for debug  ---------------
                    //        Tree t = tree.getLeaves().get(w.index()-1);
                    //        for(Tree p : tree.pathNodeToNode(t, tree)) {
                    //          if(p.label().value().equals("NP")) {
                    //            HeadFinder headFinder = new SemanticHeadFinder();
                    //            Tree head = headFinder.determineHead(p);
                    //            if(head == t.parent(tree)) {
                    //              log.info();
                    //            }
                    //            break;
                    //          }
                    //        } // for debug -------------
                    continue;
                }
                else
                {
                    ExtractMentionForHeadword(w, basic, s, mentions, mentionSpanSet, namedEntitySpanSet);
                }
            }
        }
コード例 #3
0
        static ChineseGrammaticalRelations()
        {
            /*
             * The "predicate" grammatical relation.
             */
            // Fri Feb 20 15:42:54 2009 (pichuan)
            // I'm surprise this relation has patterns.
            // However it doesn't seem to match anything in CTB6.

            /*
             * public static final GrammaticalRelation PREDICATE =
             * new GrammaticalRelation(Language.Chinese, "pred", "predicate",
             * PredicateGRAnnotation.class, DEPENDENT, "IP",
             * new String[]{
             * " IP=target !> IP"
             * });
             * public static class PredicateGRAnnotation
             * extends GrammaticalRelationAnnotation { }
             */
            // Split the first rule to the second rule to avoid the duplication:
            // ccomp(前来-12, 投资-13)
            // conj(前来-12, 投资-13)
            //
            //      (IP
            //        (VP
            //          (VP (VV 前来))
            //          (VP
            //            (VCD (VV 投资) (VV 办厂)))
            //          (CC 和)
            //          (VP (VV 洽谈)
            //            (NP (NN 生意))))))
            // TODO: this following line has to be fixed.
            //       I think for now it just doesn't match anything.
            //"VP|NP|ADJP|PP|ADVP|UCP < ( __=target $+ (PU < 、) )",
            // Consider changing the rule ABOVE to these rules.
            //"ADVP < ( /^AD/=target $+ ((PU < 、) $+ /^AD/))",
            // This is for the 'conj's separated by commas.
            // For now this creates too much duplicates with 'ccomp'.
            // Need to look at more examples.
            // Original version of this did not have the outer layer of
            // the FRAG|INC|IP|VP.  This caused a bug where the basic
            // dependencies could have cycles.
            // This following rule is too general and collides with 'ccomp'.
            // Delete it for now.
            // TODO: come up with a new rule. Does this exist in Chinese?
            //"IP < (IP=target $+ ( VP !< VC))",

            /*
             * The "indirect object" grammatical relation.
             */
            // deleted by pichuan: no real matches

            /*
             * public static final GrammaticalRelation INDIRECT_OBJECT =
             * new GrammaticalRelation(Language.Chinese,
             * "iobj", "indirect object",
             * IndirectObjectGRAnnotation.class,  OBJECT, "VP",
             * new String[]{
             * " CP !> VP < ( VV $+ ( NP|DP|QP|CLP=target . NP|DP ) )"
             * });
             * public static class IndirectObjectGRAnnotation
             * extends GrammaticalRelationAnnotation { }
             */
            //        "  VP|IP <  ( VV|VC|VRD|VCD !$+  NP|QP|LCP ) > (IP   < IP|VP|VRD|VCD=target)   "
            //          "VP < (S=target < (VP !<, TO|VBG) !$-- NP)",
            // pichuan: this is difficult to recognize in Chinese.
            // remove the rules since it (always) collides with ccomp
            // TODO: these rules seem to always collide with ccomp.
            // Is this really desirable behavior?
            //"VP !> (/^VP/ < /^VC$/ ) < (IP=target < (VP < P))",
            //"ADJP < (IP=target <, (VP <, P))",
            //"VP < (IP=target < (NP $+ NP|ADJP))",
            //"VP < (/^VC/ $+ (VP=target < VC < NP))"

            /*
             * The "adjectival complement" grammatical relation.
             * Example:
             */
            // deleted by pichuan: no real matches

            /*
             * public static final GrammaticalRelation ADJECTIVAL_COMPLEMENT =
             * new GrammaticalRelation(Language.Chinese,
             * "acomp", "adjectival complement",
             * AdjectivalComplementGRAnnotation.class, COMPLEMENT, "VP", tregexCompiler,
             * new String[]{
             * "VP < (ADJP=target !$-- NP)"
             * });
             * public static class AdjectivalComplementGRAnnotation
             * extends GrammaticalRelationAnnotation { }
             */
            /* This rule actually matches nothing.
             * There's another tmod rule. This is removed for now.
             * (pichuan) Sun Mar  8 18:22:40 2009
             */
            /*
             * public static final GrammaticalRelation TEMPORAL_MODIFIER =
             * new GrammaticalRelation(Language.Chinese,
             * "tmod", "temporal modifier",
             * TemporalModifierGRAnnotation.class, MODIFIER, "VP|IP|ADJP", tregexCompiler,
             * new String[]{
             * " VC|VE ! >> VP|ADJP < NP=target < NT",
             * "VC|VE !>>IP <( NP=target < NT $++ VP !< VC|VE )"
             * });
             * public static class TemporalModifierGRAnnotation
             * extends GrammaticalRelationAnnotation { }
             */
            // pichuan: previously "tclaus"
            // TODO: we should figure out various ways to improve this pattern to
            // improve both its precision and recall
            //"DP < DT < QP=target"

            /*
             * The "possession modifier" grammatical relation.
             */
            // Fri Feb 20 15:40:13 2009 (pichuan)
            // I think this "poss" relation is just WRONG.
            // DEC is a complementizer or a nominalizer,
            // this rule probably originally want to capture "DEG".
            // But it seems like it's covered by "assm" (associative marker).

            /*
             * public static final GrammaticalRelation POSSESSION_MODIFIER =
             * new GrammaticalRelation(Language.Chinese,
             * "poss", "possession modifier",
             * PossessionModifierGRAnnotation.class, MODIFIER, "NP", tregexCompiler,
             * new String[]{
             * "NP < ( PN=target $+ DEC $+  NP )"
             * });
             * public static class PossessionModifierGRAnnotation
             * extends GrammaticalRelationAnnotation { }
             */
            /*
             * The "possessive marker" grammatical relation.
             */
            // Similar to the comments to "poss",
            // I think this relation is wrong and will not appear.

            /*
             * public static final GrammaticalRelation POSSESSIVE_MODIFIER =
             * new GrammaticalRelation(Language.Chinese, "possm", "possessive marker",
             * PossessiveModifierGRAnnotation.class,
             * MODIFIER, "NP", tregexCompiler,
             * new String[]{
             * "NP < ( PN $+ DEC=target ) "
             * });
             * public static class PossessiveModifierGRAnnotation
             * extends GrammaticalRelationAnnotation { }
             */
            // pichuan: previously "clmpd"
            //ADJECTIVAL_COMPLEMENT,
            //INDIRECT_OBJECT,
            //POSSESSION_MODIFIER,
            //POSSESSIVE_MODIFIER,
            //PREDICATE,
            // Cache frequently used views of the values list
            for (int i = 0; i < rawValues.Length; i++)
            {
                GrammaticalRelation gr = rawValues[i];
                synchronizedValues.Add(gr);
            }
            ValuesLock().Lock();
            try
            {
                foreach (GrammaticalRelation gr in Edu.Stanford.Nlp.Trees.International.Pennchinese.ChineseGrammaticalRelations.Values())
                {
                    shortNameToGRel[gr.GetShortName()] = gr;
                }
            }
            finally
            {
                ValuesLock().Unlock();
            }
        }