Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dependencies"></param>
        /// <param name="token"></param>
        /// <param name="depTypeString"></param>
        /// <returns></returns>
        private edu.stanford.nlp.ling.IndexedWord FindIndexedWordByDependencyType(edu.stanford.nlp.semgraph.SemanticGraph dependencies, edu.stanford.nlp.ling.IndexedWord word, params string[] depTypeString)
        {
            if (dependencies == null || word == null)
            {
                return(null);
            }
            List <edu.stanford.nlp.trees.TypedDependency> deps = FindRefs(dependencies, word.backingLabel());

            foreach (edu.stanford.nlp.trees.TypedDependency dep in deps)
            {
                if (depTypeString.Contains(dep.reln().getShortName()))
                {
                    if (dep.gov() == word)
                    {
                        return(dep.dep());
                    }
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 搜索
        /// </summary>
        private edu.stanford.nlp.ling.IndexedWord FindNumericUnit(edu.stanford.nlp.util.CoreMap sentence, edu.stanford.nlp.ling.IndexedWord word)
        {
            edu.stanford.nlp.semgraph.SemanticGraph       dependencies = sentence.get(enhancedPlusPlusDependenciesAnnotationClass) as edu.stanford.nlp.semgraph.SemanticGraph;
            List <edu.stanford.nlp.trees.TypedDependency> tds          = FindRefs(dependencies, word.backingLabel());

            foreach (edu.stanford.nlp.trees.TypedDependency td in tds)
            {
            }
            return(null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// find the sibling relation of target word from sentence
        /// </summary>
        /// <param name="sentence"></param>
        /// <param name="word"></param>
        /// <returns>modifier words, relation type</returns>
        public List <(edu.stanford.nlp.ling.IndexedWord, string)> FindTargetIndexWordModifier(edu.stanford.nlp.util.CoreMap sentence, edu.stanford.nlp.ling.IndexedWord word)
        {
            List <(edu.stanford.nlp.ling.IndexedWord, string)> modifiers = new List <(edu.stanford.nlp.ling.IndexedWord, string)>();

            edu.stanford.nlp.semgraph.SemanticGraph       dependencies = sentence.get(enhancedPlusPlusDependenciesAnnotationClass) as edu.stanford.nlp.semgraph.SemanticGraph;
            List <edu.stanford.nlp.trees.TypedDependency> deps         = FindRefs(dependencies, word.backingLabel());

            foreach (edu.stanford.nlp.trees.TypedDependency dep in deps)
            {
                string relationType = dep.reln().ToString();
                switch (relationType)
                {
                case "nummod":      //数值修饰词,numeric modifier,搜索是否还存在单位修饰, 比如 200吨,10个
                case "amod":        //形容词修饰词,例如:红花-红
                case "nmod:of":     //of关系名词组,例如:the king of night
                case "nmod:to":     //to关系,例如:go to school, came to party
                case "nmod:into":   //名词修饰短语,例如:Investigation into the cause of the collision
                case "nmod:for":    //for关系名词修饰短语, vehicle inspections for damage assessment
                case "compound":    //multiword expression (MVE)形式
                case "advmod":      //副词修饰 safely anchored
                    modifiers.Add((dep.dep(), relationType));
                    break;
                }
                ;
            }
            return(modifiers);
        }