Skip to content

Instantly share code, notes, and snippets.

View richwhitjr's full-sized avatar

Richard Whitcomb richwhitjr

  • Osmo
  • Boston, MA
View GitHub Profile
@richwhitjr
richwhitjr / join.py
Created December 23, 2024 19:41
Join two keyed python lists using a LLM for a fuzzy inner join.
"""Join two lists of items using a language model."""
import logging
from typing import Any, Dict, Optional, Tuple, List
import numpy as np
from numpy.typing import ArrayLike
import openai
import tqdm
logger = logging.getLogger(__name__)
@richwhitjr
richwhitjr / Graph.scala
Created July 1, 2016 17:13
Example Graph API
case class Edge[T, S](source: T, dest: T, attr: S)
case class Vertex[T, S](id: T, attr: S)
case class EdgeTriplet[T, S, Q](source: Vertex[T, Q], dest: Vertex[T, Q], edge: Edge[T, S])
abstract class Graph[T: Ordering : ClassTag, S: ClassTag, Q: ClassTag, M[_], X[_, _, _] <: Graph[_, _, _, M, X]](val edges: M[Edge[T, S]], val vertices: M[Vertex[T, Q]]) {
def triplets: M[EdgeTriplet[T, S, Q]]
def outerJoinVertices[U: ClassTag, VD2: ClassTag](other: M[(T, U)])(mapFunc: (T, Q, Option[U]) => VD2): Graph[T, S, VD2, M, X]
def joinVertices[U: ClassTag, VD2: ClassTag](other: M[(T, U)])(mapFunc: (T, Q, U) => VD2): Graph[T, S, VD2, M, X]
@richwhitjr
richwhitjr / TypedPipeFoldingExtension.scala
Last active August 29, 2015 14:27
Attempt at making a folding function in scalding that makes use of map side aggregation.
/**
* Fold with map side aggregation using a monoid.
* */
class FoldExtension[T](pipe: TypedPipe[T]) {
def foldByKey[K, V, B](z : B)(fn : scala.Function2[B, V, B])
(implicit ev : scala.Predef.<:<[T, scala.Tuple2[K, V]],
ord : scala.Ordering[K],
aggPlus : Semigroup[B]) : UnsortedGrouped[K, B] = {
val sg = new Semigroup[Either[V, B]] {