Skip to content

Instantly share code, notes, and snippets.

View interrogator's full-sized avatar

Daniel interrogator

  • UZH
  • Zurich, Switzerland
View GitHub Profile
@interrogator
interrogator / fline.py
Last active May 15, 2020 06:46
first line support
#!/usr/bin/env python
"""
Utility to generate a first-line support message for a user who has submitted a roundup issue.
To only ever be one-file to discourage feature creep for a small utility.
The only main extensions I'd really consider are automatically posting this message to roundup,
but I don't think this is a good idea, as you may need to generate a couple of messages till
an appropriate one is generated
{
"patterns": {
"P1": {
"expression": "(path):(line)"
},
"P2": {
"expression": "(path)\\s+(line)",
"path": "(?:\\/[\\w\\.\\-]+)+"
}
},
@interrogator
interrogator / thod
Last active December 11, 2019 21:16
jam renamer script
#!/usr/bin/env python3
# the thing above is called a shebang. it tells your shell what program to use
# to run this script. in this case, it says, this is python3. this makes it possible
# to run the script by typing `thod...`, rather than `python3 thod ...`
# the thing below is a module docstring. it's where you describe what the script
# is and how it works. it shows up if you do `thod --help`
"""
@interrogator
interrogator / download.py
Created May 24, 2019 22:06
Download texts about ptsd
#!/usr/bin/env python3
"""
Script to make a plain text corpus of PTSD narratives,
with a little bit of metadata.
"""
import os
import time
import requests
@interrogator
interrogator / tundra-api.sh
Last active June 29, 2017 09:23
Using TüNDRA API to get matches from given CONLL-U V2
# query a conll file
CONLLU2_FILE="/Users/danielmcdonald/Downloads/test.conllu"
QUERY="[pos=/V.*/]"
LANGUAGE="german"
API="https://weblicht.sfs.uni-tuebingen.de/tundra-beta/api/query/visres"
curl -X POST -F "file=@$CONLLU2_FILE" -F "query=$QUERY" -F "lang=$LANGUAGE" "$API" > api-test.json
# query a treebank
ID="UD_French"
QUERY="[pos=/V.*/]"

README is empty

@interrogator
interrogator / blog.md
Last active November 8, 2016 06:46
daniel's blog post

Halfway through my PhD candidature in linguistics at Melbourne Uni, I was introduced by Fiona to the ResPlat family. One of their aims, I was told, was to train researchers across the university in emerging tools and methods for doing better, more reproducible research. A specific target of this agenda was the Humanities and Social Sciences, who, let's admit, sometimes lag behind a little when it comes to engagement with digital tools and methods.

IMAGE OF RESPLAT http://67.media.tumblr.com/ede2ddf22557269fd92dd13c4b344c53/tumblr_inline_nk9gcyW6pE1ssbz72.jpg "ResPlat Family"

My thesis was about corpus linguistics—that is, using computers to locate patterns in large collections of written text. Because of this, Fiona asked me if I could come on board and help out, teaching Python to researchers around the university, but with extra focus on those from the humanities. A key issue among corpus linguists, however, is that many don't really know how to code. A more common w

@interrogator
interrogator / dendo.py
Last active June 7, 2016 12:05
dendogramming
%matplotlib notebook
import seaborn as sns
import numpy as np
from scipy.spatial.distance import pdist
from scipy.cluster.hierarchy import linkage, dendrogram
# pdist can be 'braycurtis', 'canberra', 'chebyshev', 'cityblock', 'correlation', 'cosine',
# 'dice', 'euclidean', 'hamming', 'jaccard', 'kulsinski', 'mahalanobis', 'matching',
#'minkowski', 'rogerstanimoto', 'russellrao', 'seuclidean', 'sokalmichener', 'sokalsneath', 'sqeuclidean', 'yule'
from corpkit import *
corpus = corpus('corpus_name')
langmod = corpus.make_language_model('modelname')
# score string
langmod.score('Check similarity for this text to each corpus')
# score file
corpus_file = corpus.subcorpora[5].files[1]
langmod.score(corpus_file)
@interrogator
interrogator / sorter.py
Created February 8, 2016 15:47
sort a list of numbers in one line
# a list of ints
l = [4, 2, 6, 7, 8, 1, 50, 23, 13, 55, 12, 3]
# one line to sort them!
[l.insert(ind, l.pop(l.index(min(l[ind:])))) for ind in range(len(l))]
# see?
print(l)
# elaborated code