Skip to content

Instantly share code, notes, and snippets.

-- Example translated from
-- DATR: A language for lexical knowledge representation
-- Roger Evans and Gerald Gazdar (1996)
-- http://acl.ldc.upenn.edu/J/J96/J96-2002.pdf
type Atom = String
newtype Transducer =
Transducer (Transducer -- ^ context
-> [Atom] -- ^ input path
-> [Atom] -- ^ output path
@kowey
kowey / 0_before.py
Last active August 29, 2015 14:10
dubious cleanup (longer and solving a different problem)
import re
class State:
"""
Holds the resources and the buildups
"""
def __init__(self, state_chunk): #state_chunk is actually line.split("|")[4]
item_list = state_chunk.replace('|',',').split(",")
res_list = []
build_list = []
% year digits
#vars $yd1: 0 1 2 3 4 5 6 7 8 9 .
#vars $yd2: 0 1 2 3 4 5 6 7 8 9 .
#vars $yd3: 0 1 2 3 4 5 6 7 8 9 .
#vars $yd4: 0 1 2 3 4 5 6 7 8 9 .
#vars $d01: 0 1 .
#vars $d02: 0 1 2 .
#vars $d12: 1 2 .
#vars $d09: 0 1 2 3 4 5 6 7 8 9 .
main :- do_loop(10).
do_loop(N) :- N =< 0.
do_loop(N) :-
jpl_new('java.lang.Integer', [0], _),
%garbage_collect_atoms,
statistics(atoms, NumAtoms),
write(NumAtoms), nl,
Nm1 is N-1,
do_loop(Nm1).

Keybase proof

I hereby claim:

  • I am kowey on github.
  • I am kowey (https://keybase.io/kowey) on keybase.
  • I have a public key whose fingerprint is C2AA 42B7 D683 2C01 164B 17D6 054A CEC2 08AC 04F9

To claim this, I am signing this object:

% `Debug:<trace path...>` is meant to work as functionally
% a drop-in replacement for `path...`, except that it also
% prints it out to stderr.
% This can be useful if you want to avoid recomputing
% the local path (for example, if it's stateful and you want
% to avoid changing the meaning of the code)
'Debug'([trace|P], GN, GP, P) :- 'Debug'([writeline|P], GN, GP, []).
% `Debug:<writeline>` sends its output to stderr, so that you can
% avoid confusing it up with any actual output you may want to
main(L) :-
datr_query('TEST', [unwords|L], Vs),
foreach(member(V,Vs), write(V)),
nl,
halt.
# straightforward replacements
_PTB_MAPPING = {"``": "\"",
"''": "\"",
"-LRB-": "(",
"-RRB-": ")",
"-LSB-": "[",
"-RSB-": "]",
"-LCB-": "{",
"-RCB-": "}",
}
def add_fold_choice_args(psr):
"ability to select a subset of the data according to a fold"
fold_grp = psr.add_argument_group('fold selection')
fold_grp.add_argument("--fold-file", metavar="FILE",
type=argparse.FileType('r'),
help="read folds from this json file")
fold_grp.add_argument("--fold", metavar="INT",
type=int,
help="fold to select")
# pylint: disable=too-few-public-methods, redefined-builtin, invalid-name
class Torpor(object):
"""
Announce that we're about to do something, then do it,
then say we're done.
Usage: ::
with Torpor("doing a slow thing"):
some_slow_thing