Skip to content

Instantly share code, notes, and snippets.

@jeremyorme
jeremyorme / classification.py
Last active August 15, 2019 05:15
Simple text classifier
# records a type classification
class classification:
def __init__(self, start_token, end_token, type):
self.start_token = start_token
self.end_token = end_token
self.type = type
def __repr__(self):
return '{' + 's:' + str(self.start_token) + ', e:' + str(self.end_token) + ', t:' + self.type + '}'
@jeremyorme
jeremyorme / regex_classifier.py
Created December 27, 2019 15:00
Regex Classifier
import re
import random
def tokenise(s):
return ' '.join([t for t in re.split(r'([a-zA-Zñ][a-zA-Zñ\-]*|\d+\.\d+|[½⅓⅔¼¾⅕⅖⅗⅘⅙⅚⅛⅜⅝⅞\d]+|[^\w ])', s) if t.strip() != ''])
# replacement rule
class rule:
def __init__(self, pattern, substitution):
@jeremyorme
jeremyorme / ingredient_classifier.py
Last active January 28, 2020 17:25
Ingredient Classification & Aggregation
import json
import csv
import re
# Input recipe, ingredient per line, ignore blanks
recipe = '''
2 courgettes (zucchini)
1 carrot
1 avocado
1 bunch basil
@jeremyorme
jeremyorme / generate_ingredients.py
Last active February 11, 2020 17:34
Ingredient list generation
import csv
import re
forbidden = [
'milk',
'cheese',
'egg',
'yoghurt',
'meat',
'beef',
@jeremyorme
jeremyorme / ingredient_processor.py
Last active April 29, 2020 07:28
Classify free text ingredients and aggregate nutrient values
import json
import csv
import re
# Input recipe, ingredient per line, ignore blanks
recipe = '''
2 courgettes (zucchini)
1 carrot
1 avocado
1 bunch basil
@jeremyorme
jeremyorme / app-home.tsx
Created May 24, 2020 06:05
Veebe version 1
import {Component, h, State} from '@stencil/core';
interface IFoodNutrient {
name: string;
unitName: string;
amount: number;
}
interface IFood {
fdc_id: string;
@jeremyorme
jeremyorme / app-home.css
Created June 14, 2020 05:52
Veebe version 2
.rda-progress {
position: relative;
display: block;
height: 25px;
background: rgb(241,241,252);
background: linear-gradient(90deg, rgba(251,251,252,1) 0%, rgba(218,221,236,1) 100%);
overflow: hidden;
}
.nutrient-container {
@jeremyorme
jeremyorme / set-solver.py
Created November 18, 2020 06:23
Set based, monte-carlo tree search problem solver
import random
# You have a fox, a chicken and a sack of grain. You must cross a river with only one of them at a time. If you leave the fox with the chicken he will eat it; if you leave the chicken with the grain he will eat it. How can you get all three across safely?
problem_spec = {
'start_state': {
'near bank': {
'you',
'fox',
'chicken',
@jeremyorme
jeremyorme / app-home.tsx
Created January 11, 2022 14:18
Making value State
@State() value: string;
@jeremyorme
jeremyorme / business.ts
Last active January 18, 2022 17:10
Business interface
export interface Business {
name: string;
description: string;
icon: string;
url: string;
tel: string;
address: string;
longitude: number;
latitude: number;
}