Ejemplo n.º 1
0
def SaveWhiteListSemanticEdit(listWL, listBL, 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, vClsIn):
    global currentWhiteList
    global currentBlackList
    global semanticTypes
    selected = []
    for item in semanticTypes:
        if (listWL.getstatus(item) == "on"):
            selected.append(item.split(".")[-1])

    currentWhiteList = selected
    currentBlackList = []
    currentBlackList = listBL.split('\n')
    rule_path = "Projects/" + project_name + "/" + vClsIn.get(
    ) + "/" + rule_name
    FileManipulationHelper.CreateFoderIfNotExist(rule_path)
    semType = True
    FileManipulationHelper.SaveCueListSem(rule_path, rule_name,
                                          currentWhiteList, currentBlackList,
                                          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)
    #FileManipulationHelper.MakeRuleCFGFile(rule_path, look_head, look_stub, look_super, look_data, look_all,vClsIn,vDefUnit,vPosUnit,pragVar)
    WhiteListWindow.withdraw()
Ejemplo n.º 2
0
def SaveSintacticRules(rules, window, project_name, rule_name, variable_name):
    global lab2

    window.withdraw()
    #top = Toplevel()
    get_rules = FileManipulationHelper.loadRules(project_name, variable_name)
    rule_path = 'Projects/' + variable_name + '/' + project_name + '/' + rule_name
    FileManipulationHelper.SaveSyntacticRules(rules, project_name, rule_name,
                                              variable_name)
Ejemplo n.º 3
0
def FinishFirstScreen(variab, E2, Lb3, s):
    if (variab.get() == "NP"):
        project_name = E2.get()
    else:
        pos = Lb3.curselection()[0]
        project_name = Lb3.get(pos)
        #tkMessageBox.showinfo("Project selected", project_name)
    s.withdraw()
    FileManipulationHelper.CreateFoderIfNotExist("Projects/" + project_name)
    FileManipulationHelper.CreateProjectCfgFileIfNotExist("Projects/" +
                                                          project_name)
    LoadFirstCfGScreen(project_name)
Ejemplo n.º 4
0
def ClearDBTables(project_name):
    dbSettings = FileManipulationHelper.LoadDBConfigFile(project_name)
    query = QueryDBClass.QueryDBCalss(dbSettings['Host'], dbSettings['User'],
                                      dbSettings['Pass'],
                                      dbSettings['Database'])
    query.ClearCreatedTables()
    query.CreateAdditionalTables()
Ejemplo n.º 5
0
def MakeChangesToSyntacticRules(project_name, rule_name, variable_name):
    top = Toplevel()
    #top.protocol("WM_DELETE_WINDOW", on_closing)
    top.title("Modify selected rules")
    top.geometry('{}x{}'.format(400, 300))
    topframe = Frame(top, height=10)
    topframe.pack()
    frame = Frame(top)
    frame.pack()
    topframe2 = Frame(top, height=10)
    topframe2.pack()
    rules = StringVar()
    rulelist = Text(frame, height=15, width=40)
    rulelist.grid(row=1, sticky='w')
    fpaths = []
    rules = []
    path = 'Projects/' + project_name + '/' + variable_name + '/' + rule_name + '/' + 'SyntacticRules.sin'
    rules = FileManipulationHelper.LoadRules(path)

    i = 1
    for w in rules:
        rulelist.insert(str(i) + '.0', w)
        i = i + 1
    skip_val = IntVar()
    skip_val.set(0)
    saveButton = Button(
        frame,
        text="Next",
        bg="green",
        fg="black",
        command=lambda: SaveSintacticRules(rulelist.get(
            "1.0", END), top, project_name, rule_name, variable_name)).grid(
                row=2, sticky='w')
    pass
Ejemplo n.º 6
0
def SaveRuleEdit(project_name, rule_name, add, vClsIn, vDefUnit, vPosUnit,
                 pragVar, ruleType, ruleMech, wl_look_head, wl_look_stub,
                 wl_look_super, wl_look_data):
    global currentWhiteList
    global currentBlackList
    rule_path = "Projects/" + project_name + "/" + vClsIn.get().replace(
        '\n', '') + "/" + rule_name
    FileManipulationHelper.CreateFoderIfNotExist(rule_path)
    vRuleType = StringVar()
    vLexSemRule = StringVar()
    vRuleType.set(ruleType)
    vLexSemRule.set(ruleMech)
    FileManipulationHelper.MakeRuleCFGFile(rule_path, vClsIn, vDefUnit,
                                           vPosUnit, pragVar, vRuleType,
                                           vLexSemRule, wl_look_head,
                                           wl_look_stub, wl_look_super,
                                           wl_look_data)
    add.withdraw()
Ejemplo n.º 7
0
def AddEditVariable(project_name, vRuleName, vRuleType, RuleNameView,
                    RulesListBox):
    RuleNameView.withdraw()
    rule_path = "Projects/" + project_name + "/" + vRuleName.get().replace(
        '\n', '')
    FileManipulationHelper.CreateFoderIfNotExist(rule_path)
    f = open(rule_path + '/var_config.cfg', 'w')
    f.write("VariableName:" + str(vRuleName.get().replace('\n', '')) + '\n')
    f.write("VariableType:" + str(vRuleType.get().replace('\n', '')) + '\n')
    f.close()
    RulesListBox.insert('', 'end', vRuleName.get(), text=vRuleName.get())
