def LoadRulesForProcessing(project_name,before_syntactic = False):
    rules = []
    projectpath = "Projects/"+project_name
    variable_names = FileManipulationHelper.loadVariables(project_name)
    for variable_name in variable_names:
        rules_names =  FileManipulationHelper.loadRules(project_name,variable_name)
        for rule_name in rules_names:
            rule_datapath = projectpath+'/'+rule_name
            black_list = FileManipulationHelper.loadBlackList(project_name, rule_name,variable_name)
            white_list = FileManipulationHelper.loadWhiteList(project_name, rule_name,variable_name)
            cfg = FileManipulationHelper.loadRuleConfig(project_name, rule_name,variable_name)
            rule = RuleClasses_Rule.Rule()
            rule.WhiteList = []
            rule.BlackList = []
            rule.PatternList = []
            rule.PossibleUnits = []
            rule.RuleName = rule_name
            afterWordList= False
            for w in white_list:
                w = w.replace('\n','')
                splitted = w.split(':')
                if splitted[0]=='Type':
                    if splitted[1]=='WhiteList':
                        continue
                if splitted[0]=='Header':
                    if int(splitted[1]) ==1:
                        rule.wl_look_header=True
                    else:
                        rule.wl_look_header=False
                if splitted[0]=='Stub':
                    if int(splitted[1]) ==1:
                        rule.wl_look_stub=True
                    else:
                        rule.wl_look_stub=False
                if splitted[0]=='Super-row':
                    if int(splitted[1]) ==1:
                        rule.wl_look_superrow=True
                    else:
                        rule.wl_look_superrow=False
                if splitted[0]=='Data':
                    if int(splitted[1]) ==1:
                        rule.wl_look_data=True
                    else:
                        rule.wl_look_data=False
                if splitted[0]=='All':
                    if int(splitted[1]) ==1:
                        rule.wl_look_anywhere=True
                    else:
                        rule.wl_look_anywhere=False
                if w == "WordList:":
                    afterWordList = True
                    continue
                if afterWordList == True:
                    rule.WhiteList.append(w)
            afterWordList= False
            for w in black_list:
                w = w.replace('\n','')
                splitted = w.split(':')
                if splitted[0]=='Type':
                    if splitted[1]=='BlackList':
                        continue
                if splitted[0]=='Header':
                    if int(splitted[1]) ==1:
                        rule.bl_look_header=True
                    else:
                        rule.bl_look_header=False
                if splitted[0]=='Stub':
                    if int(splitted[1]) ==1:
                        rule.bl_look_stub=True
                    else:
                        rule.bl_look_stub=False
                if splitted[0]=='Super-row':
                    if int(splitted[1]) ==1:
                        rule.bl_look_superrow=True
                    else:
                        rule.bl_look_superrow=False
                if splitted[0]=='Data':
                    if int(splitted[1]) ==1:
                        rule.bl_look_data=True
                    else:
                        rule.bl_look_data=False
                if splitted[0]=='All':
                    if int(splitted[1]) ==1:
                        rule.bl_look_anywhere=True
                    else:
                        rule.bl_look_anywhere=False
                if w == "WordList:":
                    afterWordList = True
                    continue
                if afterWordList == True:
                    rule.BlackList.append(w)
            rule.RuleType = cfg['RuleType'].replace('\n','')
            if(rule.RuleType == "Numeric" or rule.RuleType == "Categorical"):
                rule.DefaultUnit = cfg['DefUnit']
            if(rule.RuleType == "Numeric"  or rule.RuleType == "Categorical"):
                rule.PossibleUnits = cfg['PosUnit'].split(',')
            rule.PragmaticClass = cfg['PragClass']
            rule.ClassName = cfg['Class']
        
            if(cfg["RuleCreationMech"]=="Semantic"):
                rule.is_semantic = True
            if('Categories' in cfg.keys()):
                rule.PossibleCategories = cfg['Categories'].split(',')
            if(before_syntactic==False):
                patterns = []
                patterns = LoadSyntacticRoles(project_name,rule_name,variable_name)
                rule.PatternList = patterns
            if('DataInHeader' in cfg.keys() and cfg['DataInHeader']!=None and cfg['DataInHeader']=='1'):
                rule.data_in_header = True
            else:
                rule.data_in_header = False
            if('DataInStub' in cfg.keys() and cfg['DataInStub']!=None and cfg['DataInStub']=='1'):
                rule.data_in_stub = True
            else:
                rule.data_in_stub = False
            if('DataInSuperRow' in cfg.keys() and cfg['DataInSuperRow']!=None and cfg['DataInSuperRow']=='1'):
                rule.data_in_super = True
            else:
                rule.data_in_super = False
            if('DataInData' in cfg.keys() and cfg['DataInData']!=None and cfg['DataInData']=='1'):
                rule.data_in_data = True
            else:
                rule.data_in_data = False
            rules.append(rule)

    return rules
        
