|
16 | 16 | "outputs": [], |
17 | 17 | "source": [ |
18 | 18 | "S1 = 'Today is 10/12/16 and tomorrow is January 01 2019.'\n", |
19 | | - "S2 = 'entries are due by January 4, 2017 at 8:00pm'\n", |
| 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 | 21 | "S4 = 'Dec.01.2015 - Dec 31 2015 - Dec,12,2015 - Dec,12,2015 - Dec,12th,2015 - DEC122014'\n", |
22 | 22 | "\n", |
|
28 | 28 | "execution_count": 3, |
29 | 29 | "metadata": {}, |
30 | 30 | "outputs": [ |
31 | | - { |
32 | | - "name": "stderr", |
33 | | - "output_type": "stream", |
34 | | - "text": [ |
35 | | - "DATETIME: 2019-07-09 21:13:28,268 INFO Extracting dates from the text.\n" |
36 | | - ] |
37 | | - }, |
38 | 31 | { |
39 | 32 | "name": "stdout", |
40 | 33 | "output_type": "stream", |
41 | 34 | "text": [ |
42 | 35 | "TEXT: Today is 10/12/16 and tomorrow is January 01 2019.\n", |
43 | | - "\n", |
44 | | - "datetime(date='january 01 2019', token_span=(34, 49), token_index=(6, 8), format='%B %d %Y')\n", |
45 | | - "----------------------------------------------------------------------------------------------------\n", |
46 | | - "datetime(date='10/12/16', token_span=(9, 17), token_index=(2, 2), format='%d/%m/%y')\n", |
47 | | - "----------------------------------------------------------------------------------------------------\n", |
48 | | - "****************************************************************************************************\n" |
| 36 | + "\n" |
49 | 37 | ] |
50 | 38 | }, |
51 | 39 | { |
52 | 40 | "name": "stderr", |
53 | 41 | "output_type": "stream", |
54 | 42 | "text": [ |
55 | | - "DATETIME: 2019-07-09 21:13:28,509 INFO Extracting dates from the text.\n" |
| 43 | + "DATETIME: 2019-07-11 16:49:44,986 INFO Extracting dates from the text.\n" |
56 | 44 | ] |
57 | 45 | }, |
58 | 46 | { |
59 | 47 | "name": "stdout", |
60 | 48 | "output_type": "stream", |
61 | 49 | "text": [ |
62 | | - "TEXT: entries are due by January 4, 2017 at 8:00pm\n", |
63 | | - "\n", |
64 | | - "EXTRACTION FAILED.\n", |
65 | | - "\n", |
66 | | - "****************************************************************************************************\n" |
| 50 | + "datetime(date='january 01 2019', token_span=(34, 49), token_index=(6, 8), format='%B %d %Y')\n", |
| 51 | + "----------------------------------------------------------------------------------------------------\n", |
| 52 | + "datetime(date='10/12/16', token_span=(9, 17), token_index=(2, 2), format='%d/%m/%y')\n", |
| 53 | + "----------------------------------------------------------------------------------------------------\n", |
| 54 | + "****************************************************************************************************\n", |
| 55 | + "TEXT: entries are due by January 04, 2017 at 8:00pm\n", |
| 56 | + "\n" |
67 | 57 | ] |
68 | 58 | }, |
69 | 59 | { |
70 | 60 | "name": "stderr", |
71 | 61 | "output_type": "stream", |
72 | 62 | "text": [ |
73 | | - "DATETIME: 2019-07-09 21:13:28,744 INFO Extracting dates from the text.\n" |
| 63 | + "DATETIME: 2019-07-11 16:49:45,222 INFO Extracting dates from the text.\n" |
74 | 64 | ] |
75 | 65 | }, |
76 | 66 | { |
77 | 67 | "name": "stdout", |
78 | 68 | "output_type": "stream", |
79 | 69 | "text": [ |
80 | | - "TEXT: created 01/15/2005 by ACME Inc. and associates.\n", |
81 | | - "\n", |
82 | | - "datetime(date='01/15', token_span=(8, 13), token_index=(1, 1), format='%m/%d')\n", |
| 70 | + "datetime(date='january 04, 2017', token_span=(19, 35), token_index=(4, 6), format='%B %d, %Y')\n", |
83 | 71 | "----------------------------------------------------------------------------------------------------\n", |
84 | | - "****************************************************************************************************\n" |
| 72 | + "****************************************************************************************************\n", |
| 73 | + "TEXT: created 01/15/2005 by ACME Inc. and associates.\n", |
| 74 | + "\n" |
85 | 75 | ] |
86 | 76 | }, |
87 | 77 | { |
88 | 78 | "name": "stderr", |
89 | 79 | "output_type": "stream", |
90 | 80 | "text": [ |
91 | | - "DATETIME: 2019-07-09 21:13:28,987 INFO Extracting dates from the text.\n" |
| 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" |
92 | 83 | ] |
93 | 84 | }, |
94 | 85 | { |
95 | 86 | "name": "stdout", |
96 | 87 | "output_type": "stream", |
97 | 88 | "text": [ |
| 89 | + "datetime(date='01/15', token_span=(8, 13), token_index=(1, 1), format='%m/%d')\n", |
| 90 | + "----------------------------------------------------------------------------------------------------\n", |
| 91 | + "****************************************************************************************************\n", |
98 | 92 | "TEXT: Dec.01.2015 - Dec 31 2015 - Dec,12,2015 - Dec,12,2015 - Dec,12th,2015 - DEC122014\n", |
99 | 93 | "\n", |
100 | 94 | "datetime(date='dec 31 2015', token_span=(14, 25), token_index=(2, 4), format='%b %d %Y')\n", |
|
115 | 109 | "for text in texts:\n", |
116 | 110 | " TEXT = f\"TEXT: {text}\\n\"\n", |
117 | 111 | " try:\n", |
118 | | - " parsed_dates = DateTimeParser(text, 2000, 2020, ['%b%d%Y', '%b.%d.%Y', '%b,%d,%Y', '%b,%d and %Y']) # pass your own custom formats, or just leave it.\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", |
119 | 114 | " print(TEXT)\n", |
120 | 115 | " for datetime in parsed_dates.datetime:\n", |
121 | 116 | " print(datetime)\n", |
|
0 commit comments