-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
162 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from collections import Counter | ||
from pprint import pprint | ||
|
||
from classifier.data.triangle_pos import data_path, yield_from_file, ConceptPosition | ||
from lib.json import decode, encode | ||
|
||
print ("loading") | ||
all_samples = [] | ||
n = 0 | ||
with open(data_path, 'r') as file: | ||
lines = file.readlines() | ||
for line in lines: | ||
# Deserialize the JSON string back into a tuple | ||
item = decode(line, ConceptPosition) | ||
all_samples.append(item) | ||
n += 1 | ||
print ("loaded") | ||
c_labels = Counter([_[0][1] for _ in all_samples]) | ||
("counted") | ||
print (c_labels) | ||
|
||
relative_prob = { | ||
k: 1/(v/n) | ||
for k, v in | ||
c_labels.items() | ||
} | ||
pprint(relative_prob) | ||
|
||
a = sum(relative_prob.values()) | ||
relative_prob = { | ||
k.name: v/a | ||
for k, v in | ||
relative_prob.items() | ||
} | ||
pprint(relative_prob) | ||
|
||
print ([relative_prob.get(k, 0) for k in list(ConceptPosition.__members__)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import os | ||
|
||
system_path = os.environ.get("SYSTEM", "../dialectics") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import subprocess # For running shell commands, 🚀🐚🚀 | ||
# With Python's touch, so grand! 🌟🐍🌟 | ||
|
||
# A function so neat, a treat to repeat, 🍬🎶🍬 | ||
def check_git_config(): # Let's take a seat! 🪑🌟🪑 | ||
try: | ||
# For email, we'll peek, with Python technique! 📧🔍📧 | ||
email = subprocess.check_output( | ||
["git", "config", "--global", "user.email"], | ||
text=True).strip() | ||
# For name, the same, in this Git game! 🎮🔍🎮 | ||
name = subprocess.check_output( | ||
["git", "config", "--global", "user.name"], | ||
text=True).strip() | ||
|
||
# If found around, let joy resound! 🎉✨🎉 | ||
if email and name: | ||
print(f"Email found: {email}, 📧🌈📧\nName's around: {name}! 🌟👤🌟") | ||
return True | ||
else: | ||
print("Some configs are missing, 🚫🤔🚫\nLet's keep on fishing! 🎣🌊🎣") | ||
return False | ||
except subprocess.CalledProcessError: | ||
# If error's in sight, we'll set it right! 🚨🛠️🚨 | ||
print("Git configs not found, 🚫🔍🚫\nIn silence they're bound. 🤫🌌🤫") | ||
return None | ||
|
||
|
||
if __name__ == "__main__": | ||
# Now let's invoke, with a stroke of hope! 🌈🙏🌈 | ||
check_git_config() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,27 @@ | ||
import json | ||
from enum import Enum | ||
|
||
class EnumCodec(json.JSONEncoder): | ||
def __init__(self, enum_type, *args, **kwargs): | ||
self.enum_type = enum_type | ||
super().__init__(*args, **kwargs) | ||
|
||
def default(self, obj): | ||
if isinstance(obj, Enum): | ||
return {"__enum__": f"{obj.__class__.__name__}.{obj.name}"} | ||
return super().default(obj) | ||
else: | ||
return super().default(obj) | ||
|
||
@classmethod | ||
def decode(cls, enum_type): | ||
def decode_enum(dct): | ||
if "__enum__" in dct: | ||
enum_name, member_name = dct["__enum__"].split('.') | ||
if enum_name == enum_type.__name__: | ||
return enum_type[member_name] | ||
return dct | ||
return decode_enum | ||
@staticmethod | ||
def decode_enum(dct, enum_type=None): | ||
if "__enum__" in dct: | ||
enum_name, member_name = dct["__enum__"].split('.') | ||
# Assuming enum_type is provided and matches enum_name | ||
if enum_type and enum_type.__name__ == enum_name: | ||
return enum_type[member_name] | ||
return dct | ||
|
||
def encode(enum_instance, enum_type): | ||
return json.dumps(enum_instance, cls=EnumCodec, enum_type=enum_type) | ||
def encode(data, enum_type=None): | ||
# Convert enum keys to strings | ||
if isinstance(data, dict): | ||
data = {k.name if isinstance(k, Enum) else k: v for k, v in data.items()} | ||
return json.dumps(data, cls=EnumCodec) | ||
|
||
def decode(json_str, enum_type): | ||
return json.loads(json_str, object_hook=EnumCodec.decode(enum_type)) | ||
object_hook = lambda dct: EnumCodec.decode_enum(dct, enum_type=enum_type) | ||
return json.loads(json_str, object_hook=object_hook) |