This file contains hidden or 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
from tastypie.resources import ModelResource | |
from .models import TodoList, TodoItem | |
from tastypie.authentication import SessionAuthentication | |
class TodoListResource(ModelResource): | |
class Meta: | |
authentication = SessionAuthentication() | |
queryset = TodoList.objects.all() | |
resource_name = 'list' |
This file contains hidden or 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
from django.db import models | |
from django.contrib.auth.models import User | |
class TodoList(models.Model): | |
name = models.CharField('List Title', max_length=200) | |
author = models.ForeignKey(User, related_name='todo_lists') | |
def __unicode__(self): | |
return '"' + self.name + '" by ' + unicode(self.author) |
This file contains hidden or 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
from django.contrib import admin | |
from models import TodoItem, TodoList | |
class TodoItemAdmin(admin.ModelAdmin): | |
pass | |
class TodoListAdmin(admin.ModelAdmin): | |
pass |
This file contains hidden or 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
import string | |
import collections | |
from nltk import word_tokenize | |
from nltk.stem import PorterStemmer | |
from nltk.corpus import stopwords | |
from sklearn.cluster import KMeans | |
from sklearn.feature_extraction.text import TfidfVectorizer | |
from pprint import pprint |
This file contains hidden or 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
print Counter([generator_choice(gen()) for _ in range(100000)]) | |
# Counter({3: 33680, 1: 33280, 2: 33040}) |
This file contains hidden or 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
def generator_choice(g): | |
choice = None | |
for idx, item in enumerate(g): | |
if random.random() < 1.0/(idx + 1): | |
choice = item | |
return choice |
This file contains hidden or 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
def gen(): | |
yield 1 | |
yield 2 | |
yield 3 | |
print random.choice(gen()) |
This file contains hidden or 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
# Access Sentiwordnet Corpus | |
from nltk.corpus import wordnet as wn | |
from wnext import sentiwordnet | |
able = wn.synset('able.a.01') | |
print able.sentiment() | |
# (0.125, 0.0) | |
# Access eXtended WordNet Domains (XWND) | |
from wnext import wndomains | |
book = wn.synset('book.n.01') |
This file contains hidden or 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
# Access Sentiwordnet Corpus | |
from nltk.corpus import wordnet as wn | |
from wnext import sentiwordnet | |
able = wn.synset('able.a.01') | |
print able.sentiment() | |
# (0.125, 0.0) | |
# Access eXtended WordNet Domains (XWND) | |
from wnext import wndomains | |
book = wn.synset('book.n.01') |
This file contains hidden or 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
# Access Sentiwordnet Corpus | |
>>> from nltk.corpus import wordnet as wn | |
>>> from wnext import sentiwordnet | |
>>> able = wn.synset('able.a.01') | |
>>> print able.sentiment() | |
(0.125, 0.0) | |
# Access eXtended WordNet Domains (XWND) | |
>>> from wnext import wndomains | |
>>> book = wn.synset('book.n.01') |