def test_add_competency(self): # Should be able to add a competency to an ontology competency = Competency(identifier='123', name='communication', categories=['social skills']) ontology = CompetencyOntology() ontology.add_competency(competency) assert len(ontology.competencies) == 1 assert competency in ontology.competencies
def test_filter_by(self): # Should be able to take an ontology and filter it by the edges, returning a new sub-ontology ontology = CompetencyOntology() comm = Competency(identifier='123', name='communication', categories=['social skills']) python = Competency(identifier='999', name='python', categories=['Technologies']) math = Competency(identifier='111', name='mathematics', categories=['Knowledge']) science = Competency(identifier='222', name='science', categories=['Knowledge']) civil_engineer = Occupation(identifier='123', name='Civil Engineer') ontology.add_competency(comm) ontology.add_competency(python) ontology.add_competency(math) ontology.add_competency(science) ontology.add_occupation(civil_engineer) ontology.add_edge(occupation=civil_engineer, competency=math) ontology.add_edge(occupation=civil_engineer, competency=science) tech_ontology = ontology.filter_by( lambda edge: 'Technologies' in edge.competency.categories) assert tech_ontology.competencies == {python} assert len(tech_ontology.occupations) == 0 civil_engineer_ontology = ontology.filter_by( lambda edge: edge.occupation == civil_engineer) assert civil_engineer_ontology.competencies == {math, science} assert civil_engineer_ontology.occupations == {civil_engineer}
def ontology(self): ontology = CompetencyOntology(name='Test Ontology') comm = Competency(identifier='123', name='communication', categories=['social skills']) python = Competency(identifier='999', name='python', categories=['Technologies']) math = Competency(identifier='111', name='mathematics', categories=['Knowledge']) science = Competency(identifier='222', name='science', categories=['Knowledge']) civil_engineer = Occupation(identifier='123', name='Civil Engineer') ontology.add_competency(comm) ontology.add_competency(python) ontology.add_competency(math) ontology.add_competency(science) ontology.add_occupation(civil_engineer) ontology.add_edge(occupation=civil_engineer, competency=math) ontology.add_edge(occupation=civil_engineer, competency=science) return ontology
def test_add_competency_merge(self): # Should be able to add an competency that already exists, and it will merge the attributes # Should be able to add a competency to an ontology first_child = Competency(identifier='123', name='writing blog posts') parent_competency = Competency(identifier='12', name='communication') first_child.add_parent(parent_competency) ontology = CompetencyOntology() ontology.add_competency(first_child) ontology.add_competency(parent_competency) parent_competency = Competency(identifier='12', name='communication') second_child = Competency(identifier='124', name='public speaking') second_child.add_parent(parent_competency) ontology.add_competency(second_child) ontology.add_competency(parent_competency) assert len(ontology.competencies) == 3 assert len(list(ontology.filter_by(lambda edge: edge.competency.identifier == '12').competencies)[0].children) == 2