|
6 | 6 | "metadata": {}, |
7 | 7 | "outputs": [], |
8 | 8 | "source": [ |
9 | | - "from dateandtimeparser import DateTimeParser" |
| 9 | + "from dateandtimeparser import DateParser" |
10 | 10 | ] |
11 | 11 | }, |
12 | 12 | { |
|
18 | 18 | "S1 = 'Today is 10/12/16 and tomorrow is January 01 2019.'\n", |
19 | 19 | "S2 = 'entries are due by January 04, 2017 at 8:00pm'\n", |
20 | 20 | "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", |
22 | 22 | "\n", |
23 | 23 | "texts = [S1, S2, S3, S4]" |
24 | 24 | ] |
25 | 25 | }, |
26 | 26 | { |
27 | 27 | "cell_type": "code", |
28 | | - "execution_count": 3, |
| 28 | + "execution_count": 14, |
29 | 29 | "metadata": {}, |
30 | 30 | "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 | | - }, |
39 | 31 | { |
40 | 32 | "name": "stderr", |
41 | 33 | "output_type": "stream", |
42 | 34 | "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" |
44 | 36 | ] |
45 | 37 | }, |
46 | 38 | { |
47 | 39 | "name": "stdout", |
48 | 40 | "output_type": "stream", |
49 | 41 | "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", |
51 | 47 | "----------------------------------------------------------------------------------------------------\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", |
53 | 49 | "----------------------------------------------------------------------------------------------------\n", |
54 | 50 | "****************************************************************************************************\n", |
55 | 51 | "TEXT: entries are due by January 04, 2017 at 8:00pm\n", |
|
60 | 56 | "name": "stderr", |
61 | 57 | "output_type": "stream", |
62 | 58 | "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" |
64 | 62 | ] |
65 | 63 | }, |
66 | 64 | { |
67 | 65 | "name": "stdout", |
68 | 66 | "output_type": "stream", |
69 | 67 | "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", |
71 | 69 | "----------------------------------------------------------------------------------------------------\n", |
72 | 70 | "****************************************************************************************************\n", |
73 | 71 | "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", |
93 | 72 | "\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", |
97 | 74 | "----------------------------------------------------------------------------------------------------\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", |
99 | 76 | "----------------------------------------------------------------------------------------------------\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", |
101 | 81 | "----------------------------------------------------------------------------------------------------\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", |
103 | 83 | "----------------------------------------------------------------------------------------------------\n", |
104 | 84 | "****************************************************************************************************\n" |
105 | 85 | ] |
|
109 | 89 | "for text in texts:\n", |
110 | 90 | " TEXT = f\"TEXT: {text}\\n\"\n", |
111 | 91 | " 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", |
114 | 93 | " 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", |
117 | 96 | " print(\"-\"*100)\n", |
118 | 97 | " print(\"*\"*100)\n", |
119 | 98 | " except Exception:\n", |
|
200 | 179 | "outputs": [], |
201 | 180 | "source": [] |
202 | 181 | }, |
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 | | - }, |
245 | 182 | { |
246 | 183 | "cell_type": "code", |
247 | 184 | "execution_count": null, |
|
0 commit comments