Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loading from json when parsed_sentences is None #77

Merged
merged 2 commits into from
Sep 12, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions markovify/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ def __init__(self, input_text, state_size=2, chain=None, parsed_sentences=None,
an infinite process, you can come very close by passing just one, very
long run.
"""
can_make_sentences = parsed_sentences is not None or input_text is not None
self.retain_original = retain_original and can_make_sentences
self.state_size = state_size
self.retain_original = retain_original

if retain_original:
if self.retain_original:
self.parsed_sentences = parsed_sentences or list(self.generate_corpus(input_text))

# Rejoined text lets us assess the novelty of generated sentences
self.rejoined_text = self.sentence_join(map(self.word_join, self.parsed_sentences))
self.chain = chain or Chain(self.parsed_sentences, state_size)
else:
parsed = parsed_sentences or self.generate_corpus(input_text)
if not chain:
parsed = parsed_sentences or self.generate_corpus(input_text)
self.chain = chain or Chain(parsed, state_size)

def to_dict(self):
Expand All @@ -54,7 +56,7 @@ def to_json(self):
return json.dumps(self.to_dict())

@classmethod
def from_dict(cls, obj):
def from_dict(cls, obj, **kwargs):
return cls(
None,
state_size=obj["state_size"],
Expand Down