示例#1
0
def test_inters_conflicting():
    a = concepts.Definition(('spam', 'eggs'), ('ni', ), [(True, ), (False, )])

    b = concepts.Definition(('ham', 'spam'), ('nini', 'ni'), [(True, True),
                                                              (False, False)])

    with pytest.raises(ValueError, match=r"\[\('spam', 'ni'\)\]"):
        a.intersection(b)
示例#2
0
def test_inters_compatible():
    a = concepts.Definition(('spam', 'eggs'), ('ni', ), [(True, ), (False, )])

    b = concepts.Definition(('ham', 'spam'), ('nini', 'ni'), [(True, True),
                                                              (False, True)])

    assert a.intersection(b) == concepts.Definition(['spam'], ['ni'],
                                                    [(True, )])
示例#3
0
def test_union_compatible():
    a = concepts.Definition(('spam', 'eggs'), ('ni', ), [(True, ), (False, )])

    b = concepts.Definition(('ham', 'spam'), ('nini', 'ni'), [(True, True),
                                                              (False, True)])

    assert a.union(b) == concepts.Definition(('spam', 'eggs', 'ham'),
                                             ('ni', 'nini'), [(True, False),
                                                              (False, False),
                                                              (True, True)])
示例#4
0
def test_inters_ignoring():
    a = concepts.Definition(('spam', 'eggs'), ('ni', ), [(True, ), (False, )])

    b = concepts.Definition(('ham', 'spam'), (
        'nini',
        'ni',
    ), [(True, True), (False, False)])

    assert a.intersection(b, ignore_conflicts=True) == \
        concepts.Definition(['spam'], ['ni'], [(False,)])
示例#5
0
def test_inters_augmented():
    a = concepts.Definition(('spam', 'eggs'), ('ni', ), [(True, ), (False, )])

    b = concepts.Definition(('ham', 'spam'), (
        'nini',
        'ni',
    ), [(True, True), (False, True)])

    a &= b

    assert a == concepts.Definition(['spam'], ['ni'], [(True, )])
示例#6
0
def test_union_ignoring():
    a = concepts.Definition(('spam', 'eggs'), ('ni', ), [(True, ), (False, )])

    b = concepts.Definition(('ham', 'spam'), ('nini', 'ni'), [(True, True),
                                                              (False, False)])

    assert a.union(b, ignore_conflicts=True) == \
        concepts.Definition(('spam', 'eggs', 'ham'),
                            ('ni', 'nini'),
                            [(True, False),
                             (False, False),
                             (True, True)])
示例#7
0
def test_union_augmented():
    a = concepts.Definition(('spam', 'eggs'), ('ni', ), [(True, ), (False, )])

    b = concepts.Definition(('ham', 'spam'), ('nini', 'ni'), [(True, True),
                                                              (False, True)])

    a |= b

    assert a == concepts.Definition(('spam', 'eggs', 'ham'),
                                    ('ni', 'nini'), [(True, False),
                                                     (False, False),
                                                     (True, True)])
示例#8
0
def dataMatrix(filepath):
    """Construction of the complete matrix"""

    dict_object = {}
    with open(filepath, "rt") as matrix_file:
        readertext = csv.reader(matrix_file, delimiter=',')
        header = readertext.__next__()
        #print("HEADER:")
        #print(header)
        list_column_header = header[1:]
        number_columns = len(list_column_header)
        #for currentColHeader in list_column_header:
            #print("  " + currentColHeader)
        #print("  => " + str(number_columns) + " columns")
        #print("")
        for current_row in readertext:
            #print("")
            #print(current_row)
            current_object = current_row[0]
            dict_object[current_object] = []
            for i in range(number_columns):
                if current_row[i+1] == '1':
                    #print("  " + list_column_header[i])
                    dict_object[current_object].append(list_column_header[i])

    definition = concepts.Definition()
    for (current_object, current_values) in dict_object.items():
        definition.add_object(current_object, current_values)
    context = concepts.Context(*definition)
    return context
示例#9
0
def graph_to_fca_context(graph, tokenize=True):
    '''
    Uses the given `graph` to generate an FCA context. 
    This feature is useful when you want to apply formal concept analysis
    to detect the possible semantic meaning of the the community structure of
    a bounded model checking problem instance.
    
    :param graph: the graph to use to produce the FCA context
    :param tokenize: split the semantic names into token (increases the chances
        of fca finding something interesting)
    '''
    d = concepts.Definition()
    
    for vertex in range(len(graph.vs)):
        repres = vertex_repr(graph, vertex)
        
        var_info   = repres.split(sep="*")
        var_name   = var_info[0]
        var_block  = var_info[-1]
        
        if tokenize:
            var_tokens = var_name.split(sep=".")
            d.add_object(str(vertex), var_tokens + [var_block] )
        else:
            d.add_object(str(vertex), [var_name, var_block] )
    
    return concepts.Context(*d)
