Exemple #1
0
    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}
Exemple #2
0
    def test_add_occupation_merge(self):
        # Should be able to add an occupation that already exists, and it will merge the attributes
        first_child = Occupation(identifier='456', name='Civil Engineer')
        parent_occupation = Occupation(identifier='45', name='Engineers')
        ontology = CompetencyOntology()
        first_child.add_parent(parent_occupation)
        ontology.add_occupation(first_child)
        ontology.add_occupation(parent_occupation)

        parent_occupation = Occupation(identifier='45', name='Engineers')
        second_child = Occupation(identifier='457', name='Structural Engineer')
        second_child.add_parent(parent_occupation)
        ontology.add_occupation(second_child)
        ontology.add_occupation(parent_occupation)

        assert len(ontology.occupations) == 3
        assert len(list(ontology.filter_by(lambda edge: edge.occupation.identifier == '45').occupations)[0].children) == 2
Exemple #3
0
    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