如何使用Stanford Parser通过python提取特征

时间:2014-10-18 10:05:15

标签: python nlp svm stanford-nlp

我在我的项目中包含了Stanford Parser。这是代码的一部分。

def parseToStanfordDependencies(self, sentence):

        tokens, tree = self.parse(sentence)
        standoffTokens = [standoffFromToken(sentence, token)
                          for token in tokens]
        posTags = [token.tag() for token in tree.taggedYield()]
        print " ".join(["%s/%s" % (word.text, tag) for word, tag in zip(standoffTokens, posTags)])
        #print tree.taggedYield().toString(False)
        result = self.package.trees.EnglishGrammaticalStructure(tree)

        returnList = []
        for dependency in result.typedDependenciesCollapsedTree():

            govStandoff = standoffTokens[dependency.gov().index() - 1]
            depStandoff = standoffTokens[dependency.dep().index() - 1]

            returnList.append((str(dependency.reln()),
                               govStandoff,
                               depStandoff))

        return Dependencies(sentence, standoffTokens, posTags, returnList)

我正在进行线性svm的文本分类任务。我试过了

from stanford_parser import parser

stanford_parser = parser.Parser()
print stanford_parser.parseToStanfordDependencies("This girl I met was your sister.")

然而,除了POS标签之外,我还想使用Stanford Parser来提取其他语法功能,例如制作规则。我该怎么办?有人愿意帮助我吗?我是Python和自然语言处理的新手。

0 个答案:

没有答案