def test_centrality(): rdf_space = Space('tests/example.n3') # Overriding _ut rdf_space._ut = np.array([[-1,1,0,0],[1,0,0,0],[2,1,0,0],[3,1,1,1]], dtype=float).T # Overriding uri_index rdf_space._uri_index = {'http://0': 0, 'http://1': 1, 'http://2': 2, 'http://3': 3} assert_equal(rdf_space.centrality('http://0'), 1) assert_equal(rdf_space.centrality('http://1'), 1) assert_equal(rdf_space.centrality('http://2'), 2) assert_equal(rdf_space.centrality('http://3'), 3)
def test_similarity(): rdf_space = Space('tests/example.n3') # Overriding _ut rdf_space._ut = np.array([[0,1,0,0],[1,0,0,0],[0,1,0,0],[1,1,1,1]], dtype=float).T # Overriding uri_index rdf_space._uri_index = {'http://0': 0, 'http://1': 1, 'http://2': 2, 'http://3': 3} assert_equal(rdf_space.similarity('http://0', 'http://0'), 1.0) assert_equal(rdf_space.similarity('http://0', 'http://1'), 0) assert_equal(rdf_space.similarity('http://0', 'http://2'), 1.0) assert_equal(rdf_space.similarity('http://0', 'http://3'), 0.5)
def test_centroid(): rdf_space = Space('tests/example.n3') # Overriding _ut rdf_space._ut = np.array([[0,1,0,0],[1,0,0,0],[0,1,0,0],[1,1,1,1]], dtype=float).T # Overriding uri_index rdf_space._uri_index = {'http://0': 0, 'http://1': 1, 'http://2': 2, 'http://3': 3} centroid = rdf_space.centroid(['http://0', 'http://1', 'http://2', 'http://3']) assert_array_equal(centroid, np.array([0.5, 0.75, 0.25, 0.25])) centroid = rdf_space.centroid(['http://0', 'http://3']) assert_array_equal(centroid, np.array([0.5, 1, 0.5, 0.5])) centroid = rdf_space.centroid(['http://0', 'http://1']) assert_array_equal(centroid, np.array([0.5, 0.5, 0, 0])) centroid = rdf_space.centroid(['http://0', 'http://6']) assert_array_equal(centroid, np.array([0, 1, 0, 0])) centroid = rdf_space.centroid([]) assert_array_equal(centroid, None)