Ejemplo n.º 8
0
def SaveRule(project_name, rule_name, add, vClsIn, vDefUnit, vPosUnit, pragVar,
             RulesListBox, vRuleType, vLexSemRule, wl_look_head, wl_look_stub,
             wl_look_super, wl_look_data):
    global currentWhiteList
    global currentBlackList
    rule_path = "Projects/" + project_name + "/" + vClsIn.get(
    ) + "/" + rule_name
    FileManipulationHelper.CreateFoderIfNotExist(rule_path)
    #FileManipulationHelper.SaveWhiteList(rule_path, currentWhiteList)
    #FileManipulationHelper.SaveBlackList(rule_path, currentBlackList)
    FileManipulationHelper.MakeRuleCFGFile(rule_path, vClsIn, vDefUnit,
                                           vPosUnit, pragVar, vRuleType,
                                           vLexSemRule, wl_look_head,
                                           wl_look_stub, wl_look_super,
                                           wl_look_data)
    RulesListBox.insert(vClsIn.get(), 'end', text=rule_name)
    add.withdraw()
    if (vLexSemRule.get() == "Lexical"):
        WhiteListWindow(project_name, rule_name, vClsIn)
    if (vLexSemRule.get() == "Semantic"):
        SemanticListWindow(project_name, rule_name, vClsIn)
Ejemplo n.º 9
0
def SaveDBSettings(HostName, PortName, UserName, PassName, DatabaseName,
                   DataConfig, project_name):

    hostname = HostName.get()
    portname = PortName.get()
    username = UserName.get()
    passname = PassName.get()
    database = DatabaseName.get()
    DataConfig.withdraw()
    FileManipulationHelper.SaveToConfigFile(project_name, hostname, portname,
                                            username, passname, database)
    pass
def SaveSintacticRules(rules, window,project_name,rule_name,variable_name):
    global lab2
    
    window.withdraw()
    #top = Toplevel()
    get_rules = FileManipulationHelper.loadRules(project_name,variable_name)
    rule_path = 'Projects/'+variable_name+'/'+project_name+'/'+rule_name
    FileManipulationHelper.SaveSyntacticRules(rules,project_name,rule_name,variable_name)
    #processing_rules = RuleClasses_LoadRulesForProcessingClass.LoadRulesForProcessing(project_name)
    #top.protocol("WM_DELETE_WINDOW", on_closing)

    
Ejemplo n.º 11
0
def LoadConfigScreen():
    s = Tix.Toplevel()
    s.protocol("WM_DELETE_WINDOW", on_closing)
    s.title("Table InfExtractor")
    s.geometry('{}x{}'.format(500, 500))
    topframe = Tix.Frame(s, height=10)
    topframe.pack()
    frame = Tix.Frame(s)
    frame.pack()
    newproject = Tix.Radiobutton(frame,
                                 text="Create New Project",
                                 variable=variab,
                                 value="NP",
                                 command=lambda: EnableLEntity(E2, Lb3))
    newproject.pack()
    newprojectFrame = Tix.Frame(frame, height=100)
    names = Tix.StringVar()
    label_projectName = Tix.Label(newprojectFrame, textvariable=names)
    names.set("Project Name")
    label_projectName.pack(side=Tix.LEFT)
    E2 = Tix.Entry(newprojectFrame, bd=5)
    E2.pack(side=Tix.LEFT)
    newprojectFrame.pack()
    loadproject = Tix.Radiobutton(frame,
                                  text="Load Project",
                                  variable=variab,
                                  value="LP",
                                  command=lambda: EnableLB(Lb3, E2))
    loadproject.pack()
    loadprojectFrame = Tix.Frame(frame, height=100)
    loadprojectFrame.pack()
    Lb3 = Tix.Listbox(loadprojectFrame, width=80, height=20)
    projects = FileManipulationHelper.readProjects()
    i = 1
    for p in projects:
        Lb3.insert(i, p)
        i = i + 1
    Lb3.pack()
    Lb3.configure(exportselection=False)
    Lb3.configure(state=Tix.DISABLED)
    variab.set("NP")
    newproject.select()
    BottomFrame = Tix.Frame(s, height=10)
    BottomFrame.pack()
    NextButtonFrame = Tix.Frame(s)
    NextButtonFrame.pack()
    NextButton = Tix.Button(
        NextButtonFrame,
        text="Next",
        fg="black",
        command=lambda: FinishFirstScreen(variab, E2, Lb3, s))
    NextButton.pack()
Ejemplo n.º 12
0
def SaveWhiteListEdit(listWL, listBL, 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, vClsIn):
    global currentWhiteList
    global currentBlackList
    listWL
    currentWhiteList = []
    currentBlackList = []
    currentWhiteList = listWL.split('\n')
    currentBlackList = listBL.split('\n')
    rule_path = "Projects/" + project_name + "/" + vClsIn.get(
    ) + "/" + rule_name
    FileManipulationHelper.CreateFoderIfNotExist(rule_path)
    FileManipulationHelper.SaveCueList(rule_path, rule_name, currentWhiteList,
                                       currentBlackList, 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)
    #FileManipulationHelper.MakeRuleCFGFile(rule_path, look_head, look_stub, look_super, look_data, look_all,vClsIn,vDefUnit,vPosUnit,pragVar)
    WhiteListWindow.withdraw()
Ejemplo n.º 13
0
def EditSintacticRules(project_name, rule_name, ChoseSintRulesWindow, fname,
                       variable_name):
    ChoseSintRulesWindow.withdraw()
    top = Toplevel()
    #top.protocol("WM_DELETE_WINDOW", on_closing)
    top.title("Modify selected rules")
    top.geometry('{}x{}'.format(400, 300))
    topframe = Frame(top, height=10)
    topframe.pack()
    frame = Frame(top)
    frame.pack()
    topframe2 = Frame(top, height=10)
    topframe2.pack()
    rules = StringVar()
    rulelist = Text(frame, height=15, width=40)
    rulelist.grid(row=1, sticky='w')
    fpaths = []

    if fname.get() == '':
        SaveSintacticRules(rulelist.get("1.0", END), top, project_name,
                           variable_name)
        return
    else:
        fpaths.append(fname.get())
    rules = []
    for path in fpaths:
        rules = rules + FileManipulationHelper.LoadRules(path)

    i = 1
    for w in rules:
        rulelist.insert(str(i) + '.0', w)
        i = i + 1
    saveButton = Button(
        frame,
        text="Next",
        bg="green",
        fg="black",
        command=lambda: SaveSintacticRules(rulelist.get(
            "1.0", END), top, project_name, rule_name, variable_name)).grid(
                row=2, sticky='w')
    pass
