mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-09-06 08:16:00 +00:00
[dev] en prompts & en time extract
This commit is contained in:
commit
258ec08f3f
6 changed files with 269 additions and 6 deletions
|
|
@ -1,6 +1,9 @@
|
|||
extract_time_system:
|
||||
cn: |
|
||||
任务指令:从语句与语句发生的时间,推断并提取语句内容中指向的时间段。回答尽可能完整的时间段。回答的格式严格遵照示例中的已有格式规范。
|
||||
任务指令:从语句与语句发生的时间,推断并提取语句内容中指向的时间段。回答尽可能完整的时间段。回答的格式严格遵照示例中的已有格式规范。若语句不涉及时间则回答无。
|
||||
|
||||
en: |
|
||||
Instructions: From the sentences and the time when they occurred, infer and extract the time periods indicated in the content of the sentences. Answer with the most complete time periods possible. The format of the answers must strictly adhere to the specifications in the examples provided. If the sentence does not involve time, respond with "none."
|
||||
|
||||
|
||||
extract_time_few_shot:
|
||||
|
|
@ -47,6 +50,60 @@ extract_time_few_shot:
|
|||
回答:
|
||||
- 年:1995 - 月:10 - 日:24
|
||||
|
||||
示例8:
|
||||
句子:我的朋友非常喜欢运动,他认为运动有助于增强身体素质。
|
||||
时间:2015年1月23日,2015年第4周,周四,7时38分0秒。
|
||||
回答:
|
||||
无
|
||||
|
||||
en: |
|
||||
Example 1:
|
||||
Sentence: I remember you went to the UAE in April the year before last. Which places in the UAE are fun? Which do you prefer, Dubai or Abu Dhabi? Are the desert views spectacular?
|
||||
Time: August 20, 1992, 34th week of 1992, Monday, 18:46:25.
|
||||
Answer:
|
||||
- Year: 1990 - Month: 4
|
||||
|
||||
Example 2:
|
||||
Sentence: Remember to attend the meeting at 3 PM the day after tomorrow. I carefully marked this important day on my calendar to remind myself not to miss it. The meeting will be held in the company conference room, and it's an important opportunity to discuss future development directions.
|
||||
Time: June 19, 2024, 25th week of 2024, Tuesday, 13:30:0.
|
||||
Answer:
|
||||
- Year: 2024 - Month: 6 - Day: 21 - Hour: 15
|
||||
|
||||
Example 3:
|
||||
Sentence: Next month on the first Saturday, let's go to Hangzhou.
|
||||
Time: July 15, 2005, 28th week of 2005, Saturday, 0:0:0.
|
||||
Answer:
|
||||
- Year: 2005 - Month: 8 - Week: 31 - Day of Week: 6
|
||||
|
||||
Example 4:
|
||||
Sentence: The small town we visited last weekend was truly beautiful.
|
||||
Time: December 2, 1999, 48th week of 1999, Tuesday, 8:40:10.
|
||||
Answer:
|
||||
- Year: 1999 - Week: 47 - Day of Week: 6, 7
|
||||
|
||||
Example 5:
|
||||
Sentence: The presentation will start in half an hour, remember to prepare the materials.
|
||||
Time: June 22, 2020, 25th week of 2020, Monday, 9:30:0
|
||||
Answer:
|
||||
- Year: 2020 - Month: 6 - Day: 22 - Hour: 10 - Minute: 0 - Second: 0
|
||||
|
||||
Example 6:
|
||||
Sentence: The start time for the 10,000-meter race was 3 minutes and 47 seconds ago.
|
||||
Time: February 17, 1987, 7th week of 1987, Wednesday, 19:54:43.
|
||||
Answer:
|
||||
- Year: 1987 - Month: 2 - Day: 17 - Hour: 19 - Minute: 50 - Second: 56
|
||||
|
||||
Example 7:
|
||||
Sentence: At this time last month, we were still preparing for the concert. Every day was busy and fulfilling, and we worked hard for the successful holding of the concert. Rehearsals, set design, and program arrangements - every detail needed careful planning and preparation.
|
||||
Time: November 24, 1995, 48th week of 1995, Tuesday, 17:45:0.
|
||||
Answer:
|
||||
- Year: 1995 - Month: 10 - Day: 24
|
||||
|
||||
Example 8:
|
||||
Sentence: My friend loves sports very much and believes that exercise helps improve physical fitness.
|
||||
Time: January 23, 2015, 4th week of 2015, Thursday, 7:38:0.
|
||||
Answer:
|
||||
None
|
||||
|
||||
|
||||
extract_time_user_query:
|
||||
|
|
@ -55,6 +112,10 @@ extract_time_user_query:
|
|||
时间:{query_time_str}
|
||||
回答:
|
||||
|
||||
en: |
|
||||
Sentence: {query}
|
||||
Time: {query_time_str}
|
||||
Answer:
|
||||
|
||||
time_string_format:
|
||||
cn: |
|
||||
|
|
|
|||
|
|
@ -1,11 +1,18 @@
|
|||
long_contra_repeat_system:
|
||||
cn: |
|
||||
对下面的{num_obs}句句子,逐一判断是否与“前面序号”的任意句子存在信息的矛盾,或者句子的主要信息被“前面序号”的任意句子中的信息包含。只判断与“前面序号”的句子的关系。
|
||||
如果句子与前面序号的句子存在矛盾,则以前面序号的句子中的信息为准,修改句子中矛盾的部分。
|
||||
对每个句子都做一个判断,最后一共输出{num_obs}条判断。如果句子与前面序号的句子存在矛盾,则以前面序号的句子中的信息为准,修改句子中矛盾的部分。
|
||||
请一步步思考,并按如下格式输出:
|
||||
思考:思考的依据和过程,30字以内。
|
||||
判断:<句子序号> <矛盾,被包含,无> <修改后的内容>,一定加<>
|
||||
|
||||
en: |
|
||||
For the following {num_obs} sentences, determine one by one if there is any contradiction with the information in any "previously numbered" sentences, or if the main information of the sentence is contained within the information of any "previously numbered" sentences. Only evaluate the relation to "previously numbered" sentences.
|
||||
Make an evaluation for each sentence, resulting in a total of {num_obs} evaluations. If the sentence conflicts with a "previously numbered" sentence, the information in the earlier sentence takes precedence, and the conflicting part of the current sentence should be modified accordingly.
|
||||
Please think step by step and output in the following format:
|
||||
Thought: The basis and process of the thought, within 30 words.
|
||||
Evaluation: <sentence number> <Contradiction, Contained or None>, <Revised content>, enclosed in <>.
|
||||
|
||||
|
||||
long_contra_repeat_few_shot:
|
||||
cn: |
|
||||
|
|
@ -50,6 +57,47 @@ long_contra_repeat_few_shot:
|
|||
思考:第6句中所有信息都被前面序号中第5句的信息完全包含。
|
||||
判断:<2> <被包含> <>
|
||||
|
||||
en: |
|
||||
Example 1
|
||||
Sentences:
|
||||
1 {user_name} suffers from insomnia frequently and is interested in the effects of sleeping pills, suggesting a possible consideration of their use.
|
||||
2 {user_name} suffers from insomnia frequently and seeks remedies.
|
||||
3 Charles is {user_name}'s supervisor.
|
||||
4 Charles is {user_name}'s supervisor.
|
||||
5 Charles is {user_name}'s supervisor and the branch manager of a bank.
|
||||
Thought: The first sentence does not have any contradictions or complete repetitions with the previously numbered sentences.
|
||||
Evaluation: <1> <None> <>
|
||||
Thought: All information in the second sentence is completely contained within the information of the first sentence.
|
||||
Evaluation: <2> <Contained> <>
|
||||
Thought: The information in the third sentence does not appear in the previously numbered sentences.
|
||||
Evaluation: <3> <None> <>
|
||||
Thought: The fourth sentence is completely repetitive of the information in the third sentence, i.e., it is completely contained.
|
||||
Evaluation: <4> <Contained> <>
|
||||
Thought: The information that Charles is {user_name}'s supervisor in the fifth sentence is contained within the information of the third sentence, but the new information that Charles is the branch manager of a bank is not, so it is not contained.
|
||||
Evaluation: <5> <None> <>
|
||||
|
||||
Example 2
|
||||
Sentences:
|
||||
1 {user_name}'s child does not perform well academically.
|
||||
2 {user_name}'s child often skips school.
|
||||
3 {user_name}'s father's birthday is on June 2, 2024, and {user_name} plans to prepare a gift.
|
||||
4 {user_name}'s father's birthday is on May 1, 2024.
|
||||
5 {user_name} loves playing basketball with classmates.
|
||||
6 {user_name} likes playing basketball.
|
||||
|
||||
Thought: The first sentence does not have any contradictions or complete repetitions with the previously numbered sentences.
|
||||
Evaluation: <1> <None> <>
|
||||
Thought: The second sentence neither contradicts nor repeats any of the previously numbered sentences.
|
||||
Evaluation: <2> <None> <>
|
||||
Thought: The third sentence neither contradicts nor repeats any of the previously numbered sentences.
|
||||
Evaluation: <3> <None> <>
|
||||
Thought: The date of {user_name}'s father's birthday in the fourth sentence contradicts the information in the third sentence.
|
||||
Evaluation: <4> <Contradiction> <{user_name}'s father's birthday is on June 2, 2024.>
|
||||
Thought: The fifth sentence neither contradicts nor repeats any of the previously numbered sentences.
|
||||
Evaluation: <5> <None> <>
|
||||
Thought: All information in the sixth sentence is completely contained within the information of the fifth sentence.
|
||||
Evaluation: <6> <Contained> <>
|
||||
|
||||
long_contra_repeat_user_query:
|
||||
cn: |
|
||||
句子:
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ contra_repeat_system:
|
|||
Make an evaluation for each sentence, resulting in a total of {num_obs} evaluations.
|
||||
Please think step by step and output in the following format:
|
||||
Thought: The basis and process of the thought, within 30 words.
|
||||
Evaluation: <Contradiction, Contained, None>, enclosed in <>.
|
||||
Evaluation: <sentence number> <Contradiction, Contained or None>, enclosed in <>.
|
||||
|
||||
|
||||
contra_repeat_few_shot:
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ time_string_format:
|
|||
|
||||
get_observation_with_time_system:
|
||||
cn: |
|
||||
任务:从下面的{num_obs}句{user_name}句子中依次提取出关于{user_name}的重要信息,相应的关键词与时间信息。
|
||||
任务指令:从下面的{num_obs}句{user_name}句子中依次提取出关于{user_name}的重要信息,相应的关键词与时间信息。
|
||||
每一句{user_name}句子的格式是:<序号> <对话时间> {user_name}:<句子>
|
||||
对每一句句子,只提取非常明确的信息和进行非常确定的推断,不要进行任何猜测。不要提取重复的信息,如果句子中的所有信息与已经提取出的信息重复了则回答“重复“,如果没有重要信息则回答“无”。
|
||||
如果{user_name}信息涉及时间,则结合对话时间推断{user_name}信息的时间信息,没有则不输出。注意区分,对于句子中包含{user_name}假设的信息或者{user_name}虚构的内容比如{user_name}创作的小说或剧本,不要提取信息。
|
||||
|
|
@ -13,6 +13,16 @@ get_observation_with_time_system:
|
|||
思考:思考的依据和过程,50字以内。
|
||||
信息:<句子序号> <时间信息或“无”> <明确的重要信息或“重复”或”无“> <关键词>
|
||||
|
||||
en: |
|
||||
Instruction: Extract important information about {user_name}, corresponding keywords, and time information from the following {num_obs} sentences by {user_name}, one by one.
|
||||
Each sentence from {user_name} is formatted as: <sentence number> <conversation time> {user_name}: <sentence>
|
||||
For each sentence, only extract very clear information and make very certain inferences without any speculation. Do not extract repeated information. If all information in the sentence repeats what has already been extracted, respond with "repeat." If there is no important information, respond with "none."
|
||||
If the information about {user_name} involves time, combine it with the conversation time to infer the time information of {user_name}'s information; if not, do not output time information. Be sure to distinguish information; for example, do not extract hypothetical or fictional content from {user_name} such as {user_name}'s novels or scripts.
|
||||
Perform information extraction for each sentence, resulting in a total of {num_obs} pieces of information.
|
||||
Please think step by step, and be sure to output in the following format, with the final output enclosed in <>:
|
||||
Thought: The basis and process of the thought, within 50 words.
|
||||
Information: <sentence number> <Time information or "none"> <Clear important information or "repeat" or "none"> <keywords>
|
||||
|
||||
|
||||
get_observation_with_time_few_shot:
|
||||
cn: |
|
||||
|
|
@ -62,7 +72,6 @@ get_observation_with_time_few_shot:
|
|||
4 2023年5月21日周六14点 {user_name}:有人说兴趣是最好的老师,也建议兴趣和职业联系起来,但我发现喜欢打篮球的人很多,但靠打篮球成职业的稀少,赚钱的更少,此外,怎么分辨兴趣和喜欢
|
||||
5 2018年3月6日周四19点 {user_name}:李增杰:这个是星座蛙设,但是我是处女座的,我妈感觉因为我的不正常,我妈不让我看了\n雌猴摸了摸李增杰的头,这样啊\n雌猴打开了哔哩哔哩看了看\n雌猴:要不换个设吧,我听你未来的你说,有一个叫难忘的朱古力232这个人,他弄的设是Windows设\n这是剧本1,剧本2未完待续
|
||||
|
||||
|
||||
思考:从第1句可以得知{user_name}和家人上个月去杭州旅游了,这是关于{user_name}的经历的重要信息。其余信息重要性不足。{user_name}信息涉及时间,结合对话时间为2023年6月推断{user_name}和家人2023年5月去杭州旅游了。
|
||||
信息:<1> <2023年5月> <{user_name}和家人2023年5月去杭州旅游了。> <家人, 杭州, 旅游>
|
||||
思考:从第2句可以得知{user_name}的生日是昨天,这是关于{user_name}重要纪念日的信息。其余信息重要性不足。{user_name}信息涉及时间,结合对话时间为2023年7月2日,
|
||||
|
|
@ -75,9 +84,70 @@ get_observation_with_time_few_shot:
|
|||
思考:第5句是{user_name}创作的剧本内容,无法提取{user_name}个人信息。
|
||||
信息:<5> <> <无> <>
|
||||
|
||||
en: |
|
||||
Example 1:
|
||||
{user_name} sentences:
|
||||
1 May 1, 2022, Tuesday, 3 PM {user_name}: Please help me write a birthday greeting for my colleague Jason's daughter who is turning three.
|
||||
2 May 2, 2022, Tuesday, 5 PM {user_name}: Chronology of major events in Chinese history from 1400 to 1550 AD.
|
||||
3 May 3, 2022, Tuesday, 6 PM {user_name}: Can you compile a list of tips on how to use large models for me, and try to keep the content concise?
|
||||
4 July 3, 2022, Thursday, 12 PM {user_name}: I got a swimming pass two months ago.
|
||||
|
||||
Thought: From the first sentence, it can be inferred that Jason is {user_name}'s colleague, which is important information about {user_name}'s interpersonal relationships. The remaining information is of insufficient importance. {user_name}'s information does not involve time.
|
||||
Information: <1> <> <Zhang San is {user_name}'s colleague> <Zhang San, colleague>
|
||||
Thought: The second sentence is a request made by {user_name}, with no clear mention of {user_name}'s personal information.
|
||||
Information: <2> <> <none> <>
|
||||
Thought: The third sentence is a request made by {user_name}, with no clear mention of {user_name}'s personal information.
|
||||
Information: <3> <> <none> <>
|
||||
Thought: From the fourth sentence, it can be inferred that {user_name} got a swimming pass two months ago. {user_name}'s information involves time. Combining it with the conversation time of July 2022, it can be inferred that {user_name} got the swimming pass in May 2022.
|
||||
Information: <4> <May 2022> <{user_name} got a swimming pass in May 2022> <swimming pass>
|
||||
|
||||
|
||||
Example 2:
|
||||
{user_name} sentences:
|
||||
1 January 4, 2020, Sunday, 10 AM {user_name}: I spent $5000 to buy 100 shares of General Motors.
|
||||
2 April 27, 2023, Friday, 8 AM {user_name}: Tomorrow is my wedding anniversary with my wife. Could you recommend a restaurant?
|
||||
3 January 4, 2020, Sunday, 10 AM {user_name}: I spent $5000 to buy 100 shares of General Motors.
|
||||
4 June 2, 2021, Thursday, 11 PM {user_name}: Thanks. I'm having lunch near the company at noon; can you recommend a restaurant near Alibaba Xuhui Riverside Campus for me?
|
||||
5 July 9, 2021, Saturday, 11 AM {user_name}: Two pieces of bad news: I broke my badminton racket while playing... Then I went to my friend's house to pet the cat and ended up having an allergic reaction to the cat fur, sneezing like crazy today...
|
||||
|
||||
Thought: From the first sentence, it can be inferred that {user_name} bought 100 shares of General Motors stock for $5000. This is important information about {user_name}'s investment decision. {user_name}'s information does not involve time.
|
||||
Information: <1> <> <{user_name} bought 100 shares of General Motors stock for $5000> <General Motors, stock>
|
||||
Thought: From the second sentence, it can be inferred that {user_name}'s wedding anniversary with his wife is tomorrow, which is important information about {user_name}'s significant dates. The remaining information is of insufficient importance. {user_name}'s information involves time. Combining it with the conversation date of April 27, 2023, and knowing that the anniversary is a recurring date, it can be inferred that {user_name}'s wedding anniversary is on April 28th each year.
|
||||
Information: <2> <April 28 each year> <{user_name}'s wedding anniversary with his wife is on April 28 each year> <wife, wedding anniversary>
|
||||
Thought: The information in the third sentence is a repeat of the first sentence.
|
||||
Information: <3> <> <repeat> <>
|
||||
Thought: From the fourth sentence, it can be inferred that {user_name} works at Alibaba Xuhui Riverside Campus, which is important information about {user_name}'s job. The remaining information is of insufficient importance. {user_name}'s information does not involve time.
|
||||
Information: <4> <> <{user_name} works at Alibaba Xuhui Riverside Campus> <Alibaba, Xuhui Riverside Campus, job>
|
||||
Thought: From the fifth sentence, it can be inferred that {user_name} broke their badminton racket the other day while playing, but this is not important information. It can also be inferred that {user_name} is allergic to cat fur, which is important information about {user_name}'s health. {user_name}'s information does not involve time.
|
||||
Information: <5> <> <{user_name} is allergic to cat fur> <cat fur, allergy>
|
||||
|
||||
|
||||
Example 3:
|
||||
{user_name} sentences:
|
||||
1 June 30, 2023, Friday, 3 PM {user_name}: Last month, my family and I went to San Jose for a trip. The scenery was very nice.
|
||||
2 July 2, 2023, Tuesday, 10 AM {user_name}: Yesterday was my birthday. I spent it alone.
|
||||
3 July 3, 2020, Thursday, 11 AM {user_name}: Remind me to go for a medical check-up next Monday.
|
||||
4 May 21, 2023, Saturday, 2 PM {user_name}: Someone said that passion is the best teacher and suggested linking passion with a career, but I found that many people like playing basketball, but few make a career out of it, and even fewer make money from it. Also, how do you distinguish passion from liking?
|
||||
5 March 6, 2018, Thursday, 7 PM {user_name}: Zack: This is a constellation frog setting, but I am a Virgo. My mom feels I am abnormal and doesn't let me watch it. \n The female monkey patted Zack's head, "Is that so?" \n The female monkey opened Bilibili and took a look. \n Female monkey: "Why don't you switch the setting? I heard from your future self that there's someone called 'Unforgettable Chocolate 232' who created a Windows setting." \n This is script 1; script 2 is to be continued.
|
||||
|
||||
Thought: From the first sentence, it can be inferred that {user_name} and their family went to San Jose for a trip last month. This is important information about {user_name}'s experience. The remaining information is of insufficient importance. {user_name}'s information involves time. Combining it with the conversation time of June 2023, it can be inferred that {user_name} and their family went to San Jose for a trip in May 2023.
|
||||
Information: <1> <May 2023> <{user_name} and their family went to San Jose for a trip in May 2023> <family, San Jose, trip>
|
||||
Thought: From the second sentence, it can be inferred that {user_name}'s birthday was yesterday. This is important information about {user_name}'s significant dates. The remaining information is of insufficient importance. {user_name}'s information involves time. Combining it with the conversation time of July 2, 2023, and knowing that the birthday is a recurring date, it can be inferred that {user_name}'s birthday is on July 2 each year.
|
||||
Information: <2> <July 2 each year> <{user_name}'s birthday is on July 2 each year> <birthday>
|
||||
Thought: From the third sentence, it can be inferred that {user_name} will go for a medical check-up next Monday, which is an important reminder for {user_name}. {user_name}'s information involves time. Combining it with the conversation time of July 3, 2020, Thursday, it can be inferred that {user_name} will go for a check-up on July 6, 2020, Monday.
|
||||
Information: <3> <July 6, 2020, Monday> <{user_name} will go for a medical check-up on July 6, 2020, Monday> <medical check-up>
|
||||
Thought: The fourth sentence is a discussion and query about other people's opinions by {user_name}, with no clear mention of {user_name}'s personal information.
|
||||
Information: <4> <> <none> <>
|
||||
Thought: The fifth sentence is content from a script written by {user_name}, with no extractable personal information about {user_name}.
|
||||
Information: <5> <> <none> <>
|
||||
|
||||
|
||||
get_observation_with_time_user_query:
|
||||
cn: |
|
||||
{user_name}句子:
|
||||
{user_query}
|
||||
|
||||
en: |
|
||||
{user_name} sentences:
|
||||
{user_query}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ get_observation_system:
|
|||
Perform information extraction for each sentence, resulting in a total of {num_obs} pieces of information.
|
||||
Please output the results in the following format, with the final output enclosed in <>:
|
||||
Thought: The basis and process of the thought, within 50 words.
|
||||
Information: <> <Clear important information or “Repeat” or “None”> <keywords>
|
||||
Information: <sentence number> <> <Clear important information or “Repeat” or “None”> <keywords>
|
||||
|
||||
|
||||
get_observation_few_shot:
|
||||
|
|
|
|||
|
|
@ -66,6 +66,90 @@ class DatetimeHandler(object):
|
|||
extracted_data[key] = int(match.group(1))
|
||||
return extracted_data
|
||||
|
||||
@classmethod
|
||||
def extract_date_parts_en(cls, input_string: str) -> dict:
|
||||
date_info = {
|
||||
"year": -1,
|
||||
"month": -1,
|
||||
"day": -1,
|
||||
"hour": -1,
|
||||
"minute": -1,
|
||||
"second": -1,
|
||||
"weekday": -1
|
||||
}
|
||||
|
||||
# Patterns to extract the parts of the date/time
|
||||
# Patterns to extract the parts of the date/time
|
||||
patterns = {
|
||||
"year": r"\b(\d{4})\b",
|
||||
"month": r"\b(January|February|March|April|May|June|July|August|September|October|November|December)\b",
|
||||
"day_month_year": r"\b(?P<month>January|February|March|April|May|June|July|August|September|October|November|December) (?P<day>\d{1,2}),? (?P<year>\d{4})\b",
|
||||
"day_month": r"\b(?P<month>January|February|March|April|May|June|July|August|September|October|November|December) (?P<day>\d{1,2})\b",
|
||||
"hour_12": r"\b(\d{1,2})\s*(AM|PM|am|pm)\b",
|
||||
"hour_24": r"\b(\d{1,2}):(\d{2}):(\d{2})\b"
|
||||
}
|
||||
|
||||
month_mapping = {
|
||||
"January": 1, "February": 2, "March": 3, "April": 4,
|
||||
"May": 5, "June": 6, "July": 7, "August": 8,
|
||||
"September": 9, "October": 10, "November": 11, "December": 12
|
||||
}
|
||||
|
||||
weekday_mapping = {
|
||||
"Monday": 1, "Tuesday": 2, "Wednesday": 3, "Thursday": 4,
|
||||
"Friday": 5, "Saturday": 6, "Sunday": 7
|
||||
}
|
||||
|
||||
day_month_year_match = re.search(patterns["day_month_year"], input_string)
|
||||
if day_month_year_match:
|
||||
date_info["year"] = int(day_month_year_match.group("year"))
|
||||
date_info["month"] = month_mapping[day_month_year_match.group("month")]
|
||||
date_info["day"] = int(day_month_year_match.group("day"))
|
||||
|
||||
# Extract month and day without year
|
||||
elif date_info["year"] == -1:
|
||||
day_month_match = re.search(patterns["day_month"], input_string)
|
||||
if day_month_match:
|
||||
date_info["month"] = month_mapping[day_month_match.group("month")]
|
||||
date_info["day"] = int(day_month_match.group("day"))
|
||||
|
||||
# Extract year
|
||||
if date_info["year"] == -1:
|
||||
year_match = re.search(patterns["year"], input_string)
|
||||
if year_match:
|
||||
date_info["year"] = int(year_match.group(0))
|
||||
|
||||
# Extract month
|
||||
if date_info["month"] == -1:
|
||||
month_match = re.search(patterns["month"], input_string)
|
||||
if month_match:
|
||||
date_info["month"] = month_mapping[month_match.group(0)]
|
||||
|
||||
# Extract 12-hour format time
|
||||
hour_12_match = re.search(patterns["hour_12"], input_string)
|
||||
if hour_12_match:
|
||||
hour, period = int(hour_12_match.group(1)), hour_12_match.group(2).lower()
|
||||
if period == 'pm' and hour != 12:
|
||||
hour += 12
|
||||
elif period == 'am' and hour == 12:
|
||||
hour = 0
|
||||
date_info["hour"] = hour
|
||||
|
||||
# # Extract 24-hour format time
|
||||
# hour_24_match = re.search(patterns["hour_24"], input_string)
|
||||
# if hour_24_match:
|
||||
# date_info["hour"] = int(hour_24_match.group(1))
|
||||
# date_info["minute"] = int(hour_24_match.group(2))
|
||||
# date_info["second"] = int(hour_24_match.group(3))
|
||||
|
||||
# Extract weekday
|
||||
for week_day, value in weekday_mapping.items():
|
||||
if week_day in input_string:
|
||||
date_info["weekday"] = value
|
||||
break
|
||||
|
||||
return date_info
|
||||
|
||||
@classmethod
|
||||
def extract_date_parts(cls, input_string: str) -> dict:
|
||||
func_name = f"extract_date_parts_{G_CONTEXT.language}"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue