Esempio n. 1
0
def predict():

    sentence_data = get_text(request.data)
    line = sentence_data.decode(encoding='utf-8')
    line = line.strip()
    # while(True):
    #     line = input('请输入一句话:')
    formatError = check(line)
    predict_examples = processor.get_test_examples(line)
    features = convert_examples_to_features(predict_examples, label_list,
                                            FLAGS.max_seq_length, tokenizer)

    result = model.predict(features)
    for prediction in result:

        clss = np.argmax(prediction, axis=-1)[0]
        # print(882, clss)

        if clss in [2, 4, 7] and ',' in line:
            formatError.append({
                'pos': line.index(',') + 1,
                'info': category[clss]
            })
        if clss in [1, 3] and '、' in line:
            formatError.append({
                'pos': line.index('、') + 1,
                'info': category[clss]
            })
        if clss in [5, 6] and '。' in line:
            formatError.append({
                'pos': line.index('。') + 1,
                'info': category[clss]
            })

    return str(formatError)
Esempio n. 2
0
def main():
    #数据库参数
    conn = pyodbc.connect("DRIVER={SQL Server};SERVER=xxx.xxx.xxx.xxx;DATABASE=xxx;UID=sa;PWD=xxx;charset=utf8")
    #获取游标
    cur = conn.cursor()
    #连接数据库
    Check = check(conn,cur)
    #清洗数据
    Check.cleandata(cur)
    #查找chucuoUserID与出错金额
    Check.checkID(cur)
    #查找出错人员姓名
    Check.checkName(cur)
    conn.close() 
Esempio n. 3
0
    def login(self):
        try:
            chrome_login = webdriver.Chrome(
                executable_path='/Add_Data/chromedriver.exe')
            #此处需要更改
            chrome_login.implicitly_wait(10)
            chrome_login.get(self.url)
            chrome_login.find_element_by_xpath(
                '/html/body/div[2]/div/div[2]/div/div[2]/div/div/div/div/div[1]/input[@class="form-control input-lg input-flat"]'
            ).send_keys(phone_num)
            #密码
            chrome_login.find_element_by_xpath(
                '/html/body/div[2]/div/div[2]/div/div[2]/div/div/div/div/div[2]/input[@class="form-control input-lg input-flat"]'
            ).send_keys(phone_passwd)
            #点击登录'/html/body/div[2]/div/div[2]/div/div[2]/div/div/div/div/div[4]/a'
            chrome_login.find_element_by_xpath(
                '/html/body/div[2]/div/div[2]/div/div[2]/div/div/div/div/div[4]/a[@class="btn btn-primary btn-block btn-lg"]'
            ).click()

            #获取页面
            init_page = chrome_login.page_source
            ## 返回账号密码错误时,重新执行登陆操作
            chrome_login.close()
            self.login()
            ## 返回账号异常时,停止一段时间然后
            time.sleep(120)
            ## 验证码问题
            ## 点击 chrome_login.click()

            ### 此处要采用循环, 直到页面加载正常
            check_address = check(init_page)
            if check_address.type == 1:
                result_check = check_address.slide_check()
                #引用解决滑动验证的函数
            if check_address.type == 2:
                result_check = check_address.click_check()
                #引用解决点击验证的函数
            ## 1. 返回正常页面
            ## 2. 验证内容
        except WebDriverException as e:
            print(e)
            info_fail = 'fail'
            return info_fail
        finally:
            try:
                chrome_login.close()
            except Exception:
                info_none = 'weizhi'
                return info_none
