34 lines
900 B
Python
34 lines
900 B
Python
from knowledge_base import KnowledgeBase
|
|
import knowledge_evaluation
|
|
import parsing
|
|
|
|
|
|
def get_fit(knowledge: KnowledgeBase, row):
|
|
for sample, ast in knowledge.trained:
|
|
if len(sample) != len(row):
|
|
continue
|
|
|
|
if all(map(lambda x: not isinstance(sample[x], str) or sample[x] == row[x],
|
|
range(len(sample)))):
|
|
return sample, ast
|
|
else:
|
|
return None
|
|
|
|
|
|
def train(knowledge_base: KnowledgeBase, examples):
|
|
|
|
# Parse everything
|
|
parsed_examples = []
|
|
for example in examples:
|
|
parsed_examples.append(parsing.integrate_language(knowledge_base, example))
|
|
|
|
# Reduce values
|
|
trained = parsing.reprocess_language_knowledge(knowledge_base, parsed_examples)
|
|
|
|
return KnowledgeBase(
|
|
knowledge=knowledge_base.knowledge,
|
|
examples=knowledge_base.examples + parsed_examples,
|
|
trained=trained,
|
|
)
|
|
|