Skip to content

Instantly share code, notes, and snippets.

@fergusq
fergusq / count_pairs.röd
Created July 18, 2017 17:53
Counts word pairs with a specified relation in conllu data. For example, if the relation is "dobj", the script finds all verb-direct object pairs and counts their occurances.
main(relation) {
lines := new map
replace("\\s+", " ") |
splitMany() | addTail(["0"]) |
for line do
continue if [ #line < 7 ]
if [ line[0] =~ "0|1" ] do
keys(lines) | [lines[_]] | for l if [ l[7] = relation ] do
push(lines[l[6]][2].."<-"..l[2])
done
@fergusq
fergusq / conllu2dot.röd
Created July 18, 2017 17:49
A script that transfers conllu files to dot files. It can be used to make graphs that represents sentences.
main {
print "digraph G {"
i := 0
filter {|a|[ #a > 0 ]} | split sep="\t" | try for n, word, base, type, form, _, ref, relation, _, _ do
i ++ if [ n = "1" ]
word ~= `\\`, `\\\\`, `"`, `\\"`
print "\t", `a${i}t$n [label="$word"];`
print "\t", `a${i}t$n -> a${i}t$ref [label="$relation"];`
done
print "}"
@fergusq
fergusq / wiktionary.röd
Last active June 11, 2017 20:34
A script for downloading category word lists from wiktionary
{ toRödaObj := require("json").jsonToRödaObj }
getadjs cat, token {
obj := toRödaObj(json([loadResourceLines("https://en.wiktionary.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:"..cat.."&cmlimit=500&format=json&cmcontinue="..token)]&" "))
for adj in obj["query"]["categorymembers"] do
STDOUT.push adj["title"], "\n"
done
return obj["continue"]["cmcontinue"] if [obj["continue"]?] else return ""
}
@fergusq
fergusq / index.html
Last active June 17, 2018 15:22
Radio Gem song generator
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>Radio Gem</title>
<meta name="description" content="Tekoälyn toimittama radiokanava." />
<meta content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no" name="viewport">
<style>
html {
box-sizing: border-box;
}
@fergusq
fergusq / liisabot.röd
Last active April 30, 2017 20:28
Liisabot IRC bot
{
irc := require("irc_client")
SERVER := "irc.freenode.net"
CHANNELS := ["#kissachann"]
}
urlencode text {
return [
chars(text) | for c do
push(c) if [ c =~ "(?i)[a-z.!'\\-]" ]
@fergusq
fergusq / commands.röd
Last active March 21, 2017 21:07
A script that turns a Röda interpreter to a command shell.
/* commands.röd */
/* by fergusq */
/*
* This does two things:
* - It creates a couple of functions for every command in $PATH.
* - It modifies the cd function to update the prompt to show the current working directory.
*
* Every command function name has this format: <in><out>'<name>
* <in> and <out> can both be zero or one letter long. <name> is the name of the command.
@fergusq
fergusq / roda.lang
Last active March 10, 2017 17:30
A gtksourceview-3.0 syntax highlighting file for Röda.
<language id="roda" _name="Röda" version="2.0" _section="Script">
<metadata>
<property name="mimetypes">text/x-roeda;application/x-roda</property>
<property name="globs">*.röd</property>
<property name="block-comment-start">/*</property>
<property name="block-comment-end">*/</property>
</metadata>
<styles>
<style id="comment" _name="Comment" map-to="def:comment"/>
my %objs = ();
while (<>) {
s/#.*//;
s/\s//g;
unless (/^$/) {
die "syntax error" unless (/^[0-9]+<(\+|-|>|\[[0-9]+|]|\.)*$/);
my ($name, $code) = split(/</);
$objs{$name} = [0, $code];
}
@fergusq
fergusq / dfi.röd
Created March 8, 2017 10:09
Deadfish i interpreter
main file {
readLines(file) | for line do
line ~= "#.*", "", "\\s+", ""
if [ line =~ "[0-9]+<(\\+|-|>|\\[[0-9]+|]|\\.)*" ] do
interpretDeclaration(line)
else
error("syntax error: ", line, "\n") unless [ line = "" ]
done
done
@fergusq
fergusq / el.html
Last active February 8, 2017 16:18
Pöytäkirjapalvelin
\define{\Alku{nimi}{aika}{paikka}{pvm}}{<html>
<head>
<title>\nimi</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
ol {
list-style-type: none;
counter-reset: item;
margin: 0;
padding: 0;