truelearn.models.Knowledge#

class truelearn.models.Knowledge(knowledge: Optional[Dict[Hashable, BaseKnowledgeComponent]] = None)[source]#

Bases: object

The representation of the learner’s knowledge.

In TrueLearn, we assume every learner’s knowledge consists of many different knowledge components. The Knowledge class is used to represent this relationship.

The class can be used to represent 1) the learner’s knowledge and 2) the knowledge of a learnable unit.

Examples

>>> from truelearn.models import Knowledge, KnowledgeComponent
>>> # construct empty knowledge
>>> knowledge = Knowledge()
>>> knowledge
Knowledge(knowledge={})
>>> # add a new kc to knowledge
>>> knowledge.update_kc(1, KnowledgeComponent(mean=1.0, variance=2.0))
>>> knowledge
Knowledge(knowledge={1: KnowledgeComponent(mean=1.0, variance=2.0, timestamp=None, title=None, description=None, url=None)})
>>> # get a kc from the knowledge
>>> knowledge.get_kc(1, KnowledgeComponent(mean=0.0, variance=1.0))
KnowledgeComponent(mean=1.0, variance=2.0, timestamp=None, title=None, description=None, url=None)
>>> # get iterator of keys and (key, value) pairs
>>> knowledge.knowledge_components()
dict_values([KnowledgeComponent(mean=1.0, variance=2.0, timestamp=None, title=None, description=None, url=None)])
>>> knowledge.topic_kc_pairs()
dict_items([(1, KnowledgeComponent(mean=1.0, variance=2.0, timestamp=None, title=None, description=None, url=None))])

Methods

__init__([knowledge])

Init the Knowledge object.

get_kc(topic_id, default)

Get the knowledge component associated with the given id.

knowledge_components()

Return an iterable of the knowledge component.

topic_kc_pairs()

Return an iterable of the (topic_id, knowledge_component) pair.

update_kc(topic_id, kc)

Update the knowledge component associated with the given topic_id.

__init__(knowledge: Optional[Dict[Hashable, BaseKnowledgeComponent]] = None) None[source]#

Init the Knowledge object.

If the given knowledge is None, the knowledge will be initialized emptily.

Parameters:

knowledge – A dict mapping a hashable id of the knowledge component to the corresponding knowledge component object.

get_kc(topic_id: Hashable, default: BaseKnowledgeComponent) BaseKnowledgeComponent[source]#

Get the knowledge component associated with the given id.

Parameters:
  • topic_id – The id that uniquely identifies a knowledge component.

  • default – The default knowledge component to return.

Returns:

The knowledge component extracted from the knowledge if the topic_id exists in the knowledge. Otherwise, the default value will be returned.

knowledge_components() Iterable[BaseKnowledgeComponent][source]#

Return an iterable of the knowledge component.

topic_kc_pairs() Iterable[Tuple[Hashable, BaseKnowledgeComponent]][source]#

Return an iterable of the (topic_id, knowledge_component) pair.

update_kc(topic_id: Hashable, kc: BaseKnowledgeComponent) None[source]#

Update the knowledge component associated with the given topic_id.

If the topic_id doesn’t exist in the AbstractKnowledge, the mapping from the topic_id to the knowledge component will be created.

Parameters:
  • topic_id – Hashable:

  • kc – BaseKnowledgeComponent: