【问题标题】:Finding similar pattern in text在文本中寻找相似的模式
【发布时间】:2017-08-01 21:44:03
【问题描述】:

我有一列包含文本数据。示例如下图。

                 column1
                  Apple
                  Mango
                  Grape
                  banana
                  Apple
                  Mango
                  Fruit

如果你看数据,苹果紧随其后的是芒果。或者可以说每当苹果出现时,下一个芒果就会出现。这样的匹配可能不止一种。这怎么能找到。我知道在 nlp 中完成的文本相似性查找技术。但是如何处理这种情况。请有任何建议。

【问题讨论】:

  • 您似乎正在寻找二元组,例如 thisthis other 问题
  • 如果您正在寻找 100% 的可预测性,那么这不是 ML 问题,而是简单的编程。如果您正在寻找“通常遵循”,那么您需要查看您提到的那些 NLP 技术。无论哪种方式,请将此问题细化为合适的 Stack Overflow 帖子。
  • 欢迎来到 StackOverflow。请阅读并遵循帮助文档中的发布指南。 on topichow to ask 在这里申请。

标签: machine-learning nlp


【解决方案1】:

不使用机器学习:

col = ['Apple', 'Mango', 'Grape', 'banana', 'Apple', 'Mango', 'Fruit']
for wrd in set(col):
    indices=[i for i, x in enumerate(col) if x == wrd]
    if len(col)-1 in indices:
        continue #Last element cannot be followed by anything
    elif len(indices) ==1:
        continue #Do we want single elements? I suppose not
    elif len(set([col[i+1] for i in indices])) ==1:
        print(wrd+" is always followed by "+col[indices[0]+1])

> Apple is always followed by Mango

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-24
    • 1970-01-01
    • 1970-01-01
    • 2015-06-09
    • 1970-01-01
    • 2021-01-10
    • 2011-12-12
    • 1970-01-01
    相关资源
    最近更新 更多