Ejemplo n.º 14
0
    Lb1.pack()
    size = Lb1.size()
    refreshButton = Tix.Button(
        top,
        text="Refresh",
        fg="black",
        command=lambda: RefreshDatabaseData(Lb1, project_name))
    refreshButton.pack()
    processing_rules = LoadRulesForProcessing(project_name)
    thread = Thread(target=ProcessDataV,
                    args=(project_name, processing_rules, top, extracted))
    thread.start()
    print "thread finished...exiting"
    pass


def on_closing():
    global main
    main.destroy()


##################################################################
lab2 = None
main = Tix.Tk()
variab = Tix.StringVar()
FileManipulationHelper.CreateFolderStructure()
main.withdraw()
LoadConfigScreen()
main.protocol("WM_DELETE_WINDOW", on_closing)
main.mainloop()
Ejemplo n.º 15
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')
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    
Ejemplo n.º 18
0
def EditRule(project_name, Lb1):
    global currentWhiteList
    global currentBlackList
    currentWhiteList = []
    currentBlackList = []

    add = Toplevel()
    add.title("Edit Rule")
    add.geometry('{}x{}'.format(400, 300))
    itemsFrame = Frame(add, height=130)
    itemsFrame.pack()
    vRuleName = StringVar()
    # Obtain rule/vaiable properly. The following won't work
    pos = Lb1.selection()[0]
    vRuleName.set(Lb1.item(pos)['text'])
    vClsIn = StringVar()
    vClsIn.set(Lb1.parent(pos).replace('\n', ''))
    namerule_label = Label(itemsFrame,
                           text="Name of the rule").grid(row=0,
                                                         column=0,
                                                         sticky='w')
    rulename_entry = Entry(itemsFrame, textvariable=vRuleName,
                           state=DISABLED).grid(row=0, column=1, sticky='w')
    rule_name = vRuleName.get()
    cfg = FileManipulationHelper.loadRuleConfig(project_name, rule_name,
                                                vClsIn.get())
    ruleType = cfg['RuleType'].replace('\n', '')
    ClassLabel = Label(itemsFrame, text="Class name of result",
                       state=DISABLED).grid(row=2, column=0, sticky='w')
    ClassInput = Entry(itemsFrame, textvariable=vClsIn)
    ClassInput.grid(row=3, sticky='w')
    vDefUnit = StringVar()
    vPosUnit = StringVar()
    if ruleType == 'Numeric' or ruleType == "Categorical":
        DefUnitLabel = Label(itemsFrame, text="Default unit")
        DefUnitLabel.grid(row=4, column=0, sticky='w')
        vDefUnit = StringVar()
        DefUnInput = Entry(itemsFrame, textvariable=vDefUnit)
        DefUnInput.grid(row=5, sticky='w')
        PosUnitLabel = Label(itemsFrame,
                             text="Possible units (comma separated)")
        PosUnitLabel.grid(row=6, column=0, sticky='w')
        PosUnInput = Entry(itemsFrame, textvariable=vPosUnit)
        PosUnInput.grid(row=7, sticky='w')
    ruleMech = cfg['RuleCreationMech'].replace('\n', '')
    where_to_look = Label(itemsFrame,
                          text="Where to look for data?").grid(row=2,
                                                               column=1,
                                                               sticky='w')
    wl_look_head = IntVar()
    if ('DataInHeader' in cfg.keys() and cfg['DataInHeader'] != None
            and cfg['DataInHeader'] == '1'):
        wl_look_head.set(1)
    else:
        wl_look_head.set(0)
    WLHeaderCB = Checkbutton(itemsFrame, text="Header",
                             variable=wl_look_head).grid(row=3,
                                                         column=1,
                                                         sticky='w')
    wl_look_stub = IntVar()
    if ('DataInStub' in cfg.keys() and cfg['DataInStub'] != None
            and cfg['DataInStub'] == '1'):
        wl_look_stub.set(1)
    else:
        wl_look_stub.set(0)
    WLStubCB = Checkbutton(itemsFrame, text="Stub",
                           variable=wl_look_stub).grid(row=4,
                                                       column=1,
                                                       sticky='w')
    wl_look_super = IntVar()
    if ('DataInSuperRow' in cfg.keys() and cfg['DataInSuperRow'] != None
            and cfg['DataInSuperRow'] == '1'):
        wl_look_super.set(1)
    else:
        wl_look_super.set(0)
    WLSuperRowCB = Checkbutton(itemsFrame,
                               text="Super-row",
                               variable=wl_look_super).grid(row=5,
                                                            column=1,
                                                            sticky='w')
    wl_look_data = IntVar()
    if ('DataInData' in cfg.keys() and cfg['DataInData'] != None
            and cfg['DataInData'] == '1'):
        wl_look_data.set(1)
    else:
        wl_look_data.set(0)
    WLDataCB = Checkbutton(itemsFrame, text="Data",
                           variable=wl_look_data).grid(row=6,
                                                       column=1,
                                                       sticky='w')
    if ruleMech == 'Lexical':
        editWhiteList = Button(itemsFrame,
                               text="Edit Sem/Lexical Cue List",
                               command=lambda: WhiteListWindowEdit(
                                   project_name, rule_name,
                                   vClsIn.get().replace('\n', ''))).grid(
                                       row=8, column=0, sticky='w')
    else:
        editWhiteList = Button(itemsFrame,
                               text="Edit Semantic Cue List",
                               command=lambda: SemanticListWindowEdit(
                                   project_name, rule_name,
                                   vClsIn.get().replace('\n', ''))).grid(
                                       row=8, column=0, sticky='w')
    if ruleType != "String":
        SyntacticRules = Button(itemsFrame,
                                text="Edit Syntactic rules",
                                command=lambda: MakeChangesToSyntacticRules(
                                    project_name, rule_name,
                                    vClsIn.get().replace('\n', ''))).grid(
                                        row=9, column=0, sticky='w')
    #editBlackList = Button(itemsFrame,text="Edit Black Cue List",command=lambda:BlackListWindowEdit(project_name,rule_name)).grid(row=2,column=0,sticky='w')
    text_of_where_to_look = StringVar()

    DBSettings = FileManipulationHelper.LoadDBConfigFile(project_name)
    db = QueryDBClass.QueryDBCalss(DBSettings['Host'], DBSettings['User'],
                                   DBSettings['Pass'], DBSettings['Database'])
    prags = db.GetPragmaticClasses()
    prags.insert(0, "Any")
    pragVar = StringVar()
    pragVar.set(cfg['PragClass'])

    if ruleType == 'Numeric' or ruleType == 'Categorical':
        vDefUnit.set(cfg['DefUnit'])
        vPosUnit.set(cfg['PosUnit'])
    vClsIn.set(cfg['Class'].replace('\n', ''))
    PragLabel = Label(itemsFrame,
                      text="Table type (pragmatics)").grid(row=7,
                                                           column=1,
                                                           sticky='w')
    drop = OptionMenu(itemsFrame, pragVar, *prags)
    drop.grid(row=8, column=1, sticky='w')
    save = Button(itemsFrame,
                  text="Save",
                  fg="black",
                  command=lambda: SaveRuleEdit(
                      project_name, rule_name, add, vClsIn, vDefUnit, vPosUnit,
                      pragVar, ruleType, ruleMech, wl_look_head, wl_look_stub,
                      wl_look_super, wl_look_data)).grid(row=9,
                                                         column=1,
                                                         sticky='w')
