Beispiel #1
0
 def OnImport(self, event):
     """Import scale, context or mvcontext to current project"""
     choices = files_categories.values()
     dialog = wx.SingleChoiceDialog(
         self, "Choose a category of the file you trying to import", "Choose a category", choices
     )
     if dialog.ShowModal() == wx.ID_OK:
         category = dialog.GetStringSelection()
         wildcard = "*.cxt files (*.cxt)|*.cxt|" "Tab-separated files (*.txt)|*.txt|" "All files (*.*)|*.*"
         dlg = wx.FileDialog(self, "Choose a file to import.", ".", "", wildcard, wx.OPEN)
         if dlg.ShowModal() == wx.ID_OK:
             path = dlg.GetPath()
             ext = os.path.splitext(path)[1]
             if category == "Scales" and ext == ".cxt":
                 new_element = fca.Scale(fca.read_cxt(path))
                 self.current_project.add_element(new_element)
                 self.tree.add_new_element("scales", new_element)
             elif category == "Contexts":
                 if ext == ".cxt":
                     new_element = fca.read_cxt(path)
                 elif ext == ".txt":
                     new_element = fca.read_txt(path)
                 self.current_project.add_element(new_element)
                 self.tree.add_new_element("contexts", new_element)
             elif category == "Many-valued contexts":
                 new_element = fca.read_mv_txt(path)
                 self.current_project.add_element(new_element)
                 self.tree.add_new_element("mvcontexts", new_element)
             elif category == "Concept Systems":
                 new_element = fca.read_xml(path)
                 self.current_project.add_element(new_element)
                 self.tree.add_new_element("concept_systems", new_element)
             else:
                 MsgDlg(self, "Not supported yet", "Error!", wx.OK)
             self.project_save()
Beispiel #2
0
def GetFilteredConcepts(item):
    dialog = FilteringDialog() 
    result = dialog.ShowModal()
    if result == wx.ID_OK:
        options = dialog.GetOptions()
        cs = uread_xml(item.path)
        
        precessor = item.precessor
        while not precessor.type == "Context":
            precessor = precessor.precessor
        (root, ext) = os.path.splitext(precessor.name)
        if ext == ".cxt":
            cxt = fca.read_cxt(precessor.path)
        elif ext == ".txt":
            cxt = fca.read_txt(precessor.path)
        cs.context = cxt
        new_cs = fca.filter_concepts(cs, options["function"], options["mode"], 
                options["opt"])
        
        default_path = item.path[:-4] + "-filtered.xml"
        newpath = default_path
        i = 1
        while (os.path.exists(newpath)):
            newpath = default_path[:-4] + "-{0}".format(i) + newpath[-4:]
            i += 1
        fca.write_xml(newpath, new_cs)
        newpath = [newpath]
    else:
        newpath = []
        
    dialog.Destroy()
    
    return newpath
Beispiel #3
0
def GetFilteredConcepts(item):
    dialog = FilteringDialog()
    result = dialog.ShowModal()
    if result == wx.ID_OK:
        options = dialog.GetOptions()
        cs = uread_xml(item.path)

        precessor = item.precessor
        while not precessor.type == "Context":
            precessor = precessor.precessor
        (root, ext) = os.path.splitext(precessor.name)
        if ext == ".cxt":
            cxt = fca.read_cxt(precessor.path)
        elif ext == ".txt":
            cxt = fca.read_txt(precessor.path)
        cs.context = cxt
        new_cs = fca.filter_concepts(cs, options["function"], options["mode"],
                                     options["opt"])

        default_path = item.path[:-4] + "-filtered.xml"
        newpath = default_path
        i = 1
        while (os.path.exists(newpath)):
            newpath = default_path[:-4] + "-{0}".format(i) + newpath[-4:]
            i += 1
        fca.write_xml(newpath, new_cs)
        newpath = [newpath]
    else:
        newpath = []

    dialog.Destroy()

    return newpath
Beispiel #4
0
    def OnLoadScaleButton(self, event):
        dlg = LoadScaleDialog(self._workspace, self.GetParent())
        dlg.CenterOnScreen()

        # this does not return until the dialog is closed.
        val = dlg.ShowModal()

        if val == wx.ID_OK:
            item = dlg.GetScale()
            if item and not item.dir:
                context = fca.read_cxt(item.path)
                scale = fca.Scale(context)
                scale.name = item.name
                self._scales.append(scale)
                self.scales_names.append(item.name)
                self.ScalesLb.Set(self.scales_names)
                self.ScalesLb.Select(0)
                self.selected_scale = self.ScalesLb.GetString(0)

        dlg.Destroy()
Beispiel #5
0
    def ComputeIndex(self, item, workspace):
        cs = uread_xml(item.path)
        functions = filtering.get_compute_functions()

        dlg = wx.SingleChoiceDialog(None, 'Choose index you want to compute',
                                    'Choose index', functions.keys(),
                                    wx.CHOICEDLG_STYLE)

        if dlg.ShowModal() == wx.ID_OK:
            name = dlg.GetStringSelection()

            precessor = item.precessor
            while not precessor.type == "Context":
                precessor = precessor.precessor
            cs.context = fca.read_cxt(precessor.path)

            fca.compute_index(cs, functions[name], name)
            fca.write_xml(item.path, cs)

        dlg.Destroy()
Beispiel #6
0
    def OnLoadScaleButton(self, event):
        dlg = LoadScaleDialog(self._workspace, self.GetParent())
        dlg.CenterOnScreen()

        # this does not return until the dialog is closed.
        val = dlg.ShowModal()
    
        if val == wx.ID_OK:
            item = dlg.GetScale()
            if item and not item.dir:
                context = fca.read_cxt(item.path)
                scale = fca.Scale(context)
                scale.name = item.name
                self._scales.append(scale)
                self.scales_names.append(item.name)
                self.ScalesLb.Set(self.scales_names)
                self.ScalesLb.Select(0)
                self.selected_scale = self.ScalesLb.GetString(0)

        dlg.Destroy()
Beispiel #7
0
    def ComputeIndex(self, item, workspace):
        cs = uread_xml(item.path)
        functions = filtering.get_compute_functions()
        
        dlg = wx.SingleChoiceDialog(
                None, 'Choose index you want to compute', 'Choose index',
                functions.keys(), 
                wx.CHOICEDLG_STYLE
                )

        if dlg.ShowModal() == wx.ID_OK:
            name = dlg.GetStringSelection()
            
            precessor = item.precessor
            while not precessor.type == "Context":
                precessor = precessor.precessor
            cs.context = fca.read_cxt(precessor.path)
            
            fca.compute_index(cs, functions[name], name)
            fca.write_xml(item.path, cs)
                               
        dlg.Destroy()
Beispiel #8
0
        if i.premise <= p[1]:   # p[1] is no longer preclosed
            break
    else:                       # p[1] becomes psuedo-closed
        impl = fca.Implication(p[1].copy(), p[1].copy())
        impl.get_conclusion().add(m)
        min_mod_impl.append(impl)
        new_preclosed.append((p[0], impl.premise, impl))
    p[1].add(m)
    mod_concepts.append(p)
    
def is_concept(p):
    return len(p) == 2


if __name__ == '__main__':
    import time
    import sys
    
    def timeit(algo, cxt):
        start = time.time()
        basis = algo(cxt)
        end = time.time()
        print(len(basis), end - start)
        return basis, end - start

    cxt = fca.read_cxt(sys.argv[1])
    print('Ganter:')
    timeit(fca.compute_dg_basis, cxt)
    print('Incremental:')
    timeit(compute_canonical_basis, cxt)
Beispiel #9
0
 def setUp(self):
     abspath = os.path.dirname(__file__)
     small_cxt_path = os.path.join(abspath, 'small_cxt.cxt')
     self.small_cxt = fca.read_cxt(small_cxt_path)
