blob.noun_phrases因ConllExtractor()而失败

时间:2019-08-27 10:44:52

标签: python yaml

我正在导入yaml文件,并且在调用blob.noun_phrases时出现错误。我通过指定unicode尝试了一个简单的示例,它可以工作,但在这种情况下不起作用。有人可以帮我吗?弄清楚这一点。预先感谢。

class TatvamNPExtractService:
    text_column_no = -1

    def Read_config(self, config_file, cust_id):
        path = {}
        config_file_obj = open(self.config_file, "r")
        consts = YAML.load(config_file_obj)

        if consts:
            log_out_path = consts['log_file_dir']
            path['log_out_path'] = log_out_path
            self.text_column_no = consts['comment_column_no']  # column contains reviews
            return path

    def NounPhraseExtrctor(self, file):
        word_chars_pattern = re.compile('\W')
        try:
            in_file_path = self.paths['in_dir_path'] + file

            with open(in_file_path, 'rb') as csvfile:
                reader = csv.reader(csvfile, delimiter="|")
                extractor = ConllExtractor()
                for row in reader:
                    if len(row) > 2:
                        mod_text = row[self.text_column_no-1]
                        print " the text is %s" % ",  ".join(mod_text)
                        tBlob = TextBlob(mod_text,  np_extractor=extractor)
                        tlist = tBlob.noun_phrases
            return True

上面的代码给我下面的错误:

AttributeError: 'str' object has no attribute 'raw'

编辑 主程序:

import TatvamNPExtractService

def main():
    cmd_args =[]
    config_file = ""

    cmd_args.extend(sys.argv)
    if len(cmd_args) < 3:
        print "Expecting Config File and Customer ID!!! Terminating..."
        sys.exit()

    config_file = sys.argv[1]
    cust_id = sys.argv[2]
    if not (os.path.exists(config_file)):
        print "config File not exists, Terminating"
        sys.exit()

    ps = TatvamNPExtractService.TatvamNPExtractService(cust_id, config_file)
    ps.doProcess()

0 个答案:

没有答案