Skip to content

Instantly share code, notes, and snippets.

import json
def load_json(path):
with open(path, encoding='utf-8') as f:
return json.load(f)
import gzip
import jsonlines # pip install jsonlines
def load_jsonlines(path):
    is_gzip = path[-2:] == 'gz'
    if is_gzip:
        with gzip.open(path, 'rb') as f:
            reader = jsonlines.Reader(f)
            for obj in reader:
                yield obj
from itertools import groupby
def groupby_(obj, key=None, to_lists=True):
sorted_ = sorted(obj, key=key)
grouped = groupby(sorted_, key)
if to_lists:
grouped = {k: list(g) for k, g in grouped}
return grouped
unique_theme_key = lambda mapping: (mapping['theme']['name']), mapping['theme']['group'])
@cyclecycle
cyclecycle / skeleton.js
Last active June 4, 2019 13:43
Modified version of skeleton.js generated by sqlite-to-rest that supports cross-origin requests
'use strict';
//---------//
// Imports //
//---------//
const Koa = require('koa')
, sqliteToRest = require('sqlite-to-rest')
, cors = require('@koa/cors');
@cyclecycle
cyclecycle / parse_tree_example.json
Created November 30, 2018 10:45
parse tree data structure example
{
"sent_i": 3,
"start_idx": 273,
"text": "Overstimulation of mTOR by its ligands, amino acids, sugars, and/or growth factors leads to physiological disorders, including cancer and neurodegenerative diseases",
"tokens": [
{
"dep_": "nsubj",
"dep_i": 12,
"i": 0,
"idx": 0,
match
$triggering_relationship (triggering: $triggering, triggered: $triggered) isa triggering-relationship;
$triggering has name "B. fragilis" has valence "UP";
$triggered has name "cancer" has valence "UP";
get
$triggering_relationship;
match
$triggering_relationship (triggering: $triggering, triggered: $triggered) isa triggering-relationship;
$triggered has name "reactive oxygen species" has valence "UP";
get
$triggering_relationship;
match
$triggering_relationship (triggering: $triggering, triggered: $triggered) isa triggering-relationship;
$triggering has name "B. fragilis" has valence "UP";
get
$triggering_relationship;
triggering-cascade sub rule
when {
$rel (triggering: $triggering, triggered: $triggered) isa triggering-relationship;
$rel2 (triggering: $triggered, triggered: $triggered2) isa triggering-relationship;
}
then {
(triggering: $triggering, triggered: $triggered2) isa triggering-relationship;
};
match
$triggering_relationship (triggering: $triggering, triggered: $triggered) isa triggering-relationship;
$triggering has name "B. fragilis";
$triggered has name "spermine oxidase";
get
$triggering_relationship;