message: fixed tag matching for YAML file format
This commit is contained in:
parent
bdce69e741
commit
1743802262
@ -372,10 +372,6 @@ class Message():
|
|||||||
tags = TagLine(fd.readline()).tags()
|
tags = TagLine(fd.readline()).tags()
|
||||||
except TagError:
|
except TagError:
|
||||||
fd.seek(pos)
|
fd.seek(pos)
|
||||||
if tags_or or tags_and or tags_not:
|
|
||||||
# match with an empty set if the file has no tags
|
|
||||||
if not match_tags(tags, tags_or, tags_and, tags_not):
|
|
||||||
return None
|
|
||||||
# AILine (Optional)
|
# AILine (Optional)
|
||||||
try:
|
try:
|
||||||
pos = fd.tell()
|
pos = fd.tell()
|
||||||
@ -390,17 +386,23 @@ class Message():
|
|||||||
fd.seek(pos)
|
fd.seek(pos)
|
||||||
# Question and Answer
|
# Question and Answer
|
||||||
text = fd.read().strip().split('\n')
|
text = fd.read().strip().split('\n')
|
||||||
try:
|
try:
|
||||||
question_idx = text.index(Question.txt_header) + 1
|
question_idx = text.index(Question.txt_header) + 1
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise MessageError(f"'{file_path}' does not contain a valid message")
|
raise MessageError(f"'{file_path}' does not contain a valid message")
|
||||||
try:
|
try:
|
||||||
answer_idx = text.index(Answer.txt_header)
|
answer_idx = text.index(Answer.txt_header)
|
||||||
question = Question.from_list(text[question_idx:answer_idx])
|
question = Question.from_list(text[question_idx:answer_idx])
|
||||||
answer = Answer.from_list(text[answer_idx + 1:])
|
answer = Answer.from_list(text[answer_idx + 1:])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
question = Question.from_list(text[question_idx:])
|
question = Question.from_list(text[question_idx:])
|
||||||
return cls(question, answer, tags, ai, model, file_path)
|
# match tags AFTER reading the whole file
|
||||||
|
# -> make sure it's a valid 'txt' file format
|
||||||
|
if tags_or or tags_and or tags_not:
|
||||||
|
# match with an empty set if the file has no tags
|
||||||
|
if not match_tags(tags, tags_or, tags_and, tags_not):
|
||||||
|
return None
|
||||||
|
return cls(question, answer, tags, ai, model, file_path)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __from_file_yaml(cls: Type[MessageInst], file_path: pathlib.Path) -> MessageInst:
|
def __from_file_yaml(cls: Type[MessageInst], file_path: pathlib.Path) -> MessageInst:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user