Ejemplo n.º 19
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
Ejemplo n.º 20
0
def GetExtractedData(project_name):
    DBSettings = FileManipulationHelper.LoadDBConfigFile(project_name)
    db = QueryDBClass.QueryDBCalss(DBSettings['Host'], DBSettings['User'],
                                   DBSettings['Pass'], DBSettings['Database'])
    extracted = db.getExtracted()
    return extracted
Ejemplo n.º 21
0
def ProcessDataBase(project_name, rules):
    global Source
    DBSettings = FileManipulationHelper.LoadDBConfigFile(project_name)
    db = QueryDBClass.QueryDBCalss(DBSettings['Host'], DBSettings['User'],
                                   DBSettings['Pass'], DBSettings['Database'])
    for rule in rules:
        posSubClass = ''
        print "Rule " + rule.RuleName + " executing"
        WhiteWordList = []
        WhiteIDList = []
        WhiteDescList = []
        BlackWordList = []
        BlackIDList = []
        BlackDescList = []
        # Get different cue lists from one big list containing annotations and lexical cues
        for word in rule.WhiteList:
            if ('[annID]:' in word):
                if (word[8:] != ''):
                    WhiteIDList.append(word[8:])
            elif ('[annType]:' in word):
                if (word[10:] != ''):
                    WhiteDescList.append(word[10:])
            elif ('[word]:' in word):
                if (word[7:] != ''):
                    WhiteWordList.append(word[7:])
            else:
                if (word != ''):
                    WhiteWordList.append(word)

        for word in rule.BlackList:
            if ('[annID]:' in word):
                if (word[8:] != ''):
                    BlackIDList.append(word[8:])
            elif ('[annType]:' in word):
                if (word[10:] != ''):
                    BlackDescList.append(word[10:])
            elif ('[word]:' in word):
                if (word[7:] != ''):
                    BlackWordList.append(word[7:])
            else:
                if (word != ''):
                    BlackWordList.append(word)
            # Get tables that contain something from white list in it
        tabres = db.getRelevantTables(WhiteWordList, WhiteIDList,
                                      WhiteDescList, rule.PragmaticClass)
        tables = []
        for res in tabres:
            tables.append(res[0])
        for table in tables:
            #Get Table cells with all the annotations
            cells = getCellsByTableID(table, db)
            #Now the data should be filtered
            for cell in cells:
                extractData = True
                extracted = False
                selectCell = False
                CueFoundInHeader = False
                CueFoundInStub = False
                CueFoundInSuperRow = False
                CueFoundInData = False

                #Check white list against data cells
                if rule.wl_look_data:
                    for word in WhiteWordList:
                        if cell.Content != None:
                            if (word in cell.Content):
                                selectCell = True
                                CueFoundInData = True
                                posSubClass = word
                    for word in WhiteDescList:
                        for ann in cell.Annotations:
                            if ann.AnnotationDesc == word:
                                selectCell = True
                                CueFoundInData = True
                                posSubClass = ann.Content
                    for word in WhiteIDList:
                        for ann in cell.Annotations:
                            if ann.AnnotationCID == word:
                                selectCell = True
                                CueFoundInData = True
                                posSubClass = ann.Content

                # Check white list against heades
                if rule.wl_look_header:
                    for word in WhiteWordList:
                        if cell.Header != None:
                            if (word in cell.Header):
                                selectCell = True
                                CueFoundInHeader = True
                                posSubClass = word
                    idHeader = cell.HeaderId
                    heads = []
                    heads = getHeaderCells(cell.HeaderId, cells, heads)
                    for head in heads:
                        for word in WhiteDescList:
                            for ann in head.Annotations:
                                if ann.AnnotationDesc == word:
                                    selectCell = True
                                    CueFoundInHeader = True
                                    posSubClass = ann.Content
                        for word in WhiteIDList:
                            for ann in head.Annotations:
                                if ann.AnnotationCID == word:
                                    selectCell = True
                                    CueFoundInHeader = True
                                    posSubClass = ann.Content

                # Check white list against stub
                if rule.wl_look_stub:
                    for word in WhiteWordList:
                        if cell.Stub != None:
                            if (word in cell.Stub):
                                selectCell = True
                                CueFoundInStub = True
                                posSubClass = word
                    idStub = cell.StubId
                    stubs = []
                    stubs = getStubCells(cell.StubId, cells, stubs)
                    for stub in stubs:
                        for word in WhiteDescList:
                            for ann in stub.Annotations:
                                if ann.AnnotationDesc == word:
                                    selectCell = True
                                    CueFoundInStub = True
                                    posSubClass = ann.Content
                        for word in WhiteIDList:
                            for ann in stub.Annotations:
                                if ann.AnnotationCID == word:
                                    selectCell = True
                                    CueFoundInStub = True
                                    posSubClass = ann.Content

                # Check white list against super-row
                if rule.wl_look_superrow:
                    for word in WhiteWordList:
                        if cell.Super_row != None:
                            if (word in cell.Super_row):
                                selectCell = True
                                CueFoundInSuperRow = True
                                posSubClass = word
                    idSuperRow = cell.SuperRowId
                    superrows = []
                    superrows = getStubCells(cell.SuperRowId, cells, superrows)
                    for superrow in superrows:
                        for word in WhiteDescList:
                            for ann in superrow.Annotations:
                                if ann.AnnotationDesc == word:
                                    selectCell = True
                                    CueFoundInSuperRow = True
                                    posSubClass = ann.Content
                        for word in WhiteIDList:
                            for ann in superrow.Annotations:
                                if ann.AnnotationCID == word:
                                    selectCell = True
                                    CueFoundInSuperRow = True
                                    posSubClass = ann.Content


