Exemplo n.º 1
0
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)
Exemplo n.º 2
0
def test_similar():
    rdf_space = Space('tests/example.n3')
    similar = rdf_space.similar('http://dbpedia.org/resource/Category:Futurama', 2)
    assert_equal(len(similar), 2)
    assert_equal(similar[0][0], 'http://dbpedia.org/resource/Category:Futurama')
    assert_equal(similar[0][1], 1.0)
    assert_equal(similar[1][0], 'http://dbpedia.org/resource/Category:New_York_City_in_fiction')
    assert_equal(similar[1][1], rdf_space.similarity('http://dbpedia.org/resource/Category:Futurama', 'http://dbpedia.org/resource/Category:New_York_City_in_fiction'))
Exemplo n.º 3
0
import rdfspace
from rdfspace.space import Space

space = Space(
    'influencedby.nt',
    ignored_predicates=['http://www.w3.org/1999/02/22-rdf-syntax-ns#type'],
    rank=50)

print "Similarity betwen JavaScript and ECMAScript:"
print space.similarity('http://dbpedia.org/resource/JavaScript',
                       'http://dbpedia.org/resource/ECMAScript')

print "Similarity between Albert Camus and JavaScript:"
print space.similarity('http://dbpedia.org/resource/Albert_Camus',
                       'http://dbpedia.org/resource/JavaScript')
Exemplo n.º 4
0
import rdfspace
from rdfspace.space import Space

space = Space('influencedby.nt', ignored_predicates=['http://www.w3.org/1999/02/22-rdf-syntax-ns#type'], rank=50)

print
print "Similarity betwen JavaScript and ECMAScript:"
print space.similarity('http://dbpedia.org/resource/JavaScript', 'http://dbpedia.org/resource/ECMAScript')
print
print "Eigenvector centrality of JavaScript:"
print space.centrality('http://dbpedia.org/resource/JavaScript')
print
print "Similarity between Albert Camus and JavaScript:"
print space.similarity('http://dbpedia.org/resource/Albert_Camus', 'http://dbpedia.org/resource/JavaScript')
print
print "Eigenvector centrality of Albert Camus"
print space.centrality('http://dbpedia.org/resource/Albert_Camus')
print
print "Most similar entities to Albert Camus"
for uri, similarity in space.similar("http://dbpedia.org/resource/Albert_Camus"):
    print uri, similarity