dirty.py 938 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. @Time : 2024/9/13 14:29
  5. @Author : cao
  6. @File : dirty.py
  7. @Desc :
  8. """
  9. import logging
  10. import utils
  11. import jieba
  12. logger = logging.getLogger(__name__)
  13. def load_dirty(file):
  14. with open(file) as f:
  15. words = [line.strip().split(" ")[0] for line in f]
  16. return words
  17. dirty = load_dirty(utils.DIRTY_DATA)
  18. def dirty_detect(sentence):
  19. if sentence in dirty:
  20. return True, {"status":1, "word":sentence, "query": sentence, "意图类别":"脏话", "intent": "转人工","isFaq":False, "query": sentence}
  21. words = jieba.lcut(sentence.lower(), cut_all=True)
  22. for word in words:
  23. if word in dirty:
  24. return True, {"status":1,"word": word,"query": sentence, "意图类别":"脏话", "intent": "转人工","isFaq":False, "query": sentence}
  25. return False, ''
  26. if __name__ == "__main__":
  27. print(dirty_detect("SB吧,怎么老停水"))