示例#10
0
def line_diagram(graph, filename=LATTICE_FILENAME):
    import concepts
    diag = concepts.Definition()
    for node in sorted(graph.keys()):
        diag.add_object(node, graph[node])
    context = concepts.Context(*diag)
    context.lattice.graphviz().render(filename=os.path.basename(filename),
                                      directory=os.path.dirname(filename),
                                      cleanup=True)  # cleanup the dot file
    assert os.path.exists(filename + '.pdf')  # output is pdf
示例#11
0
文件: borne2.py 项目: mwery/Foclass
def dictToConcept(data_matrix):
    """ From dictionnary to concepts """

    definition = concepts.Definition()
    for (current_obj, current_values) in data_matrix.items():
        definition.add_object(current_obj, current_values)
    context = Context(*definition)
    lattice = context.lattice

    return context, lattice
示例#12
0
def definition():
    return concepts.Definition(('spam', 'eggs'), ('ni', ), [(True, ),
                                                            (False, )])
示例#13
0
def test_duplicate_property():
    with pytest.raises(ValueError, match=r'duplicate properties'):
        concepts.Definition((), ('spam', 'spam'), [])
示例#14
0
def test_duplicate_object():
    with pytest.raises(ValueError, match=r'duplicate objects'):
        concepts.Definition(('spam', 'spam'), (), [])
示例#15
0
def classbymutation(dict, list_mut, result_folder):
    list_class = list(dict.keys())
    mutations_row = []

    for mutation in list_mut:
        mutations_row.append((mutation, [0] * len(list_class)))
    col_width = 0
    d = concepts.Definition()
    for clas, value in dict.items():
        if col_width < len(clas): col_width = len(clas)

        d.add_object(clas, value[1])

        for val in value[1]:
            for elem in mutations_row:
                if elem[0] == val:
                    i = list_class.index(clas)
                    elem[1][i] = 1

    c = concepts.Context(*d)
    l = c.lattice
    graphe = l.graphviz()
    graphe = apply_styles(graphe, styles)
    graphe.render(filename=result_folder + "Treillis", cleanup=True)

    list_object = []
    list_attribute = []
    maxi = 0
    for extent, intent in c.lattice:
        if len(extent) > maxi: maxi = len(extent)
        list_object.append(extent)
        list_attribute.append(intent)
    list_attribute = overlap(list_object, list_attribute, maxi)

    rest_combination = []
    specifyFile = open(result_folder + "Class_Specific_Mutations.txt", "w")
    for i, elem in enumerate(list_object):
        if len(elem) == maxi:
            specifyFile.write(
                "All classes can be achieved by those mutations :\n")
            specifyFile.write("  /  ".join(list_attribute[i]) + "\n\n")
        elif len(list_attribute[i]) == 0:
            rest_combination.append(elem)
            pass
        else:
            specifyFile.write("Only " + str(elem) +
                              " can be achieved by those mutations :\n")
            specifyFile.write("  /  ".join(list_attribute[i]) + "\n\n")
    specifyFile.write(
        "Other combination of class don't have specific mutations :\n")
    for rest in rest_combination:
        specifyFile.write(str(rest) + " ")

    df = pd.DataFrame.from_items(mutations_row,
                                 orient='index',
                                 columns=list_class)
    df.sort_index(inplace=True)

    with open(result_folder + "result.tex", 'w') as latex_file:
        latex_file.write(r'''\documentclass[10pt,a4paper,landscape]{article}
            \usepackage[left=1.5cm, right=1.5cm, top=1.5cm, bottom=1.5cm]{geometry}
            \usepackage{array}
            \usepackage{booktabs}
            \usepackage{longtable}
            \begin{document}
            ''')
        p = 'p{4cm}|'
        #print(p) , col_space=10
        col_format = '|p{5cm}|' + 'c|' * len(list_class)
        latex_file.write(df.to_latex(column_format=col_format, longtable=True))
        latex_file.write('''
            \end{document}
            ''')
    os.system('pdflatex -output-directory={} result.tex > /dev/null'.format(
        result_folder))