Download scripts/dev/3.13_get_perfect.py from SlappAI/Singularity: direct link, hf CLI and curl.
- Browser
- Download file 2.15 kB
-
https://huggingface.co/SlappAI/Singularity/resolve/c8aa03645367f13b28133e72d9204fa09654b00a/scripts/dev/3.13_get_perfect.py
- Command line
-
hf download hf://SlappAI/Singularity@c8aa03645367f13b28133e72d9204fa09654b00a/scripts/dev/3.13_get_perfect.py
-
curl -L -o 3.13_get_perfect.py https://huggingface.co/SlappAI/Singularity/resolve/c8aa03645367f13b28133e72d9204fa09654b00a/scripts/dev/3.13_get_perfect.py
2.15 kB
| import json | |
| # Sample data structure based on your JSON | |
| data = { | |
| "primes": [ | |
| {"value": 2, "category": "prime"}, | |
| {"value": 3, "category": "prime"}, | |
| {"value": 5, "category": "prime"}, | |
| # add other nodes as needed | |
| ], | |
| "perfect_numbers": [ | |
| {"value": 6, "category": "perfect_number"}, | |
| {"value": 28, "category": "perfect_number"}, | |
| # add other nodes as needed | |
| ], | |
| "relationships": [ | |
| {"source": 2, "target": 3, "relationship": "generates_Mersenne_prime"}, | |
| # add other predefined relationships | |
| ] | |
| } | |
| # Inferred relationship function | |
| def infer_relationships(nodes): | |
| inferred_relationships = [] | |
| node_values = {node['value']: node for node in nodes} | |
| # Iterate over node pairs to find possible relationships | |
| for source in nodes: | |
| for target in nodes: | |
| if source == target: | |
| continue | |
| source_value = source['value'] | |
| target_value = target['value'] | |
| # Check for multiplication relationship | |
| if target_value % source_value == 0: | |
| factor = target_value // source_value | |
| inferred_relationships.append({ | |
| "source": source_value, | |
| "target": target_value, | |
| "relationship": f"multiplied_by_{factor}" | |
| }) | |
| # Check for addition relationship | |
| if target_value - source_value > 0: | |
| addend = target_value - source_value | |
| inferred_relationships.append({ | |
| "source": source_value, | |
| "target": target_value, | |
| "relationship": f"add_{addend}" | |
| }) | |
| return inferred_relationships | |
| # Infer relationships | |
| nodes = data["primes"] + data["perfect_numbers"] | |
| new_relationships = infer_relationships(nodes) | |
| # Append new relationships to the original data | |
| data["relationships"].extend(new_relationships) | |
| # Output the updated JSON | |
| with open("updated_graph_data.json", "w") as file: | |
| json.dump(data, file, indent=4) |