Created
July 18, 2017 17:53
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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