Beispiel #10
0
    except:
        pass
    output = open(os.path.join(path, "meud.project"), "wb")
    project_.projectdirty = False
    cPickle.dump(project_, output)
    output.close()
   
def load_project(path):
    """Load project from directory in path
    
    Return project instance.
    """
    input = open(os.path.join(path, "meud.project"), "rb")
    project_ = cPickle.load(input)
    input.close()
    os.chdir(path)
    return project_


if __name__ == '__main__':
    """Test"""
    test_path = "tests/project/default"
    p = Project()
    c = fca.read_cxt("tests/imports/context.cxt")
    p.add_element(c)
    cs = fca.norris(c)
    p.add_element(cs)
    p.add_element(fca.Scale(fca.read_cxt("tests/imports/context.cxt")))
    save_project(p, test_path)
    p1 = load_project("tests/project/default/")
    
Beispiel #11
0
            break
    else:  # p[1] becomes psuedo-closed
        impl = fca.Implication(p[1].copy(), p[1].copy())
        impl.get_conclusion().add(m)
        min_mod_impl.append(impl)
        new_preclosed.append((p[0], impl.premise, impl))
    p[1].add(m)
    mod_concepts.append(p)


def is_concept(p):
    return len(p) == 2


if __name__ == '__main__':
    import time
    import sys

    def timeit(algo, cxt):
        start = time.time()
        basis = algo(cxt)
        end = time.time()
        print(len(basis), end - start)
        return basis, end - start

    cxt = fca.read_cxt(sys.argv[1])
    print('Ganter:')
    timeit(fca.compute_dg_basis, cxt)
    print('Incremental:')
    timeit(compute_canonical_basis, cxt)
Beispiel #12
0
 def setUp(self):
     abspath = os.path.dirname(__file__)
     small_cxt_path = os.path.join(abspath, 'small_cxt.cxt')
     self.small_cxt = fca.read_cxt(small_cxt_path)
Beispiel #13
0
def none_finder(*args):
    return None

path_to_cxt = 'my_cxt.cxt'
dest = '../ae_2valdomain_nocs/'
f_2_1_1 = df.DiscreteFunction.read_from_str('f_2_1_1')
f_2_1_2 = df.DiscreteFunction.read_from_str('f_2_1_2')
f_2_2_14 = df.DiscreteFunction.read_from_str('f_2_2_14')
f_2_3_150 = df.DiscreteFunction.read_from_str('f_2_3_150')
f_2_3_232 = df.DiscreteFunction.read_from_str('f_2_3_232')
funcs = [f_2_1_2]#, f_2_1_2, f_2_3_232]#, f_2_3_150]#, f_2_3_232]#, f13]
#table = [map(lambda x: df.commute(f, x) == True, funcs) for f in funcs]
#cxt = fca.Context(table, map(str, funcs), map(str, funcs))

if __name__ == '__main__':
    nonsc_cxt = fca.read_cxt('./not_self_commuting.cxt')
    full_cxt = fca.read_cxt('./my_cxt.cxt')
    full_funcs = map(df.DiscreteFunction.read_from_str, full_cxt.objects)
    noncom_funcs = map(df.DiscreteFunction.read_from_str, nonsc_cxt.objects)
    '''
    for obj in reversed(nonsc_cxt.objects):
        obj_intent = full_cxt.get_object_intent(obj)
        print '\n\nNonsc function ', obj
        print 'Commutes with: ', map(str, obj_intent)
        print 'length ', len(obj_intent)
        f_init = df.DiscreteFunction(range(3), {}, 3)
        premise = map(df.DiscreteFunction.read_from_str, obj_intent)
        conc = map(df.DiscreteFunction.read_from_str, set(full_cxt.objects) - set(obj_intent))
        print set(premise) & set(conc)
        print len(set(premise) | set(conc))
        try: