Demonstration of an ArcDiagram layout function with variably spaced nodes.
The alice.json
dataset is the first line from Lewis Carroll's
Alice in Wonderland, parsed with
the Stanford Parser.
def regenerator(gen): | |
for x in gen: | |
regen = (yield x) | |
while regen is not None: | |
yield None # send() also yields something, so don't pull from gen again | |
regen = (yield regen) | |
gen = (i for i in range(10)) | |
regen = regenerator(gen) | |
v = next(regen) # 0 |
Demonstration of an ArcDiagram layout function with variably spaced nodes.
The alice.json
dataset is the first line from Lewis Carroll's
Alice in Wonderland, parsed with
the Stanford Parser.
#!/bin/bash | |
if [ $# -ne 2 ]; then | |
echo 'usage: make-preference.sh PROFILE RESULT-ID' | |
exit 1 | |
fi | |
awk -F@ -v RES="$2" \ | |
'{ if($2 == RES) { printf("%d@-1@%d\n", $1, $2) } }' \ | |
< "$1"/result |
class AccumulationDict(dict): | |
def __init__(self, accumulator, *args, **kwargs): | |
if not hasattr(accumulator, '__call__'): | |
raise TypeError('Accumulator must be a binary function.') | |
self.accumulator = accumulator | |
self.accumulate(*args, **kwargs) | |
def __additem__(self, key, value): | |
if key in self: | |
self[key] = self.accumulator(self[key], value) |
#!/usr/bin/env python3 | |
# Copyright 2017 Michael Wayne Goodman <goodman.m.w@gmail.com> | |
# Licensed under the MIT license: https://opensource.org/licenses/MIT | |
import sys | |
import os | |
import gzip | |
import docopt |
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
# usage: python3 lark-parsimonious.py [TESTNUM] | |
# | |
# Where TESTNUM is one of: | |
# | |
# 1. Parsimonious with the faster grammar (tree-only) | |
# 2. Parsimonious with the faster grammar (transform data) | |
# 3. Parsimonious with the slower grammar (tree-only) |
#!/bin/bash | |
die() { echo "$1"; exit 1; } | |
usage() { | |
cat <<EOF | |
Usage: getargs [--help] [OPTION...] ARGUMENT... | |
Example usage of useful conventions for command-line argument parsing. |
def xpath_tokenizer(pattern, namespaces=None): | |
for token in xpath_tokenizer_re.findall(pattern): | |
tag = token[1] | |
if tag and tag[0] != "{" and ":" in tag: | |
try: | |
prefix, uri = tag.split(":", 1) | |
if not namespaces: | |
raise KeyError | |
yield token[0], "{%s}%s" % (namespaces[prefix], uri) | |
except KeyError: |
#!/bin/bash | |
ngram_count_file="$1" | |
lm_file="$2" | |
awk -v f="$ngram_count_file"\ | |
'function log10(x){ return log(x)/log(10.0) } | |
BEGIN { | |
while (getline < f) { | |
if(/[0-9]+\t[^ ]+$/) { type[1]++; token[1]=token[1]+$1 } |