def test_add_occupation(self): # Should be able to add an occupation to an ontology occupation = Occupation(identifier='456', name='Civil Engineer') ontology = CompetencyOntology() ontology.add_occupation(occupation) assert len(ontology.occupations) == 1 assert occupation in ontology.occupations
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_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
def test_import_from_researchhub(self): url = research_hub_url('testontology') httpretty.register_uri( httpretty.GET, url, body=self.jsonld(), content_type='application/json' ) assert CompetencyOntology(research_hub_name='testontology') == self.ontology()
def test_import_from_url(self): url = 'http://testurl.com/ontology.json' httpretty.register_uri( httpretty.GET, url, body=self.jsonld(), content_type='application/json' ) assert CompetencyOntology(url=url) == self.ontology()
def test_import_from_jsonld(self): assert CompetencyOntology.from_jsonld(self.jsonld()) == self.ontology()
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_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 test_save(self): with tempfile.TemporaryDirectory() as temp_dir: storage = FSStore(temp_dir) self.ontology().save(storage) assert CompetencyOntology(jsonld_string=storage.load('Test Ontology.json')) == self.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
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