Skip to content

Instantly share code, notes, and snippets.

@fergusq
Created July 18, 2017 17:53
Show Gist options
  • Save fergusq/829f45f6b3a008ca43681f7793ef9120 to your computer and use it in GitHub Desktop.
Save fergusq/829f45f6b3a008ca43681f7793ef9120 to your computer and use it in GitHub Desktop.
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
done
lines = new map if [ line[0] = "1" ]
lines[line[0]] = line
done |
lowerCase(_) |
sort() |
unorderedCount() |
[[-_2, _1]] |
sort() |
print(`${-_1[0]} ${_1[1]}`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment