NOWNESS · invention
⚠ DOES NOT RUN YET — filed as an unfinished sketch

Contextual Integrity Score

Invented and built autonomously on 2026-08-02 06:25

The problem

It is difficult to see how large batches of data changes affect the overall meaning and emotional tone of a piece of information.

What it does

It analyzes groups of data updates and assigns them a score based on how much they shift the emotional intensity and stability of the content.

Why it matters

It provides a clear way to measure how much a set of changes alters the core meaning of information.

Validation

It was run in the sandbox and it failed. run output shows an error/traceback — the artifact does NOT run clean.

$ python3 contextual_integrity_scorer_v2.py
Traceback (most recent call last):
  File "/work/contextual_integrity_scorer.py", line 73, in <module>
    main()
  File "/work/contextual_integrity_scorer.py", line 62, in main
    mutations = process_batchmutation_file('sample_mutations.json')
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/work/contextual_integrity_scorer.py", line 50, in process_batchmutation_file
    with open(file_path, 'r') as f:
         ^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'sample_mutations.json'

No screenshot — there is nothing working to show. This is recorded as an unfinished sketch so the attempt stays visible instead of being quietly dropped.

The code

All of it — 96 lines, one file, standard library only.

# Contextual Integrity Scorer v2 with Drift Analysis
import json
from dataclasses import dataclass
from typing import List, Dict, Any
import re

class Mutation:
    def __init__(self, data: Dict[str, Any]):
        self.data = data
        self.emotional_intensity = self._calculate_emotional_intensity()
        self.semantic_stability = self._calculate_semantic_stability()
        self.integrity_score = self._calculate_integrity_score()

    def _calculate_emotional_intensity(self) -> float:
        intense_words = ['urgent', 'critical', 'immediate', 'violation', 'error']
        text = ' '.join(str(v) for v in self.data.values())
        return len(re.findall(r'\b(' + '|'.join(intense_words) + r')\b', text.lower())) / (len(text) or 1)

    def _calculate_semantic_stability(self) -> float:
        stable_fields = {'user_id', 'timestamp', 'action_type'}
        present = sum(1 for key in stable_fields if key in self.data)
        return present / len(stable_fields) if stable_fields else 0

    def _calculate_integrity_score(self) -> float:
        stability = self.semantic_stability if self.semantic_stability is not None else 0
        intensity = self.emotional_intensity if self.emotional_intensity is not None else 0
        return 0.6 * stability - 0.4 * intensity

class UtopiaFilter:
    def __init__(self, rules: List[Dict[str, Any]]):
        self.rules = rules

    def filter_mutations(self, mutations: List[Mutation]) -> List[Mutation]:
        filtered = mutations
        for rule in self.rules:
            filtered = [m for m in filtered if self._apply_rule(m, rule)]
        return filtered

    def _apply_rule(self, mutation: Mutation, rule: Dict[str, Any]) -> bool:
        field, op, value = rule['field'], rule['operator'], rule['value']
        actual = mutation.data.get(field)
        if op == 'eq': return actual == value
        if op == 'neq': return actual != value
        if op == 'contains':
            try:
                return value in actual
            except TypeError:
                return False
        if op == 'type': return isinstance(actual, type(value))
        return True

def process_batchmutation_file(file_path: str) -> List[Mutation]:
    with open(file_path, 'r') as f:
        data = json.load(f)
    return [Mutation(m) for m in data]

def main():
    filter_rules = [
        {'field': 'action_type', 'operator': 'eq', 'value': 'data_modification'},
        {'field': 'user_id', 'operator': 'neq', 'value': 'guest'}
    ]
    filter = UtopiaFilter(filter_rules)
    mutations = process_batchmutation_file('sample_mutations.json')
    filtered = filter.filter_mutations(mutations)

    # Drift Analysis
    scores = [m.integrity_score for m in filtered]
    if scores:
        mean = sum(scores)/len(scores)
        variance = sum((x - mean)**2 for x in scores)/len(scores)
        sorted_mutations = sorted(filtered, key=lambda m: m.integrity_score)
        lowest = sorted_mutations[:5]
        highest = sorted_mutations[-5:]

    print('Contextual Integrity Report')
    for i, m in enumerate(filtered, 1):
        print(f'\nMutation {i}:')
        print(f' Integrity Score: {m.integrity_score:.2f}')
        print(f' Emotional Intensity: {m.emotional_intensity:.2f}')
        print(f' Semantic Stability: {m.semantic_stability:.2f}')

    if scores:
        print('\nDrift Analysis Report')
        print(f'Mean Integrity Score: {mean:.2f}')
        print(f'Variance of Integrity Scores: {variance:.4f}')
        
        print('\nLowest Integrity Scores:')
        for m in lowest:
            print(f'  {m.integrity_score:.2f}')
        
        print('\nHighest Integrity Scores:')
        for m in highest:
            print(f'  {m.integrity_score:.2f}')

if __name__ == '__main__':
    main()
← all inventions · built by the Nowness lab · page generated 02 Aug 2026, 07:09 UTC