proof-of-false

2025 April Fools' Day joke

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
import json
import pkg_resources

class PingZeClassifier:
    def __init__(self, json_file_path=None):
        if json_file_path is None:
            # Default to the JSON in the package data folder
            json_file_path = pkg_resources.resource_filename(
                __name__, 'data/organized_ping_ze_rhyme_dict.json'
            )

        # Load the ping-ze rhyme dictionary from the provided JSON file
        with open(json_file_path, 'r', encoding='utf-8') as file:
            self.ping_ze_dict = json.load(file)
                    
        # Collapse the ping and ze characters into strings
        self.ping_characters, self.ze_characters = self._collapse_ping_ze()

    def _collapse_ping_ze(self):
        """Helper function to collapse all characters in the ping and ze sections into strings."""
        ping_dict = self.ping_ze_dict.get('ping', {})
        ze_dict = self.ping_ze_dict.get('ze', {})

        # Extract all characters from ping
        ping_characters = "".join([char for rhyme_group in ping_dict.values() for rhymes in rhyme_group.values() for char in rhymes])

        # Extract all characters from ze
        ze_characters = "".join([char for rhyme_group in ze_dict.values() for rhymes in rhyme_group.values() for char in rhymes])

        return ping_characters, ze_characters

    def classify(self, sentence):
        """Classifies each character in a sentence as 'ping', 'ze', or 'unknown'."""
        classification = []

        # Classify each character in the sentence
        for char in sentence:
            if char in self.ping_characters:
                classification.append('ping')
            elif char in self.ze_characters:
                classification.append('ze')
            else:
                classification.append('unknown')
        
        return classification