使用findall regex表达式方法python

时间:2018-04-28 20:39:23

标签: python regex list

我正在使用正则表达式python模块来查找法律文档中的所有关键短语。其中一个不足5美国法典。 §8452(a)但它只打印并查找句子并在第一期停止;而不是我的输出读数:

  

根据5 U.S.C,理事会对此上诉拥有管辖权。 §8452(a)

,它读取

  

董事会对5 U下的上诉具有管辖权。

代替。这是我的代码

  ruling_corpora  = map(lambda x: x[0], re.findall('([^.]*?(I find|In sum|agree|affirm|disagree|I conclude|In light of| under| this appeal| The ALJ| I determine| we| based on| for the reasons| pursuant to| the decision is| jurisidiction|section|§+\d |conclude)[^.]*\.)', tokenized, re.I | re.DOTALL | re.M))

    reduce = 0
    for r in ruling_corpora:#*
      reduce -=5
      big_list=[]
      big_list.extend(ruling_corpora)
      rc_list=[]
      rc_list.append(set(r))
      big_string= "".join(str(x)for x in  big_list)
      if len(big_string.split('.'))<= 3:
        while len(big_string.split())<=200:
          print("Ruling Content: {} \n".format(big_string))
          break
        break
    else:                                  
      summary=summarize(big_string,word_count=250+reduce)
      print("Summarized Ruling: {}\n".format(summary))
      break
   break

1 个答案:

答案 0 :(得分:0)

你的正则表达式停在第一个字面点。

([^.]*?( _snipped lots of text_ )[^.]*\.
                                # ^^^^^^

标记的(^^^^)部分捕获所有不是点+文字点的文本,然后完成。

那是The Board has jurisdiction over this appeal under 5 U.

您没有显示真实文本,您可以更改此特殊情况以捕获不是)的任何内容,然后是)

'([^.]*?(I find|In sum|agree|affirm|disagree|I conclude|In light of| under| this appeal| The ALJ| I determine| we| based on| for the reasons| pursuant to| the decision is| jurisidiction|section|§+\d |conclude)[^)]*\))', tokenized, re.I | re.DOTALL | re.M))