Esempio n. 4
0
        except SyntaxError, syntax_error:
            dsl_syntax_error = DSLSyntaxError()

            dsl_syntax_error.args = syntax_error.args
            dsl_syntax_error.lineno = syntax_error.lineno
            dsl_syntax_error.msg = syntax_error.msg
            dsl_syntax_error.filename = syntax_error.filename
            dsl_syntax_error.message = syntax_error.message
            dsl_syntax_error.text = syntax_error.text
            dsl_syntax_error.offset = syntax_error.offset
            dsl_syntax_error.print_file_and_line = syntax_error.print_file_and_line
            
            dsl_syntax_error.understood_expression = cleaned_expression_string
            raise dsl_syntax_error
        else:
            if check(expression)():
                check_analysis_out = []
                def analysis_out(*things):
                    check_analysis_out.append("".join(map(str, things)))
                check_analysis(expression)(analysis_out)
                raise DSLTypeError(
                    "\n".join(check_analysis_out)
                )
            else:
                Build(expression)()
                return expression

from Units import (
    units,
    analysis
)
Esempio n. 5
0
def parse(expression_string):
    import re
    
    tokens = []
    out = tokens.append
    def out_all(*pieces):
        tokens.extend(pieces)
    
    def write_table_name(scanner, table_name):
        out(table_name)

    def allowed_identifier(scanner, token):
        out(token)
    
    def operator(scanner, token):
        if token == "^":
            out("**")
        else:
            out(token)

    def write_number(scanner, number):
        out(number)
    
    def number_with_units(scanner, token):
        number, units = token.split(None, 1)
        out_all("Number(", number, ",'", units, "')")
    
    def whitespace(scanner, token):
        out(token)

    def parenthesis(scanner, token):
        out(token)
    
    def comma(scanner, token):
        out(token)
    
    allowed_names = {}
    for name in (
        "Sum Average StandardDeviation Minimum Maximum Count "
        "Months FromDate ToDate Number".split()
    ):
        allowed_names[name] = globals()[name]
    for month_name in Months.options.keys():
        if not isinstance(month_name, int):
            allowed_names[month_name] = month_name
    scanner_spec = (
        (r"#.*?\n", whitespace),
        (r'"('+"|".join(SampleTable._SampleTable__names.keys())+')"', write_table_name),
        (r"(%s)(?=\W)" % "|".join(allowed_names.keys()), allowed_identifier),
        (r"\+|\-|\/|\*|\=|\^", operator),
        (r"\(|\)", parenthesis),
        (r",", comma),
        (r"\s+", whitespace),
        (
            r"-?[0-9]+(?:\.[0-9]+)?\s+(?:(?:delta|Δ)\s+)?(?: *(?:%(units)s)(?:\^[0-9])?)* *(?:\/(?: *(?:%(units)s)(?:\^[0-9])?)*)?" % dict(
                units = "|".join(units_in_out.keys())
            ),
            number_with_units
        ),
        (r"-?[0-9]*(\.[0-9]+)?", write_number),
    )
    scanner = re.Scanner(scanner_spec)
    #print scanner_spec
    #print expression_string
    _, remainder = scanner.scan(expression_string)

    if remainder:
        raise SyntaxError(
            "Syntax error near: '"+("".join(remainder))+"'"
        )
    else:
        cleaned_expression_string = "("+("".join(tokens))+")"
        #print cleaned_expression_string
        expression = eval(
            cleaned_expression_string,
            allowed_names
        )
        if check(expression):
            check_analysis_out = []
            def analysis_out(*things):
                check_analysis_out.append("".join(map(str, things)))
            check_analysis(expression, analysis_out)
            raise TypeError(
                "\n".join(check_analysis_out)
            )
        else:
            Build(expression)
            return expression
