示例#1
0
def create_jury_check(tx, txs, out, DB):
    address=addr(tx)
    mine=filter(lambda t: t['type']=='create_jury', txs)
    mine=filter(lambda t: addr(t)==address, mine)
    if len(mine)>0:
        out[0]+='you cannot create 2 juries on the same block from the same address'
        return False
    if not transactions.signature_check(tx):
        out[0]+='signature check'
        return False
    if not E_check(tx, 'vote_id', [str, unicode]): 
        out[0]+='vote id error'
        return False
    if tools.is_number(tx['vote_id']):
        out[0]+='vote_id can not be a number'
        return False
    if len(tx['vote_id'])>1000: return False
    if tools.db_existence(tx['vote_id'], DB): 
        out[0]+='this vote_id is already being used'
        return False
    if not tools.db_existence(address, DB): 
        out[0]+='this address is not used by anyone'
        return False
    acc=tools.db_get(address, DB)
    if not txs_tools.fee_check(tx, txs, DB): return False
    return True
示例#2
0
 def constraintsConduct(self):
     cnt = 1
     self.newClocks = self.newClocks.union(self.oldClocks)
     # self.newCCSLConstraintList = self.oldCCSLConstraintList
     for m in self.oldCCSLConstraintList:
         if m[0] == "on" and is_number(m[3]) is False:
             para = self.parameter[m[3]]
             self.newCCSLConstraintList.append(["on","tmp%s" %(cnt),m[2],para[2],m[4]])
             self.newCCSLConstraintList.append(["≤","tmp%s" %(cnt),m[1]])
             self.newClocks.add("tmp%s" %(cnt))
             cnt += 1
             self.newCCSLConstraintList.append(["on","tmp%s" %(cnt),m[2],para[3],m[4]])
             self.newCCSLConstraintList.append(["≤", m[1],"tmp%s" % (cnt)])
             #感觉下面这条非常关键,不是没用的
             #self.newCCSLConstraintList.append(["<", "tmp%s" %(cnt),1,"tmp%s" % (cnt - 1)])
             self.newClocks.add("tmp%s" % (cnt))
             cnt += 1
         elif m[0] == "∝±":
             self.newCCSLConstraintList.append(["∝","tmp%s" %(cnt),m[2],m[3]])
             self.newCCSLConstraintList.append(["on","tmp%s" %(cnt + 1),"tmp%s" %(cnt),m[4],m[2]])
             self.newCCSLConstraintList.append(["on","tmp%s" %(cnt),"tmp%s" %(cnt + 2),m[4],m[2]])
             self.newCCSLConstraintList.append(["≤","tmp%s" %(cnt + 2),m[1]])
             self.newCCSLConstraintList.append(["≤",m[1],"tmp%s" %(cnt + 1)])
             #下面这条约束也许就是 漂移量必须西小于一半周期的罪魁祸首把?也许
             self.newCCSLConstraintList.append(["<","tmp%s" %(cnt + 1),1,"tmp%s" %(cnt + 2)])
             self.newClocks.add("tmp%s" %(cnt))
             self.newClocks.add("tmp%s" %(cnt + 1))
             self.newClocks.add("tmp%s" %(cnt + 2))
             cnt += 3
         else:
             self.newCCSLConstraintList.append(m)
     print("real constraints")
     for each in self.newCCSLConstraintList:
         print(each)
示例#3
0
def create_jury_check(tx, txs, out, DB):
    address=addr(tx)
    mine=filter(lambda t: t['type']=='create_jury', txs)
    mine=filter(lambda t: addr(t)==address, mine)
    if len(mine)>0:
        out[0]+='you cannot create 2 juries on the same block from the same address'
        return False
    if not transactions.signature_check(tx):
        out[0]+='signature check'
        return False
    if not E_check(tx, 'vote_id', [str, unicode]): 
        out[0]+='vote id error'
        return False
    if tools.is_number(tx['vote_id']):
        out[0]+='vote_id can not be a number'
        return False
    if len(tx['vote_id'])>1000: return False
    if tools.db_existence(tx['vote_id'], DB): 
        out[0]+='this vote_id is already being used'
        return False
    if not tools.db_existence(address, DB): 
        out[0]+='this address is not used by anyone'
        return False
    acc=tools.db_get(address, DB)
    for t in txs:
        if t['type']=='prediction_market':
            if t['jury_id']==tx['jury_id']:
                out[0]+='this zeroth confirmation transaction already exists'
                return False
    if not txs_tools.fee_check(tx, txs, DB): return False
    return True