#=============================================================================================
# Check black list against data cells
                if rule.bl_look_data:
                    for word in BlackWordList:
                        if cell.Content != None:
                            if (word in cell.Content):
                                selectCell = False
                    for word in BlackDescList:
                        for ann in cell.Annotations:
                            if ann.AnnotationDesc == word:
                                selectCell = False
                    for word in BlackIDList:
                        for ann in cell.Annotations:
                            if ann.AnnotationCID == word:
                                selectCell = False

                # Check black list against heades
                if rule.bl_look_header:
                    for word in BlackWordList:
                        if cell.Header != None:
                            if (word in cell.Header):
                                selectCell = False
                    idHeader = cell.HeaderId
                    heads = []
                    heads = getHeaderCells(cell.HeaderId, cells, heads)
                    for head in heads:
                        for word in BlackDescList:
                            for ann in head.Annotations:
                                if ann.AnnotationDesc == word:
                                    selectCell = False
                        for word in BlackIDList:
                            for ann in head.Annotations:
                                if ann.AnnotationCID == word:
                                    selectCell = False

                                    # Check white list against stub
                if rule.bl_look_stub:
                    for word in BlackWordList:
                        if cell.Stub != None:
                            if (word in cell.Stub):
                                selectCell = False
                    idStub = cell.StubId
                    stubs = []
                    stubs = getStubCells(cell.StubId, cells, stubs)
                    for stub in stubs:
                        for word in BlackDescList:
                            for ann in stub.Annotations:
                                if ann.AnnotationDesc == word:
                                    selectCell = False
                        for word in BlackIDList:
                            for ann in stub.Annotations:
                                if ann.AnnotationCID == word:
                                    selectCell = False

                # Check white list against super-row
                if rule.bl_look_superrow:
                    for word in BlackWordList:
                        if cell.Super_row != None:
                            if (word in cell.Super_row):
                                selectCell = False
                    idSuperRow = cell.SuperRowId
                    superrows = []
                    superrows = getStubCells(cell.SuperRowId, cells, superrows)
                    for superrow in superrows:
                        for word in BlackDescList:
                            for ann in superrow.Annotation:
                                if ann.AnnotationDesc == word:
                                    selectCell = False
                        for word in BlackIDList:
                            for ann in superrow.Annotation:
                                if ann.AnnotationCID == word:
                                    selectCell = False

                if selectCell:
                    if ((not rule.data_in_stub) and cell.isStub):
                        continue
                    if ((not rule.data_in_data) and cell.isData):
                        continue
                    if ((not rule.data_in_header) and cell.isHeader):
                        continue
                    if ((not rule.data_in_super) and cell.isSuperRow):
                        continue
                    FoundSemantics = False
                    AllSemSaved = False
                    # Iterate trought all the patterns
                    for syn_rule in rule.PatternList:
                        if (AllSemSaved == True):
                            break
                        # check pattern
                        pattern = unicode(syn_rule.regex.replace('\n', ''),
                                          'utf-8')
                        m = re.search(pattern, cell.Content, re.UNICODE)
                        # in case pattern is not found continue to the next one
                        if m == None:
                            continue
                        c = 0
                        contains_term = False
                        last_sem_extracted = -1
                        savedSomething = False
                        # Itterate semantics for each pattern rule (syntactic rule)
                        for sem in syn_rule.SemanticValues:
                            if contains_term and sem.Semantics == 'mean':
                                contains_term = False
                                FoundSemantics = False
                                continue
                            if (AllSemSaved == True):
                                break
                            if last_sem_extracted >= sem.position:
                                continue
                            # extract value
                            value = m.group(sem.position)
                            #Checking terms in case there are multiple semantics for certain group
                            if len(sem.SemTermList) > 0:
                                contains_term = CheckSemTermListUsingRegex(
                                    True, True, True, False, sem.SemTermList,
                                    cell.Header, cell.Stub, cell.Super_row,
                                    cell.Content)
                                if (contains_term):
                                    semValue = sem.Semantics
                                    FoundSemantics = True
                            # Getting semantics for certain group
                            if len(sem.SemTermList) == 0:
                                semValue = sem.Semantics
                                FoundSemantics = True
                            c = c + 1
                            if FoundSemantics:
                                syn_rule_name = syn_rule.name
                                # Be a bit smart for generating Source
                                if (CueFoundInHeader and rule.data_in_data):
                                    if cell.Super_row != None:
                                        Source = cell.Super_row + cell.Stub
                                    else:
                                        Source = cell.Stub
                                    ClassDetails = cell.Header
                                else:
                                    Source = cell.Header
                                    if cell.Super_row != None:
                                        ClassDetails = cell.Super_row + cell.Stub
                                    else:
                                        ClassDetails = cell.Stub
                                # Get unit
                                SubClass = ''
                                if rule.RuleType == 'Categorical':
                                    SubClass = cell.Stub
                                Unit = CheckUnits(cell.Header, cell.Stub,
                                                  cell.Super_row, cell.Content,
                                                  rule.DefaultUnit,
                                                  rule.PossibleUnits)
                                #Save the value to the database
                                db.SaveExtracted(cell.idArticle, cell.idTable,
                                                 cell.tableOrder, cell.idPMC,
                                                 rule.ClassName, semValue,
                                                 value, Unit, Source,
                                                 ClassDetails, rule.RuleName,
                                                 syn_rule_name, SubClass)
                                savedSomething = True
                                last_sem_extracted = sem.position
                                FoundSemantics = False
                                if (c == len(syn_rule.SemanticValues)):
                                    AllSemSaved = True
                        if (savedSomething):
                            break

            #print cells
    print "Finished!!!"
    print "Done!!!!"
