Example #1
0
def create_question_words():
    query = Query()
    questions = query.questions
    stopwords = stopwordslist()
    for question in questions:
        cut_words = lcut(question)
        cut_words = filter(lambda s: s not in stopwords, cut_words)
        cut_words = list(cut_words)
        create_words_links(cut_words, label="问句")
Example #2
0
def contents2txt():
    query = Query()
    contents = query.questions
    print(contents)
    # contents = [','.join(content) for content in contents]
    txt = ','.join(contents)
    txt += ','.join(query.questions)
    with open('temp.txt', 'w', encoding='utf-8') as f:
        f.write(txt)
Example #3
0
def create_answer_words():
    query = Query()
    contents = query.contents
    stopwords = stopwordslist()
    for _ in contents:
        for content in _:
            cut_words = lcut(content)
            cut_words = filter(lambda s: s not in stopwords, cut_words)
            cut_words = list(cut_words)
            create_words_links(cut_words, label="答案")
Example #4
0
    def EntriesValidations_validationsTest(self):

        actual=ValidationFactory().newValidation("entries").validateWeight(None)
        expected=0.0
        self.assertEquals(actual,expected)
        actual=ValidationFactory().newValidation("entries").validateWeight(10.5)
        expected=10.5
        self.assertEquals(actual,expected)
        actual=ValidationFactory().newValidation("entries").validateVariance(None)
        expected=0.0
        self.assertEquals(actual,expected)
        actual=ValidationFactory().newValidation("entries").validateVariance(10.5)
        expected=10.5
        self.assertEquals(actual,expected)
        actual=ValidationFactory().newValidation("biometrics").validateTarget(None)
        expected=0.0
        self.assertEquals(actual,expected)
        actual=ValidationFactory().newValidation("biometrics").validateTarget(10.5)
        expected=10.5
        self.assertEquals(actual,expected)
        actual=ValidationFactory().newValidation("biometrics").validateHeight(None)
        expected=0.0
        self.assertEquals(actual,expected)
        actual=ValidationFactory().newValidation("biometrics").validateHeight(10)
        expected=10
        self.assertEquals(actual,expected)
        v=Validation()
        actual=v.getValidation()
        expected=0
        self.assertEquals(actual,expected)
        q=Query()
        actual=q.getQuery()
        expected=0
        self.assertEquals(actual,expected)
        actual=q.containsQueryType("test")
        expected=False
        self.assertEquals(actual,expected)
        self.assertRaises(ValueError,ValidationFactory().newValidation,('bio'))
        self.assertRaises(ValueError,QueryFactory().newQuery,('bio'))
Example #5
0
def test():
    results = Query.search(size=10000)['hits']['hits']

    worked_file = open('working/worked.csv', 'w')
    failed_file = open('working/failed.csv', 'w')
    worked_csv = UnicodeWriter(worked_file)
    failed_csv = UnicodeWriter(failed_file)
    worked=0
    failed=0

    for result in results:
        query_str = result['_source']['statement'].encode('utf-8', errors='replace')
        try:
            queryToParse.parseString(query_str)
            worked += 1
            worked_csv.writerow([result['_id'], result['_source']['statement']])
        except:
            failed += 1
            failed_csv.writerow([result['_id'], result['_source']['statement']])

    print "Total worked: " + str(worked)
    print "Total failed: " + str(failed)
Example #6
0
    "code": '0832',
    "k": 28
}, {
    "code": '09',
    "k": 74
}, {
    "code": '10',
    "k": 98
}, {
    "code": '11',
    "k": 14
}, {
    "code": '12',
    "k": 98
}]
a = Query(subject)


@app.route('/search', methods=['GET', 'POST'])
def index6():
    t = request.data
    if len(t) == 0:
        t = request.values['data']
    data = json.loads(t)
    text = data['keyword']
    if "filer" not in data:
        filer = {}
    else:
        filer = data['filer']
        if "school" in filer and "all" in filer["school"]:
            del filer["school"]
Example #7
0
import re

import sqlparse

from main import Query

ok = {'select':0, 'create':0, 'use':0, 'drop':0, 'desc':0,
	'show':0, 'set':0, 'insert':0, 'describe':0, 'from':0, 'alter':0}
extra={}
weirdness=[]

for statement in Query.search(size=10000)['hits']['hits']:
	if len(statement['_source']['statement'].strip()) == 0:
		break
	for query in sqlparse.parse(statement['_source']['statement'].strip()):
		if query.to_unicode():
			if query.to_unicode().lower()[:7] == 'select(':
				query = sqlparse.parse(
					re.sub(r'^select\(', 'SELECT (', query.to_unicode(), flags=re.IGNORECASE).strip())[0]
			elif query.to_unicode().strip() == ';':
				break
			try:
				keyword = query.token_next_by_type(0, sqlparse.tokens.Token.Keyword).to_unicode().lower()
				if keyword in ok.keys():
					ok[keyword]+=1
				else:
					weirdness.append(statement['_id'])
					if extra.has_key(query.tokens[0].to_unicode().lower()):
						extra[query.tokens[0].to_unicode().lower()] += 1
					else:
						extra[query.tokens[0].to_unicode().lower()] = 1
Example #8
0
    'select': 0,
    'create': 0,
    'use': 0,
    'drop': 0,
    'desc': 0,
    'show': 0,
    'set': 0,
    'insert': 0,
    'describe': 0,
    'from': 0,
    'alter': 0
}
extra = {}
weirdness = []

for statement in Query.search(size=10000)['hits']['hits']:
    if len(statement['_source']['statement'].strip()) == 0:
        break
    for query in sqlparse.parse(statement['_source']['statement'].strip()):
        if query.to_unicode():
            if query.to_unicode().lower()[:7] == 'select(':
                query = sqlparse.parse(
                    re.sub(r'^select\(',
                           'SELECT (',
                           query.to_unicode(),
                           flags=re.IGNORECASE).strip())[0]
            elif query.to_unicode().strip() == ';':
                break
            try:
                keyword = query.token_next_by_type(
                    0, sqlparse.tokens.Token.Keyword).to_unicode().lower()
@app.route('/obtain_answer')
def obtain_answer():
    question = request.args.get('question')
    answer = query.query(question)
    return answer


# 在网页端更新历史问题
@app.route('/update_history_answer')
def update_history_answer():
    history_question = get_history_question()
    answer = ""
    for question in history_question:
        answer += "<li><a href='javascript:void(0);' onclick='LinkChatSendClient(this.innerHTML)'>" + question + "</li>"
    return answer


# 在网页端更新常见问题
@app.route('/update_common_answer')
def update_common_answer():
    common_question = get_common__question()
    answer = ""
    for question in common_question:
        answer += "<li><h2><a href='javascript:void(0);' onclick='LinkChatSendClient(this.innerHTML)'>" + question + "</a></h2></li>"
    return answer


if __name__ == '__main__':
    query = Query()
    app.run(debug=False, host="127.0.0.1")