initial
This commit is contained in:
commit
2618b264f3
6 changed files with 122 additions and 0 deletions
26
chain.py
Normal file
26
chain.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import markovify
|
||||
import re
|
||||
import spacy
|
||||
|
||||
SEPARATOR = r"\s*@@note@@\s*"
|
||||
|
||||
nlp = spacy.load("en_core_web_sm")
|
||||
|
||||
class Text(markovify.Text):
|
||||
def word_split(self, sentence):
|
||||
ret = []
|
||||
|
||||
for word in nlp(sentence):
|
||||
if word.pos_ == 'PUNCT':
|
||||
continue
|
||||
|
||||
ret.append("::".join((word.orth_, word.pos_)))
|
||||
|
||||
return ret
|
||||
|
||||
def word_join(self, words):
|
||||
sentence = " ".join(word.split("::")[0] for word in words)
|
||||
return sentence
|
||||
|
||||
def sentence_split(self, text):
|
||||
return re.split(SEPARATOR, text)
|
||||
Loading…
Add table
Add a link
Reference in a new issue