Skip to main content

No project description provided

Project description

text2struct

Currently it is using OpenAI provider to do the extraction, so you need to register and retrieve an API KEY from their website at https://beta.openai.com/account/api-keys

Install

pip install text2struct

and optinally set environmental variable OPENAI_API_KEY

How to use

recipie = """
STEP 1
Put a large saucepan of water on to boil.

STEP 2
Finely chop the 100g pancetta, having first removed any rind. Finely grate 50g pecorino cheese and 50g parmesan and mix them together.

STEP 3
Beat the 3 large eggs in a medium bowl and season with a little freshly grated black pepper. Set everything aside.

STEP 4
Add 1 tsp salt to the boiling water, add 350g spaghetti and when the water comes back to the boil, cook at a constant simmer, covered, for 10 minutes or until al dente (just cooked).

STEP 5
Squash 2 peeled plump garlic cloves with the blade of a knife, just to bruise it.

STEP 6
While the spaghetti is cooking, fry the pancetta with the garlic. Drop 50g unsalted butter into a large frying pan or wok and, as soon as the butter has melted, tip in the pancetta and garlic.

STEP 7
Leave to cook on a medium heat for about 5 minutes, stirring often, until the pancetta is golden and crisp. The garlic has now imparted its flavour, so take it out with a slotted spoon and discard.

STEP 8
Keep the heat under the pancetta on low. When the pasta is ready, lift it from the water with a pasta fork or tongs and put it in the frying pan with the pancetta. Don’t worry if a little water drops in the pan as well (you want this to happen) and don’t throw the pasta water away yet.

STEP 9
Mix most of the cheese in with the eggs, keeping a small handful back for sprinkling over later.

STEP 10
Take the pan of spaghetti and pancetta off the heat. Now quickly pour in the eggs and cheese. Using the tongs or a long fork, lift up the spaghetti so it mixes easily with the egg mixture, which thickens but doesn’t scramble, and everything is coated.

STEP 11
Add extra pasta cooking water to keep it saucy (several tablespoons should do it). You don’t want it wet, just moist. Season with a little salt, if needed.

STEP 12
Use a long-pronged fork to twist the pasta on to the serving plate or bowl. Serve immediately with a little sprinkling of the remaining cheese and a grating of black pepper. If the dish does get a little dry before serving, splash in some more hot pasta water and the glossy sauciness will be revived.
"""

what_to_retrieve = ['ingredient', 'quantity']

you can retrieve either dictionary with values

d = text2dict(recipie, what_to_retrieve, config={'openai_api_key': 'your_api_key'})
d
[{'ingredient': 'pancetta', 'quantity': '100g'},
 {'ingredient': 'pecorino cheese', 'quantity': '50g'},
 {'ingredient': 'parmesan', 'quantity': '50g'},
 {'ingredient': 'eggs', 'quantity': '3'},
 {'ingredient': 'black pepper', 'quantity': 'to taste'},
 {'ingredient': 'spaghetti', 'quantity': '350g'},
 {'ingredient': 'garlic cloves', 'quantity': '2'},
 {'ingredient': 'unsalted butter', 'quantity': '50g'},
 {'ingredient': 'salt', 'quantity': 'to taste'}]

… or a data frame

df = text2df(recipie, what_to_retrieve, config={'openai_api_key': 'your_api_key'})
df
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; }
.dataframe tbody tr th {
    vertical-align: top;
}

.dataframe thead th {
    text-align: right;
}
</style>
ingredient quantity
0 pancetta 100g
1 pecorino cheese 50g
2 parmesan 50g
3 eggs 3
4 black pepper to taste
5 spaghetti 350g
6 garlic cloves 2
7 unsalted butter 50g
8 salt to taste

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

text2struct-0.0.2.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

text2struct-0.0.2-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file text2struct-0.0.2.tar.gz.

File metadata

  • Download URL: text2struct-0.0.2.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.12

File hashes

Hashes for text2struct-0.0.2.tar.gz
Algorithm Hash digest
SHA256 59e3d82d248b393c6a3f940e23541fc8b8243286dad49736b8efa1eb047db0f6
MD5 e53f2059bd3b45ba650fff35e6b4f984
BLAKE2b-256 6c3c1f427ced4ae9729490f2bf21548e14519af8d8f5c2a1682d19f49c994160

See more details on using hashes here.

File details

Details for the file text2struct-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: text2struct-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.12

File hashes

Hashes for text2struct-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5f8348abd88de7d59f7ea47e595cd395460be7fd6b3db6972b79939e9220b78b
MD5 4b8dcb3c19367f5fd784a5e14d95ac8c
BLAKE2b-256 d9b925b3cd90d2e0323f43a2bcb7aa529e2fb6698b11f957805c5db89a6ad9ba

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page