# Path: linguistica/util.py
# def double_sorted(input_object, key=lambda x: x, reverse=False,
#                   subkey=lambda x: x, subreverse=False):
#     new_sorted_list = list()
#     sorted_list = sorted(input_object, key=key, reverse=reverse)
# 
#     for _, group in groupby(sorted_list, key=key):  # groupby from itertools
# 
#         # must use "list(group)", cannot use just "group"!
#         sublist = sorted(list(group), key=subkey, reverse=subreverse)
#         # see python 3.4 documentation:
#         # https://docs.python.org/3/library/itertools.html#itertools.groupby
#         # "The returned group is itself an iterator that shares the underlying
#         # iterable with groupby(). Because the source is shared, when the
#         # groupby() object is advanced, the previous group is no longer
#         # visible. So, if that data is needed later, it should be stored as a
#         # list"
# 
#         new_sorted_list.extend(sublist)
# 
#     return new_sorted_list


from collections import defaultdict
from scipy import (sparse, spatial)
from scipy.sparse import linalg
from linguistica.util import double_sorted
import numpy as np
import networkx as nx
# -*- encoding: utf8 -*-





def get_array(wordlist, bigram_to_freq, trigram_to_freq,
              min_context_count):
    worddict = {word: wordlist.index(word) for word in wordlist}

    # convert the bigram and trigram counter dicts into list and sort them
    # throw away bi/trigrams whose frequency is below min_context_count

    bigram_to_freq_sorted = [(bigram, freq) for bigram, freq in

# Path: linguistica/util.py
# def double_sorted(input_object, key=lambda x: x, reverse=False,
#                   subkey=lambda x: x, subreverse=False):
#     new_sorted_list = list()
#     sorted_list = sorted(input_object, key=key, reverse=reverse)
# 
#     for _, group in groupby(sorted_list, key=key):  # groupby from itertools
# 
#         # must use "list(group)", cannot use just "group"!
#         sublist = sorted(list(group), key=subkey, reverse=subreverse)
#         # see python 3.4 documentation:
#         # https://docs.python.org/3/library/itertools.html#itertools.groupby
#         # "The returned group is itself an iterator that shares the underlying
#         # iterable with groupby(). Because the source is shared, when the
#         # groupby() object is advanced, the previous group is no longer
#         # visible. So, if that data is needed later, it should be stored as a
#         # list"
# 
#         new_sorted_list.extend(sublist)
# 
#     return new_sorted_list


# Path: linguistica/manifold.py
from collections import defaultdict
from scipy import (sparse, spatial)
from scipy.sparse import linalg
from linguistica.util import double_sorted
import numpy as np
import networkx as nx

# -*- encoding: utf8 -*-





def get_array(wordlist, bigram_to_freq, trigram_to_freq,
              min_context_count):
    worddict = {word: wordlist.index(word) for word in wordlist}

    # convert the bigram and trigram counter dicts into list and sort them
    # throw away bi/trigrams whose frequency is below min_context_count

    bigram_to_freq_sorted = [(bigram, freq) for bigram, freq in

                             double_sorted(bigram_to_freq.items(),