def WhiteListWindowEdit(project_name,rule_name,variable):
    typeVar =Tix.StringVar() 
    WhiteListWindow =Tix.Toplevel()
    WhiteListWindow.title("Edit White Cue List")
    WhiteListWindow.geometry('{}x{}'.format(550, 550))
    itemsFrame = Tix.Frame(WhiteListWindow)
    itemsFrame.pack(side=Tix.LEFT)
    choiseFrame = Tix.Frame(WhiteListWindow,width=130)
    choiseFrame.pack(side=Tix.RIGHT)
    wl_where_to_look = Tix.Label(choiseFrame,text="Where to look in whitelist?").grid(row=2,column=0,sticky='w')
    wl_look_head = Tix.IntVar()
    wl_HeaderCB = Tix.Checkbutton(choiseFrame,text="Header",variable = wl_look_head).grid(row=3,column=0,sticky='w')
    wl_look_stub = Tix.IntVar()
    wl_StubCB = Tix.Checkbutton(choiseFrame,text="Stub",variable = wl_look_stub).grid(row=4,column=0,sticky='w')
    wl_look_super = Tix.IntVar()
    wl_SuperRowCB = Tix.Checkbutton(choiseFrame,text="Super-row",variable = wl_look_super).grid(row=5,column=0,sticky='w')
    wl_look_data = Tix.IntVar()
    wl_DataCB = Tix.Checkbutton(choiseFrame,text="Data",variable = wl_look_data).grid(row=6,column=0,sticky='w')
    
    
    bl_where_to_look = Tix.Label(choiseFrame,text="Where to look in blacklist?").grid(row=7,column=0,sticky='w')
    bl_look_head = Tix.IntVar()
    bl_HeaderCB = Tix.Checkbutton(choiseFrame,text="Header",variable = bl_look_head).grid(row=8,column=0,sticky='w')
    bl_look_stub = Tix.IntVar()
    bl_StubCB = Tix.Checkbutton(choiseFrame,text="Stub",variable = bl_look_stub).grid(row=9,column=0,sticky='w')
    bl_look_super = Tix.IntVar()
    bl_SuperRowCB = Tix.Checkbutton(choiseFrame,text="Super-row",variable = bl_look_super).grid(row=10,column=0,sticky='w')
    bl_look_data = Tix.IntVar()
    bl_DataCB = Tix.Checkbutton(choiseFrame,text="Data",variable = bl_look_data).grid(row=11,column=0,sticky='w')
    #look_all = Tix.IntVar()
    #EverywhereCB = Tix.Checkbutton(choiseFrame,text="Everywhere",variable=look_all).grid(row=7,column=0,sticky='w')
    
    namerule_label2 = Tix.Label(itemsFrame,text="To look for annotations ids (such as CUI from UMLS)\nwrite [annID]: (eg. '[annID]:C1696465'). To look\nfor annotation types (such as Semantic Type\nin UMLS) write [annType]: in front of cue (e.g.\n'[annType]:Biomedical or Dental Materia' or\n'[annType]:(bodm)'). To write just lexical cue,\njust write word, without prefixes, or [word]:\n(e.g. 'age' or '[word]:age')", justify=Tix.LEFT).grid(row=0,sticky='w')
    
    namerule_label = Tix.Label(itemsFrame,text="List of terms in whitelsit").grid(row=1,sticky='w')
    WhiteListText = Tix.Text(itemsFrame,height=10,width=50)
    WhiteListText.grid(row=2,sticky='w')
    whitelist = FileManipulationHelper.loadWhiteList(project_name, rule_name,variable)
    
    namerule_label2 = Tix.Label(itemsFrame,text="List of terms in blacklsit").grid(row=3,sticky='w')
    BlackListText = Tix.Text(itemsFrame,height=10,width=50)
    BlackListText.grid(row=4,sticky='w')
    blacklist = FileManipulationHelper.loadBlackList(project_name, rule_name,variable)
    i = 1
    afterWordList = False
    for w in whitelist:
        w = w.replace('\n','')
        splitted = w.split(':')
        #if splitted[0]=='Type':
        #    if splitted[1]=='WhiteList':
        #        typeVar.set(type[0])
        #    else:
        #        typeVar.set(type[1])
        if splitted[0]=='Header':
            wl_look_head.set(int(splitted[1]))
        if splitted[0]=='Stub':
            wl_look_stub.set(int(splitted[1]))
        if splitted[0]=='Super-row':
            wl_look_super.set(int(splitted[1]))
        if splitted[0]=='Data':
            wl_look_data.set(int(splitted[1]))
        #if splitted[0]=='All':
        #    look_all.set(int(splitted[1]))
        if w == "WordList:":
            afterWordList = True
            continue
        
        if afterWordList == True:
            WhiteListText.insert(str(i)+'.0',w+'\n')
            i=i+1
            
    afterWordList = False
    for w in blacklist:
        w = w.replace('\n','')
        splitted = w.split(':')
        #if splitted[0]=='Type':
        #    if splitted[1]=='WhiteList':
        #        typeVar.set(type[0])
        #    else:
        #        typeVar.set(type[1])
        if splitted[0]=='Header':
            bl_look_head.set(int(splitted[1]))
        if splitted[0]=='Stub':
            bl_look_stub.set(int(splitted[1]))
        if splitted[0]=='Super-row':
            bl_look_super.set(int(splitted[1]))
        if splitted[0]=='Data':
            bl_look_data.set(int(splitted[1]))
        #if splitted[0]=='All':
        #    look_all.set(int(splitted[1]))
        if w == "WordList:":
            afterWordList = True
            continue
        
        if afterWordList == True:
            BlackListText.insert(str(i)+'.0',w+'\n')
            i=i+1
    ClsVar = Tix.StringVar()
    ClsVar.set(variable)
    saveButton = Tix.Button(itemsFrame,text="Save",fg="black",command=lambda:SaveWhiteListEdit(WhiteListText.get("1.0",Tix.END),BlackListText.get("1.0",Tix.END),typeVar,wl_look_head,wl_look_stub,wl_look_super,wl_look_data,bl_look_head,bl_look_stub,bl_look_super,bl_look_data,WhiteListWindow,project_name,rule_name,ClsVar)).grid(row=12,column=0,sticky='w')
def SemanticListWindowEdit(project_name,rule_name,variable_name):#
    WhiteListWindow =Tix.Toplevel()
    WhiteListWindow.title("Edit Cue List")
    WhiteListWindow.geometry('{}x{}'.format(550, 400))
    itemsFrame = Tix.Frame(WhiteListWindow)
    itemsFrame.pack(side=Tix.LEFT)
    choiseFrame = Tix.Frame(WhiteListWindow,width=130)
    choiseFrame.pack(side=Tix.RIGHT)
    #type = ['WhiteList','BlackList']
    typeVar = Tix.StringVar()
    #typeVar.set(type[0])
    #TypeLabel = Label(choiseFrame,text="ListType").grid(row=0,column=0,sticky='w')
    #drop = OptionMenu(choiseFrame,typeVar,*type)
    #drop.grid(row=1,column=0,sticky='w')
    where_to_look = Tix.Label(choiseFrame,text="Where to look for white list variables?").grid(row=2,column=0,sticky='w')
    wl_look_head = Tix.IntVar()
    WLHeaderCB = Tix.Checkbutton(choiseFrame,text="Header",variable = wl_look_head).grid(row=3,column=0,sticky='w')
    wl_look_stub = Tix.IntVar()
    WLStubCB = Tix.Checkbutton(choiseFrame,text="Stub",variable = wl_look_stub).grid(row=4,column=0,sticky='w')
    wl_look_super = Tix.IntVar()
    WLSuperRowCB = Tix.Checkbutton(choiseFrame,text="Super-row",variable = wl_look_super).grid(row=5,column=0,sticky='w')
    wl_look_data = Tix.IntVar()
    WLDataCB = Tix.Checkbutton(choiseFrame,text="Data",variable = wl_look_data).grid(row=6,column=0,sticky='w')
    
    where_to_look2 = Tix.Label(choiseFrame,text="Where to look for black list variables?").grid(row=7,column=0,sticky='w')
    bl_look_head = Tix.IntVar()
    BLHeaderCB = Tix.Checkbutton(choiseFrame,text="Header",variable = bl_look_head).grid(row=8,column=0,sticky='w')
    bl_look_stub = Tix.IntVar()
    BLStubCB = Tix.Checkbutton(choiseFrame,text="Stub",variable = bl_look_stub).grid(row=9,column=0,sticky='w')
    bl_look_super = Tix.IntVar()
    BLSuperRowCB = Tix.Checkbutton(choiseFrame,text="Super-row",variable = bl_look_super).grid(row=10,column=0,sticky='w')
    bl_look_data = Tix.IntVar()
    BLDataCB = Tix.Checkbutton(choiseFrame,text="Data",variable = bl_look_data).grid(row=11,column=0,sticky='w')
    
    namerule_label = Tix.Label(itemsFrame,text="List of terms in whitelsit").grid(row=0,sticky='w')
    whitelist = Tix.CheckList(itemsFrame,width=350)
    whitelist.grid(row=1,sticky='w')
    createSemanticWhiteList(whitelist)
    whitelist.autosetmode()
    namerule_label2 = Tix.Label(itemsFrame,text="List of terms in blacklist").grid(row=2,sticky='w')
    blacklist = Tix.Text(itemsFrame,height=5,width=50)
    blacklist.grid(row=3,sticky='w')
    
    
    whitelist_list = FileManipulationHelper.loadWhiteList(project_name, rule_name,variable_name)
    blacklist_list = FileManipulationHelper.loadBlackList(project_name, rule_name,variable_name)
    
    
    i = 1
    afterWordList = False
    for w in whitelist_list:
        w = w.replace('\n','')
        splitted = w.split(':')
        #if splitted[0]=='Type':
        #    if splitted[1]=='WhiteList':
        #        typeVar.set(type[0])
        #    else:
        #        typeVar.set(type[1])
        if splitted[0]=='Header':
            wl_look_head.set(int(splitted[1]))
        if splitted[0]=='Stub':
            wl_look_stub.set(int(splitted[1]))
        if splitted[0]=='Super-row':
            wl_look_super.set(int(splitted[1]))
        if splitted[0]=='Data':
            wl_look_data.set(int(splitted[1]))
        #if splitted[0]=='All':
        #    look_all.set(int(splitted[1]))
        if w == "SemanticTypes:":
            afterWordList = True
            continue
        
        if afterWordList == True:
            cur = 0
            for item in semanticTypes:
                if(w == item.split('.')[-1]):
                    whitelist.setstatus(item,"on")
                cur = cur + 1
            i=i+1
                    
        
    afterWordList = False
    for w in blacklist_list:
        w = w.replace('\n','')
        splitted = w.split(':')
        #if splitted[0]=='Type':
        #    if splitted[1]=='WhiteList':
        #        typeVar.set(type[0])
        #    else:
        #        typeVar.set(type[1])
        if splitted[0]=='Header':
            bl_look_head.set(int(splitted[1]))
        if splitted[0]=='Stub':
            bl_look_stub.set(int(splitted[1]))
        if splitted[0]=='Super-row':
            bl_look_super.set(int(splitted[1]))
        if splitted[0]=='Data':
            bl_look_data.set(int(splitted[1]))
        #if splitted[0]=='All':
        #    look_all.set(int(splitted[1]))
        if w == "WordList:":
            afterWordList = True
            continue
        
        if afterWordList == True:
            blacklist.insert(str(i)+'.0',w+'\n')
            i=i+1
    
    saveButton = Tix.Button(itemsFrame,text="Save",fg="black",command=lambda:SaveWhiteListSemanticEdit(whitelist,blacklist.get("1.0",Tix.END),typeVar,wl_look_head,wl_look_stub,wl_look_super,wl_look_data,bl_look_head,bl_look_stub,bl_look_super,bl_look_data,WhiteListWindow,project_name,rule_name)).grid(row=4,sticky='w')

    pass    
