예제 #1
0
def test_list_suggestions_vector_enforce_score_range(subject_index):
    suggestions = ListSuggestionResult([
        SubjectSuggestion(uri='http://www.yso.fi/onto/yso/p7141',
                          label='sinetit',
                          notation=None,
                          score=1.5),
        SubjectSuggestion(uri='http://www.yso.fi/onto/yso/p6479',
                          label='viikingit',
                          notation=None,
                          score=1.0),
        SubjectSuggestion(uri='http://www.yso.fi/onto/yso/p14173',
                          label='kaivaukset',
                          notation=None,
                          score=0.5),
        SubjectSuggestion(uri='http://www.yso.fi/onto/yso/p14588',
                          label='riimukivet',
                          notation=None,
                          score=0.0),
        SubjectSuggestion(uri='http://www.yso.fi/onto/yso/p12738',
                          label='viikinkiaika',
                          notation=None,
                          score=-0.5)
    ])
    vector = suggestions.as_vector(subject_index)
    assert vector.sum() == 2.5
    for subject_id, score in enumerate(vector):
        if subject_index[subject_id][1] == 'sinetit':
            assert score == 1.0
        elif subject_index[subject_id][1] == 'viikinkiaika':
            assert score == 0.0
        else:
            assert score in (1.0, 0.5, 0.0)
예제 #2
0
def test_list_suggestion_result_vector_notfound(subject_index):
    suggestions = ListSuggestionResult([
        SubjectSuggestion(uri='http://example.com/notfound',
                          label='not found',
                          notation=None,
                          score=1.0)
    ])
    assert suggestions.as_vector(subject_index).sum() == 0
예제 #3
0
def test_list_suggestion_result_vector_destination(subject_index):
    suggestions = ListSuggestionResult([
        SubjectSuggestion(uri='http://www.yso.fi/onto/yso/p7141',
                          label='sinetit',
                          notation=None,
                          score=1.0),
        SubjectSuggestion(uri='http://www.yso.fi/onto/yso/p6479',
                          label='viikingit',
                          notation=None,
                          score=0.5)
    ])
    destination = np.zeros(len(subject_index), dtype=np.float32)
    vector = suggestions.as_vector(subject_index, destination=destination)
    assert vector is destination
예제 #4
0
def test_list_suggestion_result_vector(subject_index):
    suggestions = ListSuggestionResult([
        SubjectSuggestion(uri='http://www.yso.fi/onto/yso/p7141',
                          label='sinetit',
                          notation=None,
                          score=1.0),
        SubjectSuggestion(uri='http://www.yso.fi/onto/yso/p6479',
                          label='viikingit',
                          notation=None,
                          score=0.5)
    ])
    vector = suggestions.as_vector(subject_index)
    assert isinstance(vector, np.ndarray)
    assert len(vector) == len(subject_index)
    assert vector.sum() == 1.5
    for subject_id, score in enumerate(vector):
        if subject_index[subject_id][1] == 'sinetit':
            assert score == 1.0
        elif subject_index[subject_id][1] == 'viikingit':
            assert score == 0.5
        else:
            assert score == 0.0