Method and apparatus for determining time information based on natural language
By extracting and parsing time-level information from natural language using a large language model, generating time-structured data and parsing it into standard time objects, the problem of inaccurate semantic understanding and calculation in time parsing in existing technologies is solved, and the accuracy and rigor of time calculation in the field of intelligent control are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHENGDU BOSS INNOVATION TECH CO LTD
- Filing Date
- 2026-04-22
- Publication Date
- 2026-07-17
AI Technical Summary
In the field of intelligent control, existing technologies based on rule and regular expression matching for time parsing have weak semantic understanding capabilities, making it difficult to handle complex logic and discontinuous time intervals. End-to-end large model solutions are inaccurate in calculation and have unstable output formats, making it difficult to meet the requirements of rigor.
By extracting temporal information from natural language data using a large language model, generating time-structured data, and parsing it at the execution layer to determine standard time objects, fine-grained parsing is performed using anchors and selectors to avoid computational errors in the execution layer of the large language model.
It improves the accuracy and rigor of time calculation, avoids the illusion and output errors in date calculation by large language models, and meets the rigor requirements of the field of intelligent control.
Smart Images

Figure CN122412484A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the technical field of large language models, and in particular to a method and apparatus for determining time information based on natural language. Background Technology
[0002] Currently, in the field of intelligent control, accurately understanding and calculating time is a basic requirement, especially when interacting with intelligent appliances or intelligent telephone customer service appointment systems, where time calculation is particularly important.
[0003] In related technologies, traditional solutions based on rules and regular expression matching or end-to-end large-scale models are often used. However, traditional solutions based on rules and regular expression matching have weak semantic understanding capabilities, lack complex judgment logic, struggle to handle discontinuous time intervals, and are difficult to identify dynamic timeliness. End-to-end large-scale model solutions are prone to inaccurate calculations and unstable output formats. Therefore, the time calculation solutions in related technologies are insufficient to meet the rigorous requirements of time calculation in the field of intelligent control. Summary of the Invention
[0004] In view of this, the purpose of the present invention is to provide a method and apparatus for determining time information based on natural language, which can perform more reasonable time reasoning and logical calibration, thereby alleviating the above-mentioned technical problems.
[0005] In a first aspect, embodiments of the present invention provide a method for determining time information based on natural language. The method includes: acquiring natural language information and a current reference time; extracting time-level information included in the natural language information based on the reference time and a preset semantic template using a pre-configured large language model, and generating time-structured data to express the time intent of the natural language information based on the time-level information; and parsing the time-structured data in an execution layer to determine the standard time object contained in the natural language information.
[0006] In conjunction with the first aspect, this embodiment of the invention provides a first possible implementation of the first aspect, wherein the steps of extracting time-level information included in the natural language information based on a reference time and a preset semantic template using a pre-configured large language model, and generating time-structured data for expressing the time intent of the natural language information based on the time-level information, include: parsing the natural language information using the large language model to determine the semantic template matched by the natural language information; extracting a preliminary time range and time positioning information representing the time intent from the natural language information based on the reference time and the semantic template; wherein the time positioning information is used to refine the preliminary time range; and generating time-structured data expressing the time intent based on the preliminary time range and the time positioning information.
[0007] In conjunction with the first possible implementation of the first aspect, this embodiment of the invention provides a second possible implementation of the first aspect, wherein the semantic template is a semantic template corresponding to multiple types of anchors defined according to a mutual exclusion principle; the step of extracting a preliminary time range from the natural language information based on the reference time and according to the semantic template includes: selecting an anchor that matches the natural language information from a predefined anchor library; wherein the anchor library stores multiple types of anchors defined according to a mutual exclusion principle; using the reference time as a reference, extracting first time granularity information contained in the natural language information according to the semantic template corresponding to the anchor; the first time granularity information is used to characterize the preliminary time range.
[0008] In conjunction with the second possible implementation of the first aspect, this embodiment of the invention provides a third possible implementation of the first aspect, wherein the step of extracting the first temporal granular information contained in the natural language information based on the semantic template corresponding to the anchor point includes: extracting the field corresponding to the anchor point in the semantic template; extracting the corresponding time information from the natural language information according to the field; and outputting the first temporal granular information containing the field and the time information of the anchor point.
[0009] In conjunction with the second possible implementation of the first aspect, this embodiment of the invention provides a fourth possible implementation of the first aspect, wherein the step of extracting time location information representing time intent from the natural language information based on the reference time and the semantic template includes: using a pre-configured selector to extract time location information from the natural language information according to the fields of the selector, wherein the time granularity of the selector is smaller than the time granularity of the preliminary time range extracted by the anchor point.
[0010] In conjunction with the first aspect, this embodiment of the invention provides a fifth possible implementation of the first aspect, wherein the method further includes: identifying absolute date information contained in the natural language information; and determining the standard time object based on the absolute date information.
[0011] In conjunction with the second possible implementation of the first aspect, this embodiment of the invention provides a sixth possible implementation of the first aspect, wherein the aforementioned time-structured data includes the identifier of the anchor point; the step of parsing the time-structured data in the execution layer to determine the standard time object contained in the natural language information includes: extracting the identifier of the anchor point in the time-structured data; determining the parsing logic of the time-structured data based on the identifier of the anchor point; and parsing the time-structured data according to the parsing logic to obtain the standard time object contained in the natural language information.
[0012] In conjunction with the fourth possible implementation of the first aspect, this embodiment of the invention provides a seventh possible implementation of the first aspect, wherein the aforementioned time-structured data includes the fields of the selector; the step of parsing the time-structured data in the execution layer to determine the standard time object contained in the natural language information further includes: extracting the fields of the selector contained in the time-structured data; and generating the standard time object based on the attribute values corresponding to the fields of the selector contained in the time-structured data.
[0013] In conjunction with the sixth possible implementation of the first aspect, this embodiment of the invention provides an eighth possible implementation of the first aspect, wherein the multiple types of anchors defined in the anchor library according to the mutual exclusion principle include: absolute date anchors, used to identify absolute date information contained in the natural language information; calendar container anchors, used to point to a preset time range based on the current reference time; physical displacement anchors, used to point to a time point after a specific physical duration based on the current reference time; and recursive relative anchors, used to handle time offsets of non-reference times.
[0014] Secondly, embodiments of the present invention also provide an apparatus for determining time information based on natural language. The apparatus includes: an acquisition module for acquiring natural language information and a current reference time; an extraction module for extracting time-level information included in the natural language information based on the reference time and a preset semantic template using a pre-configured large language model, and generating time-structured data for expressing the time intent of the natural language information based on the time-level information; and a determination module for parsing the time-structured data in an execution layer to determine the standard time object contained in the natural language information.
[0015] The embodiments of the present invention bring the following beneficial effects: This invention provides a method and apparatus for determining time information based on natural language. It acquires natural language information and a reference time; extracts time-level information from the natural language information using a pre-configured large language model based on the reference time and a preset semantic template; and generates time-structured data to express the time intent of the natural language information based on the time-level information. The time-structured data is parsed at the execution layer to determine the standard time objects contained in the natural language information. During the parsing process, the large language model performs semantic parsing at the semantic layer without participating in the calculation process at the execution layer. This avoids numerical errors and date illusions caused by the large language model during logical calculations, which can lead to incorrect date outputs. Furthermore, the semantic parsing by the large language model can eliminate the difficulty in handling context dependencies in regular expression matching methods in related technologies, thereby improving the accuracy of time calculation and effectively meeting the rigorous requirements for time calculation in the field of intelligent control.
[0016] Other features and advantages of the invention will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention are realized and obtained in accordance with the structures particularly pointed out in the description, claims and drawings.
[0017] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0018] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0019] Figure 1 A flowchart illustrating a method for determining time information based on natural language, provided as an embodiment of the present invention; Figure 2 A flowchart illustrating another method for determining time information based on natural language, provided in an embodiment of the present invention; Figure 3 This is a schematic diagram of the structure of a device for determining time information based on natural language, provided in an embodiment of the present invention. Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0020] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0021] Currently, existing time parsing technologies mainly include traditional solutions based on rule and regular expression matching, such as JionLP and dateutil. These traditional solutions have the following drawbacks: Weak semantic understanding: They cannot understand ambiguous expressions that depend on context. For example, "the previous two months" might refer to "January and February" or "two months ago" in different contexts, which traditional rule and regular expression matching solutions cannot distinguish. Lack of complex logic: They struggle to handle non-continuous time intervals. For example, for an instruction like "every morning at 7 AM, except weekends," traditional tools typically only identify "every day" and "weekends" as two independent entities, unable to perform set operations to handle "exclusion" logic. Lack of dynamic timeliness: For dates like "the 15th," traditional tools usually only match the current month and cannot automatically determine whether to extend to the next month based on whether the 15th has already passed.
[0022] Besides the traditional rule-based and regular expression matching solutions mentioned above, related technologies also include solutions based directly on end-to-end large models. However, such solutions are prone to inaccuracy due to the illusion problem of large models. This is because while large language models have strong semantic understanding, they suffer from "arithmetic weaknesses" in date calculations. For example, for date calculations like "what is the date of the third Friday in September 2025?", they are prone to illusions, outputting incorrect dates. Furthermore, the output format of such large language models is unstable, making it difficult to directly call them by code (datetime objects), and they are easily affected by Prompts, outputting redundant explanatory text, which does not meet the rigorous requirements of industrial-grade control systems.
[0023] Based on this, the present invention provides a method and apparatus for determining time information based on natural language, which can perform more reasonable time reasoning and logical calibration, thereby alleviating the above-mentioned technical problems.
[0024] To facilitate understanding of this embodiment, a method for determining time information based on natural language, as disclosed in this embodiment of the invention, will first be described in detail.
[0025] In one possible implementation, embodiments of the present invention provide a method for determining time information based on natural language, such as... Figure 1 The flowchart shown illustrates a method for determining time information based on natural language, including the following steps: Step S102: Obtain natural language information and current reference time; Step S104: Extract time-level information from the natural language information based on a reference time and a preset semantic template using a pre-configured large language model, and generate time-structured data to express the time intent of the natural language information based on the time-level information. Step S106: Parse the time-structured data in the execution layer to determine the standard time objects contained in the natural language information.
[0026] The aforementioned natural language information can be control language information input by the user to the smart device, such as "set an alarm for 7:00 AM on weekdays," etc. The user can directly input text information through the interactive interface, or input language information through the microphone, which will be received by the smart device. When the smart device receives the natural language information, it can determine the time or point in time when the natural language information is received, thereby determining the reference time of the natural language information, and then executing the method for determining time information based on natural language provided in this embodiment of the invention.
[0027] Furthermore, in the embodiments of the present invention, the standard time object refers to a standard time format that includes year, month, day and specific time, such as 2026-01-1600:00:00. That is, the purpose of the method for determining time information based on natural language in the embodiments of the present invention is to directly identify and output a standard time object with a standard time format from natural language information.
[0028] Furthermore, in this embodiment of the invention, the semantic induction capability of the large language model is used to perform semantic analysis on natural language information in step S104, without participating in the time determination process in step S106, which can avoid the illusion problem of the large language model.
[0029] Therefore, the method for determining time information based on natural language provided in this embodiment of the invention, in the parsing process, uses a large language model to perform semantic parsing at the semantic layer without participating in the calculation process at the execution layer. This avoids the phenomenon of numerical errors and date illusions caused by the large language model when performing logical calculations, which lead to the output of incorrect dates. Furthermore, by parsing the semantics through the large language model, the defects of regular expression matching in related technologies that are difficult to handle context dependencies can be eliminated, thereby improving the accuracy of time calculation and effectively meeting the rigorous requirements of time calculation in the field of intelligent control.
[0030] In practical use, in this embodiment of the invention, the large language model in step S104 is usually deployed as a semantic layer in the smart device, while the process of determining time in step S106 is usually deployed as an execution layer in the smart device. An intermediate protocol, such as the Intermediate Representation Protocol, is usually deployed between the semantic layer and the execution layer. This intermediate protocol can serve as a standard interface between the large language model of the semantic layer and the logical algorithm of the execution layer, thereby realizing a two-layer structure based on semantics and logic.
[0031] Furthermore, in this embodiment of the invention, when parsing the temporal intent contained in natural language information, the large language model typically first performs coarse-grained segmentation, then performs fine-grained recognition, and finally expresses the accurate temporal intent through time-structured data.
[0032] Specifically, for ease of understanding, in the above Figure 1 On this basis, Figure 2 A flowchart of another method for determining time information based on natural language is also shown, further illustrating the parsing of time intent and the calculation process of standard time objects. Specifically, such as... Figure 2 As shown, it includes the following steps: Step S202: Obtain natural language information and current reference time; Step S204: Parse natural language information using a large language model to determine the semantic template matched by the natural language information; Step S206: Based on the reference time, extract the preliminary time range and time location information representing the time intention from the natural language information according to the semantic template; Among them, the time location information is used to refine the initial time range; Step S208: Generate time-structured data expressing time intent based on the preliminary time range and time location information; Specifically, in this embodiment of the invention, the large language model adopts a hierarchical convergence approach to parse temporal intent, that is, first determines the preliminary time range contained in the natural language information, and then performs more detailed time positioning.
[0033] Furthermore, in this embodiment of the invention, anchor points are used to determine the initial time range. During this process, the anchor points can obtain a reference time, and then further determine the initial time range based on the reference time.
[0034] Specifically, in this embodiment of the invention, the semantic template is a semantic template corresponding to multiple types of anchors defined according to the mutual exclusion principle. When parsing natural language information through a large language model, anchors that match the natural language information can be selected from a predefined anchor library first. Then, based on the reference time, the first time granularity information contained in the natural language information is extracted according to the semantic template corresponding to the anchor. The first time granularity information is used to characterize the above-mentioned preliminary time range.
[0035] In this embodiment of the invention, the anchor point library stores multiple types of anchor points defined according to the mutual exclusion principle to eliminate parsing ambiguity. That is, the large language model can only select one anchor point that matches the natural language information at a time. In specific implementation, the large language model can be trained using the natural language information corresponding to each anchor point. This allows the large language model to use semantic understanding and inductive abilities to identify the natural language information and its relationship with the corresponding anchor point. Therefore, after receiving natural language information, the trained large language model can automatically identify which anchor point to use to extract the first-time granular information.
[0036] Furthermore, for the anchor points matched by the large language model, the corresponding fields in the semantic template of the anchor point can be extracted; the corresponding time information can be extracted from the natural language information according to the fields; and the first time granular information containing the fields and time information of the anchor point can be output.
[0037] In practical use, the anchor point library in this embodiment of the invention includes multiple types of anchor points defined according to the mutual exclusion principle, including: (1) Absolute date anchors are used to identify absolute date information contained in natural language information; The identifier for this absolute date anchor can be represented as "absolute". Specifically, the absolute date anchor is defined as a date that has unique certainty on the physical timeline, i.e., an absolute date. Its semantic template structure includes fields for the complete `year`, `month`, and `day`. The function of this absolute date anchor is to directly lock onto a specific date, such as "May 1, 2026", or other precise absolute date information.
[0038] Furthermore, in this embodiment of the invention, based on the absolute date anchor, the absolute date information contained in the natural language information can be directly identified; based on the absolute date information, the standard time object can be determined, that is, the absolute date information can be directly used as the standard time object for seeding without further time intent parsing.
[0039] (2) Calendar container anchor point, used to point to a preset time range based on the current reference time; The current reference time refers to the current time. For example, when recognizing natural language information, the current time can be obtained simultaneously. For instance, if a user inputs "set an alarm for 7:00 AM on a weekday," the large language model can extract the current time when it received the natural language information as the current reference time, such as 2026-01-16 09:00:00. Then, further time extrapolation can be performed. Specifically, the identifier for a calendar container anchor can be represented as "calendar," defined as: a logical time container offset relative to the current base time. It doesn't directly point to a specific day, but rather to a time range, such as "next week" or "next year." Specifically, its semantic template includes several fields: `unit`: the time unit, with values including `year` | `month` | `week` | `day` | `business_day`. `offset`: a signed integer, where `0` represents the current unit (e.g., this week), positive integers represent the future direction (e.g., `1` for the next week), and negative integers represent the past direction. Its function is to handle expressions relative to calendar cycles such as "next week," "last month," and "next year." These fields constitute the semantic template of the calendar container anchor; that is, when using this calendar container anchor, the corresponding time information can be extracted according to these fields.
[0040] (3) Physical displacement anchor point, used to point to a time point after a specific physical duration based on the current reference time; The physical displacement anchor point is represented by the offset, which is defined to indicate the point in time after a specific physical duration from the "base time". Its semantic template also includes several fields: `unit`: the time unit, supporting full granularity from `year` to `minute`, specifically including `business_day` (working day) to support industry-specific calculations. It also includes a `value` field: a signed integer, where positive numbers represent "after" and negative numbers represent "before". Its purpose is to handle time-based expressions such as "3 days later", "2 hours ago", "5 working days later".
[0041] (4) Recursive relative anchor point, used to handle time offsets of non-reference time.
[0042] The recursive relative anchor point can be represented as `relative`, defined to handle complex nested time logic, where one time point is an offset relative to another non-baseline time point. Its semantic template includes the following fields: `reference` field: a nested time point object (`TimePoint`) serving as a secondary reference (e.g., "Mid-Autumn Festival"). `Offset` field: a displacement object applied to the secondary reference (containing `unit` and `value`); its main function is to support higher-order semantics such as "the day before the Mid-Autumn Festival" or "10 minutes after cooking rice," and through recursive definition, it theoretically supports the resolution of an infinite number of relative relationships.
[0043] Furthermore, based on the aforementioned anchor library, the large language model can parse anchors suitable for the current natural language information, and then extract the corresponding time information through the fields in the semantic template of the anchors to output the first time-granularity information.
[0044] Furthermore, in step S206 above, the time positioning information used when refining the first time granularity information is extracted based on a selector. Specifically, a pre-configured selector can be used to extract time positioning information from natural language information according to the fields of the selector. Here, the time granularity of the selector is smaller than the time granularity of the initial time range extracted from the anchor point, which is equivalent to a further refinement of the initial time range.
[0045] Specifically, in this embodiment of the invention, the following selectors can be used when refining the time granularity: basic selector and ordinal selector; The basic selector includes fields such as `month` (1-12), `day` (1-31), and `weekday` (1-7). For example, if the anchor point is "next week" (calendar week offset=1), the selector `weekday: 5` will precisely locate "next Friday". The ordinal selector is used to handle the logic of the "Nth" or "Nth to last" sub-unit. Its structure also includes multiple fields, such as the `unit` field: the unit being selected (e.g., `week`, `day`, `weekday`). And the `value` field, which is usually a positive integer representing an ascending index and a negative integer representing a descending index. For example, to parse "the second Wednesday of May", the anchor point is set to "May", and the ordinal selector is described as `unit: weekday, value: 2`.
[0046] Furthermore, the time positioning information in this embodiment of the invention is also used to describe specific time scales. Therefore, in this embodiment of the invention, strict mutual exclusion logic is specified based on time-division precision and mutual exclusion processing to ensure data consistency. Specifically, the time positioning information in this embodiment of the invention also includes a precise time field, such as containing `hour` (0-23) and `minute` (0-59). If only the hour is provided, the default minute is 0; fuzzy time period (`part_of_day`): uses predefined enumerated values (such as `morning`, `afternoon`, `evening`, etc.) to represent the approximate time period.
[0047] Furthermore, the mutual exclusion logic here includes: mutual exclusion constraints, that is, forcibly stipulating that `hour / minute` and `part_of_day` are mutually exclusive. That is, a time location information cannot be both "3 pm" (precise) and "afternoon" (fuzzy) at the same time. The large language model must explicitly choose one to output based on semantics.
[0048] Furthermore, the preliminary time range and time location information determined by the above method can be used to generate time-structured data expressing time intent. In steps S204-S206, the large language model does not perform specific time calculations but is configured to only perform the "translation" task. According to the protocol, the large language model maps the natural language text information into the following mutually exclusive logical components: (1) Anchor extraction: Determine the type of time reference point. At this point, the large language model needs to choose one of four options: absolute date anchor, calendar container anchor, physical displacement anchor, and recursive relative anchor.
[0049] (2) Refinement of Selectors: During this process, the large language model extracts more granular time location information, such as `weekday: [1, 3, 5]` (Monday, Wednesday, Friday) and `time: {hour: 7, minute: 0}`.
[0050] (3) Exclusion logic identification: Explicitly extract reverse constraints, such as identifying "excluding holidays", and generate `exclude: [{festivals: true}]` or the corresponding rule structure.
[0051] Furthermore, the time-structured data in this embodiment of the invention refers to time-structured text, such as a standard YAML text that can describe the logical structure of a time intent, rather than a specific time.
[0052] For ease of understanding, five different types of natural language information and their corresponding time-structured data are provided below. The time-structured data in this embodiment is normalized data, and its structure is illustrated below: Example 1: Calendar container anchor and basic selector, handling dates containing "next Friday": The natural language information at this time could include: "Please schedule an installation appointment for me next Friday at 3 pm." The parsing logic is as follows: (1) Initial time range for anchor point positioning: The large language model can parse that "next week" is not 7 days from now, but "next week" on the calendar. Therefore, the calendar container anchor is used, that is, the `calendar` anchor, and the unit field is `week`, and the offset field is `1`.
[0053] (2) Fine-grained positioning: Within the container of "next week", which day specifically? "Friday". At this point, the large language model continues to use `weekday: 5` from the basic selectors.
[0054] 3. Time: The specific time is 3 PM, or 3:00 PM.
[0055] At this point, time-structured data can be output. For example, using YAML text, it can be represented as: anchor: {calendar: {unit: week, offset: 1}} selectors: {weekday: 5} time: {hour: 15, minute: 0} Example 2: Physical displacement anchor point, processing "3 days later"; A user instruction could be "Remind me in 3 days". The parsing logic is as follows: (1) Displacement positioning: First, the large language model parses out that this is a physical time shift based on the current base time, which does not depend on calendar page turning. Therefore, a physical displacement anchor point is used, that is, the `offset` anchor point; (2) The unit field for time is `day`, and its value is `3`.
[0056] (3) Time point: No specific time was specified, so the `time` field will not be output; The output time-structured data at this point is: anchor: {offset: {unit: day, value: 3}} Example 3: Calendar container anchor + basic selector (handling "November 11th") The user's instruction at this time might be: "I want to do an event on November 11th." The parsing logic is as follows: (1) The big language model performs container positioning: The big language parsing shows that the user did not specify which year, so it defaults to "this year" and uses the calendar container anchor point. The unit field represents the time unit as `year`, and the offset is `0`. (2) When the large language model performs fine-grained localization analysis, the 11th day of the 11th month is selected from the large container of the basic selector "this year".
[0057] At this point, the following time-structured data can be output: anchor: {calendar: {unit: year, offset: 0}} selectors: {month: 11, day: 11} Example 4: Using an ordinal selector (to handle "the second Wednesday of next month") The natural language information at this point could include "Schedule for the second Wednesday of next month". Parsing logic: (1) Anchor matching process: The large language model can parse out "next month", and then determine the use of the calendar container anchor, i.e., the `calendar` anchor, and the time unit represented by the unit field is `month`, and the offset field is `1`.
[0058] (2) Ordinal Selector Logic: The large language model can parse that in that month, we need to find "Wednesday", that is, the unit field of the ordinal selector should select "weekday" and it should be "the second one". At this time, we need to add an integer field, such as `value:2`, and use the ordinal_unit field to express it. At this time, the time structured data can be output: anchor: {calendar: {unit: month, offset: 1}} selectors:ordinal_unit: {unit: weekday, value: 2} weekday: 3 Example 5: Recursively use relative anchors to handle "the day before the Mid-Autumn Festival"; The natural language information at this time could include "returning the day before the Mid-Autumn Festival". Parsing logic: (1) The large language model can resolve that this is a time that depends on another event, so recursive relative anchors, i.e., `relative` anchors, are used.
[0059] (2) Reference: The large language model resolves the reference point as "Mid-Autumn Festival". Here, "Mid-Autumn Festival" itself is resolved into a nested time point object "TimePoint", which can be injected by the system's pre-built knowledge base, assuming it is 2025-10-06.
[0060] (3) Determine the offset field. The large language model can parse the "previous day" based on the reference object, i.e., the displacement "-1 day".
[0061] At this point, time-structured data can be output: - anchor: relative: reference: anchor: {absolute: {year: 2026, month: 9, day: 25}} offset: {unit: day, value: -1} As can be seen from the above five examples, the time-structured data in this embodiment of the invention has extremely strong orthogonality, and the various fields do not interfere with each other. Furthermore, the anchor points can determine the base time, the selector is used to determine more granular time positioning information, and the Offset field can determine whether the time is forward or backward. Moreover, the time-structured data in this embodiment of the invention eliminates the need for large language models to perform complex arithmetic operations, greatly reducing the error probability of large language models.
[0062] Furthermore, as can be seen from the above examples, in this embodiment of the invention, the time-structured data includes anchor point identifiers; for example, the identifier for the absolute date anchor point is absolute, the identifier for the calendar container anchor point is calendar, the identifier for the physical displacement anchor point is offset, and the identifier for the recursive relative anchor point is relative. In this embodiment of the invention, when further parsing the time-structured data, the corresponding algorithm logic can be determined based on the anchor point identifiers. Specifically, the following steps can be referred to: Step S210: Extract the anchor point identifiers from the time-structured data; Step S212: Determine the parsing logic for time-structured data based on the anchor point identifier; Step S214: Parse the time-structured data according to the parsing logic to obtain the standard time object contained in the natural language information.
[0063] In a specific implementation, in this embodiment of the invention, the above steps S210 to S214 can be executed in the parsing engine. That is, the parsing engine is the execution object in the execution layer. When it receives the time-structured data sent by the large language model of the semantic layer, it can trigger the corresponding parsing logic algorithm through the above anchor point identifier, and finally parse the time-structured data into a specific standard time object, that is, a specific physical time.
[0064] For example, taking the aforementioned calendar container anchor as an example, the identifier of this calendar container anchor is `calendar`. When the parsing engine recognizes that the anchor `anchor` is identified as `calendar`, it can determine that the anchor type is a calendar container anchor and execute the parsing logic algorithm corresponding to the calendar container anchor type. Furthermore, in this embodiment of the invention, the parsing logic of the calendar container anchor typically executes a normalization + offset calculation logic algorithm. Normalization refers to the algorithm first "aligning" the base time to the starting boundary of the time unit based on the unit field (such as `week`, `month`, `year`). For example, if `unit: month`, the algorithm resets the base time to 00:00:00 on the 1st of the current month; if `unit: week`, it resets it to 00:00:00 on Monday of this week. The offset algorithm refers to container shifting, which applies the value of the `offset` field based on the normalized time. Then, the date calculation library is called to perform the date + offset operation. For example, `offset: 1` and `unit: week`, that is, the time unit is week, and the offset field is 1, that is, offset by one week. The final parsing logic is to add 7 days to "this Monday" to locate "next Monday".
[0065] For example, taking the aforementioned physical displacement anchor point as an example, the identifier of this physical displacement anchor point is offset. When the parsing engine recognizes that the anchor point `anchor` is of type `offset`, it can determine that the anchor point type is a physical displacement anchor point and execute the parsing logic algorithm corresponding to the physical displacement anchor point. In this embodiment of the invention, the parsing logic of the physical displacement anchor point is usually a calculation logic of base superposition. That is, the algorithm directly uses the base time Base Time as the origin and superimposes the duration defined by the `value` field and the `unit` field. For example, when parsing `unit: hour, value: 3`, the algorithm executes the base time BaseTime + the time interval timedelta (e.g., hours=3). At this time, the BusinessDay field needs to be specially handled. For example, if the `unit` field is `business_day`, the algorithm enters a special branch, that is, it does not perform a simple `+24 hours` calculation, but combines the built-in calendar rules to cyclically check whether each day is a weekend or holiday. If a non-working day is encountered, the counter pauses until the specified number of working days is accumulated. Typically, in the parsing logic of physical displacement anchor points, a precise time point can be directly generated, which is usually used to process instructions such as "3 days later" or "2 hours ago" relative to the current time.
[0066] For example, taking the aforementioned recursive relative anchor as an example, the identifier of this recursive relative anchor is `relative`. When the parsing engine recognizes that the anchor `anchor` is of type `relative`, it can determine that the anchor type is a recursive relative anchor and execute the parsing logic algorithm corresponding to the recursive relative anchor. In this embodiment of the invention, the calculation logic of the recursive relative anchor is the calculation logic of recursive resolution. For example, when the parsing engine detects the `relative` identifier, it temporarily stores the current offset `offset` field and uses the object of the internal `reference` field as the new input, recursively calling the parsing function itself. The recursive process continues to deepen until a non-relative time point (such as an absolute date or calendar time) is parsed at the lowest level. Then, backtracking is performed to obtain the underlying base time. The algorithm returns layer by layer, applying the `offset` field defined at each layer. For example, parsing "the day before the Mid-Autumn Festival": first, the specific date of "Mid-Autumn Festival" is recursively calculated, and then the offset of `-1 day` in the `offset` field is applied to this date. That is, by layering the data, the derived time points that depend on specific events are calculated.
[0067] Furthermore, in this embodiment of the invention, as can be seen from the above examples, the time-structured data also includes selector fields; therefore, in this embodiment of the invention, when parsing the time-structured data, the selector fields contained in the time-structured data can also be extracted; a standard time object is generated based on the attribute values corresponding to the selector fields contained in the time-structured data.
[0068] For example, once the anchor point determines the initial time range (or base time), the parsing engine can check for the existence of fields identified by `selectors` to perform searches and location within the initial time range. For instance, for simple basic selectors like `month` and `day`, the corresponding properties of the date object can be directly replaced. For example, within the "Year Container" range, applying `month: 11, day: 11` directly locates November 11th of that year. For the `weekday` selector, the parsing engine can calculate the difference between the target weekday and the current date, performing a "look for the nearest" logic. For example, to find "Friday" within the "Next Week" range, it calculates the 4th day after next Monday. When the selector is identified as an ordinal selector, the corresponding iterative search calculation logic is executed. For example, the parsing engine can start from the selector's starting point, step along the timeline, and count the number of times a unit that meets the condition (such as Wednesday) appears. When the count reaches the value of the `value` field, the date is locked, and both ascending (Nth) and descending (Nth from the end) searches are supported.
[0069] In this embodiment of the invention, the parsing logic of the time-structured data determined by the identifiers of the anchor points and selectors can accurately convert various static (absolute), dynamic (displacement), relative (recursive), and logical (ordinal) time intentions described in the time-structured data into standard time objects that can be executed by a computer, that is, to obtain standard physical time that can be recognized by a computer. For example, when the input contains natural language information containing "next Friday", the standard time object of "next Friday" can be output, such as 2026-03-06 00:00:00~2026-03-06 23:59:59, which can effectively meet the rigorous requirements of time calculation in the field of intelligent control.
[0070] Furthermore, the above-described time-structured data is illustrated using YAML text as an example. In other embodiments, other formats can also be used, such as a structured function call format based on JSON Schema. In this case, when the large language model outputs time-structured data, it will not directly output time-structured data in YAML text format. Instead, it will define the aforementioned intermediate protocol as a set of standard JSON Schema formats, including anchor type `anchor_type`, time unit `unit`, signed integer `value`, and selectors, etc. This standard JSON Schema format can be used as a tool description input to the large language model that supports tool calls in this embodiment of the invention. In this case, the large language model can output time-structured data in standard JSON format, instead of the time-structured data in YAML text format described in the above embodiment.
[0071] Furthermore, the parsing engine in the execution layer no longer parses strings in YAML files, but can directly deserialize JSON objects. That is, the hierarchical structure at the logical level (such as anchors, selectors, time attributes, etc.) remains unchanged, but the data carrier changes from the non-standard YAML text format to a JSON format file that conforms to the OpenAPI standard.
[0072] The specific format of the time-structured data can be set according to the actual use case, and the embodiments of the present invention do not impose any restrictions on it.
[0073] Furthermore, based on the above embodiments, this invention also provides a device for determining time information based on natural language, such as... Figure 3 The diagram shows a device for determining time information based on natural language. The device includes: Module 30 is used to acquire natural language information and the current reference time; Extraction module 32 is used to extract time-level information included in the natural language information based on a reference time and a preset semantic template through a pre-configured large language model, and generate time-structured data to express the time intent of the natural language information based on the time-level information. The determination module 34 is used to parse the time-structured data in the execution layer to determine the standard time objects contained in the natural language information.
[0074] The apparatus for determining time information based on natural language provided in this embodiment of the invention has the same technical features as the method for determining time information based on natural language provided in the above embodiments, so it can also solve the same technical problems and achieve the same technical effects.
[0075] Furthermore, embodiments of the present invention also provide an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the above method.
[0076] This invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, performs the steps of the above-described method.
[0077] Furthermore, embodiments of the present invention also provide a schematic diagram of the structure of an electronic device, such as... Figure 4 The diagram shows the structure of the electronic device, which includes a processor 41 and a memory 40. The memory 40 stores computer-executable instructions that can be executed by the processor 41, and the processor 41 executes the computer-executable instructions to implement the above-described method.
[0078] exist Figure 4 In the illustrated embodiment, the electronic device further includes a bus 42 and a communication interface 43, wherein the processor 41, the communication interface 43, and the memory 40 are connected via the bus 42.
[0079] The memory 40 may include high-speed random access memory (RAM) and may also include non-volatile memory, such as at least one disk storage device. Communication between this system network element and at least one other network element is achieved through at least one communication interface 43 (which can be wired or wireless), such as the Internet, wide area network, local area network, metropolitan area network, etc. The bus 42 may be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus, or an EISA (Extended Industry Standard Architecture) bus, etc. The bus 42 can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 4 The symbol is represented by a single double-headed arrow, but this does not mean that there is only one bus or one type of bus.
[0080] Processor 41 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed by the integrated logic circuitry in the hardware of processor 41 or by software instructions. Processor 41 can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in the embodiments of this invention can be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. The software modules can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. The storage medium is located in the memory, and the processor 41 reads the information in the memory and uses its hardware to complete the aforementioned method.
[0081] The computer program product of the method and apparatus for determining time information based on natural language provided in the embodiments of the present invention includes a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the methods described in the preceding method embodiments. For specific implementation, please refer to the method embodiments, which will not be repeated here.
[0082] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the device described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0083] Furthermore, in the description of the embodiments of the present invention, unless otherwise explicitly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in the present invention based on the specific circumstances.
[0084] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, essentially, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0085] In the description of this invention, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing the invention and for simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on the invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0086] Finally, it should be noted that the above embodiments are merely specific implementations of the present invention, used to illustrate the technical solutions of the present invention, and not to limit it. The scope of protection of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments within the technical scope disclosed in the present invention, or make equivalent substitutions for some of the technical features; and these modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method for determining time information based on natural language, characterized in that, The method includes: Obtain natural language information and current reference time; The time-level information included in the natural language information is extracted based on a reference time and a preset semantic template using a pre-configured large language model, and time-structured data for expressing the time intent of the natural language information is generated based on the time-level information. The time-structured data is parsed at the execution layer to determine the standard time objects contained in the natural language information.
2. The method according to claim 1, characterized in that, The steps include: extracting time-level information from the natural language information based on a pre-configured large language model and a preset semantic template according to a reference time; and generating time-structured data to express the time intent of the natural language information based on the time-level information. The natural language information is parsed using the large language model to determine the semantic template that matches the natural language information; Based on the reference time, preliminary time range and time positioning information representing time intent are extracted from the natural language information according to the semantic template; wherein, the time positioning information is used to refine the preliminary time range; Based on the preliminary time range and the time location information, generate time-structured data that expresses the time intent.
3. The method according to claim 2, characterized in that, The semantic template is a semantic template corresponding to multiple types of anchors defined according to the mutual exclusion principle; The steps of extracting a preliminary time range from the natural language information based on the reference time and the semantic template include: Select an anchor point that matches the natural language information from a predefined anchor point library; wherein the anchor point library stores multiple types of anchor points defined according to the mutual exclusion principle; Using the reference time as a benchmark, the first time granularity information contained in the natural language information is extracted according to the semantic template corresponding to the anchor point; the first time granularity information is used to characterize the preliminary time range.
4. The method according to claim 3, characterized in that, The step of extracting the first temporal granular information contained in the natural language information based on the semantic template corresponding to the anchor point includes: Extract the fields corresponding to the anchor points in the semantic template; Extract the corresponding time information from the natural language information according to the fields described; Output first time granularity information containing the fields of the anchor point and the time information.
5. The method according to claim 3, characterized in that, The step of extracting time location information representing time intent from the natural language information based on the reference time and according to the semantic template includes: Using a pre-configured selector, time location information is extracted from the natural language information according to the fields of the selector, wherein the time granularity of the selector is smaller than the time granularity of the preliminary time range extracted by the anchor point.
6. The method according to claim 1, characterized in that, The method further includes: Identify the absolute date information contained in the natural language information; The standard time object is determined based on the absolute date information.
7. The method according to claim 3, characterized in that, The time-structured data includes the identifier of the anchor point; The step of parsing the temporally structured data in the execution layer to determine the standard time objects contained in the natural language information includes: Extract the identifier of the anchor point from the time-structured data; The parsing logic for the time-structured data is determined based on the identifier of the anchor point. The time-structured data is parsed according to the parsing logic to obtain the standard time object contained in the natural language information.
8. The method according to claim 5, characterized in that, The time-structured data includes the fields of the selector; The step of parsing the temporally structured data in the execution layer to determine the standard time objects contained in the natural language information further includes: Extract the fields of the selector contained in the time-structured data; The standard time object is generated based on the attribute values corresponding to the fields of the selector.
9. The method according to claim 7, characterized in that, The anchor point library includes several types of anchor points defined according to the mutual exclusion principle, including: Absolute date anchors are used to identify absolute date information contained in the natural language information; Calendar container anchor point, used to point to a preset time range based on the current base time; Physical displacement anchor points are used to point to a point in time after a specific physical duration, based on the current reference time. Recursive relative anchor points are used to handle time offsets that are not based on a reference time.
10. A device for determining time information based on natural language, characterized in that, The device includes: The acquisition module is used to acquire natural language information and the current reference time; The extraction module is used to extract the time-level information included in the natural language information based on a reference time and a preset semantic template through a pre-configured large language model, and generate time-structured data to express the time intent of the natural language information based on the time-level information. A determination module is used to parse the time-structured data in the execution layer to determine the standard time objects contained in the natural language information.