示例#4
0
def create_jury_check(tx, txs, out, DB):
    address=addr(tx)
    if not transactions.signature_check(tx):
        out[0]+='signature check'
        return False
    if not E_check(tx, 'vote_id', [str, unicode]): 
        out[0]+='vote id error'
        return False
    if tools.is_number(tx['vote_id']):
        out[0]+='vote_id can not be a number'
        return False
    if len(tx['vote_id'])>1000: return False
    if tools.db_existence(tx['vote_id'], DB): 
        out[0]+='this vote_id is already being used'
        return False
    if not tools.db_existence(address, DB): 
        out[0]+='this address is not used by anyone'
        return False
    acc=tools.db_get(address, DB)
    for t in txs:
        if 'jury_id' in t:
            if t['jury_id']==tx['jury_id']:
                out[0]+='this zeroth confirmation transaction already exists'
                return False
    if not txs_tools.fee_check(tx, txs, DB): return False
    return True
示例#5
0
 def get(self):
   if(tools.is_number(self.request.get('seconds'))) :
     ytEntry = searchForVideos(int(self.request.get('seconds')), 0)
     video = Video(ytEntry)
     self.response.out.write(json.dumps(video.getJson()))
   else :
     self.response.out.write(json.dumps("error"))
示例#6
0
文件: urldb.py 项目: draseil/deskbot
 def list_urls (user, channel, word):
     target, number = False, False
     
     if len(word) == 1:
         target = user
     elif len(word) == 2:
         target = word[1] if not is_number(word[1]) else user
         number = word[1] if is_number(word[1]) else False
     elif len(word) >= 3:
         target = word[1]
         number = word[2]
     
     for nick in url_dict:
         if target.lower() == nick.lower():
             target = nick
     
     # Throw a message if the target isn't in the URL database.
     if target not in url_dict:
         err_msg = "You don't" if target == user else "{} doesn't".format(target)
         irc.msg(channel, "{} have any {} saved.".format(err_msg, dict_name))
         return
     
     # Check if the received number is a valid integer.
     if (not is_number(number)) or ((int(number) if number else 1) < 1):
         irc.msg(channel, "{}: Invalid number.".format(user))
         return
         
     if number:
         # Turning number into a numeric value.
         number = int(number) - 1
         
         if number >= len(url_dict[target]):
             err_msg = "You don't" if target == user else "{} doesn't".format(target)
             irc.msg(channel, "{} have that many {}.".format(err_msg, dict_name))
         else:
             line = "[{}] ".format("\x034NSFW\x0f" if "!" in url_dict[target][number] else number+1)
             line += "{} [{}]".format(url_dict[target][number].strip("!"), target)
             irc.msg(channel, line)
     else:
         url_list = ["[{}] {}".format(ind+1, url) for ind, url in enumerate(url_dict[target])]
         
         # Looking for NSFW URLs. (as indicated by '!')
         url_list = map(nsfw_check, url_list)
         
         line = " ".join(url_list) + " [{}]".format(target)
         irc.msg(channel, line)
示例#7
0
 def post(self):
   if(tools.is_number(self.request.get('seconds'))) :
     ytEntry = searchForVideos(int(self.request.get('seconds')), 0)
     video = Video(ytEntry)
     template_values = {
       'video': video,
       'time' : self.request.get('seconds')
       }
   else :
     template_values = {}
   path = os.path.join(os.path.dirname(__file__), 'index.html')
   self.response.out.write(template.render(path, template_values))
