repo_full_name stringlengths 6 93 | repo_url stringlengths 25 112 | repo_api_url stringclasses 28
values | owner stringclasses 28
values | repo_name stringclasses 28
values | description stringclasses 28
values | stars int64 617 98.8k | forks int64 31 355 ⌀ | watchers int64 990 999 ⌀ | license stringclasses 2
values | default_branch stringclasses 2
values | repo_created_at timestamp[s]date 2012-07-24 23:12:50 2025-06-16 08:07:28 ⌀ | repo_updated_at timestamp[s]date 2026-02-23 15:23:15 2026-05-03 18:52:12 ⌀ | repo_topics listlengths 0 13 ⌀ | repo_languages unknown | is_fork bool 1
class | open_issues int64 3 104 ⌀ | file_path stringlengths 3 208 | file_name stringclasses 509
values | file_extension stringclasses 1
value | file_size_bytes int64 101 84k ⌀ | file_url stringclasses 627
values | file_raw_url stringclasses 627
values | file_sha stringclasses 624
values | language stringclasses 8
values | parsed_at stringdate 2026-05-04 01:12:36 2026-05-04 19:41:55 | text stringlengths 100 102k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
shidenggui/easytrader | https://github.com/shidenggui/easytrader | null | null | null | null | 9,677 | null | null | mit | null | null | null | null | null | null | null | tests/test_xqtrader.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:34.507919 | # coding: utf-8
import unittest
from easytrader.xqtrader import XueQiuTrader
class TestXueQiuTrader(unittest.TestCase):
def test_prepare_account(self):
user = XueQiuTrader()
params_without_cookies = dict(
portfolio_code="ZH123456", portfolio_market="cn"
)
with self.ass... |
shidenggui/easytrader | https://github.com/shidenggui/easytrader | null | null | null | null | 9,677 | null | null | mit | null | null | null | null | null | null | null | setup.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:34.620598 | # coding:utf8
from setuptools import setup
setup(
name="easytrader",
version="0.23.7",
description="A utility for China Stock Trade",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
author="shidenggui",
author_email="longlyshidenggui@gma... |
shidenggui/easytrader | https://github.com/shidenggui/easytrader | null | null | null | null | 9,677 | null | null | mit | null | null | null | null | null | null | null | tests/test_easytrader.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:34.621666 | # coding: utf-8
import os
import sys
import time
import unittest
sys.path.append(".")
TEST_CLIENTS = set(os.environ.get("EZ_TEST_CLIENTS", "").split(","))
IS_WIN_PLATFORM = sys.platform != "darwin"
@unittest.skipUnless("yh" in TEST_CLIENTS and IS_WIN_PLATFORM, "skip yh test")
class TestYhClientTrader(unittest.Test... |
shidenggui/easytrader | https://github.com/shidenggui/easytrader | null | null | null | null | 9,677 | null | null | mit | null | null | null | null | null | null | null | tests/test_xq_follower.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:34.803413 | # coding:utf-8
import datetime
import os
import time
import unittest
from unittest import mock
from easytrader.xq_follower import XueQiuFollower
class TestXueQiuTrader(unittest.TestCase):
def test_adjust_sell_amount_without_enable(self):
follower = XueQiuFollower()
mock_user = mock.MagicMock()
... |
shidenggui/easytrader | https://github.com/shidenggui/easytrader | null | null | null | null | 9,677 | null | null | mit | null | null | null | null | null | null | null | easytrader/xqtrader.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:34.833907 | # -*- coding: utf-8 -*-
import json
import numbers
import os
import re
import time
import math
import requests
from easytrader import exceptions, webtrader
from easytrader.log import logger
from easytrader.utils.misc import parse_cookies_str
class XueQiuTrader(webtrader.WebTrader):
config_path =... |
iam-veeramalla/Jenkins-Zero-To-Hero | https://github.com/iam-veeramalla/Jenkins-Zero-To-Hero | null | null | null | null | 9,670 | null | null | mit | null | null | null | null | null | null | null | python-jenkins-argocd-k8s/todoApp/wsgi.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:38.479847 | """
WSGI config for todoApp project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTI... |
iam-veeramalla/Jenkins-Zero-To-Hero | https://github.com/iam-veeramalla/Jenkins-Zero-To-Hero | null | null | null | null | 9,670 | null | null | mit | null | null | null | null | null | null | null | python-jenkins-argocd-k8s/todoApp/urls.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:38.503107 | """todoApp URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based... |
iam-veeramalla/Jenkins-Zero-To-Hero | https://github.com/iam-veeramalla/Jenkins-Zero-To-Hero | null | null | null | null | 9,670 | null | null | mit | null | null | null | null | null | null | null | python-jenkins-argocd-k8s/manage.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:38.509372 | #!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'todoApp.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise Import... |
iam-veeramalla/Jenkins-Zero-To-Hero | https://github.com/iam-veeramalla/Jenkins-Zero-To-Hero | null | null | null | null | 9,670 | null | null | mit | null | null | null | null | null | null | null | python-jenkins-argocd-k8s/todos/models.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:39.143875 | from django.db import models
class Todo(models.Model):
title = models.CharField(max_length=100)
created_at = models.DateTimeField('Created', auto_now_add=True)
update_at = models.DateTimeField('Updated', auto_now=True)
isCompleted = models.BooleanField(default=False)
def __str__(self):
ret... |
iam-veeramalla/Jenkins-Zero-To-Hero | https://github.com/iam-veeramalla/Jenkins-Zero-To-Hero | null | null | null | null | 9,670 | null | null | mit | null | null | null | null | null | null | null | python-jenkins-argocd-k8s/todos/urls.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:39.665379 | from django.urls import path
from . import views
app_name='todos'
urlpatterns = [
path('', views.IndexView.as_view(), name='index'),
path('<int:todo_id>/delete', views.delete, name='delete'),
path('<int:todo_id>/update', views.update, name='update'),
path('add/', views.add, name='add')
] |
iam-veeramalla/Jenkins-Zero-To-Hero | https://github.com/iam-veeramalla/Jenkins-Zero-To-Hero | null | null | null | null | 9,670 | null | null | mit | null | null | null | null | null | null | null | python-jenkins-argocd-k8s/todos/views.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:39.694915 | from django.shortcuts import render, get_object_or_404, redirect
from django.views import generic
from .models import Todo
from django.http import HttpResponseRedirect
class IndexView(generic.ListView):
template_name = 'todos/index.html'
context_object_name = 'todo_list'
def get_queryset(self):
""... |
wangshub/Douyin-Bot | https://github.com/wangshub/Douyin-Bot | null | null | null | null | 9,608 | null | null | mit | null | null | null | null | null | null | null | common/config.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:42.098820 | # -*- coding: utf-8 -*-
"""
调取配置文件和屏幕分辨率的代码
"""
import os
import sys
import json
import re
from common.auto_adb import auto_adb
adb = auto_adb()
def open_accordant_config():
"""
调用配置文件
"""
screen_size = _get_screen_size()
config_file = "{path}/config/{screen_size}/config.json".format(
pa... |
wangshub/Douyin-Bot | https://github.com/wangshub/Douyin-Bot | null | null | null | null | 9,608 | null | null | mit | null | null | null | null | null | null | null | common/excel_keyword.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:42.099889 | import xlrd
import random
def get_random_keyword(filename):
"""
get random row of filename
:param filename:
:return:
"""
try:
with xlrd.open_workbook(filename) as data:
table = data.sheets()[0]
data_list = []
data_list.extend(table.col_values(0))
... |
wangshub/Douyin-Bot | https://github.com/wangshub/Douyin-Bot | null | null | null | null | 9,608 | null | null | mit | null | null | null | null | null | null | null | common/compression.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:42.749613 | from PIL import Image
import math
import os
def resize_image(origin_img, optimize_img, threshold):
"""
shrink image by size
:param origin_img:
:param optimize_img:
:param threshold:
:return:
"""
file_size = os.path.getsize(origin_img)
with Image.open(origin_img) as im:
if f... |
wangshub/Douyin-Bot | https://github.com/wangshub/Douyin-Bot | null | null | null | null | 9,608 | null | null | mit | null | null | null | null | null | null | null | common/debug.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:42.750692 | # -*- coding: utf-8 -*-
"""
这是debug的代码,当DEBUG_SWITCH开关开启的时候,会将各种信息存在本地,方便检查故障
"""
import os
import sys
import shutil
import math
from PIL import ImageDraw
import platform
if platform.system() == 'Windows':
os.chdir(os.getcwd().replace('\\common', ''))
path_split = "\\"
else:
os.chdir(os.getcwd().replace('/c... |
wangshub/Douyin-Bot | https://github.com/wangshub/Douyin-Bot | null | null | null | null | 9,608 | null | null | mit | null | null | null | null | null | null | null | common/UnicodeStreamFilter.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:42.752131 | # -*- coding: utf-8 -*-
import sys
if sys.version_info.major != 3:
class UnicodeStreamFilter:
def __init__(self, target):
self.target = target
self.encoding = 'utf-8'
self.errors = 'replace'
self.encode_to = self.target.encoding
def write(self, s):
... |
wangshub/Douyin-Bot | https://github.com/wangshub/Douyin-Bot | null | null | null | null | 9,608 | null | null | mit | null | null | null | null | null | null | null | douyin-bot.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:42.752912 | # -*- coding: utf-8 -*-
import sys
import random
import time
from PIL import Image
import argparse
if sys.version_info.major != 3:
print('Please run under Python3')
exit(1)
try:
from common import debug, config, screenshot, UnicodeStreamFilter
from common.auto_adb import auto_adb
from common import... |
wangshub/Douyin-Bot | https://github.com/wangshub/Douyin-Bot | null | null | null | null | 9,608 | null | null | mit | null | null | null | null | null | null | null | common/auto_adb.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:42.977211 | # -*- coding: utf-8 -*-
import os
import subprocess
import platform
class auto_adb():
def __init__(self):
try:
adb_path = 'adb'
subprocess.Popen([adb_path], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
self.adb_path = adb_path
exc... |
wangshub/Douyin-Bot | https://github.com/wangshub/Douyin-Bot | null | null | null | null | 9,608 | null | null | mit | null | null | null | null | null | null | null | common/apiutil.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:42.978156 | #-*- coding: UTF-8 -*-
import hashlib
import urllib
from urllib import parse
import urllib.request
import base64
import json
import time
url_preffix='https://api.ai.qq.com/fcgi-bin/'
def setParams(array, key, value):
array[key] = value
def genSignString(parser):
uri_str = ''
for key i... |
wangshub/Douyin-Bot | https://github.com/wangshub/Douyin-Bot | null | null | null | null | 9,608 | null | null | mit | null | null | null | null | null | null | null | common/screenshot.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:42.979081 | # -*- coding: utf-8 -*-
"""
手机屏幕截图的代码
"""
import subprocess
import os
import sys
from PIL import Image
from io import StringIO
try:
from common.auto_adb import auto_adb
except Exception as ex:
print(ex)
print('请将脚本放在项目根目录中运行')
print('请检查项目根目录中的 common 文件夹是否存在')
exit(1)
adb = auto_adb()
# SCREENSHOT... |
wangshub/Douyin-Bot | https://github.com/wangshub/Douyin-Bot | null | null | null | null | 9,608 | null | null | mit | null | null | null | null | null | null | null | example/test_crop.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:43.509216 | from PIL import Image
im = Image.open("../autojump.png")
w, h = im.size
area = (0, 0, 50, 50)
im_croped = im.crop(area)
im_croped.show()
|
wangshub/Douyin-Bot | https://github.com/wangshub/Douyin-Bot | null | null | null | null | 9,608 | null | null | mit | null | null | null | null | null | null | null | example/test_textInput.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:43.712461 | import os
def adb_keyboard_input(text):
"""
adb keyboard app input unicode text
:param text:
:return:
"""
cmd = 'adb shell am broadcast -a ADB_INPUT_TEXT --es msg {text}'.format(text=text.replace(' ', '%s'))
os.system(cmd)
adb_keyboard_input('hello world') |
wangshub/Douyin-Bot | https://github.com/wangshub/Douyin-Bot | null | null | null | null | 9,608 | null | null | mit | null | null | null | null | null | null | null | example/test_readExcel.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:47.862202 | import xlrd
import random
#打开excel文件
data=xlrd.open_workbook('../reply/keyword.xlsx')
#获取第一张工作表(通过索引的方式)
table=data.sheets()[0]
#data_list用来存放数据
data_list=[]
#将table中第一行的数据读取并添加到data_list中
data_list.extend(table.col_values(0))
#打印出第一行的全部数据
for item in data_list:
print(item)
|
wangshub/Douyin-Bot | https://github.com/wangshub/Douyin-Bot | null | null | null | null | 9,608 | null | null | mit | null | null | null | null | null | null | null | example/test_plot.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:48.031106 | import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
# img = mpimg.imread('../screenshot/main_page.jpeg')
# img = mpimg.imread('../screenshot/main_page.jpeg')
# img = mpimg.imread('../screenshot/news_normal.jpeg')
# img = mpimg.imread('../screenshot/news_comment.jpeg')
# img = mpimg.imre... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code-python3/egrep.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:50.363539 | # egrep.py
import sys, re
if __name__ == "__main__":
# sys.argv is the list of command-line arguments
# sys.argv[0] is the name of the program itself
# sys.argv[1] will be the regex specfied at the command line
regex = sys.argv[1]
# for every line passed into the script
for line in sys.stdin:... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code-python3/databases.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:50.383778 | import math, random, re
from collections import defaultdict
class Table:
def __init__(self, columns):
self.columns = columns
self.rows = []
def __repr__(self):
"""pretty representation of the table: columns then rows"""
return str(self.columns) + "\n" + "\n".join(map(str, self.... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code-python3/clustering.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:50.385116 | from linear_algebra import squared_distance, vector_mean, distance
import math, random
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
class KMeans:
"""performs k-means clustering"""
def __init__(self, k):
self.k = k # number of clusters
self.means = None # means of... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code-python3/getting_data.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:50.386995 | from collections import Counter
import math, random, csv, json, re
from bs4 import BeautifulSoup
import requests
######
#
# BOOKS ABOUT DATA
#
######
def is_video(td):
"""it's a video if it has exactly one pricelabel, and if
the stripped text inside that pricelabel starts with 'Video'"""
pricelabels = td... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code-python3/decision_trees.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:50.388436 | from collections import Counter, defaultdict
from functools import partial
import math, random
def entropy(class_probabilities):
"""given a list of class probabilities, compute the entropy"""
return sum(-p * math.log(p, 2) for p in class_probabilities if p)
def class_probabilities(labels):
total_count = l... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code-python3/hypothesis_and_inference.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:50.395199 | from probability import normal_cdf, inverse_normal_cdf
import math, random
def normal_approximation_to_binomial(n, p):
"""finds mu and sigma corresponding to a Binomial(n, p)"""
mu = p * n
sigma = math.sqrt(p * (1 - p) * n)
return mu, sigma
#####
#
# probabilities a normal lies in an interval
#
######... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code-python3/introduction.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:50.396256 | # at this stage in the book we haven't actually installed matplotlib,
# comment this out if you need to
from matplotlib import pyplot as plt
##########################
# #
# FINDING KEY CONNECTORS #
# #
##########################
users = [
{ "id": 0, "name": "Hero" },... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code-python3/gradient_descent.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:50.492107 | from collections import Counter
from linear_algebra import distance, vector_subtract, scalar_multiply
from functools import reduce
import math, random
def sum_of_squares(v):
"""computes the sum of squared elements in v"""
return sum(v_i ** 2 for v_i in v)
def difference_quotient(f, x, h):
return (f(x + h)... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code-python3/linear_algebra.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:50.974460 | # -*- coding: iso-8859-15 -*-
import re, math, random # regexes, math functions, random numbers
import matplotlib.pyplot as plt # pyplot
from collections import defaultdict, Counter
from functools import partial, reduce
#
# functions for working with vectors
#
def vector_add(v, w):
"""adds two vectors componentw... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code-python3/machine_learning.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:50.993215 | from collections import Counter
import math, random
#
# data splitting
#
def split_data(data, prob):
"""split data into fractions [prob, 1 - prob]"""
results = [], []
for row in data:
results[0 if random.random() < prob else 1].append(row)
return results
def train_test_split(x, y, test_pct):
... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code-python3/line_count.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:51.000372 | # line_count.py
import sys
if __name__ == "__main__":
count = 0
for line in sys.stdin:
count += 1
# print goes to sys.stdout
print(count)
|
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code-python3/mapreduce.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:51.061288 | import math, random, re, datetime
from collections import defaultdict, Counter
from functools import partial
from naive_bayes import tokenize
def word_count_old(documents):
"""word count not using MapReduce"""
return Counter(word
for document in documents
for word in tokenize(document))
def wc... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code-python3/multiple_regression.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:51.062267 | from collections import Counter
from functools import partial
from linear_algebra import dot, vector_add
from stats import median, standard_deviation
from probability import normal_cdf
from gradient_descent import minimize_stochastic
from simple_linear_regression import total_sum_of_squares
import math, random
def pre... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code-python3/naive_bayes.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:51.063585 | from collections import Counter, defaultdict
from machine_learning import split_data
import math, random, re, glob
def tokenize(message):
message = message.lower() # convert to lowercase
all_words = re.findall("[a-z0-9']+", message) # extract the words
return set(all_words) ... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code-python3/logistic_regression.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:51.071339 | from collections import Counter
from functools import partial, reduce
from linear_algebra import dot, vector_add
from gradient_descent import maximize_stochastic, maximize_batch
from working_with_data import rescale
from machine_learning import train_test_split
from multiple_regression import estimate_beta, predict
imp... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code-python3/natural_language_processing.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:51.080505 | import math, random, re
from collections import defaultdict, Counter
from bs4 import BeautifulSoup
import requests
def plot_resumes(plt):
data = [ ("big data", 100, 15), ("Hadoop", 95, 25), ("Python", 75, 50),
("R", 50, 40), ("machine learning", 80, 20), ("statistics", 20, 60),
("data science", 6... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code-python3/most_common_words.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:51.089618 | # most_common_words.py
import sys
from collections import Counter
if __name__ == "__main__":
# pass in number of words as first argument
try:
num_words = int(sys.argv[1])
except:
print("usage: most_common_words.py num_words")
sys.exit(1) # non-zero exit code indicates error
... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code-python3/nearest_neighbors.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:51.105446 | from collections import Counter
from linear_algebra import distance
from stats import mean
import math, random
import matplotlib.pyplot as plt
def raw_majority_vote(labels):
votes = Counter(labels)
winner, _ = votes.most_common(1)[0]
return winner
def majority_vote(labels):
"""assumes that labels are ... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code-python3/neural_networks.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:51.564364 | from collections import Counter
from functools import partial
from linear_algebra import dot
import math, random
import matplotlib
import matplotlib.pyplot as plt
def step_function(x):
return 1 if x >= 0 else 0
def perceptron_output(weights, bias, x):
"""returns 1 if the perceptron 'fires', 0 if not"""
re... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code-python3/network_analysis.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:51.585156 | import math, random, re
from collections import defaultdict, Counter, deque
from linear_algebra import dot, get_row, get_column, make_matrix, magnitude, scalar_multiply, shape, distance
from functools import partial
users = [
{ "id": 0, "name": "Hero" },
{ "id": 1, "name": "Dunn" },
{ "id": 2, "name": "Sue... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code-python3/recommender_systems.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:51.647764 | import math, random
from collections import defaultdict, Counter
from linear_algebra import dot
users_interests = [
["Hadoop", "Big Data", "HBase", "Java", "Spark", "Storm", "Cassandra"],
["NoSQL", "MongoDB", "Cassandra", "HBase", "Postgres"],
["Python", "scikit-learn", "scipy", "numpy", "statsmodels", "pa... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code-python3/stats.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:51.712245 | from collections import Counter
from linear_algebra import sum_of_squares, dot
import math
num_friends = [100,49,41,40,25,21,21,19,19,18,18,16,15,15,15,15,14,14,13,13,13,13,12,12,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,8,8,8,8,8,8,8,8,8,8,8,8,8,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code-python3/working_with_data.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:51.735650 | from collections import Counter, defaultdict
from functools import partial, reduce
from linear_algebra import shape, get_row, get_column, make_matrix, \
vector_mean, vector_sum, dot, magnitude, vector_subtract, scalar_multiply
from stats import correlation, standard_deviation, mean
from probability import inverse_n... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code-python3/probability.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:51.756540 | from collections import Counter
import math, random
def random_kid():
return random.choice(["boy", "girl"])
def uniform_pdf(x):
return 1 if x >= 0 and x < 1 else 0
def uniform_cdf(x):
"returns the probability that a uniform random variable is less than x"
if x < 0: return 0 # uniform random is n... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code-python3/visualizing_data.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:51.757443 | import matplotlib.pyplot as plt
from collections import Counter
def make_chart_simple_line_chart():
years = [1950, 1960, 1970, 1980, 1990, 2000, 2010]
gdp = [300.2, 543.3, 1075.9, 2862.5, 5979.6, 10289.7, 14958.3]
# create a line chart, years on x-axis, gdp on y-axis
plt.plot(years, gdp, color='green... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code-python3/plot_state_borders.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:51.812526 | import re
import matplotlib.pyplot as plt
segments = []
points = []
lat_long_regex = r"<point lat=\"(.*)\" lng=\"(.*)\""
with open("states.txt", "r") as f:
lines = [line for line in f]
for line in lines:
if line.startswith("</state>"):
for p1, p2 in zip(points, points[1:]):
segments.appe... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code-python3/simple_linear_regression.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:51.813065 | from collections import Counter, defaultdict
from linear_algebra import vector_subtract
from stats import mean, correlation, standard_deviation, de_mean
from gradient_descent import minimize_stochastic
import math, random
def predict(alpha, beta, x_i):
return beta * x_i + alpha
def error(alpha, beta, x_i, y_i):
... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code/clustering.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:52.203476 | from __future__ import division
from linear_algebra import squared_distance, vector_mean, distance
import math, random
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
class KMeans:
"""performs k-means clustering"""
def __init__(self, k):
self.k = k # number of clusters
... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code/databases.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:52.243613 | from __future__ import division
import math, random, re
from collections import defaultdict
class Table:
def __init__(self, columns):
self.columns = columns
self.rows = []
def __repr__(self):
"""pretty representation of the table: columns then rows"""
return str(self.columns) +... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code/hypothesis_and_inference.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:52.601615 | from __future__ import division
from probability import normal_cdf, inverse_normal_cdf
import math, random
def normal_approximation_to_binomial(n, p):
"""finds mu and sigma corresponding to a Binomial(n, p)"""
mu = p * n
sigma = math.sqrt(p * (1 - p) * n)
return mu, sigma
#####
#
# probabilities a nor... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code/introduction.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:52.603052 | from __future__ import division
# at this stage in the book we haven't actually installed matplotlib,
# comment this out if you need to
from matplotlib import pyplot as plt
##########################
# #
# FINDING KEY CONNECTORS #
# #
##########################
users = [... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code/egrep.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:52.765148 | # egrep.py
import sys, re
if __name__ == "__main__":
# sys.argv is the list of command-line arguments
# sys.argv[0] is the name of the program itself
# sys.argv[1] will be the regex specfied at the command line
regex = sys.argv[1]
# for every line passed into the script
for line in sys.stdin:... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code/line_count.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:53.194416 | # line_count.py
import sys
if __name__ == "__main__":
count = 0
for line in sys.stdin:
count += 1
# print goes to sys.stdout
print count |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code/decision_trees.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:53.307437 | from __future__ import division
from collections import Counter, defaultdict
from functools import partial
import math, random
def entropy(class_probabilities):
"""given a list of class probabilities, compute the entropy"""
return sum(-p * math.log(p, 2) for p in class_probabilities if p)
def class_probabilit... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code/machine_learning.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:53.405219 | from __future__ import division
from collections import Counter
import math, random
#
# data splitting
#
def split_data(data, prob):
"""split data into fractions [prob, 1 - prob]"""
results = [], []
for row in data:
results[0 if random.random() < prob else 1].append(row)
return results
def tr... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code/getting_data.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:53.420474 | from __future__ import division
from collections import Counter
import math, random, csv, json
from bs4 import BeautifulSoup
import requests
######
#
# BOOKS ABOUT DATA
#
######
def is_video(td):
"""it's a video if it has exactly one pricelabel, and if
the stripped text inside that pricelabel starts with 'Vi... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code/most_common_words.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:54.483234 | # most_common_words.py
import sys
from collections import Counter
if __name__ == "__main__":
# pass in number of words as first argument
try:
num_words = int(sys.argv[1])
except:
print "usage: most_common_words.py num_words"
sys.exit(1) # non-zero exit code indicates error
c... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code/multiple_regression.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:54.484238 | from __future__ import division
from collections import Counter
from functools import partial
from linear_algebra import dot, vector_add
from statistics import median, standard_deviation
from probability import normal_cdf
from gradient_descent import minimize_stochastic
from simple_linear_regression import total_sum_of... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code/naive_bayes.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:54.514409 | from __future__ import division
from collections import Counter, defaultdict
from machine_learning import split_data
import math, random, re, glob
def tokenize(message):
message = message.lower() # convert to lowercase
all_words = re.findall("[a-z0-9']+", message) # extract the words
... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code/mapreduce.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:54.629209 | from __future__ import division
import math, random, re, datetime
from collections import defaultdict, Counter
from functools import partial
from naive_bayes import tokenize
def word_count_old(documents):
"""word count not using MapReduce"""
return Counter(word
for document in documents
for w... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code/gradient_descent.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:54.797450 | from __future__ import division
from collections import Counter
from linear_algebra import distance, vector_subtract, scalar_multiply
import math, random
def sum_of_squares(v):
"""computes the sum of squared elements in v"""
return sum(v_i ** 2 for v_i in v)
def difference_quotient(f, x, h):
return (f(x +... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code/linear_algebra.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:57.852175 | # -*- coding: iso-8859-15 -*-
from __future__ import division # want 3 / 2 == 1.5
import re, math, random # regexes, math functions, random numbers
import matplotlib.pyplot as plt # pyplot
from collections import defaultdict, Counter
from functools import partial
#
# functions for working with vectors
#
def vector_... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code/logistic_regression.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:58.048950 | from __future__ import division
from collections import Counter
from functools import partial
from linear_algebra import dot, vector_add
from gradient_descent import maximize_stochastic, maximize_batch
from working_with_data import rescale
from machine_learning import train_test_split
from multiple_regression import es... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code/nearest_neighbors.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:58.968540 | from __future__ import division
from collections import Counter
from linear_algebra import distance
from statistics import mean
import math, random
import matplotlib.pyplot as plt
def raw_majority_vote(labels):
votes = Counter(labels)
winner, _ = votes.most_common(1)[0]
return winner
def majority_vote(lab... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code/natural_language_processing.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:58.976121 | from __future__ import division
import math, random, re
from collections import defaultdict, Counter
from bs4 import BeautifulSoup
import requests
def plot_resumes(plt):
data = [ ("big data", 100, 15), ("Hadoop", 95, 25), ("Python", 75, 50),
("R", 50, 40), ("machine learning", 80, 20), ("statistics", 20, ... |
joelgrus/data-science-from-scratch | https://github.com/joelgrus/data-science-from-scratch | null | null | null | null | 9,589 | null | null | mit | null | null | null | null | null | null | null | first-edition/code/network_analysis.py | null | null | null | null | null | null | Python | 2026-05-04T02:04:59.133007 | from __future__ import division
import math, random, re
from collections import defaultdict, Counter, deque
from linear_algebra import dot, get_row, get_column, make_matrix, magnitude, scalar_multiply, shape, distance
from functools import partial
users = [
{ "id": 0, "name": "Hero" },
{ "id": 1, "name": "Dunn... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | src/textblob/__init__.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:01.653297 | from .blob import Blobber, Sentence, TextBlob, Word, WordList
__all__ = [
"TextBlob",
"Word",
"Sentence",
"Blobber",
"WordList",
]
|
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | src/textblob/base.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:01.654548 | """Abstract base classes for models (taggers, noun phrase extractors, etc.)
which define the interface for descendant classes.
.. versionchanged:: 0.7.0
All base classes are defined in the same module, ``textblob.base``.
"""
from __future__ import annotations
from abc import ABCMeta, abstractmethod
from typing i... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | src/textblob/decorators.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:01.661658 | """Custom decorators."""
from __future__ import annotations
from functools import wraps
from typing import TYPE_CHECKING
from textblob.exceptions import MissingCorpusError
if TYPE_CHECKING:
from collections.abc import Callable
from typing import TypeVar
ReturnType = TypeVar("ReturnType")
class cached... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | docs/_themes/flask_theme_support.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:01.665222 | # flasky extensions. flasky pygments style based on tango style
from pygments.style import Style
from pygments.token import (
Comment,
Error,
Generic,
Keyword,
Literal,
Name,
Number,
Operator,
Other,
Punctuation,
String,
Whitespace,
)
class FlaskyStyle(Style):
back... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | docs/conf.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:01.666400 | import importlib.metadata
import os
import sys
sys.path.append(os.path.abspath("_themes"))
# -- General configuration -----------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | src/textblob/download_corpora.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:01.669670 | #!/usr/bin/env python
"""Downloads the necessary NLTK corpora for TextBlob.
Usage: ::
$ python -m textblob.download_corpora
If you only intend to use TextBlob's default models, you can use the "lite"
option: ::
$ python -m textblob.download_corpora lite
"""
import sys
import nltk
MIN_CORPORA = [
"br... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | src/textblob/classifiers.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:01.678809 | """Various classifier implementations. Also includes basic feature extractor
methods.
Example Usage:
::
>>> from textblob import TextBlob
>>> from textblob.classifiers import NaiveBayesClassifier
>>> train = [
... ('I love this sandwich.', 'pos'),
... ('This is an amazing place!', 'pos'),
... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | src/textblob/en/__init__.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:01.681015 | """This file is based on pattern.en. See the bundled NOTICE file for
license information.
"""
import os
from textblob._text import CHUNK, PENN, PNP, POS, UNIVERSAL, WORD, Lexicon, Spelling
from textblob._text import Parser as _Parser
from textblob._text import Sentiment as _Sentiment
try:
MODULE = os.path.dirname... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | src/textblob/blob.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:01.682740 | """Wrappers for various units of text, including the main
:class:`TextBlob <textblob.blob.TextBlob>`, :class:`Word <textblob.blob.Word>`,
and :class:`WordList <textblob.blob.WordList>` classes.
Example usage: ::
>>> from textblob import TextBlob
>>> b = TextBlob("Simple is better than complex.")
>>> b.tags... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | src/textblob/_text.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:01.723154 | """This file is adapted from the pattern library.
URL: http://www.clips.ua.ac.be/pages/pattern-web
Licence: BSD
"""
import codecs
import os
import re
import string
import types
from itertools import chain
from xml.etree import ElementTree
basestring = (str, bytes)
try:
MODULE = os.path.dirname(os.path.abspath(__... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | src/textblob/exceptions.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:02.444018 | MISSING_CORPUS_MESSAGE = """
Looks like you are missing some required data for this feature.
To download the necessary data, simply run
python -m textblob.download_corpora
or use the NLTK downloader to download the missing data: http://nltk.org/data.html
If this doesn't fix the problem, file an issue at https://... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | src/textblob/inflect.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:02.457624 | """Make word inflection default to English. This allows for backwards
compatibility so you can still import text.inflect.
>>> from textblob.inflect import singularize
is equivalent to
>>> from textblob.en.inflect import singularize
"""
from textblob.en.inflect import pluralize, singularize
__all__ = [
... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | src/textblob/mixins.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:02.478697 | import sys
class ComparableMixin:
"""Implements rich operators for an object."""
def _cmpkey(self):
raise NotImplementedError("Class must implement _cmpkey method")
def _compare(self, other, method):
try:
return method(self._cmpkey(), other._cmpkey())
except (Attribut... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | src/textblob/en/sentiments.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:02.480188 | """Sentiment analysis implementations.
.. versionadded:: 0.5.0
"""
from collections import namedtuple
import nltk
from textblob.base import CONTINUOUS, DISCRETE, BaseSentimentAnalyzer
from textblob.decorators import requires_nltk_corpus
from textblob.en import sentiment as pattern_sentiment
from textblob.tokenizers ... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | src/textblob/en/np_extractors.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:02.481347 | """Various noun phrase extractors."""
import nltk
from textblob.base import BaseNPExtractor
from textblob.decorators import requires_nltk_corpus
from textblob.taggers import PatternTagger
from textblob.utils import filter_insignificant, tree2str
class ChunkParser(nltk.ChunkParserI):
_trained: bool
def __in... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | src/textblob/formats.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:02.506315 | """File formats for training and testing data.
Includes a registry of valid file formats. New file formats can be added to the
registry like so: ::
from textblob import formats
class PipeDelimitedFormat(formats.DelimitedFormat):
delimiter = "|"
formats.register("psv", PipeDelimitedFormat)
Onc... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | src/textblob/en/parsers.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:02.507603 | """Various parser implementations.
.. versionadded:: 0.6.0
"""
from textblob.base import BaseParser
from textblob.en import parse as pattern_parse
class PatternParser(BaseParser):
"""Parser that uses the implementation in Tom de Smedt's pattern library.
http://www.clips.ua.ac.be/pages/pattern-en#parser
"... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | src/textblob/np_extractors.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:02.553242 | """Default noun phrase extractors are for English to maintain backwards
compatibility, so you can still do
>>> from textblob.np_extractors import ConllExtractor
which is equivalent to
>>> from textblob.en.np_extractors import ConllExtractor
"""
from textblob.base import BaseNPExtractor
from textblob.en.np_extractor... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | src/textblob/en/taggers.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:02.595254 | """Parts-of-speech tagger implementations."""
import nltk
import textblob as tb
from textblob.base import BaseTagger
from textblob.decorators import requires_nltk_corpus
from textblob.en import tag as pattern_tag
class PatternTagger(BaseTagger):
"""Tagger that uses the implementation in
Tom de Smedt's patte... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | src/textblob/en/inflect.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:02.618722 | """The pluralize and singular methods from the pattern library.
Licenced under the BSD.
See here https://github.com/clips/pattern/blob/master/LICENSE.txt for
complete license information.
"""
from __future__ import annotations
from collections.abc import MutableMapping
import re
from typing import TYPE_CHECKING
if T... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | tests/test_classifiers.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:03.461254 | import os
import unittest
from unittest import mock
import nltk
import pytest
from textblob import formats
from textblob.classifiers import (
DecisionTreeClassifier,
MaxEntClassifier,
NaiveBayesClassifier,
NLTKClassifier,
PositiveNaiveBayesClassifier,
_get_words_from_dataset,
basic_extract... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | src/textblob/parsers.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:03.463386 | """Default parsers to English for backwards compatibility so you can still do
>>> from textblob.parsers import PatternParser
which is equivalent to
>>> from textblob.en.parsers import PatternParser
"""
from textblob.base import BaseParser
from textblob.en.parsers import PatternParser
__all__ = [
"BaseParser",
... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | tests/test_blob.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:03.626806 | """
Tests for the text processor.
"""
import json
from datetime import datetime
from unittest import TestCase
import nltk
import pytest
import textblob as tb
import textblob.wordnet as wn
from textblob.classifiers import NaiveBayesClassifier
from textblob.np_extractors import ConllExtractor, FastNPExtractor
from tex... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | src/textblob/sentiments.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:03.674232 | """Default sentiment analyzers are English for backwards compatibility, so
you can still do
>>> from textblob.sentiments import PatternAnalyzer
which is equivalent to
>>> from textblob.en.sentiments import PatternAnalyzer
"""
from textblob.base import BaseSentimentAnalyzer
from textblob.en.sentiments import (
C... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | src/textblob/wordnet.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:03.832576 | """Wordnet interface. Contains classes for creating Synsets and Lemmas
directly.
.. versionadded:: 0.7.0
"""
import nltk
#: wordnet module from nltk
wordnet = nltk.corpus.wordnet
#: Synset constructor
Synset = nltk.corpus.wordnet.synset
#: Lemma constructor
Lemma = nltk.corpus.wordnet.lemma
# Part of speech constan... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | src/textblob/taggers.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:03.904344 | """Default taggers to the English taggers for backwards incompatibility, so you
can still do
>>> from textblob.taggers import NLTKTagger
which is equivalent to
>>> from textblob.en.taggers import NLTKTagger
"""
from textblob.base import BaseTagger
from textblob.en.taggers import NLTKTagger, PatternTagger
__all__ =... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | src/textblob/utils.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:04.002333 | from __future__ import annotations
import re
import string
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from collections.abc import Iterable
PUNCTUATION_REGEX = re.compile(f"[{re.escape(string.punctuation)}]")
def strip_punc(s: str, all=False):
"""Removes punctuation from a string.
:param s: The... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | src/textblob/tokenizers.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:04.017359 | """Various tokenizer implementations.
.. versionadded:: 0.4.0
"""
from itertools import chain
import nltk
from textblob.base import BaseTokenizer
from textblob.decorators import requires_nltk_corpus
from textblob.utils import strip_punc
class WordTokenizer(BaseTokenizer):
"""NLTK's recommended word tokenizer ... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | tests/test_formats.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:04.074677 | import os
import unittest
from textblob import formats
HERE = os.path.abspath(os.path.dirname(__file__))
CSV_FILE = os.path.join(HERE, "data.csv")
JSON_FILE = os.path.join(HERE, "data.json")
TSV_FILE = os.path.join(HERE, "data.tsv")
class TestFormats(unittest.TestCase):
def setUp(self):
pass
def te... |
sloria/TextBlob | https://github.com/sloria/TextBlob | null | null | null | null | 9,518 | null | null | mit | null | null | null | null | null | null | null | tests/test_inflect.py | null | null | null | null | null | null | Python | 2026-05-04T02:05:04.075764 | from unittest import TestCase
from textblob.en.inflect import (
plural_categories,
pluralize,
singular_ie,
singular_irregular,
singularize,
)
class InflectTestCase(TestCase):
def s_singular_pluralize_test(self):
assert pluralize("lens") == "lenses"
def s_singular_singularize_test... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.