Exemple #1
0
    def logMatch(self, logTemplate):
        for logT in logTemplate.logTDict:
            #print logT
            logT = logT.replace('(', '\(').replace(')', '\)')
            (count, results) = self.whooshUtil.search(logT)
            if count == 0:
                continue
            for hit in results:
                if logT not in self.logT2logMsg:
                    self.logT2logMsg[logT] = []
                self.logT2logMsg[logT].append(hit["content"])

        #Reverse self.logT2logMsg to self.logMsg2logT
        for logT in self.logT2logMsg:
            for logMsg in self.logT2logMsg[logT]:
                if logMsg not in self.logMsg2logT:
                    self.logMsg2logT[logMsg] = []
                self.logMsg2logT[logMsg].append(logT)

        #utils.printDict(self.logMsg2logT)

        for logMsg in self.logMsg2logT:
            maxLen = 0
            maxLogT = None
            for logT in self.logMsg2logT[logMsg]:
                if len(logT) > maxLen:
                    maxLen = len(logT)
                    maxLogT = logT
            self.logMsg2logT[logMsg] = maxLogT
        utils.printDict(self.logMsg2logT)

        return self.logMsg2logT
Exemple #2
0
    def subMethods(self, subDict):
        self.newrecipe = copy.deepcopy(self.oldrecipe)
        newPrimaryList = []
        i = 1
        for pcm in self.newrecipe["Methods"]["Primary cooking method"]:
            if pcm in subDict:
                newPrimaryList.append(subDict[pcm])
                self.newrecipe["directions"] = self.updateMethodForDirection(
                    self.newrecipe["directions"], subDict[pcm], pcm)

                print("sub:" + str(i))
                print("original method:")
                utils.printDict(pcm)
                print("new method:")
                utils.printDict(subDict[pcm])
                print("\n")

                i += 1

            else:
                newPrimaryList.append(pcm)

        self.newrecipe["Methods"]["Primary cooking method"] = list(
            set(newPrimaryList))

        # print (self.newrecipe)
        # print (json.dumps(self.newrecipe, indent=4))

        if i == 1:
            print("can not find a cooking method that can be replaced")
        else:
            utils.printRecipeNL(self.newrecipe)
Exemple #3
0
    def logMatch(self, logTemplate):
        for logT in logTemplate.logTDict:
            #print logT
            logT = logT.replace('(', '\(').replace(')', '\)')
            (count, results) = self.whooshUtil.search(logT)
            if count == 0:
                continue
            for hit in results:
                if logT not in self.logT2logMsg:
                    self.logT2logMsg[logT] = []
                self.logT2logMsg[logT].append(hit["content"])
    
        #Reverse self.logT2logMsg to self.logMsg2logT
        for logT in self.logT2logMsg:
            for logMsg in self.logT2logMsg[logT]:
                if logMsg not in self.logMsg2logT:
                    self.logMsg2logT[logMsg] = []
                self.logMsg2logT[logMsg].append(logT)

        #utils.printDict(self.logMsg2logT)
    
        for logMsg in self.logMsg2logT:
            maxLen = 0
            maxLogT = None
            for logT in self.logMsg2logT[logMsg]:
                if len(logT) > maxLen:
                    maxLen = len(logT)
                    maxLogT = logT
            self.logMsg2logT[logMsg] = maxLogT
        utils.printDict(self.logMsg2logT)

        return self.logMsg2logT
    def addItems(self, treeItem):
        '''
        Given a treeItem, if its a folder, it will fetch the contents on the server,
        empty the local elements (if it has something already) and it will add whatever
        it gets from the server.
        
        It will get only its child elements.
        '''
        remoteSession = self.getRemoteSession()
        
        theTree = self.getView()
        treeItem.setTreeController(self)

        rootElement = theTree.topLevelItem(0)
        
        if treeItem == rootElement or treeItem.isDirectory():
            treeItem.takeChildren() #Clear whatever was in there, we'll add again

        if treeItem == rootElement:
            self.hireWorker(self.fetchFolderContents,
                            rootElement,
                            0)
        elif treeItem.isDirectory():
            utils.printDict(treeItem.getItemData())
            self.hireWorker(self.fetchFolderContents,
                            treeItem,
                            treeItem.getItemData()['directoryID'])
            mainView = AppController.getInstance().getMainView()
            mainView.statusBar().showMessage(i18n.LABEL_ERROR_REFRESHING_FOLDER)
