import collections
import csv


def read_dataset(dataset_path):
	"""
	Returns a tuple of three dicts. The gloss data is a {gloss: [[lang, trans,
	segments, cog_class],]} dict. The concepticon data is a {gloss: global_id}
	dict. The ISO codes data is a {lang: iso_code} dict.
	"""
	data = collections.defaultdict(list)
	gloss_ids = {}
	iso_codes = {}
	
	with open(dataset_path, newline='', encoding='utf-8') as f:
		reader = csv.DictReader(f, delimiter='\t')
		for row in reader:
			li = [
				row['language'], row['transcription'],
				row['tokens'], row['cognate_class']]
			
			if li not in data[row['gloss']]:
				data[row['gloss']].append(li)
			
			gloss_ids[row['gloss']] = row['global_id']
			iso_codes[row['language']] = row['iso_code']
	
	return dict(data), gloss_ids, iso_codes