def EditRule(project_name,Lb1):
    global currentWhiteList
    global currentBlackList
    currentWhiteList = []
    currentBlackList = []


    
    add = Toplevel()
    add.title("Edit Rule")
    add.geometry('{}x{}'.format(400, 300))
    itemsFrame = Frame(add,height=130)
    itemsFrame.pack()
    vRuleName = StringVar()
    # Obtain rule/vaiable properly. The following won't work
    pos = Lb1.selection()[0]
    vRuleName.set(Lb1.item(pos)['text'])
    vClsIn = StringVar()
    vClsIn.set(Lb1.parent(pos).replace('\n',''))
    namerule_label = Label(itemsFrame,text="Name of the rule").grid(row=0,column=0,sticky='w')
    rulename_entry = Entry(itemsFrame,textvariable=vRuleName,state=DISABLED).grid(row=0,column=1,sticky='w')
    rule_name = vRuleName.get()
    cfg = FileManipulationHelper.loadRuleConfig(project_name, rule_name,vClsIn.get())
    ruleType = cfg['RuleType'].replace('\n','')
    ClassLabel = Label(itemsFrame,text="Class name of result",state=DISABLED).grid(row=2,column=0,sticky='w')
    ClassInput = Entry(itemsFrame,textvariable=vClsIn)
    ClassInput.grid(row=3,sticky='w')
    vDefUnit = StringVar()
    vPosUnit = StringVar()
    if ruleType =='Numeric' or ruleType=="Categorical":
        DefUnitLabel = Label(itemsFrame,text="Default unit")
        DefUnitLabel.grid(row=4,column=0,sticky='w')
        vDefUnit = StringVar()
        DefUnInput = Entry(itemsFrame,textvariable=vDefUnit)
        DefUnInput.grid(row=5,sticky='w')
        PosUnitLabel = Label(itemsFrame,text="Possible units (comma separated)")
        PosUnitLabel.grid(row=6,column=0,sticky='w')
        PosUnInput = Entry(itemsFrame,textvariable=vPosUnit)
        PosUnInput.grid(row=7,sticky='w')
    ruleMech = cfg['RuleCreationMech'].replace('\n','')
    where_to_look = Label(itemsFrame,text="Where to look for data?").grid(row=2,column=1,sticky='w')
    wl_look_head = IntVar()
    if('DataInHeader' in cfg.keys() and cfg['DataInHeader']!=None and cfg['DataInHeader']=='1'):
        wl_look_head.set(1)
    else:
        wl_look_head.set(0)
    WLHeaderCB = Checkbutton(itemsFrame,text="Header",variable = wl_look_head).grid(row=3,column=1,sticky='w')
    wl_look_stub = IntVar()
    if('DataInStub' in cfg.keys() and cfg['DataInStub']!=None and cfg['DataInStub']=='1'):
        wl_look_stub.set(1)
    else:
        wl_look_stub.set(0)
    WLStubCB = Checkbutton(itemsFrame,text="Stub",variable = wl_look_stub).grid(row=4,column=1,sticky='w')
    wl_look_super = IntVar()
    if('DataInSuperRow' in cfg.keys() and cfg['DataInSuperRow']!=None and cfg['DataInSuperRow']=='1'):
        wl_look_super.set(1)
    else:
        wl_look_super.set(0)
    WLSuperRowCB = Checkbutton(itemsFrame,text="Super-row",variable = wl_look_super).grid(row=5,column=1,sticky='w')
    wl_look_data = IntVar()
    if('DataInData' in cfg.keys() and cfg['DataInData']!=None and cfg['DataInData']=='1'):
        wl_look_data.set(1)
    else:
        wl_look_data.set(0)
    WLDataCB = Checkbutton(itemsFrame,text="Data",variable = wl_look_data).grid(row=6,column=1,sticky='w')
    if ruleMech == 'Lexical':
        editWhiteList = Button(itemsFrame,text="Edit Sem/Lexical Cue List",command=lambda:WhiteListWindowEdit(project_name,rule_name,vClsIn.get().replace('\n',''))).grid(row=8,column=0,sticky='w')
    else:
        editWhiteList = Button(itemsFrame,text="Edit Semantic Cue List",command=lambda:SemanticListWindowEdit(project_name,rule_name,vClsIn.get().replace('\n',''))).grid(row=8,column=0,sticky='w')
    if ruleType != "String":
        SyntacticRules = Button(itemsFrame,text="Edit Syntactic rules",command=lambda:MakeChangesToSyntacticRules(project_name,rule_name,vClsIn.get().replace('\n',''))).grid(row=9,column=0,sticky='w')
    #editBlackList = Button(itemsFrame,text="Edit Black Cue List",command=lambda:BlackListWindowEdit(project_name,rule_name)).grid(row=2,column=0,sticky='w')
    text_of_where_to_look = StringVar()
    
    DBSettings = FileManipulationHelper.LoadDBConfigFile(project_name)
    db = QueryDBClass.QueryDBCalss(DBSettings['Host'],DBSettings['User'],DBSettings['Pass'],DBSettings['Database'])
    prags = db.GetPragmaticClasses()
    prags.insert(0,"Any")
    pragVar = StringVar()
    pragVar.set(cfg['PragClass'])
    
    if ruleType == 'Numeric' or ruleType == 'Categorical':
        vDefUnit.set(cfg['DefUnit'])
        vPosUnit.set(cfg['PosUnit'])
    vClsIn.set(cfg['Class'].replace('\n',''))
    PragLabel = Label(itemsFrame,text="Table type (pragmatics)").grid(row=7,column=1,sticky='w')
    drop = OptionMenu(itemsFrame,pragVar,*prags)
    drop.grid(row=8,column=1,sticky='w')
    save = Button(itemsFrame, text="Save", fg="black",command=lambda:SaveRuleEdit(project_name,rule_name,add,vClsIn,vDefUnit,vPosUnit,pragVar,ruleType,ruleMech,wl_look_head,wl_look_stub,wl_look_super,wl_look_data)).grid(row=9,column=1,sticky='w')
Ejemplo n.º 23
0
def LoadFirstCfGScreen(project_name):
    top = Tix.Toplevel()
    top.protocol("WM_DELETE_WINDOW", on_closing)
    top.title("Table InfExtractor")
    top.geometry('{}x{}'.format(500, 500))
    topframe = Tix.Frame(top, height=10)
    topframe.pack()
    frame = Tix.Frame(top)
    frame.pack()
    topframe2 = Tix.Frame(top, height=10)
    topframe2.pack()
    middleframe = Tix.Frame(top)
    middleframe.pack()
    bottomframe2 = Tix.Frame(top, height=10)
    bottomframe2.pack(side=Tix.BOTTOM)
    bottomframe = Tix.Frame(top)
    bottomframe.pack(side=Tix.BOTTOM)

    name = Tix.StringVar()
    label_name = Tix.Label(frame, textvariable=name)
    name.set("Name of task:")
    label_name.pack(side=Tix.LEFT)
    name2 = Tix.StringVar()
    label_name2 = Tix.Label(frame, textvariable=name2)
    name2.set(project_name)
    label_name2.pack(side=Tix.LEFT)
    ConfigureDB = Tix.Button(
        frame,
        text="Configure Database",
        fg="black",
        command=lambda: ConfigureDatabaseScreen(project_name))
    ConfigureDB.pack(side=Tix.LEFT)
    clearTable = Tix.Button(frame,
                            text="Clear DB Table",
                            fg="black",
                            command=lambda: ClearDBTables(project_name))
    clearTable.pack(side=Tix.LEFT)
    vars = FileManipulationHelper.loadVariables(project_name)
    Lb1 = ttk.Treeview(middleframe, columns=40, height=19)

    Lb1.pack()
    size = Lb1.size()
    for var in vars:
        Lb1.insert('', 'end', var, text=var)
        rules = FileManipulationHelper.loadRules(project_name, var)
        for rule in rules:
            Lb1.insert(var, 'end', text=rule)
        #Lb1.insert(size,rule)
        size = Lb1.size()
    AddVariables = Tix.Button(bottomframe,
                              text="Add Variable",
                              fg="black",
                              command=lambda: AddVariable(project_name, Lb1))
    AddVariables.pack(side=Tix.LEFT)

    AddRules = Tix.Button(bottomframe,
                          text="Add Rule",
                          fg="black",
                          command=lambda: AddEditRule(project_name, Lb1))
    AddRules.pack(side=Tix.LEFT)
    DeleteRule = Tix.Button(bottomframe,
                            text="Delete Rule",
                            fg="black",
                            command=lambda: RemoveRule(Lb1, project_name))
    DeleteRule.pack(side=Tix.LEFT)
    EditRuleA = Tix.Button(bottomframe,
                           text="Edit Rule",
                           fg="black",
                           command=lambda: EditRule(project_name, Lb1))
    EditRuleA.pack(side=Tix.LEFT)
    #MoveUpRule = Tix.Button(bottomframe, text="Move Up Rule", fg="black",command=lambda:MoveRuleUp(Lb1))
    #MoveUpRule.pack( side = Tix.LEFT)
    #MoveDownRule =Tix.Button(bottomframe, text="Move Down Rule", fg="black",command=lambda:MoveRuleDown(Lb1))
    #MoveDownRule.pack( side = Tix.LEFT)
    skip_val = 0
    Next = Tix.Button(
        bottomframe,
        text="Next",
        bg="green",
        command=lambda: MakeWorkingScreen(rules, top, project_name, skip_val))
    Next.pack(side=Tix.LEFT)