Exemple #5
0
def parseCfgFile(_path = cfgFilePath, _dbCfg = {}, _globalCfg = {}):
    config = ConfigParser.ConfigParser()
    config.read(_path)
    for k, v in config.items('database'):
        _dbCfg[k] = v
    for k, v in config.items('global'):
        _globalCfg[k] = v
    if (int(_globalCfg['debug']) >= int(_globalCfg['debug.info'])):
        utils.printDict(_globalCfg, '_globalCfg')
        utils.printDict(_dbCfg, '_dbCfg')
Exemple #6
0
    def fromHealthy(self):
        print("transfomation from healthy recipe to non-healthy recipe")
        self.newrecipe = copy.deepcopy(self.oldrecipe)
        newingredientlist = []
        i = 1
        for ing in self.newrecipe["ingredients"]:
            # print (ing)

            flag = True
            if ing["name"] in healtyDict:
                if "butter" in ing["name"] or "sugar" in ing["name"]:
                    halfquantity = 2
                else:
                    halfquantity = None

                need = False
                for dep in healtyDict[ing["name"]]["descriptor"]:
                    if dep not in ing["descriptor"]:
                        need = True
                if need:
                    self.newrecipe[
                        "directions"] = self.updateingredForDirection(
                            self.newrecipe["directions"],
                            healtyDict[ing["name"]]["name"], ing["name"])

                    newTemp = self.updateingredForIngredient(
                        healtyDict[ing["name"]], ing, halfquantity)
                    newingredientlist.append(newTemp)
                    print("sub" + str(i))
                    i += 1
                    print("original ingredient:")
                    utils.printDict(ing)
                    print("new ingredient:")
                    utils.printDict(newTemp)
                    print("\n")
                    flag = False

            if flag and (ing["name"] == "butter" or ing["name"] == "sugar"):
                halfquantity = 2
                newTemp = self.updateingredForIngredient(
                    copy.deepcopy(ing), ing, halfquantity)
                newingredientlist.append(newTemp)
                print("sub" + str(i))
                i += 1
                print("original ingredient:")
                utils.printDict(ing)
                print("new ingredient:")
                utils.printDict(newTemp)
                print("\n")
                flag = False

            if flag:
                newingredientlist.append(ing)
        if i == 1:
            print(
                "can not find anything healthy that can change to something non-healthy"
            )
        else:
            utils.printRecipeNL(self.newrecipe)
        self.newrecipe["ingredients"] = newingredientlist
Exemple #7
0
    def toIndian(self):
        print("transfomation to make recipe more indian")
        self.newrecipe = copy.deepcopy(self.oldrecipe)
        newingredientlist = []
        i = 1
        cnt = 0
        for ing in self.newrecipe["ingredients"]:
            # print (ing)

            flag = True
            if ing["name"] in nonIndianDict:
                self.newrecipe["directions"] = self.updateingredForDirection(
                    self.newrecipe["directions"],
                    nonIndianDict[ing["name"]]["name"], ing["name"])

                newTemp = self.updateingredForIngredient(
                    nonIndianDict[ing["name"]], ing, None)
                newingredientlist.append(newTemp)
                print("sub" + str(i))
                i += 1
                print("original ingredient:")
                utils.printDict(ing)
                print("new ingredient:")
                utils.printDict(newTemp)
                print("\n")
                flag = False
            elif ing["measurement"][0] in [
                    "teaspoon", "teaspoons", "taste", "pinch", "dash"
            ] and cnt < len(mexicanSpicyList):
                self.newrecipe["directions"] = self.updateingredForDirection(
                    self.newrecipe["directions"],
                    copy.deepcopy(indianSpciyList[cnt]["name"]), ing["name"])
                newTemp = self.updateingredForIngredient(
                    indianSpciyList[cnt], ing, None)
                newingredientlist.append(newTemp)
                print("sub" + str(i))
                i += 1
                print("original ingredient:")
                utils.printDict(ing)
                print("new ingredient:")
                utils.printDict(newTemp)
                print("\n")
                flag = False
                cnt = cnt + 1

            if flag:
                newingredientlist.append(ing)

        if i == 1:
            print("can not find anything that can make recipe more indian")
        else:
            utils.printRecipeNL(self.newrecipe)

        self.newrecipe["ingredients"] = newingredientlist
