| """ |
| Direct test of the Purpose Assessment functionality |
| """ |
|
|
| class PurposeDimension(str): |
| JUSTICE = "justice_orientation" |
| COMMUNITY = "community_focus" |
| GROWTH = "growth_mindset" |
| SELF_EXPRESSION = "self_expression" |
| AUTONOMY = "autonomy" |
| COMPASSION = "compassion" |
| MASTERY = "mastery" |
| HARMONY = "harmony" |
|
|
| class PurposeAssessmentEngine: |
| """ |
| Simplified version of the purpose assessment engine for testing |
| """ |
| def __init__(self): |
| self.keyword_weight = 0.4 |
| self.semantic_weight = 0.6 |
| |
| self.dimensions = { |
| PurposeDimension.JUSTICE: { |
| 'keywords': ['fair', 'unfair', 'justice', 'rights', 'equality'], |
| 'description': 'Focus on fairness, ethics, and moral correctness' |
| }, |
| PurposeDimension.COMMUNITY: { |
| 'keywords': ['we', 'us', 'together', 'community', 'support'], |
| 'description': 'Focus on social connections and community building' |
| }, |
| PurposeDimension.GROWTH: { |
| 'keywords': ['learn', 'grow', 'improve', 'develop', 'better'], |
| 'description': 'Focus on personal development and learning' |
| }, |
| PurposeDimension.SELF_EXPRESSION: { |
| 'keywords': ['feel', 'think', 'believe', 'express', 'voice'], |
| 'description': 'Focus on self-expression and authenticity' |
| }, |
| PurposeDimension.AUTONOMY: { |
| 'keywords': ['free', 'choose', 'decide', 'control', 'independent'], |
| 'description': 'Focus on independence and self-determination' |
| }, |
| PurposeDimension.COMPASSION: { |
| 'keywords': ['care', 'kind', 'empathy', 'understand', 'support'], |
| 'description': 'Focus on caring for others and emotional support' |
| }, |
| PurposeDimension.MASTERY: { |
| 'keywords': ['skill', 'master', 'excel', 'achieve', 'succeed'], |
| 'description': 'Focus on achievement and skill development' |
| }, |
| PurposeDimension.HARMONY: { |
| 'keywords': ['peace', 'balance', 'calm', 'serene', 'tranquil'], |
| 'description': 'Focus on balance and inner peace' |
| } |
| } |
| |
| def analyze_text(self, text: str) -> dict: |
| """Analyze text for purpose indicators""" |
| if not text or not isinstance(text, str): |
| return {dim: 0.0 for dim in self.dimensions} |
| |
| text_lower = text.lower() |
| words = text_lower.split() |
| total_words = max(1, len(words)) |
| |
| scores = {} |
| |
| |
| for dim, config in self.dimensions.items(): |
| matches = sum(1 for word in config['keywords'] if word in text_lower) |
| keyword_score = min(1.0, (matches / total_words) * 10) |
| scores[dim] = keyword_score * self.keyword_weight |
| |
| |
| semantic_boost = self._analyze_semantic_patterns(text_lower) |
| for dim, boost in semantic_boost.items(): |
| scores[dim] = min(1.0, scores.get(dim, 0) + (boost * self.semantic_weight)) |
| |
| return scores |
| |
| def _analyze_semantic_patterns(self, text: str) -> dict: |
| """Analyze text for semantic patterns indicating purpose dimensions""" |
| boosts = {dim: 0.0 for dim in self.dimensions} |
| |
| if any(word in text for word in ['i feel', 'i think', 'i believe']): |
| boosts[PurposeDimension.SELF_EXPRESSION] += 0.3 |
| |
| if any(word in text for word in ['we should', 'let\'s', 'together we']): |
| boosts[PurposeDimension.COMMUNITY] += 0.4 |
| |
| if any(word in text for word in ['unfair', 'not right', 'should be']): |
| boosts[PurposeDimension.JUSTICE] += 0.5 |
| |
| if any(word in text for word in ['learn', 'grow', 'improve']): |
| boosts[PurposeDimension.GROWTH] += 0.4 |
| |
| return boosts |
|
|
| def test_purpose_assessment(): |
| """Test the purpose assessment functionality""" |
| engine = PurposeAssessmentEngine() |
| |
| |
| justice_text = "This policy is unfair and violates basic human rights" |
| scores = engine.analyze_text(justice_text) |
| print("\nTest 1 - Justice-oriented text:") |
| print(f"Justice score: {scores[PurposeDimension.JUSTICE]:.2f}") |
| print(f"Community score: {scores[PurposeDimension.COMMUNITY]:.2f}") |
| assert scores[PurposeDimension.JUSTICE] > 0.2 |
| assert scores[PurposeDimension.JUSTICE] > scores[PurposeDimension.COMMUNITY] |
| |
| |
| community_text = "We should work together to support our local community" |
| scores = engine.analyze_text(community_text) |
| print("\nTest 2 - Community-oriented text:") |
| print(f"Community score: {scores[PurposeDimension.COMMUNITY]:.2f}") |
| print(f"Justice score: {scores[PurposeDimension.JUSTICE]:.2f}") |
| assert scores[PurposeDimension.COMMUNITY] > 0.2 |
| assert scores[PurposeDimension.COMMUNITY] > scores[PurposeDimension.JUSTICE] |
| |
| |
| growth_text = "I want to learn new skills and improve myself" |
| scores = engine.analyze_text(growth_text) |
| print("\nTest 3 - Growth-oriented text:") |
| print(f"Growth score: {scores[PurposeDimension.GROWTH]:.2f}") |
| print(f"Self-expression score: {scores[PurposeDimension.SELF_EXPRESSION]:.2f}") |
| assert scores[PurposeDimension.GROWTH] > 0.2 |
| |
| print("\n✅ All tests passed!") |
|
|
| if __name__ == "__main__": |
| test_purpose_assessment() |
|
|