コード例 #1
0
ファイル: actions.py プロジェクト: bok/AI-with-Pyke
def ask_ref(universe, agent, other, situation, target):
    """An agent asks for the value of a fact."""
    them = universe.get(other)
    # Search the fact in their knowledge
    knowledge = get_facts(them.knowledge, 'know', other)
    values = get_facts(knowledge, situation, target)
    if len(values) != 1:
        raise(ValueError, "couldn't find the fact") 
    value = values[0]
    my_knowledge = ('know', agent, (situation, target, value))
    # Insert new goal in first position
    them.goals.insert(0, ('know', other, my_knowledge))
    them.satisfied = False
コード例 #2
0
ファイル: actions.py プロジェクト: bok/AI-with-Pyke
def inform_if(universe, agent, other, situation, target):
    """An agent responds to an ask_if."""
    me = universe.get(agent)
    them = universe.get(other)
    # Search the fact in the agent's knowledge
    knowledge = get_facts(me.knowledge, 'know', agent)
    this_fact = get_facts(knowledge, situation, target)
    if this_fact != []: 
        # I know about the fact:
        my_knowledge = ('knowif', agent, (situation, target))
        print '-+- %s informs %s that it knows about %s' \
            % (agent, other, (situation, target))
    else:
        # I don't know about the fact:
        my_knowledge = ('dontknow', agent, (situation, target))
        print '-+- %s informs %s that it doesn\'t know about %s' \
            % (agent, other, (situation, target))

    # Update knowledge of the two agents
    me.update_knowledge(('know', other, my_knowledge))
    them.update_knowledge(my_knowledge)
コード例 #3
0
def upload():
	import keras.backend.tensorflow_backend as tb
	tb._SYMBOLIC_SCOPE.value = True

	if request.method == 'POST':
		try:
			files = request.files.getlist('reports[]')
			subjects = request.form['subjects'].lower().strip()
			print(subjects)
			filenames = []
			for f in files:
				filename = secure_filename(f.filename)
				filenames.append(os.path.join(app.config['UPLOAD_FOLDER'], filename))
				f.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
			timestamped_facts = get_facts(files=filenames, num=len(filenames), subjects=subjects)

			final_list = []
			svo_list = []
			for date, facts_tuple in timestamped_facts.items():
				facts, svo = facts_tuple[0], facts_tuple[1]
				svo_list = []
				for f in svo:
					sub, verb, obj = f.split("|")
					if sub != "%":
						svo_list.append((sub, verb, obj))
				year, month, d = date.split("-")
				mnt = "January"
				if int(month) == 2:
					mnt = "February"
				elif int(month) == 3:
					mnt = "March"
				elif int(month) == 4:
					mnt = "April"
				elif int(month) == 5:
					mnt = "May"
				elif int(month) == 6:
					mnt = "June"
				elif int(month) == 7:
					mnt = "July"
				elif int(month) == 8:
					mnt = "August"
				elif int(month) == 9:
					mnt = "September"
				elif int(month) == 10:
					mnt = "October"
				elif int(month) == 11:
					mnt = "November"
				elif int(month) == 12:
					mnt = "December"
				cp_facts = facts
				results = label_sentences(cp_facts)
				pos = []
				neg = []
				for result in results:
					if result[1] == "POS":
						pos.append(result[0])
					elif result[1] == "NEG":
						neg.append(result[0])
					else:
						print(result[0])
				final_list.append(((year,mnt,d, month),pos,neg,svo_list))
			final_list = sorted(final_list,key=lambda x: (int(x[0][0]), int(x[0][3]),int(x[0][2])))

			return render_template("display_facts.html",display_data1=enumerate(final_list), display_data2=final_list)

		except Exception as e:
			traceback.print_exc()
			return str(e)