Exemple #8
0
    def fromVegetarian(self):
        print("transfomation from non-healthy recipe to healthy recipe")
        self.newrecipe = copy.deepcopy(self.oldrecipe)
        newingredientlist = []
        cnt = 0
        i = 1
        for ing in self.newrecipe["ingredients"]:
            # print (ing)
            namewords = ing["name"].split()
            flag = True
            for n in namewords:
                if n in nonMeatList and cnt < len(nonMeatSubList):
                    self.newrecipe[
                        "directions"] = self.updateingredForDirection(
                            self.newrecipe["directions"],
                            copy.deepcopy(nonMeatSubList[cnt]["name"]),
                            ing["name"])
                    newTemp = self.updateingredForIngredient(
                        nonMeatSubList[cnt], ing, None)
                    newingredientlist.append(newTemp)
                    print("sub" + str(i))
                    i += 1
                    print("original ingredient:")
                    utils.printDict(ing)
                    print("new ingredient:")
                    utils.printDict(newTemp)
                    print("\n")

                    cnt = cnt + 1
                    flag = False
                    break
            if flag:
                newingredientlist.append(ing)

        self.newrecipe["ingredients"] = newingredientlist
        if i == 1:
            print(
                "can not find anything that can change from Vegetarian to Non-Vegetarian"
            )
        else:
            utils.printRecipeNL(self.newrecipe)
Exemple #9
0
    def toHealthy(self):
        print("transfomation from non-healthy recipe to healthy recipe")
        self.newrecipe = copy.deepcopy(self.oldrecipe)
        newingredientlist = []
        i = 1
        for ing in self.newrecipe["ingredients"]:
            # print (ing)

            flag = True
            if ing["name"] in nonHealthyDict:
                if "butter" in ing["name"] or "sugar" in ing["name"]:
                    halfquantity = 0.5
                else:
                    halfquantity = None
                self.newrecipe["directions"] = self.updateingredForDirection(
                    self.newrecipe["directions"],
                    nonHealthyDict[ing["name"]]["name"], ing["name"])
                newTemp = self.updateingredForIngredient(
                    nonHealthyDict[ing["name"]], ing, halfquantity)
                newingredientlist.append(newTemp)
                print("sub" + str(i))
                i += 1
                print("original ingredient:")
                utils.printDict(ing)
                print("new ingredient:")
                utils.printDict(newTemp)
                print("\n")
                flag = False

            if flag:
                newingredientlist.append(ing)

        if i == 1:
            print(
                "can not find anything non-healthy that can change to something healthy"
            )
        else:
            utils.printRecipeNL(self.newrecipe)
        self.newrecipe["ingredients"] = newingredientlist
Exemple #10
0
def main():
    file = open("verbs.txt", "r", encoding='utf-8')
    Dict = {}
    for line in file:
        tokens = utils.extractTokens(line)
        t, e, v = utils.parseTokens(tokens)
        if e != '':
            print(line)
            print(tokens)
            print(t)
            print(e)
            print(v)
        else:
            Dict = utils.includeInDict(v, Dict)
    file.close()
    for Verb in Dict.keys():
        Paradigm = Dict[Verb]['Paradigm']
        if Paradigm != '':
            for Mood in utils.moodId:
                if Mood in Dict[Paradigm]:
                    Dict[Verb][Mood] = utils.conjugate(Verb, Mood, Paradigm,
                                                       Dict)
    utils.printDict(Dict)
Exemple #11
0
    def DIY(self):
        print("transfomation to make recipe easier")
        self.newrecipe = copy.deepcopy(self.oldrecipe)
        newingredientlist = []
        i = 1
        cnt = 0
        for ing in self.newrecipe["ingredients"]:
            flag = True
            if ing["measurement"][0] in [
                    "teaspoon", "teaspoons", "taste", "pinch", "dash"
            ]:
                need = True
                for cp in commonSpicesList:
                    if cp in ing["name"]:
                        need = False
                        break
                if need:
                    self.newrecipe[
                        "directions"] = self.removeingredForDirection(
                            self.newrecipe["directions"], ing["name"])
                    print("remove" + str(i))
                    i += 1
                    print("remove ingredient:")
                    utils.printDict(ing)
                    print("\n")
                    flag = False
                    cnt = cnt + 1

            if flag:
                newingredientlist.append(ing)

        if i == 1:
            print("can not find anything that can make recipe easier")
        else:
            utils.printRecipeNL(self.newrecipe)

        self.newrecipe["ingredients"] = newingredientlist
