in microservices/course_ingestion/services/import_learning_content.py [0:0]
def create_clustering_learning_content_collections(title, description,
gcs_path,
start_page,
end_page,
content_type,
parsed_output_json,
last_modified_by="",
created_by="",
create_learning_units=True,
create_triples=False,
course_category=""
):
"""creates new set of collections
for a given learning_content using clustering"""
learning_content_item = LearningContentItem()
learning_content_item.title = title
learning_content_item.description = description
learning_content_item.gcs_path = gcs_path
learning_content_item.document_type = content_type
learning_content_item.last_modified_by = last_modified_by
learning_content_item.created_by = created_by
learning_content_item.course_category = course_category
learning_content_item.start_page = start_page
learning_content_item.end_page = end_page
competency_ids = []
with open(parsed_output_json) as json_file:
competencies = ast.literal_eval(json.load(json_file))
for competency_item in competencies:
competency = Competency()
competency.title = competency_item["title"]
competency.description = competency_item["title"]
competency.label = competency_item["title"]
competency.last_modified_by = last_modified_by
competency.created_by = created_by
competency.save()
competency_ids.append(competency.id)
for sub_comp_item in competency_item["sub_competencies"]:
subcompentency = competency.add_sub_competency()
subcompentency.title = sub_comp_item["title"]
subcompentency.description = sub_comp_item["title"]
subcompentency.all_learning_resource = ""
subcompentency.label = sub_comp_item["title"]
subcompentency.last_modified_by = last_modified_by
subcompentency.created_by = created_by
total_lus = 0
if create_learning_units:
for lo in sub_comp_item["learning_objectives"]:
total_lus+=len(lo["learning_units"])
subcompentency.total_lus = total_lus
subcompentency.save()
for learning_objective_item in sub_comp_item["learning_objectives"]:
learning_objective = subcompentency.add_learning_objective()
learning_objective.title = learning_objective_item["title"]
learning_objective.description = learning_objective_item["title"]
learning_objective.text = learning_objective_item["text"]
learning_objective.last_modified_by = last_modified_by
learning_objective.created_by = created_by
learning_objective.save()
if create_learning_units:
for learning_unit_item in learning_objective_item["learning_units"]:
learning_unit = learning_objective.add_learning_unit()
learning_unit.title = learning_unit_item["title"]
learning_unit.text = learning_unit_item["text"]
learning_unit.topics = str(learning_unit_item["topics"])
learning_unit.pdf_title = ""
learning_unit.last_modified_by = last_modified_by
learning_unit.created_by = created_by
learning_unit.save()
if create_triples:
for triple_item in learning_unit_item["triples"]:
triple = learning_unit.add_triple()
triple.subject = triple_item["subject"]
triple.predicate = triple_item["predicate"]
triple.object = triple_item["object"]
triple.confidence = triple_item["confidence"]
triple.sentence = triple_item["sentence"]
triple.save()
learning_content_item.competency_ids = competency_ids
learning_content_item.save()
return learning_content_item.id