def go():
    import face_recognition
    import cv2
    import time
    import numpy as np
    from logfile import timee
    from Check import check
    from outtime import timeout
    import datetime
    x = str(datetime.datetime.now())
    date = (x.split(" ", )[0])
    video_capture = cv2.VideoCapture(0)
    employee_face = ["obama.jpg", "harsh.jpg"]
    obama_image = face_recognition.load_image_file(employee_face[0])
    obama_face_encoding = face_recognition.face_encodings(obama_image)[0]
    harsh_image = face_recognition.load_image_file(employee_face[1])
    harsh_face_encoding = face_recognition.face_encodings(harsh_image)[0]
    known_face_encodings = [obama_face_encoding, harsh_face_encoding]
    known_face_names = ["Barack Obama", "harsh"]
    face = []
    face_locations = []
    face_encodings = []
    face_names = []
    process_this_frame = True

    while True:
        ret, frame = video_capture.read()
        small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
        rgb_small_frame = small_frame[:, :, ::-1]
        if process_this_frame:
            # Find all the faces and face encodings in the current frame of video
            face_locations = face_recognition.face_locations(rgb_small_frame)
            face_encodings = face_recognition.face_encodings(
                rgb_small_frame, face_locations)

            face_names = []
            for face_encoding in face_encodings:
                # See if the face is a match for the known face(s)
                matches = face_recognition.compare_faces(
                    known_face_encodings, face_encoding)
                name = "Unknown"

                # # If a match was found in known_face_encodings, just use the first one.
                # if True in matches:
                #     first_match_index = matches.index(True)
                #     name = known_face_names[first_match_index]
                # Or instead, use the known face with the smallest distance to the new face
                face_distances = face_recognition.face_distance(
                    known_face_encodings, face_encoding)
                best_match_index = np.argmin(face_distances)
                if matches[best_match_index]:
                    name = known_face_names[best_match_index]

                face_names.append(name)

        process_this_frame = not process_this_frame

        # Display the results
        for (top, right, bottom, left), name in zip(face_locations,
                                                    face_names):
            # Scale back up face locations since the frame we detected in was scaled to 1/4 size
            top *= 4
            right *= 4
            bottom *= 4
            left *= 4

            # Draw a box around the face
            cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)

            # Draw a label with a name below the face
            cv2.rectangle(frame, (left, bottom - 35), (right, bottom),
                          (0, 0, 255), cv2.FILLED)
            font = cv2.FONT_HERSHEY_DUPLEX
            cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0,
                        (255, 255, 255), 1)

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

        # dict1 = {"harsh":"12421","raj":"84511","santosh":"45132"}
        # for key,values in dict1:
        #     if(key in name == [""])

        if (name != "Unknown"):
            # timee(name)
            # face.append(name)
            # cv2.imshow('Video', frame)
            # cv2.waitKey(4000)
            # if name in face:
            #     timeout(name)
            #     face.clear()
            # else:
            #check(name,date)

            # video_capture.release()
            # time.sleep(7)
            # video_capture = cv2.VideoCapture(0)

            if (check(name, date) == True):
                timeout(name)
                cv2.imshow('Video', frame)
                cv2.waitKey(4000)

            exit()
            break
            video_capture.release()
            cv2.destroyAllWindows()

    # start from here
    # to recognise the face for timeout

    # import sqlite3
    # conn = sqlite3.connect('logfile.db')
    # cursor = conn.execute("SELECT DATE,NAME from names")
    # for row in cursor:
    #     if(row[0] == date and row[1] == name):
    #         timeout(name)

    video_capture.release()
    cv2.destroyAllWindows()
Esempio n. 7
0
from Check import check
random_que = [
    "Rock | Paper | Scissor ? \n", "Rock | Paper | Scissor ? \n",
    "Rock | Paper | Scissor ? \n"
]

random_check = [
    check(random_que[0], 'scissor'),
    check(random_que[1], 'rock'),
    check(random_que[2], 'paper')
]


def run_game(random_check):
    score = 0
    for check in random_check:
        answer = input(check.prompt)
        if answer == check.choose:
            score += 1
            print('Matched!\n')
        else:
            print('Not Matched!\n')

    winorlose = int(len(random_check)) / 2
    if winorlose < int(score):
        print("Congrates! You Won.  (Your score is " + str(score) +
              " out of " + str(len(random_check)) + ')')
    else:
        print("Bad Luck! You lost.  (Your score is " + str(score) +
              " out of " + str(len(random_check)) + ')')