Exemple #12
0
def materialReport(items, components, materials):
    """prints list of items and required components and materials"""
    print("TO BUILD ITEMS:\n")
    items = {utils.productID(itemID): items[itemID] for itemID in items}
    utils.printDict(items)
    print("\nCOMPONENTS REQUIRED:\n")
    utils.printDict(components)
    print("\nRAW MATERIALS REQUIRED:\n")
    utils.printDict(materials)

    market.totalInstantaneousProfits(materials, items)
Exemple #13
0
    while True:
        select = input(
            "press 0: exit this process\npress 1: enter an URL to parse a recipe\n\
press 2: do transformation\npress 3: show old recipe(you can also find the old recipe in ./output/parserOutput.json)\npress 4: show new recipe(to see the complete new recipe of last transformation)(you can also find the new recipe in ./output/newRecipeOutput.json)\n"
        )
        if select == '1':
            url = str(
                input("please enter an URL from allrecipe\n\
(default:https://www.allrecipes.com/recipe/232458/pork-chops-with-creamy-scalloped-potatoes/)\n"
                      ))
            if len(url.strip()) == 0:
                url = 'https://www.allrecipes.com/recipe/232458/pork-chops-with-creamy-scalloped-potatoes/'
            test = parser.parser(url, resPath)
            test.parserIngredient()
            test.parserDirection()
            utils.printDict(utils.recipeAddNumber(test.res))
            utils.writeDict(utils.recipeAddNumber(test.res), resPath)
            utils.printRecipeNL(test.res)

        elif select == '2':
            if url == None:
                print(
                    "you need to press 1 to enter an URL to parser an recipe first"
                )
                continue
            transfromtest = transfrom.transform(test.res)
            tran = input("press 0: exit this process\n\
press 1: change recipe to Vegetarian\n\
press 2: change recipe to Non-Vegetarian\n\
press 3: change recipe to Healthy recipe\n\
press 4: change recipe to Non-healthy recipe\n\
Exemple #14
0
    def toVegetarian(self):
        print("transfomation from non-healthy recipe to healthy recipe")
        self.newrecipe = copy.deepcopy(self.oldrecipe)
        newingredientlist = []
        cnt = 0
        i = 1
        for ing in self.newrecipe["ingredients"]:
            #print (ing)

            if ing["name"] == "chicken broth" or ing["name"].find(
                    "chicken broth") >= 0 or ing["name"].find(
                        "chicken-broth") >= 0:
                self.newrecipe["directions"] = self.updateingredForDirection(
                    self.newrecipe["directions"],
                    copy.deepcopy(nonChickenBroh.ing["name"]), ing["name"])
                newTemp = self.updateingredForIngredient(
                    copy.deepcopy(nonChickenBroh.ing), ing, None)
                newingredientlist.append(newTemp)

                print("sub" + str(i))
                i += 1
                print("original ingredient:")
                utils.printDict(ing)
                print("new ingredient:")
                utils.printDict(newTemp)
                print("\n")
                flag = False
                continue

            if ing["name"] == "beef broth" or ing["name"].find(
                    "beef broth") >= 0 or ing["name"].find("beef-broth") >= 0:
                self.newrecipe["directions"] = self.updateingredForDirection(
                    self.newrecipe["directions"],
                    copy.deepcopy(nonBeefBroh.ing["name"]), ing["name"])
                newTemp = self.updateingredForIngredient(
                    copy.deepcopy(nonBeefBroh.ing), ing, None)
                newingredientlist.append(newTemp)

                print("sub" + str(i))
                i += 1
                print("original ingredient:")
                utils.printDict(ing)
                print("new ingredient:")
                utils.printDict(newTemp)
                print("\n")
                flag = False
                continue

            namewords = ing["name"].split()
            flag = True
            for n in namewords:

                if n in meatlist and cnt < len(meatsubList):

                    self.newrecipe[
                        "directions"] = self.updateingredForDirection(
                            self.newrecipe["directions"],
                            meatsubList[cnt]["name"], ing["name"])
                    newTemp = self.updateingredForIngredient(
                        meatsubList[cnt], ing, None)
                    newingredientlist.append(newTemp)

                    print("sub" + str(i))
                    i += 1
                    print("original ingredient:")
                    utils.printDict(ing)
                    print("new ingredient:")
                    utils.printDict(newTemp)
                    print("\n")

                    cnt = cnt + 1
                    flag = False
                    break
            if flag:
                newingredientlist.append(ing)

        self.newrecipe["ingredients"] = newingredientlist
        if i == 1:
            print(
                "can not find anything that can change from Non-Vegetarian to Vegetarian"
            )
        else:
            utils.printRecipeNL(self.newrecipe)