예제 #1
0
파일: sequence.py 프로젝트: jworr/ml_tools
def readRelationSequences(conn, datasetId):
	"""
	Reads a list of relational seqences from the database with the given dataset id

	Outputs sequences of predicate((arg1, type), (arg2, type), ...)
	"""
	def groupArgs(sequence):
		"""
		Add book ends since those have no arguments
		"""
		#TODO some predicates besides the beginning and ending symbols could have no args
		return [[]] + groupUp(sequence, itemgetter(1)) + [[]]

	def joinSeq(itemSeq, argSeq):
		"""
		Return list of tuples
		"""
		return [tuple([item] + zip(third(args), fourth(args))) for item, args 
			in zip(itemSeq, groupArgs(argSeq))]

	#read sequences
	seqs = readSequences(conn, datasetId)

	#read the arguments to the items
	args = conn.execute("""select sequence_id, sindex, value, type
	from argument where ds_id = ? 
	order by sequence_id, sindex, arg_index;""", [datasetId]).fetchall()

	#group up args according to sequence item they correspond to
	return [joinSeq(seq, argSeq) 
		for seq, argSeq in zip(seqs, groupUp(args, itemgetter(0)))]
예제 #2
0
파일: sequence.py 프로젝트: jworr/ml_tools
def readSequences(conn, datasetId):
	"""
	Reads the sequences associtated with the given data set id
	"""
	pointer = conn.execute("""select sequence_id, value 
	from item where ds_id = ?
	order by sequence_id, sindex""", [datasetId]).fetchall()

	#group up the items into sequences
	return [second(seq) for seq in groupUp(pointer, itemgetter(0))]
예제 #3
0
파일: sequence.py 프로젝트: jworr/ml_tools
	def groupArgs(sequence):
		"""
		Add book ends since those have no arguments
		"""
		#TODO some predicates besides the beginning and ending symbols could have no args
		return [[]] + groupUp(sequence, itemgetter(1)) + [[]]