示例#8
0
 def replace_url (user, channel, word):
     
     
     # This command receives two pieces of information.
     if len(word) < 4:
         irc.msg(channel, "{}: Wrong syntax. Check .help".format(user))
         return
     
     
     # The first must be a number.
     if not is_number(word[2]):
         irc.msg(channel, "{}: Invalid number.".format(user))
         return
     
     # The second must be a URL.
     if not (word[3].startswith("http://") or word[3].startswith("https://")):
         irc.msg(channel, "{}: Invalid URL.".format(user))
         return
     
     
     # Turn it into a numeric value.
     number = int(word[2]) - 1
     
     
     # Check if it's in the max range, and no negative indexes will be accepted.
     if number > max-1 or number < 0:
         irc.msg(channel, "{}: Invalid number.".format(user))
         return
     
     
     # Ignore case.
     for nick in url_dictionary:
         if user.lower() == nick.lower():
             user = nick
             break
     
     
     # Try to replace URL using received number.
     try:
         url_dictionary[user][number] = trim(word[3])
         ini.add_to_ini(section = section_name, option = user, 
                         data = '\n'.join(url_dictionary[user]), filename = filename)
         irc.msg(channel, "{}: {} replaced.".format(user, section_name.rstrip("s")))
     
     
     # It might not work, if the list isn't long enough.
     except IndexError:
         irc.msg(channel, "{}: Invalid number.".format(user))
     
     # And it won't work if the user isn't in the URL database.
     except KeyError:
         irc.msg(channel, "{}: You don't have any {} saved.".format(user, dictionary_name))
示例#9
0
def clean_feat_0424(x):
    x = str(x)
    if x == "nan":
        return np.NaN
    if tols.is_number(x):
        return x
    else:
        if '过缓' in x:
            return 50
        elif '过速' in x:
            return 110
        elif '正常' in x:
            xx = re.sub("\D", "", x)
            return xx if len(xx) != 0 else 75
示例#10
0
文件: urldb.py 项目: draseil/deskbot
 def delete_url (user, channel, word):
     del_list = [int(x) - 1 for x in word[2].split(',') if (is_number(x) and int(x) > 0)]
     
     for nick in url_dict:
         if user.lower() == nick.lower():
             user = nick
     
     # Wildcard removes everything saved for that user from the database.
     if word[2] == "*" and user in url_dict:
         del url_dict[user]
         ini.remove_from_ini(sect_name, user, file)
         irc.msg(channel, "{}: All of your {} were removed successfully.".format(user, dict_name))
         return
     
     # The list only needs numbers.
     if not del_list:
         irc.msg(channel, "{}: Invalid number(s).".format(user))
         return
     
     # The user must be in the database to be able to remove URLs.
     if user not in url_dict:
         irc.msg(channel, "{}: You don't have any {} saved.".format(user, dict_name))
         return
     
     # Copy contents of indexed list in database to deletion list.
     for index, number in enumerate(del_list):
         if len(url_dict[user]) > number:
             del_list[index] = url_dict[user][number]
     
     # Proceed to remove them one by one.
     for entry in del_list:
         if entry in url_dict[user]:
             url_dict[user].remove(entry)
     
     # Delete entry in database for an empty list and remove user from ini file.
     if not url_dict[user]:
         del url_dict[user]
         ini.remove_from_ini(sect_name, user, file)
         irc.msg(channel, "{}: All of your {} were removed successfully.".format(user, dict_name))
         return
     
     ini.add_to_ini(sect_name, user, '\n'.join(url_dict[user]), file)
     irc.msg(channel, "{}: {} deleted.".format(user, sect_name))
示例#11
0
while True:
    time.sleep(0.5)
    ## Parse IMU values in the form "#A=a1,a2,a3#E=y,p,r\n"
    #while imu_ser.in_waiting():
    imu_data = imu_ser.readline()
    print(imu_data)

    imu_data = imu_data.rstrip()
    imu_data = filter(None, imu_data.split('#'))

    for i in range(len(imu_data)):
        if "A=" in imu_data[i]:
            temp = imu_data[i].replace("A=", "")
            temp = np.array(temp.split(','))
            if (is_number(temp[0]) == True and is_number(temp[1]) == True
                    and is_number(temp[2]) == True):
                accel = np.asarray(
                    [float(temp[0]),
                     float(temp[1]),
                     float(temp[2])])
            else:
                print(temp)
                print('Invalid Input')
                exit()

        if "E=" in imu_data[i]:
            temp = imu_data[i].replace("E=", "")
            temp = np.array(temp.split(','))
            if (is_number(temp[0]) == True and is_number(temp[1]) == True
                    and is_number(temp[2]) == True):
