Пример #1
0
def segment_words():
  """
  Using the final list of affixes, segment the words using a longest
  match approach, where you segment based on the longest occuring morpheme
  in the word.
  """
  global CUTS
  global CORRECT_CUTS
  global TRUE_BOUNDARIES
  #build the chunks
  for word in STANDARD:
    affixes = trim_affixes([x for x in AFFIXES if x.strip(dash) in word])
    segments = splits(word, affixes)    
    a,b,c = metrics(' '.join(segments), STANDARD[word])
    CUTS += b
    CORRECT_CUTS += a
    TRUE_BOUNDARIES += c
Пример #2
0
def predecessor_segmentor():
  """
  User our global list of test words and segment them basing on predecessor
  counts that exist within the trie RTRIE that we have globally 
  instantiated.
  """
  global CUTS
  global CORRECT_CUTS
  global TRUE_BOUNDARIES

  #initialize
  CUTS, CORRECT_CUTS, TRUE_BOUNDARIES = (0,0,0)
  correct = 0 #number of correct annotations
  
  for word in WORDS:
    a,b,c = metrics(segment_word(word, reverse=True), WORDS[word])
    CUTS += b
    CORRECT_CUTS += a
    TRUE_BOUNDARIES += c
Пример #3
0
def generate_states_from_rule_and_seed(
    f_name=None,
    rule=None,
    seed=[],
    scale_num=None,
    scale_type="maj",
    states=[],
    steps=DEFAULT_SEQUENCE_STEPS,
    sampler_name=None,
    debug=False,
    save_png=False,
    save_json=False,
    save_midi=False,
    beat_duration=DEFAULT_BEAT_DURATION,
    dont_ignore_odd=False,
):
    sc_num = scale_num
    sc_type = scale_type

    if len(seed):
        width = len(seed)
    else:
        width = 128

    scale = get_scale(scale_num, scale_type, debug)

    if not len(seed):
        # Start from a default seed with 1 activated bit
        seed = DEFAULT_SEED

    k = rule["k"]
    a = np.array(rule["rule"])

    # THIS IS SUPER IMPORTANT TO GETTING GOOD RESULTS.  It prevents [0,0,0] -> 1 transitions which clutter up CA
    # Flip final bit
    if not dont_ignore_odd:
        a[-1] = 0

    k_states = np.array(list(map(np.int64, rule["k_states"])))

    # generate rule from k_states / mask
    r_set = k_states[a.astype(bool)]

    r = lambda x, k: eca(x, k, r_set)

    states = run(steps, seed=seed, kernel=k, f=r)

    # apply a sampling filter to the states.
    if sampler_name:
        sampler = getattr(sampling, sampler_name)
        states = sampler(states)

    # TODO: add a conditional flag for image generation
    if save_png:
        f_name_img = f_name + ".tendril.png"
        image_from_states(states, f_name_img)
    if debug:
        print_states(states[0:10])
    mets = metrics(states)

    # g(states, steps, beat_duration)
    if sc_num != None:
        g = lambda x, y, z: generate_pianoroll(x, y, z, scale[0:width])
    else:
        g = lambda x, y, z: generate_pianoroll(x, y, z, CHROMATIC_SCALE[0:width
                                                                        ])

    if save_json or save_midi:
        write_files_from_states(
            states,
            mets,
            seed,
            [],
            f_name,
            g=g,
            save_json=save_json,
            save_midi=save_midi,
            debug=debug,
            beat_duration=beat_duration,
            steps=steps,
        )
    return
Пример #4
0
def calculate_elos():
    process.processYears(start_year, end_year)
    stats.metrics()
    stats.mean()