Esempio n. 1
0
def test_lattice(datafiles):
    for lattice in datafiles.listdir():
        lattice_dict = cex_to_list(lattice)

        Objects = bitset('Objects', lattice_dict['context']['objects'])
        Attributes = bitset(
            'Attributes', lattice_dict['context']['attributes'])

        print(Objects.supremum.members())
        print(Attributes.supremum.members())

        context = Context(
            lattice_dict['context']['table'],
            Objects,
            Attributes)

        expected_concepts = []

        for intent in lattice_dict['concepts']:
            intent = Attributes.frombools(intent)
            extent = context.down(intent)
            expected_concepts.append(Concept(extent, intent))

        result = Lattice(context)

        assert len(expected_concepts) == len(result.get_concepts())
        assert set(expected_concepts) == set(result.get_concepts())
Esempio n. 2
0
def test_cohesion_min(similarity_function):
    bools = ((0, 1), (1, 1))
    Objects = bitset('Objects', ('a', 'b'))
    Attributes = bitset('Attributes', ('1', '2'))

    context = Context(bools, Objects, Attributes)

    concept = Concept(Objects(['a', 'b']), Attributes(['2']))

    rows = context.filter_rows_by_extent(concept.extent)

    expected_coh = similarity_function(rows[0], rows[1])

    assert cohesion_min(concept, context, similarity_function) == expected_coh
Esempio n. 3
0
def test_cohesion_avg_2(similarity_function):
    bools = ((0, 1), (1, 1), (0, 1))
    Objects = bitset('Objects', ('a', 'b', 'c'))
    Attributes = bitset('Attributes', ('1', '2'))

    context = Context(bools, Objects, Attributes)

    concept = Concept(Objects(['a', 'b', 'c']), Attributes(['2']))

    rows = context.filter_rows_by_extent(concept.extent)

    suma = similarity_function(rows[0], rows[1]) + \
        similarity_function(rows[1], rows[2]) + \
        similarity_function(rows[0], rows[2])

    expected_coh = suma / (len(concept.extent) * (len(concept.extent) - 1) / 2)

    assert cohesion_avg(concept, context, similarity_function) == expected_coh
Esempio n. 4
0
def test_lattice_creation():
    bools = ((0, 1), (1, 1))
    Objects = bitset('Objects', ('a', 'b'))
    Attributes = bitset('Attributes', ('1', '2'))

    context = Context(bools, Objects, Attributes)

    lattice = Lattice(context)

    assert len(lattice.get_concepts()) == 2
Esempio n. 5
0
def context_from_dataframe(df):
    Objects = bitset('Objects', tuple(df.index))
    Attributes = bitset('Attributes', tuple(df.columns))

    return Context(matrix=df.values, Objects=Objects, Attributes=Attributes)