-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New app: testing, interface for testing interactively algos and such
- Loading branch information
Guillaume Hélouis
committed
May 30, 2015
1 parent
26c3a94
commit 7b2f9b5
Showing
25 changed files
with
52,545 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,4 +30,4 @@ | |
} | ||
} | ||
}); | ||
</script> | ||
</script> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ django-stdimage==1.2.2 | |
Pillow==2.8.1 | ||
progressbar2==2.7.3 | ||
numpy | ||
requests | ||
beautifulsoup4 |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#! /usr/bin/env python | ||
# coding: utf-8 | ||
|
||
class Ingredient: | ||
""" Parse given string to extract a name, a unit and a quantity """ | ||
|
||
def __init__(self, s): | ||
self.text = s | ||
self.name = None | ||
self.unit = None | ||
self.quantity = None | ||
|
||
word2num = { | ||
"un demi" : 1/2, | ||
"trois-quarts" : 3/4, "trois quarts" : 3/4, | ||
"un" : 1, "une" : 1, | ||
"deux" : 2, | ||
"trois" : 3, | ||
"quatre" : 4, | ||
"cinq" : 5, | ||
"six" : 6, | ||
"sept" : 7, | ||
"huit" : 8, | ||
"neuf" : 9, | ||
"dix" : 10, "une dizaine" : 10, | ||
"onze" : 11, "une onzaine" : 11, | ||
"douze" : 12, "une douzaine" : 12 | ||
} | ||
|
||
word2unit = { | ||
"quelques gouttes" : "1 g", "un peu" : "1 g", "une pincée" : "1 g", "un soupçon" : "1 g", "une goutte" : "1 g", "un nuage" : "1 g", "un zeste" : "1 g", "un fond" : "1 g", | ||
"milligramme" : "mg", "milligrammes" : "mg", | ||
"centigramme" : "cg", "centigrammes" : "cg", | ||
"decigramme" : "dg", "decigrammes" : "dg", | ||
"gramme" : "g", "grammes" : "g", | ||
"kilogramme" : "kg", "kilogrammes" : "kg", "kilo" : "kg", "kilos" : "kg", | ||
"litre" : "l", | ||
"cuillères à soupe" : "cuillère à soupe", "cuillerée" : "cuillère à soupe", | ||
"cuillères à café" : "cuillère à café", | ||
"verres" : "verre", | ||
"tranches" : "tranche", | ||
"gousses" : "gousse" | ||
} | ||
|
||
units = [ "mg", "g", "cg", "kg", "l", "cl", "cuillère à soupe", "cuillère à café", "verre", "tranche" , "gousse" ] | ||
|
||
useless = [ "de" ] | ||
|
||
# step 1: numerize | ||
for key, val in word2num.items(): | ||
s = s.replace(" " + key + " ", " " + str(val) + " ") | ||
if s.startswith(key + " ") or s.endswith(" " + key): | ||
s = s.replace(key, str(val)) | ||
|
||
# step 2: unify units | ||
for key, val in word2unit.items(): | ||
s = s.replace(" " + key + " ", " " + val + " ") | ||
if s.startswith(key + " ") or s.endswith(" " + key): | ||
s = s.replace(key, val) | ||
|
||
# step 3: remove useless words | ||
for w in useless: | ||
s = s.replace(" " + w, "") | ||
|
||
# step 4: parse delicately | ||
after_quantity = False | ||
in_unit = False | ||
for word in s.split(" "): | ||
if in_unit: | ||
self.unit += " " + word | ||
self.name += " " + word | ||
for u in units: | ||
if self.unit == u: | ||
in_unit = False | ||
self.name = None | ||
continue | ||
if self.quantity: | ||
after_quantity = True | ||
try: | ||
if self.quantity: | ||
self.quantity = self.quantity * int(word) | ||
self.name = None | ||
else: | ||
self.quantity = int(word) | ||
self.name = None | ||
except: | ||
if self.quantity and (self.unit or self.name): | ||
self.name = self.name + " " + word if self.name else word | ||
continue | ||
if "/" in word: | ||
word = word.split("/") | ||
try: | ||
self.quantity = int(word[0]) / int(word[1]) | ||
except: | ||
pass | ||
else: | ||
if word in units: | ||
self.unit = word | ||
else: | ||
for u in units: | ||
if u.split(" ")[0] == word: | ||
self.unit = word | ||
self.name = word # in case not a unit | ||
in_unit = True | ||
if after_quantity: | ||
after_quantity = False | ||
self.name = word | ||
pass | ||
|
||
if not self.quantity and not self.unit: | ||
self.name = s | ||
|
||
if self.name == self.unit: | ||
self.unit = None |
Oops, something went wrong.