Skip to content

Instantly share code, notes, and snippets.

View benui-dev's full-sized avatar
🌱

benui benui-dev

🌱
View GitHub Profile
@benui-dev
benui-dev / gist:2981095
Created June 24, 2012 02:15
Löve2d code for loading and drawing a tetured polygon
function love.load()
-- Load our repeating texture
local img = love.graphics.newImage("dirt.png")
-- Points for our polygon
local vertices = {12,0, 396,7, 500,375, 195,520, 78,377}
texturedPoly = newTexturedPoly(vertices, img)
end
@benui-dev
benui-dev / knp_file.pl
Created April 9, 2012 06:29
Reading KNP data from a file
# Iterate through pre-parsed KNP output stored in a file. Useful for processing a batch of
# sentences offline, and then dealing with them later.
use strict;
use warnings;
use KNP::File;
# File is the result of "juman | knp -tab > knp.out"
my $knp_file = new KNP::File( file => $ARGV[0], encoding => 'utf-8' )
or die "Couldn't make KNP from file $!";
from mwlib.refine import compat
raw = """
=Sup=
Je suis le voyageur dans le baked beans.
"""
parsed = compat.parse_txt(raw)
@benui-dev
benui-dev / parse_raw_wiki.py
Created February 1, 2012 01:57
Parse wiki markup with mwlib
from mwlib.refine import compat,core
from mwlib.parser import nodes
import pprint
def main():
pp = pprint.PrettyPrinter(indent=2)
raw = """
=Cake=
Modern cake, especially layer cakes, normally contain a
@benui-dev
benui-dev / dict.xml
Created January 25, 2012 06:57
Sample from JEdict
<entry>
<ent_seq>1000220</ent_seq>
<k_ele>
<keb>明白</keb>
<ke_pri>ichi1</ke_pri>
<ke_pri>news1</ke_pri>
<ke_pri>nf10</ke_pri>
</k_ele>
<r_ele>
<reb>めいはく</reb>
@benui-dev
benui-dev / edict.pl
Created January 25, 2012 06:55
Simple example of how to parse Edict XML file with Perl and XML::LibXML
#!/usr/local/bin/perl
use strict;
use warnings;
use XML::LibXML;
use encoding "utf-8";
my $file = $ARGV[0];
my $parser = XML::LibXML->new();
my $doc = $parser->parse_file($file);
@benui-dev
benui-dev / print_tree.py
Created January 20, 2012 00:38
Print the entire tree of a Wiki article using mwlib
# Print the entire tree of a Wiki article using mwlib
from mwlib import wiki
from mwlib.parser import nodes
def print_tree(node, indent):
tabs = indent * " "
print tabs + node.__class__.__name__
indent += 1
for child in node.children:
print_tree(child, indent)
from mwlib import wiki
from mwlib.parser import nodes
env = wiki.makewiki('/home/ben/wiki/simple/wikiconf.txt') # wiki Environment object
a = env.wiki.getParsedArticle('cheese')
for child in a.allchildren():
if isinstance(child, nodes.Section): # Yay global function
print "Section title: " + child.children[0].asText()
if isinstance(child, nodes.LangLink):
<?xml version="1.0"?>
<root>
<list>
<item>
<name>Magical stuff</name>
<identifier>private.magical</identifier>
<!-- Need this explicitly, otherwise the forward delete thing doesn't work -->
<autogen>
--KeyToKey--
KeyCode::SEMICOLON, ModifierFlag::NONE,
@benui-dev
benui-dev / gist:1402976
Created November 29, 2011 01:45
example data
{ "NICT-ATR" : { "A" : { "adequacy" : 3, "fluency" : 4 }, "B" : { "adequacy" : 3, "fluency" : 3 }, "C" : { "adequacy" : 4, "fluency" : 2 }, "output" : "図12を参照して、本発明の第三実施例に説明説明次に、。" }, "NTT" : { "A" : { "adequacy" : 5, "fluency" : 5 }, "B" : { "adequacy" : 5, "fluency" : 5 }, "C" : { "adequacy" : 5, "fluency" : 5 }, "output" : "次に、 図 12 を参照して、 本発明の第 3 の実施例について説明する。" }, "_id" : { "$oid" : "4ed3428a7f7130fdf093a41d" }, "english" : "Next, explanation will be given on a third embodiment of the present invention, by referring to FIG. 12.", "id" : "20000523-155948-EMBODIMENTS-73", "kuro" : { "A" : { "adequacy" : 5, "fluency" : 5 }, "B" : { "adequacy" : 5, "fluency" : 5 }, "C" : { "adequacy" : 5, "fluency" : 5 }, "output" : "次に、本発明の第3の実施例について12図である参照して説明する。" }, "moses" : { "A" : { "adequacy" : 5, "fluency" : 5 }, "B" : { "adequacy" : 5, "fluency" : 5 }, "C" : { "adequacy" : 5, "fluency" : 5 }, "output" : "次に 、 図 12 を 参照 し て 、 本 発明 の 第 3 実施 例 について 説明 する 。 " }, "ref" : "次に、本発明の第3実施例を図12用いて説明する。", "tsbmt" : { "A" : { "a