Ejemplo n.º 24
0
def AddEditRule(project_name, RulesListBox):
    global currentWhiteList
    global currentBlackList
    currentWhiteList = []
    currentBlackList = []
    rule = RulesListBox.selection()[0]

    add = Toplevel()
    #add.protocol("WM_DELETE_WINDOW", on_closing)
    add.title("Add Rule")
    add.geometry('{}x{}'.format(400, 350))
    itemsFrame = Frame(add, height=130)
    itemsFrame.pack()
    namerule_label = Label(itemsFrame,
                           text="Name of the rule").grid(row=0,
                                                         column=0,
                                                         sticky='w')
    vRule = StringVar()

    rulename_entry = Entry(itemsFrame, textvariable=vRule).grid(row=0,
                                                                column=1,
                                                                sticky='w')
    #editCueList = Button(itemsFrame,text="Edit Cue List",command=lambda:WhiteListWindow(project_name,rule_name)).grid(row=1,column=0,sticky='w')
    ClassLabel = Label(
        itemsFrame, text="Variable name (Information class)").grid(row=3,
                                                                   column=0,
                                                                   sticky='w')
    vClsIn = StringVar()
    vClsIn.set(rule)
    ClassInput = Entry(itemsFrame, textvariable=vClsIn,
                       state=DISABLED).grid(row=4, sticky='w')
    vDefUnit = StringVar()
    vPosUnit = StringVar()
    cfg = loadVariableConfig(project_name, rule)
    vRuleType = StringVar()
    vRuleType.set(cfg["VariableType"])
    if (cfg["VariableType"] == "Numeric"
            or cfg["VariableType"] == "Categorical"):
        DefUnitLabel = Label(itemsFrame, text="Default unit").grid(row=5,
                                                                   column=0,
                                                                   sticky='w')
        DefUnInput = Entry(itemsFrame, textvariable=vDefUnit).grid(row=6,
                                                                   sticky='w')
        PosUnitLabel = Label(itemsFrame,
                             text="Possible units (comma separated)").grid(
                                 row=7, column=0, sticky='w')
        PosUnInput = Entry(itemsFrame, textvariable=vPosUnit).grid(row=8,
                                                                   sticky='w')
    #if(vRuleType.get() == "Categorical"):
    #    PosUnitLabel = Label(itemsFrame,text="Possible categories (comma separated)").grid(row=7,column=0,sticky='w')
    #    vPosUnit = StringVar()
    #    PosUnInput = Entry(itemsFrame,textvariable=vPosUnit).grid(row=8,sticky='w')
    DBSettings = FileManipulationHelper.LoadDBConfigFile(project_name)
    db = QueryDBClass.QueryDBCalss(DBSettings['Host'], DBSettings['User'],
                                   DBSettings['Pass'], DBSettings['Database'])
    prags = db.GetPragmaticClasses()
    prags.insert(0, "Any")
    pragVar = StringVar()
    pragVar.set(prags[0])
    PragLabel = Label(itemsFrame,
                      text="Table type (pragmatics)").grid(row=9,
                                                           column=0,
                                                           sticky='w')
    drop = OptionMenu(itemsFrame, pragVar, *prags)
    drop.grid(row=10, column=0, sticky='w')
    vLexSemRule = StringVar()
    vLexSemRule.set("Lexical")
    #PosUnitLabel = Label(itemsFrame,text="Select rule creation mechanism").grid(row=11,column=0,sticky='w')
    #Radiobutton(itemsFrame, text="Lexical (White List+Black list)", variable=vLexSemRule, value="Lexical").grid(row=12,sticky='w')
    #Radiobutton(itemsFrame, text="Semantic (UMLS Sem. type+Black list)", variable=vLexSemRule, value="Semantic").grid(row=13,sticky='w')
    where_to_look = Label(itemsFrame,
                          text="Where to look for data?").grid(row=2,
                                                               column=1,
                                                               sticky='w')
    wl_look_head = IntVar()
    WLHeaderCB = Checkbutton(itemsFrame, text="Header",
                             variable=wl_look_head).grid(row=3,
                                                         column=1,
                                                         sticky='w')
    wl_look_stub = IntVar()
    WLStubCB = Checkbutton(itemsFrame, text="Stub",
                           variable=wl_look_stub).grid(row=4,
                                                       column=1,
                                                       sticky='w')
    wl_look_super = IntVar()
    WLSuperRowCB = Checkbutton(itemsFrame,
                               text="Super-row",
                               variable=wl_look_super).grid(row=5,
                                                            column=1,
                                                            sticky='w')
    wl_look_data = IntVar()
    WLDataCB = Checkbutton(itemsFrame, text="Data",
                           variable=wl_look_data).grid(row=6,
                                                       column=1,
                                                       sticky='w')
    save = Button(
        itemsFrame,
        text="Save",
        fg="black",
        command=lambda: SaveRule(project_name, vRule.get(
        ), add, vClsIn, vDefUnit, vPosUnit, pragVar, RulesListBox, vRuleType,
                                 vLexSemRule, wl_look_head, wl_look_stub,
                                 wl_look_super, wl_look_data)).grid(row=14,
                                                                    column=1,
                                                                    sticky='w')
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
        
Ejemplo n.º 26
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