import codecs


def read_wordpairs(wordpair_path, format="google"):
	"""
	Read wordpair file with wordpairs and their similarity scores assigned by humans.

	Args:
		wordpair_path (str): Path to word pair file.
		format (str): Format of wor pair file {google|semrel}

	Returns:
		tuple: Tuple of a list of word pairs and a list of similarity scores for those same pair assigned by humans.
	"""
	pairs, x = [], []
	with codecs.open(wordpair_path, "rb", "utf-8") as wordpair_file:
		if format == "google":
			for line in wordpair_file:
				line_parts = line.strip().split()
				word_pair = line_parts[0].split("-")
				pairs.append((word_pair[0], word_pair[1]))
				x.append(float(line_parts[1]))
		elif format == "semrel":
			for line in wordpair_file:
				if line.startswith('#'):
					continue
				line_parts = line.strip().split(":")
				pairs.append((line_parts[0], line_parts[1]))
				x.append(float(line_parts[2]))
	return pairs, x