mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-04-01 11:26:43 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
2c279c492d
commit
521d7a23fa
@ -4,6 +4,7 @@ from collections import defaultdict
|
||||
|
||||
# Description for the ppm algorithm can be found at https://en.wikipedia.org/wiki/Prediction_by_partial_matching
|
||||
|
||||
|
||||
class PPMNode:
|
||||
def __init__(self) -> None:
|
||||
# Initialize a PPMNode with a dictionary for child nodes and a count of total occurrences
|
||||
@ -73,11 +74,13 @@ class PPM:
|
||||
if symbol:
|
||||
decompressed_output.append(symbol)
|
||||
# Update the context with the newly decoded symbol
|
||||
context = (context + symbol)[-self.order:] # Keep the context within order
|
||||
context = (context + symbol)[
|
||||
-self.order :
|
||||
] # Keep the context within order
|
||||
else:
|
||||
break # Stop if a symbol cannot be found
|
||||
|
||||
return ''.join(decompressed_output) # Join the list into a single string
|
||||
return "".join(decompressed_output) # Join the list into a single string
|
||||
|
||||
def decode_symbol(self, context: str, prob: float) -> str | None:
|
||||
# Decode a symbol from the given context based on the probability
|
||||
@ -98,7 +101,7 @@ class PPM:
|
||||
|
||||
def read_file(file_path: str) -> str:
|
||||
"""Read the entire file and return its content as a string."""
|
||||
with open(file_path, 'r') as f:
|
||||
with open(file_path, "r") as f:
|
||||
return f.read()
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user