예제 #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}
예제 #2
0
 def test_add_edge(self):
     # Should be able to add an edge between an occupation and a competency to an ontology
     occupation = Occupation(identifier='456', name='Civil Engineer')
     competency = Competency(identifier='123', name='communication', categories=['social skills'])
     ontology = CompetencyOntology()
     ontology.add_edge(competency=competency, occupation=occupation)
     assert competency in ontology.competencies
     assert occupation in ontology.occupations
     assert len([edge for edge in ontology.edges if edge.occupation == occupation and edge.competency == competency]) == 1
예제 #3
0
    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