【问题标题】:How to split concatenated strings of this kind: "howdoIsplitthis?"如何拆分这种连接的字符串:“howdoIsplitthis?”
【发布时间】:2018-03-11 12:09:51
【问题描述】:

假设我有一个这样的字符串:

"IgotthistextfromapdfIscraped.HowdoIsplitthis?"

我想制作:

"I got this text from a pdf I scraped. How do I split this?"

我该怎么做?

【问题讨论】:

  • "wheeloffortune" -> "wheel" "off" "or" "tune"?
  • @RobertLozyniak python-wordsegmentsegment 函数将其拆分为 ['wheel', 'of', 'fortune']。不错吧?

标签: string algorithm tokenize text-segmentation


【解决方案1】:

简短的回答:没有现实的机会。

长答案:

分割字符串的唯一提示是在字符串中找到有效的单词。所以你需要一本预期语言的字典,不仅包含词根,还包含所有的屈曲(这是正确的语言术语吗?)。然后您可以尝试找到与您的字符串字符匹配的这些单词的序列。

【讨论】:

  • ... 并且可能通过带有“auto-fix”的语法检查器
  • python-wordsegment 库可以做我在这种情况下需要做的事情。
【解决方案2】:

原来这个任务叫word segmentation,有一个python library可以做到:

>>> from wordsegment import load, segment
>>> load()
>>> segment("IgotthistextfromapdfIscraped.HowdoIsplitthis?")
['i', 'got', 'this', 'text', 'from', 'a', 'pdf', 'i', 'scraped', 'how',
 'do', 'i', 'split', 'this']

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-07
    • 1970-01-01
    • 2017-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多