def runTest(self):
     """
     test the relating service for terms in relation with generic scopes
     """
     for i, t in enumerate(self.test1):
         print '<RELATING API>'
         results = []
         for spot in [s['spot'] for s in TagMeService.check_spotting(t)['value']['spots']]:
             result = TagMeService.retrieve_taggings(spot.encode('utf-8'), method='POST')
             print result
             for n in result['annotations']:
                 title = n['title'].replace(' ', '_')  # strip whitespaces from dbpedia tag
                 results.append(TagMeService.relate(title, self.scopes))  # compare the spotted and tagged term to the generic scopes
         print i, results
         # 'couple' are the two wikipedia terms been checked, 'rel' is the correlation index (rho). The more the rho
         # is closer to 0.5 the more the terms are related. The standard interval of relevance is 0.42 < rho < 0.61
         if i == 0:
             expected = [[{u'couple': u'Functional_(mathematics) Physics', u'rel': u'0.4235'}], [{u'couple': u'Electron_mobility Cosmic_ray', u'rel': u'0.4784'}], [{u'couple': u'Units_of_measurement Astrophysics', u'rel': u'0.4353'}, {u'couple': u'Units_of_measurement Geodesy', u'rel': u'0.5333'}, {u'couple': u'Units_of_measurement Astronomical_object', u'rel': u'0.4824'}, {u'couple': u'Units_of_measurement Astronomy', u'rel': u'0.4824'}, {u'couple': u'Units_of_measurement Navigation', u'rel': u'0.4706'}, {u'couple': u'Units_of_measurement Physics', u'rel': u'0.4275'}, {u'couple': u'Units_of_measurement Planetary_science', u'rel': u'0.4275'}], [], [], [{u'couple': u'Accuracy_and_precision Geodesy', u'rel': u'0.5176'}, {u'couple': u'Accuracy_and_precision Astronomical_object', u'rel': u'0.4471'}, {u'couple': u'Accuracy_and_precision Navigation', u'rel': u'0.4745'}], [], [], [], [{u'couple': u'Extra-vehicular_activity Aerospace', u'rel': u'0.4392'}, {u'couple': u'Extra-vehicular_activity Astrophysics', u'rel': u'0.4471'}, {u'couple': u'Extra-vehicular_activity Cosmic_ray', u'rel': u'0.5804'}, {u'couple': u'Extra-vehicular_activity Spaceflight', u'rel': u'0.8353'}, {u'couple': u'Extra-vehicular_activity Spacecraft', u'rel': u'0.7059'}, {u'couple': u'Extra-vehicular_activity Geodesy', u'rel': u'0.5137'}, {u'couple': u'Extra-vehicular_activity Astronomical_object', u'rel': u'0.5137'}, {u'couple': u'Extra-vehicular_activity Aircraft', u'rel': u'0.4235'}, {u'couple': u'Extra-vehicular_activity Atmosphere', u'rel': u'0.4784'}, {u'couple': u'Extra-vehicular_activity Navigation', u'rel': u'0.4941'}, {u'couple': u'Extra-vehicular_activity Satellite', u'rel': u'0.6941'}, {u'couple': u'Extra-vehicular_activity Spaceflight', u'rel': u'0.8353'}, {u'couple': u'Extra-vehicular_activity NASA', u'rel': u'0.6000'}], [{u'couple': u'Extra-vehicular_activity Aerospace', u'rel': u'0.4392'}, {u'couple': u'Extra-vehicular_activity Astrophysics', u'rel': u'0.4471'}, {u'couple': u'Extra-vehicular_activity Cosmic_ray', u'rel': u'0.5804'}, {u'couple': u'Extra-vehicular_activity Spaceflight', u'rel': u'0.8353'}, {u'couple': u'Extra-vehicular_activity Spacecraft', u'rel': u'0.7059'}, {u'couple': u'Extra-vehicular_activity Geodesy', u'rel': u'0.5137'}, {u'couple': u'Extra-vehicular_activity Astronomical_object', u'rel': u'0.5137'}, {u'couple': u'Extra-vehicular_activity Aircraft', u'rel': u'0.4235'}, {u'couple': u'Extra-vehicular_activity Atmosphere', u'rel': u'0.4784'}, {u'couple': u'Extra-vehicular_activity Navigation', u'rel': u'0.4941'}, {u'couple': u'Extra-vehicular_activity Satellite', u'rel': u'0.6941'}, {u'couple': u'Extra-vehicular_activity Spaceflight', u'rel': u'0.8353'}, {u'couple': u'Extra-vehicular_activity NASA', u'rel': u'0.6000'}]]
             assert results == expected
         elif i == 1:
             expected = [[{u'couple': u'NASA Astrophysics', u'rel': u'0.4549'}, {u'couple': u'NASA Cosmic_ray', u'rel': u'0.4745'}, {u'couple': u'NASA Spaceflight', u'rel': u'0.5765'}, {u'couple': u'NASA Spacecraft', u'rel': u'0.5569'}, {u'couple': u'NASA Astronomical_object', u'rel': u'0.4471'}, {u'couple': u'NASA Astronomy', u'rel': u'0.4510'}, {u'couple': u'NASA Atmosphere', u'rel': u'0.4863'}, {u'couple': u'NASA Satellite', u'rel': u'0.5451'}, {u'couple': u'NASA Spaceflight', u'rel': u'0.5765'}, {u'couple': u'NASA Planetary_science', u'rel': u'0.4588'}], [{u'couple': u'Research Physics', u'rel': u'0.4431'}], [], [], [{u'couple': u'Research Physics', u'rel': u'0.4431'}], [], [], [], [], [], [], [], [], [], [], [{u'couple': u'Experience Navigation', u'rel': u'0.4275'}], [{u'couple': u'Robotics Aerospace', u'rel': u'0.5255'}, {u'couple': u'Robotics Astrophysics', u'rel': u'0.5608'}, {u'couple': u'Robotics Spaceflight', u'rel': u'0.4667'}, {u'couple': u'Robotics Spacecraft', u'rel': u'0.4863'}, {u'couple': u'Robotics Geodesy', u'rel': u'0.5882'}, {u'couple': u'Robotics Astronomy', u'rel': u'0.4706'}, {u'couple': u'Robotics Spaceflight', u'rel': u'0.4667'}, {u'couple': u'Robotics Physics', u'rel': u'0.4549'}, {u'couple': u'Robotics Planetary_science', u'rel': u'0.5843'}], [{u'couple': u'Human_spaceflight Aerospace', u'rel': u'0.4471'}, {u'couple': u'Human_spaceflight Astrophysics', u'rel': u'0.4706'}, {u'couple': u'Human_spaceflight Cosmic_ray', u'rel': u'0.6039'}, {u'couple': u'Human_spaceflight Spaceflight', u'rel': u'0.8392'}, {u'couple': u'Human_spaceflight Spacecraft', u'rel': u'0.7333'}, {u'couple': u'Human_spaceflight Avionics', u'rel': u'0.5216'}, {u'couple': u'Human_spaceflight Geodesy', u'rel': u'0.5020'}, {u'couple': u'Human_spaceflight Astronomical_object', u'rel': u'0.5412'}, {u'couple': u'Human_spaceflight Astronomy', u'rel': u'0.4275'}, {u'couple': u'Human_spaceflight Atmosphere', u'rel': u'0.5333'}, {u'couple': u'Human_spaceflight Navigation', u'rel': u'0.4510'}, {u'couple': u'Human_spaceflight Satellite', u'rel': u'0.7137'}, {u'couple': u'Human_spaceflight Spaceflight', u'rel': u'0.8392'}, {u'couple': u'Human_spaceflight NASA', u'rel': u'0.5922'}, {u'couple': u'Human_spaceflight Planetary_science', u'rel': u'0.4471'}], [], [], [{u'couple': u'Observation Astrophysics', u'rel': u'0.5451'}, {u'couple': u'Observation Geodesy', u'rel': u'0.5569'}, {u'couple': u'Observation Astronomical_object', u'rel': u'0.5725'}, {u'couple': u'Observation Astronomy', u'rel': u'0.5059'}, {u'couple': u'Observation Atmosphere', u'rel': u'0.4392'}, {u'couple': u'Observation Physics', u'rel': u'0.4824'}, {u'couple': u'Observation Planetary_science', u'rel': u'0.5490'}], [], [], [{u'couple': u'NASA Astrophysics', u'rel': u'0.4549'}, {u'couple': u'NASA Cosmic_ray', u'rel': u'0.4745'}, {u'couple': u'NASA Spaceflight', u'rel': u'0.5765'}, {u'couple': u'NASA Spacecraft', u'rel': u'0.5569'}, {u'couple': u'NASA Astronomical_object', u'rel': u'0.4471'}, {u'couple': u'NASA Astronomy', u'rel': u'0.4510'}, {u'couple': u'NASA Atmosphere', u'rel': u'0.4863'}, {u'couple': u'NASA Satellite', u'rel': u'0.5451'}, {u'couple': u'NASA Spaceflight', u'rel': u'0.5765'}, {u'couple': u'NASA Planetary_science', u'rel': u'0.4588'}], [], [], [], [], [{u'couple': u'Missile_guidance Spaceflight', u'rel': u'0.4235'}, {u'couple': u'Missile_guidance Avionics', u'rel': u'0.4549'}, {u'couple': u'Missile_guidance Command_and_control', u'rel': u'0.4510'}, {u'couple': u'Missile_guidance Spaceflight', u'rel': u'0.4235'}], []]
             assert results == expected
         elif i == 2:
             expected = [[{u'couple': u'University Physics', u'rel': u'0.4235'}], [{u'couple': u'University Physics', u'rel': u'0.4235'}], [], [], [], [], [{u'couple': u'Exploration_Systems_Architecture_Study Cosmic_ray', u'rel': u'0.4588'}, {u'couple': u'Exploration_Systems_Architecture_Study Spaceflight', u'rel': u'0.4863'}, {u'couple': u'Exploration_Systems_Architecture_Study Spacecraft', u'rel': u'0.5412'}, {u'couple': u'Exploration_Systems_Architecture_Study Avionics', u'rel': u'0.5059'}, {u'couple': u'Exploration_Systems_Architecture_Study Spaceflight', u'rel': u'0.4863'}, {u'couple': u'Exploration_Systems_Architecture_Study NASA', u'rel': u'0.4667'}], [], [], [], [], [{u'couple': u'Scientific_journal Astrophysics', u'rel': u'0.4706'}, {u'couple': u'Scientific_journal Astronomy', u'rel': u'0.4314'}, {u'couple': u'Scientific_journal Physics', u'rel': u'0.4510'}, {u'couple': u'Scientific_journal Planetary_science', u'rel': u'0.4314'}], [{u'couple': u'Research Physics', u'rel': u'0.4431'}], [], [{u'couple': u'Electricity Astrophysics', u'rel': u'0.4275'}, {u'couple': u'Electricity Physics', u'rel': u'0.4627'}], [], [], [], [{u'couple': u'Plant_cell Atmosphere', u'rel': u'0.5020'}], [], [], [], [], []]
             assert results == expected
         else:
             assert False
 def runTest(self):
     """
     test the function that checks if any term has a proper correlation with the aerospace/astronomy/physics
     """
     for i, t in enumerate(self.test1):
         print '<CHECK IF TERMS are related to SPACEKNOWLEDGE>'
         results = []
         for spot in [s['spot'] for s in TagMeService.check_spotting(t)['value']['spots']]:
             result = TagMeService.retrieve_taggings(spot.encode('utf-8'), method='POST')
             for n in result['annotations']:
                 title = n['title'].replace(' ', '_')  # strip whitespaces from dbpedia tag
                 relate = TagMeService.relate(title, self.scopes)  # compare the spotted and tagged term to the generic scopes
                 results.append(TagMeService.check_if_rho_fits_spaceknowledge(relate))
         print i, results
         # print True, name and the mean of the rho of the term in relation with the scopes
         if i == 0:
             expected = [(True, u'Functional_(mathematics)', 0.4235), (True, u'Electron_mobility', 0.4784), (True, u'Units_of_measurement', 0.46557142857142864), False, False, (True, u'Accuracy_and_precision', 0.4797333333333333), False, False, False, (True, u'Extra-vehicular_activity', 0.5815923076923076), (True, u'Extra-vehicular_activity', 0.5815923076923076)]
             assert results == expected
         elif i == 1:
             expected = [(True, u'NASA', 0.5027600000000001), (True, u'Research', 0.4431), False, False, (True, u'Research', 0.4431), False, False, False, False, False, False, False, False, False, False, (True, u'Experience', 0.4275), (True, u'Robotics', 0.5115555555555555), (True, u'Human_spaceflight', 0.5775266666666666), False, False, (True, u'Observation', 0.5215714285714286), False, False, (True, u'NASA', 0.5027600000000001), False, False, False, False, (True, u'Missile_guidance', 0.43822500000000003), False]
             assert results == expected
         elif i == 2:
             expected = [(True, u'University', 0.4235), (True, u'University', 0.4235), False, False, False, False, (True, u'Exploration_Systems_Architecture_Study', 0.4908666666666666), False, False, False, False, (True, u'Scientific_journal', 0.4461), (True, u'Research', 0.4431), False, (True, u'Electricity', 0.4451), False, False, False, (True, u'Plant_cell', 0.502), False, False, False, False, False]
             assert results == expected
         else:
             assert False
 def runTest(self):
     """
     test the function that checks if any term has a proper correlation with the aerospace/astronomy/physics
     """
     for i, t in enumerate(self.test1):
         print "<CHECK IF TERMS are related to SPACEKNOWLEDGE>"
         results = []
         for spot in [s["spot"] for s in TagMeService.check_spotting(t)["value"]["spots"]]:
             result = TagMeService.retrieve_taggings(spot.encode("utf-8"), method="POST")
             for n in result["annotations"]:
                 title = n["title"].replace(" ", "_")  # strip whitespaces from dbpedia tag
                 relate = TagMeService.relate(
                     title, self.scopes
                 )  # compare the spotted and tagged term to the generic scopes
                 results.append(TagMeService.check_if_rho_fits_spaceknowledge(relate))
         print i, results
         # print True, name and the mean of the rho of the term in relation with the scopes
         if i == 0:
             expected = [
                 (True, u"Functional_(mathematics)", 0.4235),
                 (True, u"Electron_mobility", 0.4784),
                 (True, u"Units_of_measurement", 0.46557142857142864),
                 False,
                 False,
                 (True, u"Accuracy_and_precision", 0.4797333333333333),
                 False,
                 False,
                 False,
                 (True, u"Extra-vehicular_activity", 0.5815923076923076),
                 (True, u"Extra-vehicular_activity", 0.5815923076923076),
             ]
             assert results == expected
         elif i == 1:
             expected = [
                 (True, u"NASA", 0.5027600000000001),
                 (True, u"Research", 0.4431),
                 False,
                 False,
                 (True, u"Research", 0.4431),
                 False,
                 False,
                 False,
                 False,
                 False,
                 False,
                 False,
                 False,
                 False,
                 False,
                 (True, u"Experience", 0.4275),
                 (True, u"Robotics", 0.5115555555555555),
                 (True, u"Human_spaceflight", 0.5775266666666666),
                 False,
                 False,
                 (True, u"Observation", 0.5215714285714286),
                 False,
                 False,
                 (True, u"NASA", 0.5027600000000001),
                 False,
                 False,
                 False,
                 False,
                 (True, u"Missile_guidance", 0.43822500000000003),
                 False,
             ]
             assert results == expected
         elif i == 2:
             expected = [
                 (True, u"University", 0.4235),
                 (True, u"University", 0.4235),
                 False,
                 False,
                 False,
                 False,
                 (True, u"Exploration_Systems_Architecture_Study", 0.4908666666666666),
                 False,
                 False,
                 False,
                 False,
                 (True, u"Scientific_journal", 0.4461),
                 (True, u"Research", 0.4431),
                 False,
                 (True, u"Electricity", 0.4451),
                 False,
                 False,
                 False,
                 (True, u"Plant_cell", 0.502),
                 False,
                 False,
                 False,
                 False,
                 False,
             ]
             assert results == expected
         else:
             assert False
 def runTest(self):
     """
     test the relating service for terms in relation with generic scopes
     """
     for i, t in enumerate(self.test1):
         print "<RELATING API>"
         results = []
         for spot in [s["spot"] for s in TagMeService.check_spotting(t)["value"]["spots"]]:
             result = TagMeService.retrieve_taggings(spot.encode("utf-8"), method="POST")
             print result
             for n in result["annotations"]:
                 title = n["title"].replace(" ", "_")  # strip whitespaces from dbpedia tag
                 results.append(
                     TagMeService.relate(title, self.scopes)
                 )  # compare the spotted and tagged term to the generic scopes
         print i, results
         # 'couple' are the two wikipedia terms been checked, 'rel' is the correlation index (rho). The more the rho
         # is closer to 0.5 the more the terms are related. The standard interval of relevance is 0.42 < rho < 0.61
         if i == 0:
             expected = [
                 [{u"couple": u"Functional_(mathematics) Physics", u"rel": u"0.4235"}],
                 [{u"couple": u"Electron_mobility Cosmic_ray", u"rel": u"0.4784"}],
                 [
                     {u"couple": u"Units_of_measurement Astrophysics", u"rel": u"0.4353"},
                     {u"couple": u"Units_of_measurement Geodesy", u"rel": u"0.5333"},
                     {u"couple": u"Units_of_measurement Astronomical_object", u"rel": u"0.4824"},
                     {u"couple": u"Units_of_measurement Astronomy", u"rel": u"0.4824"},
                     {u"couple": u"Units_of_measurement Navigation", u"rel": u"0.4706"},
                     {u"couple": u"Units_of_measurement Physics", u"rel": u"0.4275"},
                     {u"couple": u"Units_of_measurement Planetary_science", u"rel": u"0.4275"},
                 ],
                 [],
                 [],
                 [
                     {u"couple": u"Accuracy_and_precision Geodesy", u"rel": u"0.5176"},
                     {u"couple": u"Accuracy_and_precision Astronomical_object", u"rel": u"0.4471"},
                     {u"couple": u"Accuracy_and_precision Navigation", u"rel": u"0.4745"},
                 ],
                 [],
                 [],
                 [],
                 [
                     {u"couple": u"Extra-vehicular_activity Aerospace", u"rel": u"0.4392"},
                     {u"couple": u"Extra-vehicular_activity Astrophysics", u"rel": u"0.4471"},
                     {u"couple": u"Extra-vehicular_activity Cosmic_ray", u"rel": u"0.5804"},
                     {u"couple": u"Extra-vehicular_activity Spaceflight", u"rel": u"0.8353"},
                     {u"couple": u"Extra-vehicular_activity Spacecraft", u"rel": u"0.7059"},
                     {u"couple": u"Extra-vehicular_activity Geodesy", u"rel": u"0.5137"},
                     {u"couple": u"Extra-vehicular_activity Astronomical_object", u"rel": u"0.5137"},
                     {u"couple": u"Extra-vehicular_activity Aircraft", u"rel": u"0.4235"},
                     {u"couple": u"Extra-vehicular_activity Atmosphere", u"rel": u"0.4784"},
                     {u"couple": u"Extra-vehicular_activity Navigation", u"rel": u"0.4941"},
                     {u"couple": u"Extra-vehicular_activity Satellite", u"rel": u"0.6941"},
                     {u"couple": u"Extra-vehicular_activity Spaceflight", u"rel": u"0.8353"},
                     {u"couple": u"Extra-vehicular_activity NASA", u"rel": u"0.6000"},
                 ],
                 [
                     {u"couple": u"Extra-vehicular_activity Aerospace", u"rel": u"0.4392"},
                     {u"couple": u"Extra-vehicular_activity Astrophysics", u"rel": u"0.4471"},
                     {u"couple": u"Extra-vehicular_activity Cosmic_ray", u"rel": u"0.5804"},
                     {u"couple": u"Extra-vehicular_activity Spaceflight", u"rel": u"0.8353"},
                     {u"couple": u"Extra-vehicular_activity Spacecraft", u"rel": u"0.7059"},
                     {u"couple": u"Extra-vehicular_activity Geodesy", u"rel": u"0.5137"},
                     {u"couple": u"Extra-vehicular_activity Astronomical_object", u"rel": u"0.5137"},
                     {u"couple": u"Extra-vehicular_activity Aircraft", u"rel": u"0.4235"},
                     {u"couple": u"Extra-vehicular_activity Atmosphere", u"rel": u"0.4784"},
                     {u"couple": u"Extra-vehicular_activity Navigation", u"rel": u"0.4941"},
                     {u"couple": u"Extra-vehicular_activity Satellite", u"rel": u"0.6941"},
                     {u"couple": u"Extra-vehicular_activity Spaceflight", u"rel": u"0.8353"},
                     {u"couple": u"Extra-vehicular_activity NASA", u"rel": u"0.6000"},
                 ],
             ]
             assert results == expected
         elif i == 1:
             expected = [
                 [
                     {u"couple": u"NASA Astrophysics", u"rel": u"0.4549"},
                     {u"couple": u"NASA Cosmic_ray", u"rel": u"0.4745"},
                     {u"couple": u"NASA Spaceflight", u"rel": u"0.5765"},
                     {u"couple": u"NASA Spacecraft", u"rel": u"0.5569"},
                     {u"couple": u"NASA Astronomical_object", u"rel": u"0.4471"},
                     {u"couple": u"NASA Astronomy", u"rel": u"0.4510"},
                     {u"couple": u"NASA Atmosphere", u"rel": u"0.4863"},
                     {u"couple": u"NASA Satellite", u"rel": u"0.5451"},
                     {u"couple": u"NASA Spaceflight", u"rel": u"0.5765"},
                     {u"couple": u"NASA Planetary_science", u"rel": u"0.4588"},
                 ],
                 [{u"couple": u"Research Physics", u"rel": u"0.4431"}],
                 [],
                 [],
                 [{u"couple": u"Research Physics", u"rel": u"0.4431"}],
                 [],
                 [],
                 [],
                 [],
                 [],
                 [],
                 [],
                 [],
                 [],
                 [],
                 [{u"couple": u"Experience Navigation", u"rel": u"0.4275"}],
                 [
                     {u"couple": u"Robotics Aerospace", u"rel": u"0.5255"},
                     {u"couple": u"Robotics Astrophysics", u"rel": u"0.5608"},
                     {u"couple": u"Robotics Spaceflight", u"rel": u"0.4667"},
                     {u"couple": u"Robotics Spacecraft", u"rel": u"0.4863"},
                     {u"couple": u"Robotics Geodesy", u"rel": u"0.5882"},
                     {u"couple": u"Robotics Astronomy", u"rel": u"0.4706"},
                     {u"couple": u"Robotics Spaceflight", u"rel": u"0.4667"},
                     {u"couple": u"Robotics Physics", u"rel": u"0.4549"},
                     {u"couple": u"Robotics Planetary_science", u"rel": u"0.5843"},
                 ],
                 [
                     {u"couple": u"Human_spaceflight Aerospace", u"rel": u"0.4471"},
                     {u"couple": u"Human_spaceflight Astrophysics", u"rel": u"0.4706"},
                     {u"couple": u"Human_spaceflight Cosmic_ray", u"rel": u"0.6039"},
                     {u"couple": u"Human_spaceflight Spaceflight", u"rel": u"0.8392"},
                     {u"couple": u"Human_spaceflight Spacecraft", u"rel": u"0.7333"},
                     {u"couple": u"Human_spaceflight Avionics", u"rel": u"0.5216"},
                     {u"couple": u"Human_spaceflight Geodesy", u"rel": u"0.5020"},
                     {u"couple": u"Human_spaceflight Astronomical_object", u"rel": u"0.5412"},
                     {u"couple": u"Human_spaceflight Astronomy", u"rel": u"0.4275"},
                     {u"couple": u"Human_spaceflight Atmosphere", u"rel": u"0.5333"},
                     {u"couple": u"Human_spaceflight Navigation", u"rel": u"0.4510"},
                     {u"couple": u"Human_spaceflight Satellite", u"rel": u"0.7137"},
                     {u"couple": u"Human_spaceflight Spaceflight", u"rel": u"0.8392"},
                     {u"couple": u"Human_spaceflight NASA", u"rel": u"0.5922"},
                     {u"couple": u"Human_spaceflight Planetary_science", u"rel": u"0.4471"},
                 ],
                 [],
                 [],
                 [
                     {u"couple": u"Observation Astrophysics", u"rel": u"0.5451"},
                     {u"couple": u"Observation Geodesy", u"rel": u"0.5569"},
                     {u"couple": u"Observation Astronomical_object", u"rel": u"0.5725"},
                     {u"couple": u"Observation Astronomy", u"rel": u"0.5059"},
                     {u"couple": u"Observation Atmosphere", u"rel": u"0.4392"},
                     {u"couple": u"Observation Physics", u"rel": u"0.4824"},
                     {u"couple": u"Observation Planetary_science", u"rel": u"0.5490"},
                 ],
                 [],
                 [],
                 [
                     {u"couple": u"NASA Astrophysics", u"rel": u"0.4549"},
                     {u"couple": u"NASA Cosmic_ray", u"rel": u"0.4745"},
                     {u"couple": u"NASA Spaceflight", u"rel": u"0.5765"},
                     {u"couple": u"NASA Spacecraft", u"rel": u"0.5569"},
                     {u"couple": u"NASA Astronomical_object", u"rel": u"0.4471"},
                     {u"couple": u"NASA Astronomy", u"rel": u"0.4510"},
                     {u"couple": u"NASA Atmosphere", u"rel": u"0.4863"},
                     {u"couple": u"NASA Satellite", u"rel": u"0.5451"},
                     {u"couple": u"NASA Spaceflight", u"rel": u"0.5765"},
                     {u"couple": u"NASA Planetary_science", u"rel": u"0.4588"},
                 ],
                 [],
                 [],
                 [],
                 [],
                 [
                     {u"couple": u"Missile_guidance Spaceflight", u"rel": u"0.4235"},
                     {u"couple": u"Missile_guidance Avionics", u"rel": u"0.4549"},
                     {u"couple": u"Missile_guidance Command_and_control", u"rel": u"0.4510"},
                     {u"couple": u"Missile_guidance Spaceflight", u"rel": u"0.4235"},
                 ],
                 [],
             ]
             assert results == expected
         elif i == 2:
             expected = [
                 [{u"couple": u"University Physics", u"rel": u"0.4235"}],
                 [{u"couple": u"University Physics", u"rel": u"0.4235"}],
                 [],
                 [],
                 [],
                 [],
                 [
                     {u"couple": u"Exploration_Systems_Architecture_Study Cosmic_ray", u"rel": u"0.4588"},
                     {u"couple": u"Exploration_Systems_Architecture_Study Spaceflight", u"rel": u"0.4863"},
                     {u"couple": u"Exploration_Systems_Architecture_Study Spacecraft", u"rel": u"0.5412"},
                     {u"couple": u"Exploration_Systems_Architecture_Study Avionics", u"rel": u"0.5059"},
                     {u"couple": u"Exploration_Systems_Architecture_Study Spaceflight", u"rel": u"0.4863"},
                     {u"couple": u"Exploration_Systems_Architecture_Study NASA", u"rel": u"0.4667"},
                 ],
                 [],
                 [],
                 [],
                 [],
                 [
                     {u"couple": u"Scientific_journal Astrophysics", u"rel": u"0.4706"},
                     {u"couple": u"Scientific_journal Astronomy", u"rel": u"0.4314"},
                     {u"couple": u"Scientific_journal Physics", u"rel": u"0.4510"},
                     {u"couple": u"Scientific_journal Planetary_science", u"rel": u"0.4314"},
                 ],
                 [{u"couple": u"Research Physics", u"rel": u"0.4431"}],
                 [],
                 [
                     {u"couple": u"Electricity Astrophysics", u"rel": u"0.4275"},
                     {u"couple": u"Electricity Physics", u"rel": u"0.4627"},
                 ],
                 [],
                 [],
                 [],
                 [{u"couple": u"Plant_cell Atmosphere", u"rel": u"0.5020"}],
                 [],
                 [],
                 [],
                 [],
                 [],
             ]
             assert results == expected
         else:
             assert False
 def runTest(self):
     """
     test the function that checks if any term has a proper correlation with the aerospace/astronomy/physics
     """
     for i, t in enumerate(self.test1):
         print '<CHECK IF TERMS are related to SPACEKNOWLEDGE>'
         results = []
         for spot in [
                 s['spot']
                 for s in TagMeService.check_spotting(t)['value']['spots']
         ]:
             result = TagMeService.retrieve_taggings(spot.encode('utf-8'),
                                                     method='POST')
             for n in result['annotations']:
                 title = n['title'].replace(
                     ' ', '_')  # strip whitespaces from dbpedia tag
                 relate = TagMeService.relate(
                     title, self.scopes
                 )  # compare the spotted and tagged term to the generic scopes
                 results.append(
                     TagMeService.check_if_rho_fits_spaceknowledge(relate))
         print i, results
         # print True, name and the mean of the rho of the term in relation with the scopes
         if i == 0:
             expected = [
                 (True, u'Functional_(mathematics)', 0.4235),
                 (True, u'Electron_mobility', 0.4784),
                 (True, u'Units_of_measurement', 0.46557142857142864),
                 False, False,
                 (True, u'Accuracy_and_precision', 0.4797333333333333),
                 False, False, False,
                 (True, u'Extra-vehicular_activity', 0.5815923076923076),
                 (True, u'Extra-vehicular_activity', 0.5815923076923076)
             ]
             assert results == expected
         elif i == 1:
             expected = [
                 (True, u'NASA', 0.5027600000000001),
                 (True, u'Research', 0.4431), False, False,
                 (True, u'Research', 0.4431), False, False, False, False,
                 False, False, False, False, False, False,
                 (True, u'Experience', 0.4275),
                 (True, u'Robotics', 0.5115555555555555),
                 (True, u'Human_spaceflight',
                  0.5775266666666666), False, False,
                 (True, u'Observation', 0.5215714285714286), False, False,
                 (True, u'NASA', 0.5027600000000001), False, False,
                 False, False,
                 (True, u'Missile_guidance', 0.43822500000000003), False
             ]
             assert results == expected
         elif i == 2:
             expected = [(True, u'University', 0.4235),
                         (True, u'University', 0.4235), False, False, False,
                         False,
                         (True, u'Exploration_Systems_Architecture_Study',
                          0.4908666666666666), False, False, False, False,
                         (True, u'Scientific_journal', 0.4461),
                         (True, u'Research', 0.4431), False,
                         (True, u'Electricity', 0.4451), False, False,
                         False, (True, u'Plant_cell', 0.502), False, False,
                         False, False, False]
             assert results == expected
         else:
             assert False
 def runTest(self):
     """
     test the relating service for terms in relation with generic scopes
     """
     for i, t in enumerate(self.test1):
         print '<RELATING API>'
         results = []
         for spot in [
                 s['spot']
                 for s in TagMeService.check_spotting(t)['value']['spots']
         ]:
             result = TagMeService.retrieve_taggings(spot.encode('utf-8'),
                                                     method='POST')
             for n in result['annotations']:
                 title = n['title'].replace(
                     ' ', '_')  # strip whitespaces from dbpedia tag
                 results.append(
                     TagMeService.relate(title, self.scopes)
                 )  # compare the spotted and tagged term to the generic scopes
         print i, results
         # 'couple' are the two wikipedia terms been checked, 'rel' is the correlation index (rho). The more the rho
         # is closer to 0.5 the more the terms are related. The standard interval of relevance is 0.42 < rho < 0.61
         if i == 0:
             expected = [
                 [{
                     u'couple': u'Functional_(mathematics) Physics',
                     u'rel': u'0.4235'
                 }],
                 [{
                     u'couple': u'Electron_mobility Cosmic_ray',
                     u'rel': u'0.4784'
                 }],
                 [{
                     u'couple': u'Units_of_measurement Astrophysics',
                     u'rel': u'0.4353'
                 }, {
                     u'couple': u'Units_of_measurement Geodesy',
                     u'rel': u'0.5333'
                 }, {
                     u'couple': u'Units_of_measurement Astronomical_object',
                     u'rel': u'0.4824'
                 }, {
                     u'couple': u'Units_of_measurement Astronomy',
                     u'rel': u'0.4824'
                 }, {
                     u'couple': u'Units_of_measurement Navigation',
                     u'rel': u'0.4706'
                 }, {
                     u'couple': u'Units_of_measurement Physics',
                     u'rel': u'0.4275'
                 }, {
                     u'couple': u'Units_of_measurement Planetary_science',
                     u'rel': u'0.4275'
                 }], [], [],
                 [{
                     u'couple': u'Accuracy_and_precision Geodesy',
                     u'rel': u'0.5176'
                 }, {
                     u'couple':
                     u'Accuracy_and_precision Astronomical_object',
                     u'rel': u'0.4471'
                 }, {
                     u'couple': u'Accuracy_and_precision Navigation',
                     u'rel': u'0.4745'
                 }], [], [], [],
                 [{
                     u'couple': u'Extra-vehicular_activity Aerospace',
                     u'rel': u'0.4392'
                 }, {
                     u'couple': u'Extra-vehicular_activity Astrophysics',
                     u'rel': u'0.4471'
                 }, {
                     u'couple': u'Extra-vehicular_activity Cosmic_ray',
                     u'rel': u'0.5804'
                 }, {
                     u'couple': u'Extra-vehicular_activity Spaceflight',
                     u'rel': u'0.8353'
                 }, {
                     u'couple': u'Extra-vehicular_activity Spacecraft',
                     u'rel': u'0.7059'
                 }, {
                     u'couple': u'Extra-vehicular_activity Geodesy',
                     u'rel': u'0.5137'
                 }, {
                     u'couple':
                     u'Extra-vehicular_activity Astronomical_object',
                     u'rel': u'0.5137'
                 }, {
                     u'couple': u'Extra-vehicular_activity Aircraft',
                     u'rel': u'0.4235'
                 }, {
                     u'couple': u'Extra-vehicular_activity Atmosphere',
                     u'rel': u'0.4784'
                 }, {
                     u'couple': u'Extra-vehicular_activity Navigation',
                     u'rel': u'0.4941'
                 }, {
                     u'couple': u'Extra-vehicular_activity Satellite',
                     u'rel': u'0.6941'
                 }, {
                     u'couple': u'Extra-vehicular_activity Spaceflight',
                     u'rel': u'0.8353'
                 }, {
                     u'couple': u'Extra-vehicular_activity NASA',
                     u'rel': u'0.6000'
                 }],
                 [{
                     u'couple': u'Extra-vehicular_activity Aerospace',
                     u'rel': u'0.4392'
                 }, {
                     u'couple': u'Extra-vehicular_activity Astrophysics',
                     u'rel': u'0.4471'
                 }, {
                     u'couple': u'Extra-vehicular_activity Cosmic_ray',
                     u'rel': u'0.5804'
                 }, {
                     u'couple': u'Extra-vehicular_activity Spaceflight',
                     u'rel': u'0.8353'
                 }, {
                     u'couple': u'Extra-vehicular_activity Spacecraft',
                     u'rel': u'0.7059'
                 }, {
                     u'couple': u'Extra-vehicular_activity Geodesy',
                     u'rel': u'0.5137'
                 }, {
                     u'couple':
                     u'Extra-vehicular_activity Astronomical_object',
                     u'rel': u'0.5137'
                 }, {
                     u'couple': u'Extra-vehicular_activity Aircraft',
                     u'rel': u'0.4235'
                 }, {
                     u'couple': u'Extra-vehicular_activity Atmosphere',
                     u'rel': u'0.4784'
                 }, {
                     u'couple': u'Extra-vehicular_activity Navigation',
                     u'rel': u'0.4941'
                 }, {
                     u'couple': u'Extra-vehicular_activity Satellite',
                     u'rel': u'0.6941'
                 }, {
                     u'couple': u'Extra-vehicular_activity Spaceflight',
                     u'rel': u'0.8353'
                 }, {
                     u'couple': u'Extra-vehicular_activity NASA',
                     u'rel': u'0.6000'
                 }]
             ]
             assert results == expected
         elif i == 1:
             expected = [[{
                 u'couple': u'NASA Astrophysics',
                 u'rel': u'0.4549'
             }, {
                 u'couple': u'NASA Cosmic_ray',
                 u'rel': u'0.4745'
             }, {
                 u'couple': u'NASA Spaceflight',
                 u'rel': u'0.5765'
             }, {
                 u'couple': u'NASA Spacecraft',
                 u'rel': u'0.5569'
             }, {
                 u'couple': u'NASA Astronomical_object',
                 u'rel': u'0.4471'
             }, {
                 u'couple': u'NASA Astronomy',
                 u'rel': u'0.4510'
             }, {
                 u'couple': u'NASA Atmosphere',
                 u'rel': u'0.4863'
             }, {
                 u'couple': u'NASA Satellite',
                 u'rel': u'0.5451'
             }, {
                 u'couple': u'NASA Spaceflight',
                 u'rel': u'0.5765'
             }, {
                 u'couple': u'NASA Planetary_science',
                 u'rel': u'0.4588'
             }], [{
                 u'couple': u'Research Physics',
                 u'rel': u'0.4431'
             }], [], [],
                         [{
                             u'couple': u'Research Physics',
                             u'rel': u'0.4431'
                         }], [], [], [], [], [], [], [], [], [], [],
                         [{
                             u'couple': u'Experience Navigation',
                             u'rel': u'0.4275'
                         }],
                         [{
                             u'couple': u'Robotics Aerospace',
                             u'rel': u'0.5255'
                         }, {
                             u'couple': u'Robotics Astrophysics',
                             u'rel': u'0.5608'
                         }, {
                             u'couple': u'Robotics Spaceflight',
                             u'rel': u'0.4667'
                         }, {
                             u'couple': u'Robotics Spacecraft',
                             u'rel': u'0.4863'
                         }, {
                             u'couple': u'Robotics Geodesy',
                             u'rel': u'0.5882'
                         }, {
                             u'couple': u'Robotics Astronomy',
                             u'rel': u'0.4706'
                         }, {
                             u'couple': u'Robotics Spaceflight',
                             u'rel': u'0.4667'
                         }, {
                             u'couple': u'Robotics Physics',
                             u'rel': u'0.4549'
                         }, {
                             u'couple': u'Robotics Planetary_science',
                             u'rel': u'0.5843'
                         }],
                         [{
                             u'couple': u'Human_spaceflight Aerospace',
                             u'rel': u'0.4471'
                         }, {
                             u'couple': u'Human_spaceflight Astrophysics',
                             u'rel': u'0.4706'
                         }, {
                             u'couple': u'Human_spaceflight Cosmic_ray',
                             u'rel': u'0.6039'
                         }, {
                             u'couple': u'Human_spaceflight Spaceflight',
                             u'rel': u'0.8392'
                         }, {
                             u'couple': u'Human_spaceflight Spacecraft',
                             u'rel': u'0.7333'
                         }, {
                             u'couple': u'Human_spaceflight Avionics',
                             u'rel': u'0.5216'
                         }, {
                             u'couple': u'Human_spaceflight Geodesy',
                             u'rel': u'0.5020'
                         }, {
                             u'couple':
                             u'Human_spaceflight Astronomical_object',
                             u'rel': u'0.5412'
                         }, {
                             u'couple': u'Human_spaceflight Astronomy',
                             u'rel': u'0.4275'
                         }, {
                             u'couple': u'Human_spaceflight Atmosphere',
                             u'rel': u'0.5333'
                         }, {
                             u'couple': u'Human_spaceflight Navigation',
                             u'rel': u'0.4510'
                         }, {
                             u'couple': u'Human_spaceflight Satellite',
                             u'rel': u'0.7137'
                         }, {
                             u'couple': u'Human_spaceflight Spaceflight',
                             u'rel': u'0.8392'
                         }, {
                             u'couple': u'Human_spaceflight NASA',
                             u'rel': u'0.5922'
                         }, {
                             u'couple':
                             u'Human_spaceflight Planetary_science',
                             u'rel': u'0.4471'
                         }], [], [],
                         [{
                             u'couple': u'Observation Astrophysics',
                             u'rel': u'0.5451'
                         }, {
                             u'couple': u'Observation Geodesy',
                             u'rel': u'0.5569'
                         }, {
                             u'couple': u'Observation Astronomical_object',
                             u'rel': u'0.5725'
                         }, {
                             u'couple': u'Observation Astronomy',
                             u'rel': u'0.5059'
                         }, {
                             u'couple': u'Observation Atmosphere',
                             u'rel': u'0.4392'
                         }, {
                             u'couple': u'Observation Physics',
                             u'rel': u'0.4824'
                         }, {
                             u'couple': u'Observation Planetary_science',
                             u'rel': u'0.5490'
                         }], [], [],
                         [{
                             u'couple': u'NASA Astrophysics',
                             u'rel': u'0.4549'
                         }, {
                             u'couple': u'NASA Cosmic_ray',
                             u'rel': u'0.4745'
                         }, {
                             u'couple': u'NASA Spaceflight',
                             u'rel': u'0.5765'
                         }, {
                             u'couple': u'NASA Spacecraft',
                             u'rel': u'0.5569'
                         }, {
                             u'couple': u'NASA Astronomical_object',
                             u'rel': u'0.4471'
                         }, {
                             u'couple': u'NASA Astronomy',
                             u'rel': u'0.4510'
                         }, {
                             u'couple': u'NASA Atmosphere',
                             u'rel': u'0.4863'
                         }, {
                             u'couple': u'NASA Satellite',
                             u'rel': u'0.5451'
                         }, {
                             u'couple': u'NASA Spaceflight',
                             u'rel': u'0.5765'
                         }, {
                             u'couple': u'NASA Planetary_science',
                             u'rel': u'0.4588'
                         }], [], [], [], [],
                         [{
                             u'couple': u'Missile_guidance Spaceflight',
                             u'rel': u'0.4235'
                         }, {
                             u'couple': u'Missile_guidance Avionics',
                             u'rel': u'0.4549'
                         }, {
                             u'couple':
                             u'Missile_guidance Command_and_control',
                             u'rel': u'0.4510'
                         }, {
                             u'couple': u'Missile_guidance Spaceflight',
                             u'rel': u'0.4235'
                         }], []]
             assert results == expected
         elif i == 2:
             expected = [
                 [{
                     u'couple': u'University Physics',
                     u'rel': u'0.4235'
                 }], [{
                     u'couple': u'University Physics',
                     u'rel': u'0.4235'
                 }], [], [], [], [],
                 [{
                     u'couple':
                     u'Exploration_Systems_Architecture_Study Cosmic_ray',
                     u'rel': u'0.4588'
                 }, {
                     u'couple':
                     u'Exploration_Systems_Architecture_Study Spaceflight',
                     u'rel': u'0.4863'
                 }, {
                     u'couple':
                     u'Exploration_Systems_Architecture_Study Spacecraft',
                     u'rel': u'0.5412'
                 }, {
                     u'couple':
                     u'Exploration_Systems_Architecture_Study Avionics',
                     u'rel': u'0.5059'
                 }, {
                     u'couple':
                     u'Exploration_Systems_Architecture_Study Spaceflight',
                     u'rel': u'0.4863'
                 }, {
                     u'couple':
                     u'Exploration_Systems_Architecture_Study NASA',
                     u'rel': u'0.4667'
                 }], [], [], [], [],
                 [{
                     u'couple': u'Scientific_journal Astrophysics',
                     u'rel': u'0.4706'
                 }, {
                     u'couple': u'Scientific_journal Astronomy',
                     u'rel': u'0.4314'
                 }, {
                     u'couple': u'Scientific_journal Physics',
                     u'rel': u'0.4510'
                 }, {
                     u'couple': u'Scientific_journal Planetary_science',
                     u'rel': u'0.4314'
                 }], [{
                     u'couple': u'Research Physics',
                     u'rel': u'0.4431'
                 }], [],
                 [{
                     u'couple': u'Electricity Astrophysics',
                     u'rel': u'0.4275'
                 }, {
                     u'couple': u'Electricity Physics',
                     u'rel': u'0.4627'
                 }], [], [], [],
                 [{
                     u'couple': u'Plant_cell Atmosphere',
                     u'rel': u'0.5020'
                 }], [], [], [], [], []
             ]
             assert results == expected
         else:
             assert False