예제 #1
0
def test_distance_between_overlapping_items():
    from rdflib_django import utils
    g1 = utils.get_named_graph('http://dbpedia.org/resource/Scotland')
    g1.add((URIRef('http://dbpedia.org/resource/Scotland'), TOPICA.tag, URIRef('http://dbpedia.org/resource/Robert_Burns')))
    g1.add((URIRef('http://dbpedia.org/resource/Robert_Burns'), RDFS.label, Literal('Robert Burns')))
    g1.add((URIRef('http://dbpedia.org/resource/Scotland'), TOPICA.tag, URIRef('http://dbpedia.org/resource/United_Kingdom')))
    g1.add((URIRef('http://dbpedia.org/resource/United_Kingdom'), RDFS.label, Literal('United Kingdom')))

    g2 = utils.get_named_graph('http://dbpedia.org/resource/England')
    g2.add((URIRef('http://dbpedia.org/resource/England'), TOPICA.tag, URIRef('http://dbpedia.org/resource/United_Kingdom')))
    g2.add((URIRef('http://dbpedia.org/resource/United_Kingdom'), RDFS.label, Literal('United Kingdom')))
    g2.add((URIRef('http://dbpedia.org/resource/England'), TOPICA.tag, URIRef('http://dbpedia.org/resource/William_Shakespeare')))
    g2.add((URIRef('http://dbpedia.org/resource/William_Shakespeare'), RDFS.label, Literal('William Shakespeare')))

    item1 = Item(iri='http://dbpedia.org/resource/Scotland')
    item1.save()
    item2 = Item(iri='http://dbpedia.org/resource/England')
    item2.save()

    assert item1.get_distance(item2) == 2.0/3.0
    assert item2.get_distance(item1) == 2.0/3.0
예제 #2
0
def test_distance_between_identical_items_is_zero():
    from rdflib_django import utils
    g1 = utils.get_named_graph('http://dbpedia.org/resource/Scotland')
    g1.add((URIRef('http://dbpedia.org/resource/Scotland'), TOPICA.tag, URIRef('http://dbpedia.org/resource/Robert_Burns')))
    g1.add((URIRef('http://dbpedia.org/resource/Robert_Burns'), RDFS.label, Literal('Robert Burns')))
    g1.add((URIRef('http://dbpedia.org/resource/Scotland'), TOPICA.tag, URIRef('http://dbpedia.org/resource/William_Wallace')))
    g1.add((URIRef('http://dbpedia.org/resource/William_Wallace'), RDFS.label, Literal('William Wallace')))

    g2 = utils.get_named_graph('http://dbpedia.org/resource/Alba')
    g2.add((URIRef('http://dbpedia.org/resource/Alba'), TOPICA.tag, URIRef('http://dbpedia.org/resource/Robert_Burns')))
    g2.add((URIRef('http://dbpedia.org/resource/Robert_Burns'), RDFS.label, Literal('Robert Burns')))
    g2.add((URIRef('http://dbpedia.org/resource/Alba'), TOPICA.tag, URIRef('http://dbpedia.org/resource/William_Wallace')))
    g2.add((URIRef('http://dbpedia.org/resource/William_Wallace'), RDFS.label, Literal('William Wallace')))

    item1 = Item(iri='http://dbpedia.org/resource/Scotland')
    item1.save()
    item2 = Item(iri='http://dbpedia.org/resource/Alba')
    item2.save()

    assert item1.get_distance(item2) == 0.0
    assert item2.get_distance(item1) == 0.0