2017-02-10 53 views
0

我需要提取句子的头文字(更具体地说,是句子中最高名词短语的头文字)。我通过py-corenlp使用斯坦福CoreNLP服务器来注释我的句子。该套件修改了Michael Collin的词头查找算法,但我还没有找到任何通过服务器使用它的方法。我想避免重蹈覆辙,那么有什么方法可以通过Python中的现有工具实现?在Python中查找头文字

实施例:

数在1个摩尔的物质被称为什么的基本实体的

(ROOT 
    (S 
    (NP 
     (NP (DT The) (NN number)) 
     (PP (IN of) 
     (NP 
      (NP (JJ elementary) (NNS entities)) 
      (PP (IN in) 
      (NP 
       (NP (CD 1) (NN mole)) 
       (PP (IN of) 
       (NP (DT a) (NN substance)))))))) 
    (VP (VBZ is) 
     (VP (VBN known) 
     (PP (IN as) 
      (NP (WP what))))) 
    (. ?))) 

“基本实体在1个摩尔的物质的数量”是最高的名词短语。

“number”是我要提取的短语的首字。


编辑:增加的例子。

+0

请添加一个例子,你想要什么;) – Ika8

回答

0

看起来使用类型化依赖而不是语法分析可能更容易。您的句子将被动词引用,然后找到该动词的依存关系nsubj或nsubjpas。 例如:

root (ROOT-0 , known-13) <- Start with this one 
det (number-2 , The-1) 
nsubjpass (known-13 , number-2) <- Then this one 
case (entities-5 , of-3) 
amod (entities-5 , elementary-4) 
nmod (number-2 , entities-5) 
case (mole-8 , in-6) 
nummod (mole-8 , 1-7) 
nmod (entities-5 , mole-8) 
case (substance-11 , of-9) 
det (substance-11 , a-10) 
nmod (mole-8 , substance-11) 
auxpass (known-13 , is-12) 
case (what-15 , as-14) 
nmod (known-13 , what-15)