【问题标题】:Extract unique terms from a document从文档中提取唯一术语
【发布时间】:2021-10-25 05:15:10
【问题描述】:

我正在寻找一种有效的方法来从文档中提取对他来说独一无二且不会出现在任何其他文档中的术语。 天真的方法是索引数据库中的所有文档,例如 elasticsearch,并在所有索引中搜索新文档中的每个术语。这可能会非常低效。 该问题是一种特征提取问题。 我的问题是 elasticsearch 或任何其他工具是否可以提供解决此问题的有效方法?

【问题讨论】:

    标签: elasticsearch feature-extraction tf-idf


    【解决方案1】:

    如果您有大量数据,我建议您使用 Redis 数据库在 Redis 中存储和获取数据,您还可以预先缓存您的数据,以便再次加载 Redis 也使用键值对,但比 python 字典快

    为了让它独一无二,你可以做一些键值组合

    有关 Redis 的更多详细信息,请查看此 https://realpython.com/python-redis/

    【讨论】:

      【解决方案2】:
      **try this**
      
      import re
       
      # Declare a dictionary
      dict = {}
       
      # Method to check whether the word
      # exists in dictionary or not
      def uniqueWord(Word):
       
          if Word in dict:
       
              # If the word exists in dictionary then
              # simply increase its count
              dict[words] += 1
       
          else:
       
              # If the word does not exists in
              # dictionary update the dictionary
              # and make its count 1
              dict.update({words: 1})
       
      # Driver code
      if __name__ == '__main__':
           
          string = "Java is great. Grails is also great"
           
          # re.split() method is used to split
          # all the words in a string separated
          # by non-alphanumeric characters (\W)
          ListOfWords = re.split("[\W]+", string)
       
          # Extract each word from ListOfWords
          # and pass it to the method uniqueWord()
          for words in ListOfWords:
              uniqueWord(words)
       
          # Iterate over dictionary if the value
          # of the key is 1, then print the element
          for elements in dict:
              if dict[elements] == 1:
                  print(elements)
      

      【讨论】:

      • 谢谢!我说的是大量文件,每个新文件都应该很快计算出来。我想我可以在一些键值存储上管理我自己的字典,但我更喜欢使用已经存在的东西。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-10
      • 2012-02-05
      • 1970-01-01
      • 2022-01-24
      • 2013-05-28
      • 1970-01-01
      相关资源
      最近更新 更多