A neo4j-based dynamic semantic relationship graph construction method and system
By building an index and calculating semantic relationship determination in the Neo4j graph database, the instability of the graph structure under multi-source heterogeneous real-world data is solved, and the stability and consistency of the dynamic semantic relationship graph are achieved, supporting real-time response warnings and retrieval.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- GUANGZHOU ZHONGYUAN NETWORK TECH CO LTD
- Filing Date
- 2026-03-26
- Publication Date
- 2026-05-19
AI Technical Summary
In multi-source heterogeneous real-world data environments, existing technologies suffer from frequent flipping of the real-time relationship graph structure, resulting in poor stability, high false alarm rates, and difficulty in long-term stable operation and large-scale deployment in engineering.
By acquiring real-world object identifiers, category labels, and time numbers, relationship observation units are generated. An index is built based on the Neo4j graph database. The validity status of the relationship is determined by using time number sequence buffer rolling clipping, smoothing intensity calculation, and semantic relationship determination, and scene response events are output.
It achieves stability and consistency of the graph structure under multi-source out-of-order update conditions, reduces the jitter of query and early warning, ensures the continuity and availability of relation state, and supports real-time response of early warning and retrieval.
Smart Images

Figure CN121902959B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of data processing, and in particular relates to a method and system for constructing dynamic semantic relationship graphs based on Neo4j. Background Technology
[0002] Constructing semantic relationship graphs using real-scene perception data has become a crucial foundation for situational understanding, risk warning, and intelligent retrieval. Current engineering implementations typically use detection results from cameras, radar, positioning systems, and various sensors as input, abstracting real-scene objects such as people, vehicles, equipment, and facilities as graph nodes. Spatial location relationships, attribute relationships, temporal relationships, and logical rule relationships are used as edges to form a relationship network in a graph database, enabling the expression, querying, and linkage of scene states. Graph databases are widely used due to their advantages in expressing multi-hop relationships and supporting graph traversal queries. However, in real-world deployment environments, real-scene data is characterized by multi-source heterogeneity, real-time arrival, and high uncertainty. Different devices exhibit significant differences in spatiotemporal accuracy, sampling frequency, occlusion, and noise levels, leading to repeated, intermittent, or contradictory observations of the same object pair's relationship within a short period. This is accompanied by common engineering issues such as out-of-order arrival, duplicate reporting, and delayed reporting. The common update methods in existing technologies, such as "event-triggered writing" and "overwriting old results with the latest results," cause relationship edges to frequently flip in the database. The graph structure changes with the input order and short-term fluctuations, making it difficult to maintain the stability of the output. On the other hand, many systems treat relationship writing as a one-time fact determination, lacking an organizational and continuous discrimination mechanism for the basis of relationship formation. Once subsequent observations weaken or negate previous relationships, they can only be corrected by deletion or overwriting, which not only disrupts the continuity of relationship evolution but also causes warnings and retrievals to be repeatedly triggered, deactivated, or return inconsistent results in a short period of time, leading to false alarms, jitter, and uninterpretable problems. These contradictions are particularly prominent in multi-source dynamic scenarios and have become a key bottleneck restricting the long-term stable operation and large-scale deployment of dynamic semantic relationship graphs based on graph databases in engineering. Summary of the Invention
[0003] This invention discloses a method and system for constructing dynamic semantic relation graphs based on Neo4j, in order to solve the above-mentioned technical problems existing in the prior art.
[0004] To achieve the above objectives, a method for constructing a dynamic semantic relation graph based on Neo4j is provided in a first aspect of the present invention, the method comprising:
[0005] Obtain real-world object identifiers, category labels, and time numbers; generate relational observation units based on the location association, attribute association, temporal association, or logical association of candidate object pairs.
[0006] An index is constructed using real-scene object pairs and relationship types as keys. The time number of the relationship observation unit is appended to the time number sequence buffer, and the time number sequence buffer is scroll-trimmed based on the window length parameter.
[0007] The decay observation intensity of the time-numbered sequence buffer is calculated, and the smoothing intensity of the current time is updated based on the smoothing coefficient and the smoothing intensity cache value of the previous time step.
[0008] The semantic relationship determination score is calculated based on the smoothing intensity, the attenuation observation intensity, and the relation type weight parameter, and the semantic relationship determination score is compared with the determination threshold to obtain the semantic relationship validity status.
[0009] Based on the semantic relationship validity status and holding window length parameter, a relationship validity flag is determined. The corresponding node and relationship edge are located or created in the Neo4j graph database. The relationship validity flag is written into the available status attribute of the relationship edge. A scene response event is generated when the relationship validity flag changes.
[0010] Furthermore, the relation generation observation unit includes:
[0011] Calculate the spatial distance between the first real-world object and the second real-world object in the candidate object pair, and generate a position-related observation when the spatial distance is less than the proximity determination threshold;
[0012] Read the category labels of the first real-world object and the second real-world object, and generate attribute association observations when the category labels meet the preset category matching rules;
[0013] The number of times the first real-world object and the second real-world object appear simultaneously within the most recent preset number of time numbers is counted. When the number of occurrences reaches a preset counting threshold, a time-series correlation observation is generated.
[0014] Based on preset scenario logic rules, a Boolean identifier is determined, and a logical association observation is generated when the Boolean identifier is true.
[0015] The generated location-related observations, attribute-related observations, time-series-related observations, or logical-related observations are encapsulated into relational observation units containing real-world object identifiers, relation type identifiers, and time numbers.
[0016] Further, calculating the decay observation intensity of the time-numbered sequence buffer includes:
[0017] Iterate through each time number in the time number sequence buffer and calculate the time difference between each time number and the current time number;
[0018] The weight value corresponding to each time number is calculated based on the time difference, window length parameter and attenuation coefficient parameter, wherein the weight value decreases as the time difference increases;
[0019] The attenuation observation intensity is obtained by summing the weight values corresponding to each of the time numbers.
[0020] Furthermore, the update to obtain the smoothing intensity at the current moment includes:
[0021] Retrieve the cached value of the smoothing intensity under the previous time number;
[0022] The attenuation observation intensity under the current time number is used as the input value, and the input value and the smooth intensity buffer value are weighted and calculated using the first-order exponential moving average formula;
[0023] The weighted calculation result is used as the smoothing intensity under the current time number, and the smoothing intensity cache value is updated.
[0024] Furthermore, the calculation of the semantic relationship determination score includes:
[0025] Calculate the absolute value of the deviation between the observed attenuation intensity and the smoothing intensity;
[0026] The absolute value of the deviation is added to a constant to obtain the denominator term;
[0027] The numerator is obtained by multiplying the attenuation observation intensity by the relation type weight parameter.
[0028] Divide the numerator by the denominator to obtain the intermediate term, and add the intermediate term to the smoothing intensity to obtain the semantic relationship determination score.
[0029] Furthermore, the valid criteria for determining the relationship include:
[0030] When the semantic relationship validity status indicates that the relationship is valid, the relationship validity flag is set to the first value, and the current time number is recorded as the most recent valid time number;
[0031] When the semantic relationship validity status indicates that the relationship is invalid, calculate the time difference between the current time number and the most recent valid time number;
[0032] When the time difference is less than or equal to the holding window length parameter, the relationship validity flag is kept at the first value;
[0033] When the time difference is greater than the holding window length parameter, the relationship validity flag is set to the second value.
[0034] Furthermore, locating or creating corresponding nodes and relational edges in the Neo4j graph database includes:
[0035] Use the MERGE statement to find or create a first and second node with a unique primary key attribute based on the real-world object identifier;
[0036] Use the MERGE statement to find or create a relation edge connecting the first node and the second node based on the first node, the second node, and the relation type.
[0037] Read the most recent valid time number attribute of the relation edge. If the relation edge is newly created and the most recent valid time number attribute has not been written, then write the current time number into the most recent valid time number attribute.
[0038] Furthermore, the generated scene response events include:
[0039] Obtain the available state attribute values of the relation edge at the current time number, and the historical values of the available state attributes at the previous processing time.
[0040] When the available state attribute value changes from the second value to the first value, a relationship activation event is constructed, which includes the real-world object pair identifier and the relationship type identifier.
[0041] When the available state attribute value changes from the first value to the second value, a relationship failure event containing the real-world object pair identifier and the relationship type identifier is constructed.
[0042] Output the event indicating whether the relationship is effective or ineffective.
[0043] Furthermore, after generating the scene response event, the method further includes:
[0044] Parse the relationship type identifier and real-world object pair identifier in the scene response event;
[0045] If the scenario response event is a relationship activation event, an alarm control signal is generated according to the pre-stored rule configuration data, and the local index status flag is updated to indicate that subsequent graph query operations will only traverse the relationship edges whose available status attribute is the first value.
[0046] If the scenario response event is a relationship failure event, an alarm cancellation control signal is generated according to the pre-stored rule configuration data, and the local index status flag is updated to indicate that subsequent graph query operations will exclude relation edges with the second value as the available status attribute.
[0047] In a second aspect, the present invention provides a dynamic semantic relation graph construction system based on Neo4j, the system comprising:
[0048] The observation unit generation module is used to obtain real-world object identifiers, category labels, and time numbers, and generate relational observation units based on the location association, attribute association, temporal association, or logical association of candidate object pairs.
[0049] The sequence maintenance and intensity calculation module is used to construct an index with real-scene object pairs and relationship types as keys, append the time number of the relationship observation unit to the time number sequence buffer, and perform rolling clipping on the time number sequence buffer based on the window length parameter; calculate the decay observation intensity of the time number sequence buffer, and update the smoothing intensity at the current time based on the smoothing coefficient and the smoothing intensity cache value of the previous time.
[0050] The semantic relationship determination module is used to calculate the semantic relationship determination score based on the smoothing intensity, the attenuation observation intensity and the relationship type weight parameter, and compare the semantic relationship determination score with the determination threshold to obtain the semantic relationship validity status.
[0051] The graph update and event response module is used to determine the validity flag of the relationship based on the validity status of the semantic relationship and the holding window length parameter, locate or create the corresponding node and relationship edge in the Neo4j graph database, write the validity flag of the relationship into the available status attribute of the relationship edge, and generate a scene response event when the validity flag of the relationship changes.
[0052] The beneficial technical effects of the present invention are at least as follows:
[0053] To address the aforementioned issues, this invention provides a method and system for constructing a dynamic semantic relation graph based on Neo4j. It unifies and abstracts discrete observations of real-world object pairs across four types of relationships—location, attribute, temporal sequence, and logical—into structured relation observation units. Based on this, a rollable and maintainable relation observation set is constructed according to object pairs and relation types. By introducing recentity and trend characterization into the observation set, the system can use stable set states rather than single observations as the basis for relation determination. Furthermore, this invention generates semantic relation validity results based on the internal states of the observation set, driving the entry of a relation into the main graph structure through an interpretable determination process, thereby reducing the impact of short-term noise and sporadic observations on relation edges. At the graph database implementation level, this invention maps the semantic relation validity results to the available states of relation edges in Neo4j, and combines a discrete-time holding mechanism to ensure continuous availability of relations within a short window, avoiding query and alert jitter caused by frequent creation, deletion, or flipping. Simultaneously, relation state changes are output as events to drive immediate responses to alerts and retrieval. Through the above improvements, this invention enables the dynamic map to maintain a consistent, stable, and usable external performance under conditions of multi-source, out-of-order, and concurrent updates, and realizes an engineering closed loop that links map structure updates with early warning retrieval in practical scenarios. Attached Figure Description
[0054] The present invention will be further described with reference to the accompanying drawings, but the embodiments in the drawings do not constitute any limitation on the present invention. For those skilled in the art, other drawings can be obtained based on the following drawings without creative effort.
[0055] Figure 1 This is a flowchart of a method for constructing a dynamic semantic relation graph based on Neo4j according to the present invention.
[0056] Figure 2 This is a framework diagram of a dynamic semantic relation graph construction system based on Neo4j according to the present invention. Detailed Implementation
[0057] Embodiments of the present invention are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention.
[0058] In one or more embodiments, such as Figure 1 As shown, a method for constructing a dynamic semantic relation graph based on Neo4j is disclosed, the method comprising the following:
[0059] S1: Obtain the real-world object identifier, category label, and time number, and generate relational observation units based on the location association, attribute association, temporal association, or logical association of candidate object pairs;
[0060] Specifically, this step is driven by a real-time dynamic update engine in the actual system. Taking a typical park or factory scenario as an example, several fixed network cameras are deployed in the area. The cameras collect video streams at a fixed sampling frequency and process them in real time through edge computing devices. The video frames first enter the target detection and multi-target tracking module, which uses a convolutional neural network to complete target recognition and localization. The network structure includes an input layer, several convolutional layers for extracting spatial features, pooling layers for feature compression, and two output branches: a classification branch that outputs the target category label, and a regression branch that outputs the target bounding box coordinates. The detection results enter the target tracking module, where a stable and unique identifier is assigned to each continuously appearing target through inter-frame feature matching and Hungarian matching algorithms. Therefore, within any given sampling period, the system can obtain several real-world object identifiers and their corresponding center coordinates. Category labels and time numbers Time number It is generated by an internal system counter that increments at a fixed period and is used to identify the current sampling time.
[0061] Within the current sampling period, the system pairs all detected real-world objects to form candidate object pairs. For each pair of objects, a positional correlation determination is first performed. The system calculates the spatial distance between the objects based on the center coordinates output by the detection module.
[0062] ;
[0063] in, Represents objects The center coordinate components are output by the regression branch of the detection network; Represents objects The center coordinate components; This represents the spatial distance between two objects in the current sampling period. During the deployment phase, the system configures the proximity threshold based on the scene scale. For example, in a warehouse aisle scenario, this threshold corresponds to the aisle width range. When At that time, it is assumed that the object is numbered at the current time. The location association condition must be met. For example, within a certain sampling period, if the object... With objects The coordinate difference calculation results satisfy The system records one location-related observation; if the calculation result is If not, then this type of observation will not be recorded.
[0064] Attribute association is determined by reading the category labels output by the detection network. During the initialization phase, the system defines category matching rules, such as "person-equipment" or "same type of equipment-same type of equipment" to establish attribute associations. When a candidate object... When the category combination satisfies the rule, it is numbered at the current time. The next generation generates an attribute association observation. Temporal association is achieved by maintaining a length of [length missing] for each object pair. This is implemented using a time-sliding window. The system maintains a count record for each object pair in memory, tracking its most recent occurrences. The system generates a time-series correlation observation by counting the number of times two individuals appear simultaneously within a given time period, once the count reaches a preset threshold. For example, in a collaborative behavior analysis scenario, if two individuals appear close to each other across multiple consecutive sampling periods, a time-series correlation observation will be triggered. Logical correlation is determined by a Boolean identifier generated by the rule-based judgment module. The rules module makes judgments based on preset scenario logic, such as "objects". Entering the restricted area and the object "Not entered" When true, generate logically related observations.
[0065] When any semantic relation condition is met, the system generates a relation observation unit. .in The real-world object identifier originates from the target tracking module; It serves as an identifier for the relation type, and its value is limited to one of position, attribute, time sequence, or logic; This is the current sampling time number. If the same object pair satisfies multiple relational conditions simultaneously within the same time number, then multiple [relationships] will be generated respectively. For example, numbering at a certain time. At that time, the object With objects If the distance satisfies the proximity condition and the category matching rule is also met, then two relation observation units are generated, corresponding to location association and attribute association respectively. All relation observation units generated within the current sampling period. Constituting the set of relational observation units This set provides a unified and well-structured input for subsequent steps in constructing relational observation sets.
[0066] S2: Construct an index using real-scene object pairs and relationship types as keys, append the time number of the relationship observation unit to the time number sequence buffer, and perform rolling clipping on the time number sequence buffer based on the window length parameter; calculate the attenuation observation intensity of the time number sequence buffer, and update the smoothing intensity at the current time based on the smoothing coefficient and the smoothing intensity cache value of the previous time.
[0067] Specifically, the construction of the relation observation set is based on the relation observation unit set output in step one. For input, each observation unit is... Here and It is a real-world object identifier, output by the target detection and tracking module and kept consistent across adjacent sampling periods; It is a relation type identifier, limited to one of position, attribute, time sequence, or logic; This is a time number, generated by the system clock counter incrementing according to the sampling period. The system establishes a triplet in memory. This is an index structure for keys, where the index value is a buffer of time sequence numbers corresponding to that key. This is used to collect multiple observations of the same real-world object pair under the same relation type. Whenever a new... Upon arrival, the system uses position ,Will Append to the end of the sequence, based on the window length parameter. Perform a rolling pruning on the sequence so that only those sequences satisfying the following conditions are retained. Time number To ensure computational stability, a comparison is performed on the tail element during sequence appending: if the tail element is already equal to... It maintains a single record so that repeated writes within the same sampling period do not create duplicate time numbers in the set.
[0068] In real-world scenarios oriented towards early warning and retrieval, relationship observation commonly encounters two types of interference: one is transient jitter (e.g., a short-term occlusion causing a missing observation), and the other is sporadic crossing (e.g., two people briefly crossing each other, resulting in a proximity observation). Relying solely on hard counting of "occurrence counts" within a window often confuses these two types of situations; therefore, a set of... While storing the time-numbered sequence, an observation intensity with "stronger recentity" is calculated. This allows observations closer to the current time to contribute more significantly. The initial source of this calculation comes from the mathematical concept of the exponentially decaying kernel, whose classic use is to apply weights to historical samples in a time series that decay exponentially with time difference. Building upon this, this step changes the independent variable of the kernel function from continuous time to the discrete-time index difference. And introduce a window scale normalization term. This ensures that the attenuation pattern remains consistent across different window lengths, thus adapting to different sampling frequencies and scene scales. The observation intensity is calculated using the following formula:
[0069] ;
[0070] in, For key Time-numbered sequence buffer, Number a specific time in the buffer. Number the current time. For window length parameter, For the attenuation coefficient parameter, This represents the attenuation observation intensity at the current time number. This formula is derived from the classic form of "window counting". Derived from: constant weights Replace with weights that vary with time difference This causes the contribution of each observation to decrease as its interval from the current observation increases; where As a dimensionless ratio, it ensures that the form of the independent variable of the exponential function is consistent with common exponential kernels. The numerical range of this intensity varies with the number of observations and the attenuation parameter, but under the same configuration, the stability of the relationship between different object pairs can be directly compared.
[0071] In terms of engineering implementation, The calculation can be obtained by traversing the buffer. To demonstrate operability, a set of calculation examples based on proportional values and configuration parameters are given: Let... , Current time number ,and Internal time number is The time differences of the three observations are respectively The corresponding weights are respectively , , Use commonly used approximate values. , , ,but Under the same parameters, if another object pair only... If an observation occurs, then its The value is approximately The difference between the two can reflect a stronger relationship of "occurring multiple times in the recent period".
[0072] To ensure smoother and more continuous input for subsequent steps when reading the set state, this step... Further maintain smoothness strength The initial source of this recursive form is the classic first-order exponential moving average (EMA), which is equivalent to a discrete implementation of a first-order low-pass filter in signal processing and control systems. The standard recursive formula for EMA is... ,in This step involves inputting the sequence. Specifically, the above formula yields... This transforms the "recent weighted count" into a more stable state variable, reducing the impact of single-observation jitter on the ensemble state. The recursive formula is as follows:
[0073] ;
[0074] in, The smoothing intensity at the current time number. The smoothing intensity cache value is the same as the previous time number. For smoothing coefficient parameters, This is the attenuation observation intensity calculated according to the previous formula. The logical relationship between this formula and the previous formula is: first, from the buffer... Calculate instantaneous intensity Then Update as EMA input This allows the set state to simultaneously possess both "short-termity" (represented by the exponential kernel) and "continuity" (represented by the EMA). Here's another set of calculation examples: continuing from the previous example... ,Pick If the previous moment ,but The result, numerically positioned between the previous state and the current instantaneous intensity, reflects the gradual change in the strength of the relationship.
[0075] Relationship Observation Set The entries are therefore maintained in a uniform structure: each key Corresponding to a time-numbered sequence buffer And simultaneously maintain the states of two scalars. and The final output is the set of relational observations. This includes all keys and their corresponding keys. , , This provides a basis for the next step to determine the validity of semantic relationships based on the set state.
[0076] S3: Calculate the semantic relationship determination score based on the smoothing intensity, the attenuation observation intensity, and the relationship type weight parameter, and compare the semantic relationship determination score with the determination threshold to obtain the semantic relationship validity status;
[0077] Specifically, the relational observation set In step two, keys have been constructed for each real-world object pair and relation type. It also maintains a time-number sequence buffer. Attenuation of observation intensity and smoothness strength .in It is derived from the weighted summation form of the exponential decay kernel, which is mathematically derived from the weighting method of the exponential function in the time series. Derived from the classic exponential moving average recursive model, its essence is a first-order linear difference equation used to characterize the trend term. Both are dimensionless intensity values, belonging to the weighted statistical results of the number of observations, and therefore can be directly linearly combined numerically. This step, based on this, robustly fuses the trend term and the recent term to obtain a semantic relationship determination score. And further generate semantic relation validity states. .
[0078] The standard recursive form of exponential moving average is ,in As the current observation input, This is the smoothing coefficient. It has already been set in step two. Concretize into ,therefore This can be regarded as a Trend estimation. To semantically distinguish between "persistent relationships" and "occasional spikes," this step introduces a bias-based suppression term on top of the classic linear weighted fusion. This suppression idea originates from the error penalty function in robust statistics: when the instantaneous value deviates too much from the trend value, its contribution is attenuated.
[0079] Based on this, the key-oriented In time number The following linear fusion form
[0080] ;
[0081] Rewrite in a form that includes a deviation adjustment term:
[0082] ;
[0083] in, The smoothing intensity is calculated in step two. To attenuate the observation intensity, For relation type The corresponding weight parameters, This represents the deviation between instantaneous intensity and trend intensity. This formula is an improvement on the classic linear fusion: when and When they approach each other, the denominator tends to be close to the nearest integer. The instantaneous term basically maintains its original weight; when Significantly higher or lower When the denominator increases, the impact of the instantaneous term on the final score is reduced. This form mathematically maintains dimensional consistency between the two sides because... , Both the denominator and the difference are dimensionless intensity values, and the denominator is... Even with the dimensionless difference, the overall quantity remains dimensionless. and , Maintain consistent dimensions.
[0084] In actual calculations, the system performs the following steps: reading a specific key. of and Look up the table to get the weight of this relation type. Calculate the deviation Substituting into the above formula, we get The calculation process is illustrated with a specific example: Let's assume a time number... Below, a certain object pair has under the location association type , Relationship type weight Then the deviation The instantaneous term is The trend item is ,final If another object pair produces only one sudden observation, assume , ,but The instantaneous term is The trend item is ,final The comparison shows that relationships formed through continuous observation score significantly higher than those formed through sporadic observation.
[0085] After obtaining the judgment score Then, the semantic relationship validity state is generated according to the threshold determination principle. This principle is derived from the threshold decision rule in classic binary classification: when consecutive scores are higher than a set threshold, it is classified as a positive class; otherwise, it is classified as a negative class. The specific form is as follows:
[0086] ;
[0087] in, For relation type The threshold for determining this is set during the system deployment phase based on historical debugging data or simulation calculation results. For example, in the above calculation, if the location-related threshold... ,but correspond This indicates that the relationship is valid at the current moment; while correspond This indicates that the relationship will not be included in the main structure of the dynamic graph for the time being. The system processes sets... All keys Repeat the above calculation process to form a set of semantic relation validity states. Each item in this set It can be directly used to update relation edges in the graph database, thereby transforming the statistically significant set of observations into an operable semantic relation structure.
[0088] S4: Determine the validity flag of the relationship based on the semantic relationship validity status and the holding window length parameter, locate or create the corresponding node and relationship edge in the Neo4j graph database, write the validity flag of the relationship into the available status attribute of the relationship edge, and generate a scene response event when the validity flag of the relationship changes.
[0089] Specifically, the set of semantic relation validity states In the previous step, it was already... Generated in the form of, where Indicates the time number Real-world object pairs In relation types The judgment result below. Variables and Stable object identifiers derived from the target detection and tracking module; It is one of the four types of semantic relations; This is the number of the system time counter in the current sampling period; This is the binary result obtained in step three by comparing the judgment score with the threshold. All the variables mentioned above are discrete dimensionless quantities, therefore there is no issue of dimension conversion in subsequent calculations. This step introduces a time-holding mechanism at the graph database level, its mathematical basis derived from the interval-keeping model in discrete-time systems: when a state is valid within a finite time interval in the past, it retains its validity at the current moment. This idea can be formalized as a judgment function based on the time difference and a fixed window length. Based on this, the most recent valid time number is recorded as a relation attribute. The holding window length related to the relation type is denoted as Construct a valid indicator for the current relationship. .
[0090] ;
[0091] in, To write the value of the Neo4j relation attribute active; This refers to the semantic relationship validity status output in step three. The most recent satisfaction recorded in the relation edge attribute The time number; For relation type The corresponding holding length parameter is set in the configuration file during system deployment and stored in memory. Obtained by looking up the table; This is the current time number. (Variable) and All are integers representing time numbers, therefore The time difference is dimensionless, and Having the same physical meaning, the comparison operations maintain dimensional consistency. The formula logic can be divided into two parts: when the current decision... At that time, directly ordered Update the database ;when At that time, by comparing the current time difference with the holding length Decide whether to keep it in effect.
[0092] In actual execution, the system updates Neo4j using transactions. For each... First, locate or create a node using the MERGE statement. and The node's primary key attribute is either oid=i or oid=j. Subsequently, the relationship type is located or created. The edge is defined, and its current attribute `last_on` is read; if the edge is newly created and `last_on` has not yet been written, `last_on` is initialized to the current time number. And write it into the relation attribute. Substitute it into the above formula to calculate. Then, the calculation result is written to the relation attribute `active`, and the relation attribute `last_t=t` is updated synchronously to record the most recent processing time. For example, suppose a location association occurs at time number... Timely satisfaction Then, write `last_on=240` and `active=1` to the database. When the time progresses to... and If the holding length parameter of this relation type Then calculate the time difference. ,because Therefore The relationship remains valid. Progress will continue until... and The time difference is ,because ,but The system updates the `active` attribute of the relation to 0 in the database. The above calculation process directly demonstrates the operability of the formula; all parameters are integers, and the calculations involve only addition, subtraction, and comparison operations.
[0093] When the relation attribute `active` changes, the system generates a scenario response event in the same transaction or the immediately following event queue. If `active` changes from 0 to 1, a relation activation event is generated; if it changes from 1 to 0, a relation failure event is generated. The event data includes... And the internal database relationship identifier, used for calls between the early warning module and the retrieval module. The early warning module determines the relationship type based on the relationship type. The system matches preset rules, such as triggering alarm creation for events that are effective for logical associations and triggering alarm cancellation for events that are ineffective. The retrieval module refreshes the query cache after receiving an event, allowing the query statement to be filtered by active=1 and return the currently valid subgraph. The final output is the updated Neo4j dynamic graph structure and the corresponding scene response event stream, thus achieving closed-loop execution of relationship state updates and business responses under the same logical conditions.
[0094] In one or more embodiments, such as Figure 2 As shown, a dynamic semantic relation graph construction system based on Neo4j is disclosed, the system comprising:
[0095] The observation unit generation module is used to obtain real-world object identifiers, category labels, and time numbers, and generate relational observation units based on the location association, attribute association, temporal association, or logical association of candidate object pairs.
[0096] The sequence maintenance and intensity calculation module is used to construct an index with real-scene object pairs and relationship types as keys, append the time number of the relationship observation unit to the time number sequence buffer, and perform rolling clipping on the time number sequence buffer based on the window length parameter; calculate the decay observation intensity of the time number sequence buffer, and update the smoothing intensity at the current time based on the smoothing coefficient and the smoothing intensity cache value of the previous time.
[0097] The semantic relationship determination module is used to calculate the semantic relationship determination score based on the smoothing intensity, the attenuation observation intensity and the relationship type weight parameter, and compare the semantic relationship determination score with the determination threshold to obtain the semantic relationship validity status.
[0098] The graph update and event response module is used to determine the validity flag of the relationship based on the validity status of the semantic relationship and the holding window length parameter, locate or create the corresponding node and relationship edge in the Neo4j graph database, write the validity flag of the relationship into the available status attribute of the relationship edge, and generate a scene response event when the validity flag of the relationship changes.
[0099] It is worth noting that the specific workflow of the Neo4j-based dynamic semantic relation graph construction system provided in this embodiment of the invention is the same as that of the Neo4j-based dynamic semantic relation graph construction method described in the above embodiment, and will not be repeated here.
[0100] This invention also provides a Neo4j-based dynamic semantic relation graph construction device, including a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, it implements the steps described in the above embodiment of a Neo4j-based dynamic semantic relation graph construction method, for example... Figure 1 The steps S1 to S4 described above; or, when the processor executes the computer program, it implements the functions of each module in the above system embodiments.
[0101] For example, the computer program can be divided into one or more modules, which are stored in the memory and executed by the processor to complete the present invention. The one or more modules can be a series of computer program instruction segments capable of performing specific functions, which describe the execution process of the computer program in the Neo4j-based dynamic semantic relation graph construction device.
[0102] The Neo4j-based dynamic semantic graph construction device can be a computing device such as a desktop computer, laptop, handheld computer, or cloud server. This Neo4j-based dynamic semantic graph construction device may include, but is not limited to, a processor and memory. Those skilled in the art will understand that the Neo4j-based dynamic semantic graph construction device may also include input / output devices, network access devices, buses, etc.
[0103] The processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor. The processor is the control center of the Neo4j-based dynamic semantic relation graph construction device, connecting all parts of the device via various interfaces and lines.
[0104] The memory can be used to store the computer program and / or modules. The processor implements various functions of the Neo4j-based dynamic semantic relationship graph construction device by running or executing the computer program and / or modules stored in the memory, and by calling the data stored in the memory. The memory may mainly include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function, etc.; the data storage area may store data created according to the operation of the controller, etc. In addition, the memory may include high-speed random access memory, and may also include non-volatile memory, such as hard disk, memory, plug-in hard disk, smart media card (SMC), secure digital card (SD card), flash card, at least one disk storage device, flash memory device, or other volatile solid-state storage device.
[0105] The module integrated into the Neo4j-based dynamic semantic relationship graph construction device, if implemented as a software functional unit and sold or used as an independent product, can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the above embodiments of the present invention can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a portable hard drive, a magnetic disk, an optical disk, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium, etc.
[0106] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The storage medium can be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.
[0107] The above description represents the preferred embodiments of the present invention. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principles of the present invention, and these improvements and modifications are also considered to be within the scope of protection of the present invention.
Claims
1. A method for constructing a dynamic semantic relation graph based on Neo4j, characterized in that, The method includes: Obtain real-world object identifiers, category labels, and time numbers; generate relational observation units based on the location association, attribute association, temporal association, or logical association of candidate object pairs. An index is constructed using real-scene object pairs and relationship types as keys. The time number of the relationship observation unit is appended to the time number sequence buffer, and the time number sequence buffer is scroll-trimmed based on the window length parameter. The decay observation intensity of the time-numbered sequence buffer is calculated, and the smoothing intensity at the current time is updated based on the smoothing coefficient and the smoothing intensity cache value of the previous time step; the calculation of the decay observation intensity of the time-numbered sequence buffer includes: Iterate through each time number in the time number sequence buffer and calculate the time difference between each time number and the current time number; The weight value corresponding to each time number is calculated based on the time difference, window length parameter and attenuation coefficient parameter, wherein the weight value decreases as the time difference increases; The attenuation observation intensity is obtained by summing the weight values corresponding to each of the aforementioned time numbers; The semantic relationship determination score is calculated based on the smoothing intensity, the attenuation observation intensity, and the relation type weight parameter, and the semantic relationship determination score is compared with the determination threshold to obtain the semantic relationship validity status. Based on the semantic relationship validity status and holding window length parameter, a relationship validity flag is determined. The corresponding node and relationship edge are located or created in the Neo4j graph database. The relationship validity flag is written into the available status attribute of the relationship edge. A scene response event is generated when the relationship validity flag changes.
2. The method for constructing a dynamic semantic relation graph based on Neo4j according to claim 1, characterized in that, The relation generation observation unit includes: Calculate the spatial distance between the first real-world object and the second real-world object in the candidate object pair, and generate a position-related observation when the spatial distance is less than the proximity determination threshold; Read the category labels of the first real-world object and the second real-world object, and generate attribute association observations when the category labels meet the preset category matching rules; The number of times the first real-world object and the second real-world object appear simultaneously within the most recent preset number of time numbers is counted. When the number of occurrences reaches a preset counting threshold, a time-series correlation observation is generated. Based on preset scenario logic rules, a Boolean identifier is determined, and a logical association observation is generated when the Boolean identifier is true. The generated location-related observations, attribute-related observations, time-series-related observations, or logical-related observations are encapsulated into relational observation units containing real-world object identifiers, relation type identifiers, and time numbers.
3. The method for constructing a dynamic semantic relation graph based on Neo4j according to claim 1, characterized in that, The update to obtain the smoothing intensity at the current moment includes: Retrieve the cached value of the smoothing intensity under the previous time number; The attenuation observation intensity under the current time number is used as the input value, and the input value and the smooth intensity buffer value are weighted and calculated using the first-order exponential moving average formula; The weighted calculation result is used as the smoothing intensity under the current time number, and the smoothing intensity cache value is updated.
4. The method for constructing a dynamic semantic relation graph based on Neo4j according to claim 1, characterized in that, The calculation of the semantic relationship determination score includes: Calculate the absolute value of the deviation between the observed attenuation intensity and the smoothing intensity; The absolute value of the deviation is added to a constant to obtain the denominator term; The numerator is obtained by multiplying the attenuation observation intensity by the relation type weight parameter. Divide the numerator by the denominator to obtain the intermediate term, and add the intermediate term to the smoothing intensity to obtain the semantic relationship determination score.
5. The method for constructing a dynamic semantic relation graph based on Neo4j according to claim 1, characterized in that, The valid criteria for determining the relationship include: When the semantic relationship validity status indicates that the relationship is valid, the relationship validity flag is set to the first value, and the current time number is recorded as the most recent valid time number; When the semantic relationship validity status indicates that the relationship is invalid, calculate the time difference between the current time number and the most recent valid time number; When the time difference is less than or equal to the holding window length parameter, the relationship validity flag is kept at the first value; When the time difference is greater than the holding window length parameter, the relationship validity flag is set to the second value.
6. The method for constructing a dynamic semantic relation graph based on Neo4j according to claim 1, characterized in that, The process of locating or creating corresponding nodes and relation edges in the Neo4j graph database includes: Use the MERGE statement to find or create a first and second node with a unique primary key attribute based on the real-world object identifier; Use the MERGE statement to find or create a relation edge connecting the first node and the second node based on the first node, the second node, and the relation type. Read the most recent valid time number attribute of the relation edge. If the relation edge is newly created and the most recent valid time number attribute has not been written, then write the current time number into the most recent valid time number attribute.
7. The method for constructing a dynamic semantic relation graph based on Neo4j according to claim 1, characterized in that, The generated scene response events include: Obtain the available state attribute values of the relation edge at the current time number, and the historical values of the available state attributes at the previous processing time. When the available state attribute value changes from the second value to the first value, a relationship activation event is constructed, which includes the real-world object pair identifier and the relationship type identifier. When the available state attribute value changes from the first value to the second value, a relationship failure event containing the real-world object pair identifier and the relationship type identifier is constructed. Output the event indicating whether the relationship is effective or ineffective.
8. The method for constructing a dynamic semantic relation graph based on Neo4j according to claim 1, characterized in that, Following the generation of the scene response event, the following is also included: Parse the relationship type identifier and real-world object pair identifier in the scene response event; If the scenario response event is a relationship activation event, an alarm control signal is generated according to the pre-stored rule configuration data, and the local index status flag is updated to indicate that subsequent graph query operations will only traverse the relationship edges whose available status attribute is the first value. If the scenario response event is a relationship failure event, an alarm cancellation control signal is generated according to the pre-stored rule configuration data, and the local index status flag is updated to indicate that subsequent graph query operations will exclude relation edges with the second value as the available status attribute.
9. A dynamic semantic relation graph construction system based on Neo4j, characterized in that, The system includes: The observation unit generation module is used to obtain real-world object identifiers, category labels, and time numbers, and generate relational observation units based on the location association, attribute association, temporal association, or logical association of candidate object pairs. The sequence maintenance and intensity calculation module is used to construct an index using real-scene object pairs and relationship types as keys, append the time number of the relationship observation unit to the time number sequence buffer, and perform rolling clipping on the time number sequence buffer based on the window length parameter; calculate the decay observation intensity of the time number sequence buffer, and update the smoothing intensity at the current time based on the smoothing coefficient and the smoothing intensity cache value of the previous time step; the calculation of the decay observation intensity of the time number sequence buffer includes: Iterate through each time number in the time number sequence buffer and calculate the time difference between each time number and the current time number; The weight value corresponding to each time number is calculated based on the time difference, window length parameter and attenuation coefficient parameter, wherein the weight value decreases as the time difference increases; The attenuation observation intensity is obtained by summing the weight values corresponding to each of the aforementioned time numbers; The semantic relationship determination module is used to calculate the semantic relationship determination score based on the smoothing intensity, the attenuation observation intensity and the relationship type weight parameter, and compare the semantic relationship determination score with the determination threshold to obtain the semantic relationship validity status. The graph update and event response module is used to determine the validity flag of the relationship based on the validity status of the semantic relationship and the holding window length parameter, locate or create the corresponding node and relationship edge in the Neo4j graph database, write the validity flag of the relationship into the available status attribute of the relationship edge, and generate a scene response event when the validity flag of the relationship changes.