示例#12
0
from tools import is_number

a = "123.45"
af = float(a)
print(is_number(a))
print(af)
b = "123."
bf = float(b)
print(is_number(b))
print(bf)
c = "123"
cf = float(c)
print(is_number(c))
print(cf)
d = '-0.1'
df = float(d)
print(is_number(d))
print(df)
e = '89.0\x009'
print(is_number(e))
示例#13
0
    def addOriginSMTConstraints(self):
        """
        Realize to transfer the CCSL constraints into SMT formula.
        :return:
        """
        cnt = 0
        for each in self.newCCSLConstraintList:
            if each[0] == "<" and len(each) == 3:
                tick1 = self.tickDict["t_%s" % (each[1])]
                tick2 = self.tickDict["t_%s" % (each[2])]
                history1 = self.historyDict["h_%s" % (each[1])]
                history2 = self.historyDict["h_%s" % (each[2])]
                x = z3.Int("x")
                if self.bound > 0:
                    for i in range(1, self.bound + 2):
                        self.solver.add(
                            z3.Implies(
                                history1(i) == history2(i), z3.Not(tick2(i))))
                    # self.solver.add(z3.ForAll(x, z3.Implies(
                    #     z3.And(x >= 1, x <= self.n, history1(x) == history2(x)),
                    #     z3.Not(tick2(x)))))
                else:
                    self.solver.add(
                        z3.ForAll(
                            x,
                            z3.Implies(
                                z3.And(x >= 1,
                                       history1(x) == history2(x)),
                                z3.Not(tick2(x)))))

            elif each[0] == "<" and len(each) == 4:
                tick1 = self.tickDict["t_%s" % (each[1])]
                delay = each[2]
                tick2 = self.tickDict["t_%s" % (each[3])]
                history1 = self.historyDict["h_%s" % (each[1])]
                history2 = self.historyDict["h_%s" % (each[3])]
                x = z3.Int("x")
                if self.bound > 0:
                    for i in range(1, self.bound + 2):
                        self.solver.add(
                            z3.Implies(
                                history2(i) - history1(i) == delay,
                                z3.Not(tick2(i))))
                    # self.solver.add(z3.ForAll(x, z3.Implies(
                    #     z3.And(x >= 1, x <= self.n, history2(x) - history1(x) == delay),
                    #     z3.Not(tick2(x)))))
                else:
                    self.solver.add(
                        z3.ForAll(
                            x,
                            z3.Implies(
                                z3.And(x >= 1,
                                       history2(x) - history1(x) == delay),
                                z3.Not(tick2(x)))))

            elif each[0] == "≤":
                history1 = self.historyDict["h_%s" % (each[1])]
                history2 = self.historyDict["h_%s" % (each[2])]
                x = z3.Int("x")
                if self.bound > 0:
                    for i in range(1, self.bound + 2):
                        self.solver.add(history1(i) >= history2(i))
                    # self.solver.add(z3.ForAll(x, z3.Implies(
                    #     z3.And(x >= 1, x <= self.n + 1),
                    #     history1(x) >= history2(x))))
                else:
                    self.solver.add(
                        z3.ForAll(
                            x, z3.Implies(x >= 1,
                                          history1(x) >= history2(x))))

            elif each[0] == "⊆":
                tick1 = self.tickDict["t_%s" % (each[1])]
                tick2 = self.tickDict["t_%s" % (each[2])]
                x = z3.Int("x")
                if self.bound > 0:
                    for i in range(1, self.bound + 1):
                        self.solver.add(z3.Implies(tick1(i), tick2(i)))
                    # self.solver.add(z3.ForAll(x, z3.Implies(
                    #     z3.And(x >= 1, x <= self.n, tick1(x)),
                    #     tick2(x))))
                else:
                    self.solver.add(
                        z3.ForAll(
                            x, z3.Implies(z3.And(x >= 1, tick1(x)), tick2(x))))

            elif each[0] == "#":
                tick1 = self.tickDict["t_%s" % (each[1])]
                tick2 = self.tickDict["t_%s" % (each[2])]
                x = z3.Int("x")
                if self.bound > 0:
                    for i in range(1, self.bound + 1):
                        self.solver.add(
                            z3.Or(z3.Not(tick1(i)), z3.Not(tick2(i))))
                    # self.solver.add(z3.ForAll(x, z3.Implies(
                    #     z3.And(x >= 1, x <= self.n),
                    #     z3.Or(z3.Not(tick1(x)), z3.Not(tick2(x))))))
                else:
                    self.solver.add(
                        z3.ForAll(
                            x,
                            z3.Implies(
                                x >= 1,
                                z3.Or(z3.Not(tick1(x)), z3.Not(tick2(x))))))

            elif each[0] == "+":
                tick1 = self.tickDict["t_%s" % (each[1])]
                tick2 = self.tickDict["t_%s" % (each[2])]
                tick3 = self.tickDict["t_%s" % (each[3])]
                x = z3.Int("x")
                if self.bound > 0:
                    for i in range(1, self.bound + 1):
                        self.solver.add(tick1(i) == z3.Or(tick2(i), tick3(i)))
                    # self.solver.add(z3.ForAll(x, z3.Implies(
                    #         z3.And(x >= 1, x <= self.n),
                    #         tick1(x) == z3.Or(tick2(x), tick3(x)))))
                else:
                    self.solver.add(
                        z3.ForAll(
                            x,
                            z3.Implies(x >= 1,
                                       tick1(x) == z3.Or(tick2(x), tick3(x)))))

            elif each[0] == "*":
                tick1 = self.tickDict["t_%s" % (each[1])]
                tick2 = self.tickDict["t_%s" % (each[2])]
                tick3 = self.tickDict["t_%s" % (each[3])]
                x = z3.Int("x")
                if self.bound > 0:
                    for i in range(1, self.bound + 1):
                        self.solver.add(
                            z3.Implies(tick1(i), z3.And(tick2(i), tick3(i))))
                    # self.solver.add(z3.ForAll(x, z3.Implies(
                    #         z3.And(x >= 1, x <= self.n),
                    #         tick1(x) == z3.And(tick2(x), tick3(x)))))
                else:
                    self.solver.add(
                        z3.ForAll(
                            x,
                            z3.Implies(x >= 1,
                                       tick1(x) == z3.And(tick2(x),
                                                          tick3(x)))))

            elif each[0] == "∧":
                history1 = self.historyDict["h_%s" % (each[1])]
                history2 = self.historyDict["h_%s" % (each[2])]
                history3 = self.historyDict["h_%s" % (each[3])]
                x = z3.Int("x")
                if self.bound > 0:
                    for i in range(1, self.bound + 2):
                        self.solver.add(
                            history1(i) == z3.If(
                                history2(i) >= history3(i), history2(i),
                                history3(i)))
                    # self.solver.add(z3.ForAll(x, z3.Implies(
                    #     z3.And(x >= 1, x <= self.n + 1),
                    #     history1(x) == z3.If(history2(x) >= history3(x),history2(x),history3(x)))))
                else:
                    self.solver.add(
                        z3.ForAll(
                            x,
                            z3.Implies(
                                x >= 1,
                                history1(x) == z3.If(
                                    history2(x) >= history3(x), history2(x),
                                    history3(x)))))

            elif each[0] == "∨":
                history1 = self.historyDict["h_%s" % (each[1])]
                history2 = self.historyDict["h_%s" % (each[2])]
                history3 = self.historyDict["h_%s" % (each[3])]
                x = z3.Int("x")
                if self.bound > 0:
                    for i in range(1, self.bound + 2):
                        self.solver.add(
                            history1(i) == z3.If(
                                history2(i) <= history3(i), history2(i),
                                history3(i)))
                    # self.solver.add(z3.ForAll(x, z3.Implies(
                    #     z3.And(x >= 1, x <= self.n + 1),
                    #     history1(x) == z3.If(history2(x) <= history3(x), history2(x), history3(x)))))
                else:
                    self.solver.add(
                        z3.ForAll(
                            x,
                            z3.Implies(
                                x >= 1,
                                history1(x) == z3.If(
                                    history2(x) <= history3(x), history2(x),
                                    history3(x)))))

            elif each[0] == "$":
                history1 = self.historyDict["h_%s" % (each[1])]
                history2 = self.historyDict["h_%s" % (each[2])]
                delay = z3.IntVal(int(each[3]))
                x = z3.Int("x")
                if self.bound > 0:
                    for i in range(1, self.bound + 2):
                        self.solver.add(
                            history1(i) == z3.If(
                                history2(i) >= delay,
                                history2(i) - delay, 0))
                    # self.solver.add(z3.ForAll(x, z3.Implies(
                    #     z3.And(x >= 1, x <= self.n + 1),
                    #     history1(x) == z3.If(history2(x) >= delay,history2(x) - delay,0))))
                else:
                    self.solver.add(
                        z3.ForAll(
                            x,
                            z3.Implies(
                                x >= 1,
                                history1(x) == z3.If(
                                    history2(x) >= delay,
                                    history2(x) - delay, 0))))

            elif each[0] == "on":
                tick1 = self.tickDict["t_%s" % (each[1])]
                tick2 = self.tickDict["t_%s" % (each[2])]
                tick3 = self.tickDict["t_%s" % (each[4])]
                history1 = self.historyDict["h_%s" % (each[1])]
                history2 = self.historyDict["h_%s" % (each[2])]
                history3 = self.historyDict["h_%s" % (each[4])]
                self.addTickStep(each[1])
                self.addTickStep(each[2])
                self.addTickStep(each[4])
                tickStep1 = self.tickStep["s_%s" % (each[1])]
                tickStep2 = self.tickStep["s_%s" % (each[2])]
                tickStep3 = self.tickStep["s_%s" % (each[4])]
                x = z3.Int("x")
                if self.bound > 0:
                    for i in range(1, int(each[3]) + 1):
                        self.solver.add(z3.Not(tick1(i)))
                    for i in range(int(each[3]) + 1, self.bound + 1):
                        t = []
                        for j in range(1, i - int(each[3]) + 1):
                            t.append(
                                z3.And(
                                    tick2(j),
                                    history3(i) - history3(j) == int(each[3])))
                        self.solver.add(z3.And(tick3(i), z3.Or(t)) == tick1(i))
                    self.solver.add(
                        z3.ForAll(
                            x,
                            z3.Implies(z3.And(x > 0, x <= self.n + 1),
                                       history2(x) >= history1(x))))
                    self.solver.add(
                        z3.ForAll(
                            x,
                            z3.Implies(z3.And(x > 0, x <= self.n, tick1(x)),
                                       tick3(x))))
                    # self.solver.add(
                    #     z3.ForAll(x, z3.Implies(
                    #         z3.And(x > 0, x <= history1(self.bound + 1)),
                    #         history3(tickStep2(x)) - history3(tickStep1(x)) == int(each[3])
                    # )))
                    # for i in range(self.bound + 1):
                    #     self.solver.add(history2(i) >= history1(i))
                    # for i in range(self.bound):
                    #     self.solver.add(
                    #         z3.Implies(
                    #             tick1(i), tick3(i)
                    #         )
                    #     )
                    # for i in range(self.bound + 1):
                    #     self.solver.add(
                    #         history3(tickStep1(i)) - history3(tickStep2(i)) == int(each[3])
                    #     )

                    # self.solver.add(z3.ForAll(x, z3.And(
                    #     z3.Implies(z3.And(x >= 1, x <= history1(self.bound + 1),tick2(x)),
                    #         tick1(tickStep3(history3(x) + int(each[3])))
                    #     ))))
                else:
                    self.solver.add(
                        z3.ForAll(
                            x,
                            z3.And(
                                z3.Implies(x >= 1,
                                           history2(x) >= history1(x)))))
                    self.solver.add(
                        z3.ForAll(
                            x,
                            z3.And(
                                z3.Implies(z3.And(x >= 1, tick1(x)),
                                           tick3(x)))))
                    self.solver.add(
                        z3.ForAll(
                            x,
                            z3.And(
                                z3.Implies(x >= 1, (history3(tickStep1(x)) -
                                                    history3(tickStep2(x))
                                                    == int(each[3]))))))
            elif each[0] == "∝":
                tick1 = self.tickDict["t_%s" % (each[1])]
                tick2 = self.tickDict["t_%s" % (each[2])]
                history1 = self.historyDict["h_%s" % (each[1])]
                history2 = self.historyDict["h_%s" % (each[2])]
                x = z3.Int("x")
                left = tick1(x)
                if is_number(each[3]):
                    k = z3.Int("k_%s" % (cnt))
                    self.solver.add(k >= 0, k < int(each[3]))
                    right = z3.And(tick2(x),
                                   history2(x) >= 0,
                                   (history2(x) + k) % z3.IntVal(each[3]) == 0)
                    cnt += 1
                    # right = z3.And(tick2(x), history2(x) > 0, (history2(x)) % z3.IntVal(each[3]) == 0)
                else:
                    period = z3.Int("%s" % each[3])
                    tmp = self.parameter[each[3]]
                    self.printParameter[each[3]] = period
                    k = z3.Int("k_%s" % (cnt))
                    self.solver.add(k >= 0, k < period)
                    right = z3.And(tick2(x),
                                   history2(x) >= 0,
                                   (history2(x) + k) % period == 0)
                    self.solver.add(period >= int(tmp[2]))
                    self.solver.add(period <= int(tmp[3]))
                    cnt += 1
                if self.bound > 0:
                    self.solver.add(
                        z3.ForAll(
                            x,
                            z3.And(
                                z3.Implies(z3.And(x >= 1, x <= self.n),
                                           left == right))))
                else:
                    self.solver.add(
                        z3.ForAll(x, z3.And(z3.Implies(x >= 1,
                                                       left == right))))

            elif each[0] == "☇":
                tick1 = self.tickDict["t_%s" % (each[1])]
                tick2 = self.tickDict["t_%s" % (each[2])]
                tick3 = self.tickDict["t_%s" % (each[3])]
                history1 = self.historyDict["h_%s" % (each[1])]
                history2 = self.historyDict["h_%s" % (each[2])]
                history3 = self.historyDict["h_%s" % (each[3])]
                self.addTickStep(each[1])
                self.addTickStep(each[3])
                tickStep1 = self.tickStep["s_%s" % (each[1])]
                tickStep3 = self.tickStep["s_%s" % (each[3])]
                x = z3.Int("x")
                if self.bound > 0:
                    self.solver.add(
                        z3.ForAll(
                            x,
                            z3.Implies(
                                z3.And(x >= 2, x <= history3(self.bound + 1)),
                                tick1(tickStep1(x)) == (
                                    history2(tickStep3(x)) -
                                    history2(tickStep3(x - 1)) >= 1))))
                else:
                    self.solver.add(
                        z3.ForAll(
                            x,
                            z3.Implies(
                                x >= 2,
                                z3.And(
                                    tick1(tickStep1(x)),
                                    history2(tickStep3(x)) -
                                    history2(tickStep3(x - 1)) >= 1))))

            elif each[0] == "==":
                tick1 = self.tickDict["t_%s" % (each[1])]
                tick2 = self.tickDict["t_%s" % (each[2])]
                x = z3.Int("x")
                if self.bound > 0:
                    self.solver.add(
                        z3.ForAll(
                            x,
                            z3.Implies(z3.And(x >= 1, x <= self.n),
                                       tick1(x) == tick2(x))))
                else:
                    self.solver.add(
                        z3.ForAll(x, z3.Implies(x >= 1,
                                                tick1(x) == tick2(x))))
            elif each[0] == "⋈±":
                tick1 = self.tickDict["t_%s" % (each[1])]
                tick2 = self.tickDict["t_%s" % (each[2])]
                history1 = self.historyDict["h_%s" % (each[1])]
                history2 = self.historyDict["h_%s" % (each[2])]
                self.addTickStep(each[1])
                self.addTickStep(each[2])
                tickStep1 = self.tickStep["s_%s" % (each[1])]
                tickStep2 = self.tickStep["s_%s" % (each[2])]

                lower = int(each[3]) - int(each[4])
                upper = int(each[3]) + int(each[4])
                x = z3.Int("x")
                if self.bound > 0:
                    self.solver.add(
                        z3.ForAll(
                            x,
                            z3.Implies(
                                z3.And(x >= 1, x <= self.bound + 1, tick1(x)),
                                history1(tickStep2(history2(x) + upper)) -
                                history1(
                                    tickStep2(history2(x) + lower)) == 1)))
                    self.solver.add(
                        z3.ForAll(
                            x,
                            z3.Implies(
                                z3.And(x >= 2, x <= history1(self.bound + 1)),
                                z3.And(
                                    (history2(tickStep1(x)) -
                                     history2(tickStep1(x - 1)) >= lower),
                                    (history2(tickStep1(x)) -
                                     history2(tickStep1(x - 1)) <= upper)))))
                else:
                    self.solver.add(
                        z3.ForAll(
                            x,
                            z3.Implies(
                                x >= 2,
                                z3.And(
                                    (history2(tickStep1(x)) -
                                     history2(tickStep1(x - 1)) >= lower),
                                    (history2(tickStep1(x)) -
                                     history2(tickStep1(x - 1)) <= upper)))))