Esempio n. 8
0
        except SyntaxError, syntax_error:
            dsl_syntax_error = DSLSyntaxError()

            dsl_syntax_error.args = syntax_error.args
            dsl_syntax_error.lineno = syntax_error.lineno
            dsl_syntax_error.msg = syntax_error.msg
            dsl_syntax_error.filename = syntax_error.filename
            dsl_syntax_error.message = syntax_error.message
            dsl_syntax_error.text = syntax_error.text
            dsl_syntax_error.offset = syntax_error.offset
            dsl_syntax_error.print_file_and_line = syntax_error.print_file_and_line

            dsl_syntax_error.understood_expression = cleaned_expression_string
            raise dsl_syntax_error
        else:
            if check(expression):
                check_analysis_out = []

                def analysis_out(*things):
                    check_analysis_out.append("".join(map(str, things)))

                check_analysis(expression, analysis_out)
                raise DSLTypeError("\n".join(check_analysis_out))
            else:
                Build(expression)
                return expression


from Units import (Units, units, analysis, WhateverUnitsAreNeeded,
                   MeaninglessUnitsException, DimensionError)
from Check import check, check_analysis
Esempio n. 9
0
def parse(expression_string):
    import re

    tokens = []
    out = tokens.append

    def out_all(*pieces):
        tokens.extend(pieces)

    def write_table_name(scanner, table_name):
        out(table_name)

    def allowed_identifier(scanner, token):
        out(token)

    def operator(scanner, token):
        if token == "^":
            out("**")
        else:
            out(token)

    def write_number(scanner, number):
        out(number)

    def number_with_units(scanner, token):
        number, units = token.split(None, 1)
        out_all("Number(", number, ",'", units, "')")

    def whitespace(scanner, token):
        out(token)

    def parenthesis(scanner, token):
        out(token)

    def comma(scanner, token):
        out(token)

    allowed_names = {}
    for name in ("Sum Average StandardDeviation Minimum Maximum Count "
                 "Months FromDate ToDate Number".split()):
        allowed_names[name] = globals()[name]
    for month_name in Months.options.keys():
        if not isinstance(month_name, int):
            allowed_names[month_name] = month_name
    scanner_spec = (
        (r"#.*?\n", whitespace),
        (r'"(' + "|".join(SampleTable._SampleTable__names.keys()) + ')"',
         write_table_name),
        (r"(%s)(?=\W)" % "|".join(allowed_names.keys()), allowed_identifier),
        (r"\+|\-|\/|\*|\=|\^", operator),
        (r"\(|\)", parenthesis),
        (r",", comma),
        (r"\s+", whitespace),
        (r"-?[0-9]+(?:\.[0-9]+)?\s+(?:(?:delta|Δ)\s+)?(?: *(?:%(units)s)(?:\^[0-9])?)* *(?:\/(?: *(?:%(units)s)(?:\^[0-9])?)*)?"
         % dict(units="|".join(units_in_out.keys())), number_with_units),
        (r"-?[0-9]*(\.[0-9]+)?", write_number),
    )
    scanner = re.Scanner(scanner_spec)
    #print scanner_spec
    #print expression_string
    _, remainder = scanner.scan(expression_string)

    if remainder:
        raise SyntaxError("Syntax error near: '" + ("".join(remainder)) + "'")
    else:
        cleaned_expression_string = "(" + ("".join(tokens)) + ")"
        #print cleaned_expression_string
        expression = eval(cleaned_expression_string, allowed_names)
        if check(expression):
            check_analysis_out = []

            def analysis_out(*things):
                check_analysis_out.append("".join(map(str, things)))

            check_analysis(expression, analysis_out)
            raise TypeError("\n".join(check_analysis_out))
        else:
            Build(expression)
            return expression