Skip to content

Commit 521d7a2

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 2c279c4 commit 521d7a2

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

compression/ppm.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import sys
33
from collections import defaultdict
44

5-
#Description for the ppm algorithm can be found at https://en.wikipedia.org/wiki/Prediction_by_partial_matching
5+
# Description for the ppm algorithm can be found at https://en.wikipedia.org/wiki/Prediction_by_partial_matching
6+
67

78
class PPMNode:
89
def __init__(self) -> None:
@@ -43,7 +44,7 @@ def compress(self, data: str) -> list[float]:
4344
# Encode the symbol based on the current context
4445
compressed_output.append(self.encode_symbol(context, symbol))
4546
# Update the context by appending the symbol, keeping it within the specified order
46-
context = (context + symbol)[-self.order:] # Keep the context within order
47+
context = (context + symbol)[-self.order :] # Keep the context within order
4748

4849
return compressed_output
4950

@@ -73,11 +74,13 @@ def decompress(self, compressed_data: list[float]) -> str:
7374
if symbol:
7475
decompressed_output.append(symbol)
7576
# Update the context with the newly decoded symbol
76-
context = (context + symbol)[-self.order:] # Keep the context within order
77+
context = (context + symbol)[
78+
-self.order :
79+
] # Keep the context within order
7780
else:
7881
break # Stop if a symbol cannot be found
7982

80-
return ''.join(decompressed_output) # Join the list into a single string
83+
return "".join(decompressed_output) # Join the list into a single string
8184

8285
def decode_symbol(self, context: str, prob: float) -> str | None:
8386
# Decode a symbol from the given context based on the probability
@@ -98,7 +101,7 @@ def decode_symbol(self, context: str, prob: float) -> str | None:
98101

99102
def read_file(file_path: str) -> str:
100103
"""Read the entire file and return its content as a string."""
101-
with open(file_path, 'r') as f:
104+
with open(file_path, "r") as f:
102105
return f.read()
103106

104107

@@ -123,4 +126,4 @@ def ppm(file_path: str) -> None:
123126
sys.exit(1)
124127

125128
# Call the ppm function with the provided file path
126-
ppm(sys.argv[1])
129+
ppm(sys.argv[1])

0 commit comments

Comments
 (0)