示例#14
0
 def list_urls (user, channel, word):
     
     
     target = False
     number = False
     
     # Grab values from message.
     if len(word) == 1:
         target = user
     elif len(word) == 2:
         target = word[1] if not is_number(word[1]) else user
         number = word[1] if is_number(word[1]) else False
     elif len(word) >= 3:
         target = word[1]
         number = word[2]
     
     
     # Check if it's a URL or a number.
     if target.startswith("http://") or target.startswith("https://"):
         irc.msg(channel, "Did you mean to use -a {}?".format(target))
         return
     elif number and target.isdigit():
         irc.msg(channel, "Did you mean to use -re {} {}?".format(target, number))
         return
     
     
     # Check if an action string was misused.
     if target.startswith("-"):
         
         # Grab tuple containing string.
         commands = ()
         
         for str_list in syntax:
             if target in str_list:
                 commands = str_list
                 break
         
         if commands in syntax:
             line = syntax[commands].format(word[0], target)
             irc.msg(channel, "Syntax for {}: {}".format(target, line))
         else:
             irc.msg(channel, "{}: Unknown command.".format(user))
         
         return
     
     
     # Case insensitive check.
     for nick in url_dictionary:
         if target.lower() == nick.lower():
             target = nick
             break
     
     
     # Throw a message if the target isn't in the URL database.
     if target not in url_dictionary:
         err_msg = "You don't" if target == user else "{} doesn't".format(target)
         irc.msg(channel, "{} have any {} saved.".format(err_msg, dictionary_name))
         return
     
     
     # Check if the received number is a valid integer.
     if (not is_number(number)) or ((int(number) if number else 1) < 1):
         irc.msg(channel, "{}: Invalid number.".format(user))
         return
     
     
     # Finally gather results and display them.
     if number:
         # Turning number into a numeric value.
         number = int(number) - 1
         
         if number >= len(url_dictionary[target]):
             err_msg = "You don't" if target == user else "{} doesn't".format(target)
             irc.msg(channel, "{} have that many {}.".format(err_msg, dictionary_name))
         else:
             
             # Looking for NSFW URLs. (as indicated by '!')
             if "!" in url_dictionary[target][number]:
                 line = "[\x034NSFW\x0f] "
             else:
                 line = "[{}] ".format(number + 1)
             
             line += "{} [{}]".format(url_dictionary[target][number].strip("!"), target)
             irc.msg(channel, line)
     
     else:
         url_list = ["[{}] {}".format(ind+1, url) for ind, url in \
                             enumerate(url_dictionary[target])]
         
         # Looking for NSFW URLs. (as indicated by '!')
         url_list = map(nsfw_check, url_list)
         
         line = " ".join(url_list) + " [{}]".format(target)
         irc.msg(channel, line)
consamples = open("ContrastSamples.txt", encoding='utf-8').read()

#load user dict
jieba.load_userdict("all_dict.txt")

#use jieba to separate the words into sets
discut = set(jieba.lcut(dissamples))
concut = set(jieba.lcut(consamples))

#get disease features from set difference
res = discut.difference(concut)

result = set()
#remove numbers
for item in res:
    if tools.is_number(item):
        continue
    else:
        result.add(item)

print(result)

#use tf-idf
result = jieba.analyse.extract_tags(dissamples, 100)
print(result)

#vocabulary type tag
words = jieba.posseg.cut(dissamples)
for w in words:
    print(w.word, w.flag)