Skip to content

Instantly share code, notes, and snippets.

View rmax's full-sized avatar
:octocat:
(⌐■_■) ♬

R Max Espinoza rmax

:octocat:
(⌐■_■) ♬
View GitHub Profile
@laserson
laserson / avrostreaming.py
Created February 11, 2014 18:55
Allow streaming of Avro data using the Python client. Simulates a seekable file type.
# The Python avro client expects a seekable Avro data file, which makes it annoying
# to stream bytes through it using HDFS clients that just give you cat (like snakebite).
# It's idiotic because the client only seeks to the end in order to call tell() to get
# the file size, which in turn is only used to determine when you get to EOF.
import snakebite.client
class AvroStreamWrapper(object):
# this class can be provided to DataFileReader to read Avro data.
def __init__(self, hdfs_client, path):
@mallamanis
mallamanis / texttilling.py
Created December 31, 2011 18:47
Text-tilling implementation with nltk
#!/usr/bin/env python
import nltk
from nltk.stem.porter import PorterStemmer
def preprocessText(text):
# To lower case
text = text.lower();
# Tokenize text
@rgaidot
rgaidot / gist:792451
Created January 23, 2011 21:24
Entity Extraction using NLTK
import nltk
text = """Barack Hussein Obama II (born August 4, 1961) is the 44th and current President of the United States. He is the first African American to hold the office. Obama previously served as a United States Senator from Illinois, from January 2005 until he resigned after his election to the presidency in November 2008."""
sentences = nltk.sent_tokenize(text)
tokenized_sentences = [nltk.word_tokenize(sentence) for sentence in sentences]
tagged_sentences = [nltk.pos_tag(sentence) for sentence in tokenized_sentences]
chunked_sentences = nltk.batch_ne_chunk(tagged_sentences, binary=True)
def extract_entity_names(t):