Пример #4
0
def WhiteListWindowEdit(project_name, rule_name, variable):
    typeVar = Tix.StringVar()
    WhiteListWindow = Tix.Toplevel()
    WhiteListWindow.title("Edit White Cue List")
    WhiteListWindow.geometry('{}x{}'.format(550, 550))
    itemsFrame = Tix.Frame(WhiteListWindow)
    itemsFrame.pack(side=Tix.LEFT)
    choiseFrame = Tix.Frame(WhiteListWindow, width=130)
    choiseFrame.pack(side=Tix.RIGHT)
    wl_where_to_look = Tix.Label(choiseFrame,
                                 text="Where to look in whitelist?").grid(
                                     row=2, column=0, sticky='w')
    wl_look_head = Tix.IntVar()
    wl_HeaderCB = Tix.Checkbutton(choiseFrame,
                                  text="Header",
                                  variable=wl_look_head).grid(row=3,
                                                              column=0,
                                                              sticky='w')
    wl_look_stub = Tix.IntVar()
    wl_StubCB = Tix.Checkbutton(choiseFrame,
                                text="Stub",
                                variable=wl_look_stub).grid(row=4,
                                                            column=0,
                                                            sticky='w')
    wl_look_super = Tix.IntVar()
    wl_SuperRowCB = Tix.Checkbutton(choiseFrame,
                                    text="Super-row",
                                    variable=wl_look_super).grid(row=5,
                                                                 column=0,
                                                                 sticky='w')
    wl_look_data = Tix.IntVar()
    wl_DataCB = Tix.Checkbutton(choiseFrame,
                                text="Data",
                                variable=wl_look_data).grid(row=6,
                                                            column=0,
                                                            sticky='w')

    bl_where_to_look = Tix.Label(choiseFrame,
                                 text="Where to look in blacklist?").grid(
                                     row=7, column=0, sticky='w')
    bl_look_head = Tix.IntVar()
    bl_HeaderCB = Tix.Checkbutton(choiseFrame,
                                  text="Header",
                                  variable=bl_look_head).grid(row=8,
                                                              column=0,
                                                              sticky='w')
    bl_look_stub = Tix.IntVar()
    bl_StubCB = Tix.Checkbutton(choiseFrame,
                                text="Stub",
                                variable=bl_look_stub).grid(row=9,
                                                            column=0,
                                                            sticky='w')
    bl_look_super = Tix.IntVar()
    bl_SuperRowCB = Tix.Checkbutton(choiseFrame,
                                    text="Super-row",
                                    variable=bl_look_super).grid(row=10,
                                                                 column=0,
                                                                 sticky='w')
    bl_look_data = Tix.IntVar()
    bl_DataCB = Tix.Checkbutton(choiseFrame,
                                text="Data",
                                variable=bl_look_data).grid(row=11,
                                                            column=0,
                                                            sticky='w')
    #look_all = Tix.IntVar()
    #EverywhereCB = Tix.Checkbutton(choiseFrame,text="Everywhere",variable=look_all).grid(row=7,column=0,sticky='w')

    namerule_label2 = Tix.Label(
        itemsFrame,
        text=
        "To look for annotations ids (such as CUI from UMLS)\nwrite [annID]: (eg. '[annID]:C1696465'). To look\nfor annotation types (such as Semantic Type\nin UMLS) write [annType]: in front of cue (e.g.\n'[annType]:Biomedical or Dental Materia' or\n'[annType]:(bodm)'). To write just lexical cue,\njust write word, without prefixes, or [word]:\n(e.g. 'age' or '[word]:age')",
        justify=Tix.LEFT).grid(row=0, sticky='w')

    namerule_label = Tix.Label(
        itemsFrame, text="List of terms in whitelsit").grid(row=1, sticky='w')
    WhiteListText = Tix.Text(itemsFrame, height=10, width=50)
    WhiteListText.grid(row=2, sticky='w')
    whitelist = FileManipulationHelper.loadWhiteList(project_name, rule_name,
                                                     variable)

    namerule_label2 = Tix.Label(
        itemsFrame, text="List of terms in blacklsit").grid(row=3, sticky='w')
    BlackListText = Tix.Text(itemsFrame, height=10, width=50)
    BlackListText.grid(row=4, sticky='w')
    blacklist = FileManipulationHelper.loadBlackList(project_name, rule_name,
                                                     variable)
    i = 1
    afterWordList = False
    for w in whitelist:
        w = w.replace('\n', '')
        splitted = w.split(':')
        #if splitted[0]=='Type':
        #    if splitted[1]=='WhiteList':
        #        typeVar.set(type[0])
        #    else:
        #        typeVar.set(type[1])
        if splitted[0] == 'Header':
            wl_look_head.set(int(splitted[1]))
        if splitted[0] == 'Stub':
            wl_look_stub.set(int(splitted[1]))
        if splitted[0] == 'Super-row':
            wl_look_super.set(int(splitted[1]))
        if splitted[0] == 'Data':
            wl_look_data.set(int(splitted[1]))
        #if splitted[0]=='All':
        #    look_all.set(int(splitted[1]))
        if w == "WordList:":
            afterWordList = True
            continue

        if afterWordList == True:
            WhiteListText.insert(str(i) + '.0', w + '\n')
            i = i + 1

    afterWordList = False
    for w in blacklist:
        w = w.replace('\n', '')
        splitted = w.split(':')
        #if splitted[0]=='Type':
        #    if splitted[1]=='WhiteList':
        #        typeVar.set(type[0])
        #    else:
        #        typeVar.set(type[1])
        if splitted[0] == 'Header':
            bl_look_head.set(int(splitted[1]))
        if splitted[0] == 'Stub':
            bl_look_stub.set(int(splitted[1]))
        if splitted[0] == 'Super-row':
            bl_look_super.set(int(splitted[1]))
        if splitted[0] == 'Data':
            bl_look_data.set(int(splitted[1]))
        #if splitted[0]=='All':
        #    look_all.set(int(splitted[1]))
        if w == "WordList:":
            afterWordList = True
            continue

        if afterWordList == True:
            BlackListText.insert(str(i) + '.0', w + '\n')
            i = i + 1
    ClsVar = Tix.StringVar()
    ClsVar.set(variable)
    saveButton = Tix.Button(
        itemsFrame,
        text="Save",
        fg="black",
        command=lambda: SaveWhiteListEdit(
            WhiteListText.get("1.0", Tix.END), BlackListText.get(
                "1.0", Tix.END), typeVar, wl_look_head, wl_look_stub,
            wl_look_super, wl_look_data, bl_look_head, bl_look_stub,
            bl_look_super, bl_look_data, WhiteListWindow, project_name,
            rule_name, ClsVar)).grid(row=12, column=0, sticky='w')
Пример #5
0
def SemanticListWindowEdit(project_name, rule_name, variable_name):  #
    WhiteListWindow = Tix.Toplevel()
    WhiteListWindow.title("Edit Cue List")
    WhiteListWindow.geometry('{}x{}'.format(550, 400))
    itemsFrame = Tix.Frame(WhiteListWindow)
    itemsFrame.pack(side=Tix.LEFT)
    choiseFrame = Tix.Frame(WhiteListWindow, width=130)
    choiseFrame.pack(side=Tix.RIGHT)
    #type = ['WhiteList','BlackList']
    typeVar = Tix.StringVar()
    #typeVar.set(type[0])
    #TypeLabel = Label(choiseFrame,text="ListType").grid(row=0,column=0,sticky='w')
    #drop = OptionMenu(choiseFrame,typeVar,*type)
    #drop.grid(row=1,column=0,sticky='w')
    where_to_look = Tix.Label(
        choiseFrame,
        text="Where to look for white list variables?").grid(row=2,
                                                             column=0,
                                                             sticky='w')
    wl_look_head = Tix.IntVar()
    WLHeaderCB = Tix.Checkbutton(choiseFrame,
                                 text="Header",
                                 variable=wl_look_head).grid(row=3,
                                                             column=0,
                                                             sticky='w')
    wl_look_stub = Tix.IntVar()
    WLStubCB = Tix.Checkbutton(choiseFrame, text="Stub",
                               variable=wl_look_stub).grid(row=4,
                                                           column=0,
                                                           sticky='w')
    wl_look_super = Tix.IntVar()
    WLSuperRowCB = Tix.Checkbutton(choiseFrame,
                                   text="Super-row",
                                   variable=wl_look_super).grid(row=5,
                                                                column=0,
                                                                sticky='w')
    wl_look_data = Tix.IntVar()
    WLDataCB = Tix.Checkbutton(choiseFrame, text="Data",
                               variable=wl_look_data).grid(row=6,
                                                           column=0,
                                                           sticky='w')

    where_to_look2 = Tix.Label(
        choiseFrame,
        text="Where to look for black list variables?").grid(row=7,
                                                             column=0,
                                                             sticky='w')
    bl_look_head = Tix.IntVar()
    BLHeaderCB = Tix.Checkbutton(choiseFrame,
                                 text="Header",
                                 variable=bl_look_head).grid(row=8,
                                                             column=0,
                                                             sticky='w')
    bl_look_stub = Tix.IntVar()
    BLStubCB = Tix.Checkbutton(choiseFrame, text="Stub",
                               variable=bl_look_stub).grid(row=9,
                                                           column=0,
                                                           sticky='w')
    bl_look_super = Tix.IntVar()
    BLSuperRowCB = Tix.Checkbutton(choiseFrame,
                                   text="Super-row",
                                   variable=bl_look_super).grid(row=10,
                                                                column=0,
                                                                sticky='w')
    bl_look_data = Tix.IntVar()
    BLDataCB = Tix.Checkbutton(choiseFrame, text="Data",
                               variable=bl_look_data).grid(row=11,
                                                           column=0,
                                                           sticky='w')

    namerule_label = Tix.Label(
        itemsFrame, text="List of terms in whitelsit").grid(row=0, sticky='w')
    whitelist = Tix.CheckList(itemsFrame, width=350)
    whitelist.grid(row=1, sticky='w')
    createSemanticWhiteList(whitelist)
    whitelist.autosetmode()
    namerule_label2 = Tix.Label(
        itemsFrame, text="List of terms in blacklist").grid(row=2, sticky='w')
    blacklist = Tix.Text(itemsFrame, height=5, width=50)
    blacklist.grid(row=3, sticky='w')

    whitelist_list = FileManipulationHelper.loadWhiteList(
        project_name, rule_name, variable_name)
    blacklist_list = FileManipulationHelper.loadBlackList(
        project_name, rule_name, variable_name)

    i = 1
    afterWordList = False
    for w in whitelist_list:
        w = w.replace('\n', '')
        splitted = w.split(':')
        #if splitted[0]=='Type':
        #    if splitted[1]=='WhiteList':
        #        typeVar.set(type[0])
        #    else:
        #        typeVar.set(type[1])
        if splitted[0] == 'Header':
            wl_look_head.set(int(splitted[1]))
        if splitted[0] == 'Stub':
            wl_look_stub.set(int(splitted[1]))
        if splitted[0] == 'Super-row':
            wl_look_super.set(int(splitted[1]))
        if splitted[0] == 'Data':
            wl_look_data.set(int(splitted[1]))
        #if splitted[0]=='All':
        #    look_all.set(int(splitted[1]))
        if w == "SemanticTypes:":
            afterWordList = True
            continue

        if afterWordList == True:
            cur = 0
            for item in semanticTypes:
                if (w == item.split('.')[-1]):
                    whitelist.setstatus(item, "on")
                cur = cur + 1
            i = i + 1

    afterWordList = False
    for w in blacklist_list:
        w = w.replace('\n', '')
        splitted = w.split(':')
        #if splitted[0]=='Type':
        #    if splitted[1]=='WhiteList':
        #        typeVar.set(type[0])
        #    else:
        #        typeVar.set(type[1])
        if splitted[0] == 'Header':
            bl_look_head.set(int(splitted[1]))
        if splitted[0] == 'Stub':
            bl_look_stub.set(int(splitted[1]))
        if splitted[0] == 'Super-row':
            bl_look_super.set(int(splitted[1]))
        if splitted[0] == 'Data':
            bl_look_data.set(int(splitted[1]))
        #if splitted[0]=='All':
        #    look_all.set(int(splitted[1]))
        if w == "WordList:":
            afterWordList = True
            continue

        if afterWordList == True:
            blacklist.insert(str(i) + '.0', w + '\n')
            i = i + 1

    saveButton = Tix.Button(
        itemsFrame,
        text="Save",
        fg="black",
        command=lambda: SaveWhiteListSemanticEdit(
            whitelist, blacklist.get("1.0", Tix.END), typeVar, wl_look_head,
            wl_look_stub, wl_look_super, wl_look_data, bl_look_head,
            bl_look_stub, bl_look_super, bl_look_data, WhiteListWindow,
            project_name, rule_name)).grid(row=4, sticky='w')

    pass
Пример #6
0
def LoadRulesForProcessing(project_name, before_syntactic=False):
    rules = []
    projectpath = "Projects/" + project_name
    variable_names = FileManipulationHelper.loadVariables(project_name)
    for variable_name in variable_names:
        rules_names = FileManipulationHelper.loadRules(project_name,
                                                       variable_name)
        for rule_name in rules_names:
            rule_datapath = projectpath + '/' + rule_name
            black_list = FileManipulationHelper.loadBlackList(
                project_name, rule_name, variable_name)
            white_list = FileManipulationHelper.loadWhiteList(
                project_name, rule_name, variable_name)
            cfg = FileManipulationHelper.loadRuleConfig(
                project_name, rule_name, variable_name)
            rule = RuleClasses_Rule.Rule()
            rule.WhiteList = []
            rule.BlackList = []
            rule.PatternList = []
            rule.PossibleUnits = []
            rule.RuleName = rule_name
            afterWordList = False
            for w in white_list:
                w = w.replace('\n', '')
                splitted = w.split(':')
                if splitted[0] == 'Type':
                    if splitted[1] == 'WhiteList':
                        continue
                if splitted[0] == 'Header':
                    if int(splitted[1]) == 1:
                        rule.wl_look_header = True
                    else:
                        rule.wl_look_header = False
                if splitted[0] == 'Stub':
                    if int(splitted[1]) == 1:
                        rule.wl_look_stub = True
                    else:
                        rule.wl_look_stub = False
                if splitted[0] == 'Super-row':
                    if int(splitted[1]) == 1:
                        rule.wl_look_superrow = True
                    else:
                        rule.wl_look_superrow = False
                if splitted[0] == 'Data':
                    if int(splitted[1]) == 1:
                        rule.wl_look_data = True
                    else:
                        rule.wl_look_data = False
                if splitted[0] == 'All':
                    if int(splitted[1]) == 1:
                        rule.wl_look_anywhere = True
                    else:
                        rule.wl_look_anywhere = False
                if w == "WordList:":
                    afterWordList = True
                    continue
                if afterWordList == True:
                    rule.WhiteList.append(w)
            afterWordList = False
            for w in black_list:
                w = w.replace('\n', '')
                splitted = w.split(':')
                if splitted[0] == 'Type':
                    if splitted[1] == 'BlackList':
                        continue
                if splitted[0] == 'Header':
                    if int(splitted[1]) == 1:
                        rule.bl_look_header = True
                    else:
                        rule.bl_look_header = False
                if splitted[0] == 'Stub':
                    if int(splitted[1]) == 1:
                        rule.bl_look_stub = True
                    else:
                        rule.bl_look_stub = False
                if splitted[0] == 'Super-row':
                    if int(splitted[1]) == 1:
                        rule.bl_look_superrow = True
                    else:
                        rule.bl_look_superrow = False
                if splitted[0] == 'Data':
                    if int(splitted[1]) == 1:
                        rule.bl_look_data = True
                    else:
                        rule.bl_look_data = False
                if splitted[0] == 'All':
                    if int(splitted[1]) == 1:
                        rule.bl_look_anywhere = True
                    else:
                        rule.bl_look_anywhere = False
                if w == "WordList:":
                    afterWordList = True
                    continue
                if afterWordList == True:
                    rule.BlackList.append(w)
            rule.RuleType = cfg['RuleType'].replace('\n', '')
            if (rule.RuleType == "Numeric" or rule.RuleType == "Categorical"):
                rule.DefaultUnit = cfg['DefUnit']
            if (rule.RuleType == "Numeric" or rule.RuleType == "Categorical"):
                rule.PossibleUnits = cfg['PosUnit'].split(',')
            rule.PragmaticClass = cfg['PragClass']
            rule.ClassName = cfg['Class']

            if (cfg["RuleCreationMech"] == "Semantic"):
                rule.is_semantic = True
            if ('Categories' in cfg.keys()):
                rule.PossibleCategories = cfg['Categories'].split(',')
            if (before_syntactic == False):
                patterns = []
                patterns = LoadSyntacticRoles(project_name, rule_name,
                                              variable_name)
                rule.PatternList = patterns
            if ('DataInHeader' in cfg.keys() and cfg['DataInHeader'] != None
                    and cfg['DataInHeader'] == '1'):
                rule.data_in_header = True
            else:
                rule.data_in_header = False
            if ('DataInStub' in cfg.keys() and cfg['DataInStub'] != None
                    and cfg['DataInStub'] == '1'):
                rule.data_in_stub = True
            else:
                rule.data_in_stub = False
            if ('DataInSuperRow' in cfg.keys()
                    and cfg['DataInSuperRow'] != None
                    and cfg['DataInSuperRow'] == '1'):
                rule.data_in_super = True
            else:
                rule.data_in_super = False
            if ('DataInData' in cfg.keys() and cfg['DataInData'] != None
                    and cfg['DataInData'] == '1'):
                rule.data_in_data = True
            else:
                rule.data_in_data = False
            rules.append(rule)

    return rules