Skip to content

Commit 765005c

Browse files
committed
usage
1 parent 467017c commit 765005c

File tree

1 file changed

+24
-87
lines changed

1 file changed

+24
-87
lines changed

notebooks/lib-usage-notebook.ipynb

Lines changed: 24 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"metadata": {},
77
"outputs": [],
88
"source": [
9-
"from dateandtimeparser import DateTimeParser"
9+
"from dateandtimeparser import DateParser"
1010
]
1111
},
1212
{
@@ -18,38 +18,34 @@
1818
"S1 = 'Today is 10/12/16 and tomorrow is January 01 2019.'\n",
1919
"S2 = 'entries are due by January 04, 2017 at 8:00pm'\n",
2020
"S3 = 'created 01/15/2005 by ACME Inc. and associates.'\n",
21-
"S4 = 'Dec.01.2015 - Dec 31 2015 - Dec,12,2015 - Dec,12,2015 - Dec,12th,2015 - DEC122014'\n",
21+
"S4 = 'Dec.01.2015 - Dec 31 2015 - Dec,12,2015 - Dec,12,2015 - Dec,12th,2015 - DEC122014 '\n",
2222
"\n",
2323
"texts = [S1, S2, S3, S4]"
2424
]
2525
},
2626
{
2727
"cell_type": "code",
28-
"execution_count": 3,
28+
"execution_count": 14,
2929
"metadata": {},
3030
"outputs": [
31-
{
32-
"name": "stdout",
33-
"output_type": "stream",
34-
"text": [
35-
"TEXT: Today is 10/12/16 and tomorrow is January 01 2019.\n",
36-
"\n"
37-
]
38-
},
3931
{
4032
"name": "stderr",
4133
"output_type": "stream",
4234
"text": [
43-
"DATETIME: 2019-07-11 16:49:44,986 INFO Extracting dates from the text.\n"
35+
"DATEPARSER: 2019-07-12 13:59:09,258 INFO Extracting dates from the text.\n"
4436
]
4537
},
4638
{
4739
"name": "stdout",
4840
"output_type": "stream",
4941
"text": [
50-
"datetime(date='january 01 2019', token_span=(34, 49), token_index=(6, 8), format='%B %d %Y')\n",
42+
"TEXT: Today is 10/12/16 and tomorrow is January 01 2019.\n",
43+
"\n",
44+
"DATE(date='january 01 2019', token_span=(34, 49), token_index=(6, 8), format='%B %d %Y')\n",
45+
"----------------------------------------------------------------------------------------------------\n",
46+
"DATE(date='10/12/16', token_span=(9, 17), token_index=(2, 2), format='%m/%-d/%y')\n",
5147
"----------------------------------------------------------------------------------------------------\n",
52-
"datetime(date='10/12/16', token_span=(9, 17), token_index=(2, 2), format='%d/%m/%y')\n",
48+
"DATE(date='10/12/16', token_span=(9, 17), token_index=(2, 2), format='%m/%d/%y')\n",
5349
"----------------------------------------------------------------------------------------------------\n",
5450
"****************************************************************************************************\n",
5551
"TEXT: entries are due by January 04, 2017 at 8:00pm\n",
@@ -60,46 +56,30 @@
6056
"name": "stderr",
6157
"output_type": "stream",
6258
"text": [
63-
"DATETIME: 2019-07-11 16:49:45,222 INFO Extracting dates from the text.\n"
59+
"DATEPARSER: 2019-07-12 13:59:09,380 INFO Extracting dates from the text.\n",
60+
"DATEPARSER: 2019-07-12 13:59:09,613 INFO Extracting dates from the text.\n",
61+
"DATEPARSER: 2019-07-12 13:59:09,717 INFO Extracting dates from the text.\n"
6462
]
6563
},
6664
{
6765
"name": "stdout",
6866
"output_type": "stream",
6967
"text": [
70-
"datetime(date='january 04, 2017', token_span=(19, 35), token_index=(4, 6), format='%B %d, %Y')\n",
68+
"DATE(date='january 04, 2017', token_span=(19, 35), token_index=(4, 6), format='%B %d, %Y')\n",
7169
"----------------------------------------------------------------------------------------------------\n",
7270
"****************************************************************************************************\n",
7371
"TEXT: created 01/15/2005 by ACME Inc. and associates.\n",
74-
"\n"
75-
]
76-
},
77-
{
78-
"name": "stderr",
79-
"output_type": "stream",
80-
"text": [
81-
"DATETIME: 2019-07-11 16:49:45,455 INFO Extracting dates from the text.\n",
82-
"DATETIME: 2019-07-11 16:49:45,693 INFO Extracting dates from the text.\n"
83-
]
84-
},
85-
{
86-
"name": "stdout",
87-
"output_type": "stream",
88-
"text": [
89-
"datetime(date='01/15', token_span=(8, 13), token_index=(1, 1), format='%m/%d')\n",
90-
"----------------------------------------------------------------------------------------------------\n",
91-
"****************************************************************************************************\n",
92-
"TEXT: Dec.01.2015 - Dec 31 2015 - Dec,12,2015 - Dec,12,2015 - Dec,12th,2015 - DEC122014\n",
9372
"\n",
94-
"datetime(date='dec 31 2015', token_span=(14, 25), token_index=(2, 4), format='%b %d %Y')\n",
95-
"----------------------------------------------------------------------------------------------------\n",
96-
"datetime(date='dec.01.2015', token_span=(0, 11), token_index=(0, 0), format='%b.%d.%Y')\n",
73+
"DATE(date='01/15/2005', token_span=(8, 18), token_index=(1, 1), format='%m/%-d/%Y')\n",
9774
"----------------------------------------------------------------------------------------------------\n",
98-
"datetime(date='dec,12,2015', token_span=(28, 39), token_index=(6, 6), format='%b,%d,%Y')\n",
75+
"DATE(date='01/15/2005', token_span=(8, 18), token_index=(1, 1), format='%m/%d/%Y')\n",
9976
"----------------------------------------------------------------------------------------------------\n",
100-
"datetime(date='dec,12,2015', token_span=(42, 53), token_index=(8, 8), format='%b,%d,%Y')\n",
77+
"****************************************************************************************************\n",
78+
"TEXT: Dec.01.2015 - Dec 31 2015 - Dec,12,2015 - Dec,12,2015 - Dec,12th,2015 - DEC122014 \n",
79+
"\n",
80+
"DATE(date='dec 31 2015', token_span=(14, 25), token_index=(2, 4), format='%b %-d %Y')\n",
10181
"----------------------------------------------------------------------------------------------------\n",
102-
"datetime(date='dec122014', token_span=(72, 81), token_index=(12, 12), format='%b%d%Y')\n",
82+
"DATE(date='dec 31 2015', token_span=(14, 25), token_index=(2, 4), format='%b %d %Y')\n",
10383
"----------------------------------------------------------------------------------------------------\n",
10484
"****************************************************************************************************\n"
10585
]
@@ -109,11 +89,10 @@
10989
"for text in texts:\n",
11090
" TEXT = f\"TEXT: {text}\\n\"\n",
11191
" try:\n",
112-
" parsed_dates = DateTimeParser(text=text, start_year=2000, end_year=2020, \n",
113-
" datetime_format=['%b%d%Y', '%b.%d.%Y', '%b,%d,%Y', '%b,%d and %Y']) # pass your own custom formats, or just leave it.\n",
92+
" parsed_dates = DateParser(text=text, start_year=2000, end_year=2020) # pass your own custom formats, or just leave it.\n",
11493
" print(TEXT)\n",
115-
" for datetime in parsed_dates.datetime:\n",
116-
" print(datetime)\n",
94+
" for date in parsed_dates.date:\n",
95+
" print(date)\n",
11796
" print(\"-\"*100)\n",
11897
" print(\"*\"*100)\n",
11998
" except Exception:\n",
@@ -200,48 +179,6 @@
200179
"outputs": [],
201180
"source": []
202181
},
203-
{
204-
"cell_type": "code",
205-
"execution_count": null,
206-
"metadata": {},
207-
"outputs": [],
208-
"source": []
209-
},
210-
{
211-
"cell_type": "code",
212-
"execution_count": null,
213-
"metadata": {},
214-
"outputs": [],
215-
"source": []
216-
},
217-
{
218-
"cell_type": "code",
219-
"execution_count": null,
220-
"metadata": {},
221-
"outputs": [],
222-
"source": []
223-
},
224-
{
225-
"cell_type": "code",
226-
"execution_count": null,
227-
"metadata": {},
228-
"outputs": [],
229-
"source": []
230-
},
231-
{
232-
"cell_type": "code",
233-
"execution_count": null,
234-
"metadata": {},
235-
"outputs": [],
236-
"source": []
237-
},
238-
{
239-
"cell_type": "code",
240-
"execution_count": null,
241-
"metadata": {},
242-
"outputs": [],
243-
"source": []
244-
},
245182
{
246183
"cell_type": "code",
247184
"execution_count": null,

0 commit comments

Comments
 (0)