Knowledge graph generation method and device based on word document and electronic equipment

By converting Word documents into XML format and using recursive functions to identify entities and relationships, the problem of traditional technology being difficult to parse complex formats and semantic information of Word documents is solved, and a high-accurate knowledge graph generation is achieved.

CN119597930AActive Publication Date: 2025-03-11BEIJING HUARONG XINNING TECH CO LTD

Patent Information

Application Number
CN202411633682.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-15
Publication Date
2025-03-11
Estimated Expiration
2044-11-15

AI Technical Summary

Technical Problem

Traditional technology is difficult to accurately parse complex formats and rich semantic information in Word documents, resulting in low accuracy of information extraction.

Method used

By converting Word document content into XML format, preset recursive functions are used to segment the data structure, automatically identify entities and relationships, and generate knowledge graphs.

Benefits of technology

It improves the accuracy of document to knowledge graph, reduces the workload of manually constructing knowledge graphs, and enhances the readability and retrieval efficiency of documents.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119597930A_ABST
    Figure CN119597930A_ABST
Patent Text Reader

Abstract

The invention discloses a word document-based knowledge graph generation method and apparatus, and an electronic device, and relates to the field of data processing. The method comprises the following steps of: analyzing a target document to obtain a corresponding xml (Extensible Markup Language) file; the xml file is analyzed to obtain a first data structure, and the first data structure comprises a plurality of elements; in the first data structure, sorting the plurality of elements according to a preset sorting rule to obtain a second data structure; segmenting the second data structure by adopting a preset recursive function to obtain a plurality of entities and a relationship among the plurality of entities; and taking the plurality of entities as nodes of a preset knowledge graph, and taking the relationship among the plurality of entities as edges of the preset knowledge graph to obtain a target knowledge graph. According to the technical scheme provided by the invention, the document content is converted into the XML format for recognition and extraction, so that the accuracy of converting the document into the knowledge graph is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing, and specifically to a method, device and electronic device for generating a knowledge graph based on a word document. Background Art

[0002] With the rapid development of information technology, especially in the field of data processing and information management, we are facing more and more data processing challenges. Especially when dealing with a large amount of document materials, how to effectively extract valuable information from these documents and organize this information into a format that is easy to understand and retrieve has become an important requirement. As a widely used document format, Word documents contain a large amount of structured and unstructured information, but traditional document processing methods are difficult to fully mine and utilize this information.

[0003] Currently, related technologies use OCR technology to identify text content and regular expressions to parse titles and hierarchies, etc. This technology often cannot accurately parse the complex formats and rich semantic information in Word documents. For example, OCR technology often has character recognition errors when processing documents with complex layouts, and simple rule-based methods cannot effectively identify semantic relationships and hierarchical structures in documents, which leads to low accuracy in information extraction.

[0004] Therefore, there is an urgent need for a method, device and electronic device for generating a knowledge graph based on word documents. Summary of the invention

[0005] The present application provides a method, device and electronic device for generating a knowledge graph based on a word document, which improves the accuracy of document conversion into a knowledge graph by converting the document content into XML format for recognition and extraction.

[0006] In the first aspect of the present application, a method for generating a knowledge graph based on a word document is provided, the method comprising: parsing a target document to obtain a corresponding XML file; parsing the XML file to obtain a first data structure, the first data structure comprising a plurality of elements; in the first data structure, sorting the plurality of elements according to a preset sorting rule to obtain a second data structure; using a preset recursive function to segment the second data structure to obtain a plurality of entities and the relationships between the plurality of entities; using the plurality of entities as nodes of a preset knowledge graph, and using the relationships between the plurality of entities as edges of the preset knowledge graph to obtain a target knowledge graph.

[0007] By adopting the above technical solution, the target document is parsed to obtain the corresponding XML file, and then the XML file is parsed to obtain the first data structure, so that the unstructured word document can be converted into a structured data form, which is convenient for subsequent analysis and processing of the document content. The second data structure is segmented by a recursive function, which can automatically identify the entities in the target document and the relationship between the entities. The preset recursive function can analyze the entities contained in each chapter and paragraph layer by layer according to the hierarchical structure of the document, and mine the superior-subordinate and parallel semantic relationships between them. This automated information extraction method greatly reduces the workload of manually constructing a knowledge graph. Finally, the extracted entities are used as nodes of the preset knowledge graph, and the entity relationships are used as edges of the preset knowledge graph, thereby generating a target knowledge graph that reflects the semantic structure of the document. The target knowledge graph presents the core content of the target document in an intuitive graphical form, which improves the readability and retrieval efficiency of the target document. This technical solution avoids common character recognition errors in OCR by converting document content into XML format. At the same time, this technical solution utilizes the original XML structure of the target document. Compared with relying solely on regular expressions to identify titles and hierarchies, it can more accurately identify and utilize the format and structure of the target document, thereby improving the accuracy of document conversion to knowledge graphs.

[0008] Optionally, the method of using a preset recursive function to segment the second data structure to obtain multiple entities and the relationship between the multiple entities specifically includes: obtaining multiple first-level titles, and performing text parsing on each of the first-level titles to obtain a corresponding first text content; generating a corresponding functional entity based on the first text content, one first-level title corresponds to one functional entity, and multiple functional entities are in a peer relationship; obtaining a data block corresponding to each of the first-level titles, and determining a second-level title corresponding to the first-level title based on the data block; performing text parsing on each of the second-level titles to obtain a corresponding second text content; generating a corresponding functional system entity based on the second text content, the functional entity and the functional system entity are in a superior-subordinate relationship; generating a functional component entity based on the functional entity and the functional system entity, the functional system entity and the functional component entity are in a superior-subordinate relationship.

[0009] By adopting the above technical solution, the first-level chapter structure of the document can be automatically identified by obtaining the first-level title and performing text parsing. The first-level title generates the corresponding functional entity, and it is determined that the functional entities are in a peer relationship, so that the top-level framework of the document is constructed in the knowledge graph. Further, by obtaining the data block under the first-level title, the corresponding second-level title can be identified, and the corresponding functional system entity can be generated through text parsing. Since it is determined that the functional entity and the functional system entity are in a superior-subordinate relationship, under the existing top-level framework, the second-level sub-modules under each first-level chapter are added, so that the knowledge graph can represent the two-layer document structure. On this basis, the functional component entity of the lower layer can also be generated according to the functional entity and the functional system entity. By determining the superior-subordinate relationship between the functional system entity and the functional component entity, the hierarchy of the knowledge graph is further enriched. This recursive entity extraction method can continuously mine the hierarchical semantics of the document, automatically construct a knowledge graph covering the entire content of the document, and greatly improve the description ability and information carrying capacity of the knowledge graph.

[0010] Optionally, after obtaining multiple first-level titles and performing text parsing on each of the first-level titles to obtain the corresponding first text content, the method further includes: traversing the first text content, performing word segmentation processing on the first text content to obtain multiple word segmentation results; performing part-of-speech tagging on the multiple word segmentation results to obtain the part-of-speech corresponding to each of the word segmentation results; identifying nouns or noun phrases in the word segmentation results according to the part-of-speech corresponding to each of the word segmentation results, and using the identified nouns or noun phrases as the entity name of the functional entity.

[0011] By adopting the above technical solution, after obtaining the text content of the first-level title, it is segmented into multiple segmentation results through word segmentation processing, which can further granularize the title content and provide a more basic unit for semantic analysis. Part-of-speech tagging of the word segmentation results can identify the part of speech and grammatical function of each word, understand the structure of the title from a grammatical level, and help to extract semantic information more accurately in the future. According to the part-of-speech tagging results, nouns or noun phrases in the word segmentation results can be identified and used as the names of functional entities. This method automatically extracts appropriate entity names from the title, avoiding the subjectivity and inconsistency of manually defined entities. At the same time, noun phrases can express complete semantics better than single words, and the generated entity names are more readable and easier for users to understand.

[0012] Optionally, after the xml file is parsed to obtain a first data structure including multiple elements, the method further includes: traversing each element in the xml file and judging the element type corresponding to each element; generating element objects according to each element and the element type corresponding to each element; in the process of generating each element object, recording the order of appearance of each element object in the xml file, and generating a serial number attribute value for each element object according to the order of appearance; sorting each serial number attribute value in ascending order to obtain the preset sorting rule.

[0013] By adopting the above technical solution, traversing each element in the XML file and determining its element type, the content form contained in the document can be comprehensively analyzed, such as paragraphs, tables, pictures, and attachments, without missing any information. According to the element type of the element, the corresponding element object is generated, and the XML file can be converted into a data structure that can be processed by the program, which is convenient for extracting and analyzing the text, attributes and other contents therein. When generating element objects, the order in which they appear in the XML file is recorded, and the serial attribute value is generated. In this way, the elements are numbered according to their positions in the target document, which provides a basis for the subsequent analysis and reconstruction of the content according to the order of the elements. The serial attribute values ​​of the elements are sorted from small to large to generate a preset sorting rule, which ensures that the elements can be processed in the order of their original target document in subsequent processing, avoiding semantic confusion and breaks, so that the extracted knowledge graph can accurately reflect the structure and logic of the document.

[0014] Optionally, the method of using the multiple entities as nodes of a preset knowledge graph and the relationships between the multiple entities as edges of the preset knowledge graph to obtain a target knowledge graph specifically includes: constructing a cypher query statement based on the nodes and the edges; determining whether there are preset characters in the cypher query statement; if it is determined that there are preset characters in the cypher query statement, translating the preset characters to obtain a target cypher query statement; storing the target cypher query statement in a preset storage medium, and generating the target knowledge graph according to the target cypher query statement.

[0015] By adopting the above technical solution, a cypher query statement is constructed based on the extracted entity nodes and relationship edges, and the knowledge graph can be represented in a form that can be recognized and stored by the graph database. The nodes and edges of the knowledge graph can be described by the cypher query statement, and the patterns between them can be defined. After constructing the cypher query statement, whether the cypher query statement contains special characters is judged and translated to avoid syntax errors. The translated cypher query statement can be executed correctly to generate the target knowledge graph. The generated target cypher query statement is stored in a specified storage medium, so that the target knowledge graph can be stored and reused for a long time, and can also be associated and analyzed with other data. The knowledge graph generated by the target cypher query statement has a direct mapping relationship with the original document. The cypher query statement can be used to easily query and retrieve the content in the target knowledge graph and quickly locate the relevant part of the original document.

[0016] Optionally, after storing the target cypher query statement in a preset storage medium, the method also includes: displaying the target knowledge graph to the user, and obtaining the user's modification instructions for the target knowledge graph; adjusting the target knowledge graph according to the modification instructions to obtain a modified knowledge graph, and displaying the modified knowledge graph to the user.

[0017] By adopting the above technical solution, the generated target knowledge graph is displayed to the user, and the user can intuitively view the structure and content of the target knowledge graph and browse the key information in the target document in a structured manner. The user can edit and modify the target knowledge graph through a graphical interface, such as adding, deleting, merging nodes or edges, adjusting the properties of nodes and edges, etc. According to the user's modification instructions, the target knowledge graph is adjusted and a modified knowledge graph is generated and displayed to the user. In this way, the user can view the modification effect in a timely manner and continuously iterate and optimize the knowledge graph. Through the user's participation in the construction and modification of the target knowledge graph, the fit between the target knowledge graph and the user's actual needs can be improved. Users can incorporate their own understanding and insights into the target knowledge graph, and continuously enrich and improve the content of the target knowledge graph to make it more comprehensive and accurate.

[0018] In a second aspect of the present application, a knowledge graph generation device based on a word document is provided, the device comprising a document parsing module, an element sorting module, a data structure segmentation module and a knowledge graph generation module, wherein: the document parsing module is used to parse the target document to obtain a corresponding XML file; the document parsing module is also used to parse the XML file to obtain a first data structure, the first data structure comprising a plurality of elements; the element sorting module is used to sort the plurality of elements in the first data structure according to a preset sorting rule to obtain a second data structure; the data structure segmentation module is used to segment the second data structure using a preset recursive function to obtain a plurality of entities and the relationships between the plurality of entities; the knowledge graph generation module is used to use the plurality of entities as nodes of a preset knowledge graph, and the relationships between the plurality of entities as edges of the preset knowledge graph to obtain a target knowledge graph.

[0019] In the third aspect of the present application, an electronic device is provided, including a processor, a memory, a user interface and a network interface, the memory is used to store instructions, the user interface and the network interface are both used to communicate with other devices, and the processor is used to execute the instructions stored in the memory so that the electronic device executes any one of the methods described above.

[0020] In a fourth aspect of the present application, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores instructions, and when the instructions are executed, any of the methods described above is executed.

[0021] In summary, one or more technical solutions provided in the embodiments of the present application have at least the following technical effects or advantages: 1. By parsing the target document to obtain the corresponding XML file, and then parsing the XML file to obtain the first data structure, the unstructured word document can be converted into a structured data form, which is convenient for subsequent analysis and processing of the document content. The second data structure is segmented using a recursive function, which can automatically identify the entities in the target document and the relationship between the entities. The preset recursive function can analyze the entities contained in each chapter and paragraph layer by layer according to the hierarchical structure of the document, and mine the superior-subordinate and parallel semantic relationships between them. This automated information extraction method greatly reduces the workload of manually constructing a knowledge graph. Finally, the extracted entities are used as nodes of the preset knowledge graph, and the entity relationships are used as edges of the preset knowledge graph, thereby generating a target knowledge graph that reflects the semantic structure of the document. The target knowledge graph presents the core content of the target document in an intuitive graphical form, which improves the readability and retrieval efficiency of the target document. This technical solution avoids common character recognition errors in OCR by converting document content into XML format. At the same time, this technical solution utilizes the original XML structure of the target document. Compared with relying solely on regular expressions to identify titles and hierarchies, it can more accurately identify and utilize the format and structure of the target document, thereby improving the accuracy of document conversion to knowledge graphs.

[0022] 2. By obtaining the first-level title and performing text parsing, the first-level chapter structure of the document can be automatically identified. The first-level title generates the corresponding functional entity, and it is determined that the functional entities are in a peer relationship, so as to construct the top-level framework of the document in the knowledge graph. Furthermore, by obtaining the data block under the first-level title, the corresponding second-level title can be identified, and the corresponding functional system entity can be generated through text parsing. Since it is determined that the functional entity and the functional system entity are in a superior-subordinate relationship, the second-level sub-modules under each first-level chapter are added under the existing top-level framework, so that the knowledge graph can represent the two-layer document structure. On this basis, the functional component entity of the lower level can also be generated according to the functional entity and the functional system entity. By determining the superior-subordinate relationship between the functional system entity and the functional component entity, the hierarchy of the knowledge graph is further enriched. This recursive entity extraction method can continuously mine the hierarchical semantics of the document, automatically construct a knowledge graph covering the entire content of the document, and greatly improve the description ability and information carrying capacity of the knowledge graph.

[0023] 3. After obtaining the text content of the first-level title, it is segmented into multiple segmentation results through word segmentation processing, which can further granularize the title content and provide a more basic unit for semantic analysis. Part-of-speech tagging of the word segmentation results can identify the part of speech and grammatical function of each word, understand the structure of the title from a grammatical level, and help to extract semantic information more accurately later. According to the part-of-speech tagging results, nouns or noun phrases in the word segmentation results can be identified and used as the names of functional entities. This method automatically extracts appropriate entity names from the title, avoiding the subjectivity and inconsistency of manually defined entities. At the same time, noun phrases can express complete semantics better than single words, and the generated entity names are more readable and easier for users to understand. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] Figure 1 It is a flowchart of a method for generating a knowledge graph based on a word document disclosed in an embodiment of the present application; Figure 2 It is a module schematic diagram of a knowledge graph generation device based on a word document disclosed in an embodiment of the present application; Figure 3 It is a structural schematic diagram of an electronic device disclosed in an embodiment of the present application.

[0025] Explanation of the accompanying drawings: 201, document parsing module; 202, element sorting module; 203, data structure segmentation module; 204, knowledge graph generation module; 300, electronic device; 301, processor; 302, communication bus; 303, user interface; 304, network interface; 305, memory. DETAILED DESCRIPTION

[0026] In order to enable technicians in this field to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this application, not all of the embodiments.

[0027] In the description of the embodiments of the present application, words such as "for example" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "for example" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "for example" or "for example" is intended to present related concepts in a specific way.

[0028] In the description of the embodiments of the present application, the meaning of the term "multiple" refers to two or more. For example, multiple systems refer to two or more systems, and multiple screen terminals refer to two or more screen terminals. In addition, the terms "first" and "second" are used for descriptive purposes only and cannot be understood as indicating or implying relative importance or implicitly indicating the indicated technical features. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. The terms "include", "comprise", "have" and their variations all mean "including but not limited to", unless otherwise specifically emphasized.

[0029] This application provides a method for generating a knowledge graph based on a word document. Figure 1 , Figure 1 This is a flow chart of a method for generating a knowledge graph based on a word document provided in an embodiment of the present application. The method is applied to a server, and the server is used to execute a program for generating a knowledge graph based on a word document. The server can be a single server, or a server cluster composed of multiple servers, or a cloud computing service center. The method includes steps S101 to S105, and the steps are as follows: Step S101: Parse the target document to obtain the corresponding XML file.

[0030] In step S101, the server receives the target document uploaded by the user, which is a word document in doc format. The server stores the target document in the specified directory and obtains the file path of the target document. Then, the server calls the document parsing module, passes in the file path of the target document, and starts parsing the target document. The server first determines whether the format of the target document is in Word format. If the format of the target document is not in Word format, it returns an error message to the user, prompting him to upload a document in the correct format. If the format of the target document is in Word format, the server starts to decompress the target document and obtains the XML file of the target document.

[0031] Step S102: Parse the XML file to obtain a first data structure, where the first data structure includes multiple elements.

[0032] In step S102, the server uses Python's BeautifulSoup library to load the XML file and create a BeautifulSoup object. The object exists in the memory in the form of a parsed XML document tree, which is convenient for traversal and information extraction. The server defines the basic framework of the first data structure in JSON format, including four main elements: paragraphs, tables, images, and attachments. Among them, paragraphs is a list for storing paragraph information; tables is a list for storing table information; images is a list for storing image information; attachments is a list for storing attachment information.

[0033] The server traverses the XML document tree, extracts various types of document content, converts them into JSON formatted data, and adds them to the first data structure. For a paragraph in the target document, the server first determines whether the paragraph contains text, a table, or a picture. If the paragraph contains text, the text content is extracted and saved in the text field; if the paragraph contains a table, the row and column data of the table are extracted and saved in the table field; if the paragraph contains a picture, the file path of the picture is extracted and saved in the image field.

[0034] In addition, the server will also extract the paragraph style information, such as the heading level, alignment, etc., and save it in the style field. The values ​​of the style field include "heading 1" (first-level heading), "heading 2" (second-level heading), "heading 3" (third-level heading), "table" (table), "image" (picture), etc., which are used to record the style information and data type information in the document. For the images and attachments in the target document, the server saves them to the specified directory and records their file paths in the images and attachments lists of the JSON data structure (the first data structure).

[0035] In a possible implementation, after step S102, the method further includes: traversing each element in the xml file and determining the element type corresponding to each element; generating element objects according to each element and the element type corresponding to each element; in the process of generating each element object, recording the order of appearance of each element object in the xml file, and generating a serial attribute value for each element object according to the order of appearance; sorting each serial attribute value in ascending order to obtain a preset sorting rule.

[0036] Specifically, the server traverses each element in the XML file. For each element, the server determines its element type, which includes paragraphs, tables, pictures, attachments, etc. The server can determine the element type by analyzing the tag name of the element.

[0037] Depending on the element type, the server will create a corresponding element object. For example, for a paragraph element, the server will create a paragraph object containing text content, style information and other properties; for a table element, the server will create a table object containing row and column data, style information and other properties; for an image element, the server will create an image object containing image file path, style information and other properties; for an attachment element, the server will create an attachment object containing attachment file path and other properties.

[0038] When creating element objects, the server will record the order in which each element object appears in the XML file. Specifically, the server will generate a unique serial number attribute value for each element object, and the serial number attribute value will increase in the order in which the element object appears in the XML file. For example, the serial number attribute value of the first element object is 1, the serial number attribute value of the second element object is 2, and so on.

[0039] After all element objects are created, the server will sort all element objects in ascending order according to the serial number attribute value. The sorted element object list is the preset sorting rule, which is the order in which the element objects appear in the original target document.

[0040] Step S103: In the first data structure, multiple elements are sorted according to a preset sorting rule to obtain a second data structure.

[0041] In step S103, the server obtains the first data structure generated in step S102, which stores the structured information and content of the target document in JSON format, including elements such as paragraphs, tables, pictures, and attachments. The server sorts the elements in the first data structure according to a preset sorting rule. The preset sorting rule assigns a unique serial number attribute value to each element object according to the order in which the element object appears in the original target document. The smaller the serial number attribute value, the earlier the element object appears in the document.

[0042] The server sorts the elements in the first data structure according to the order of the sequence attribute values ​​of the element objects from small to large. Specifically, the server traverses the paragraphs, tables, images, and attachments lists in the first data structure and rearranges them in order from small to large according to the order attribute value of each element object.

[0043] During the sorting process, the server maintains a new JSON object to store the sorted elements. This new JSON object is the second data structure, which has a similar structure to the first data structure and also contains paragraphs, tables, images, and attachments lists, but the element objects in these lists have been reordered according to the preset sorting rules.

[0044] After the sorting is completed, the server saves the second data structure to memory or disk for subsequent processing and analysis. The order of elements in the second data structure is consistent with the order of elements in the original document, retaining the context structure and semantic information of the target document.

[0045] Step S104: using a preset recursive function to segment the second data structure to obtain a plurality of entities and relationships between the plurality of entities.

[0046] In step S104, multiple first-level titles are obtained, and text analysis is performed on each first-level title to obtain a corresponding first text content; based on the first text content, a corresponding functional entity is generated, one first-level title corresponds to one functional entity, and multiple functional entities are in a peer relationship; a data block corresponding to each first-level title is obtained, and the second-level title corresponding to the first-level title is determined based on the data block; text analysis is performed on each second-level title to obtain a corresponding second text content; based on the second text content, a corresponding functional system entity is generated, and the functional entity and the functional system entity are in a superior-subordinate relationship; based on the functional entity and the functional system entity, a functional component entity is generated, and the functional system entity and the functional component entity are in a superior-subordinate relationship.

[0047] Specifically, the server obtains the second data structure generated in step S103, which stores structured information and content arranged in the order of the original document in JSON format, including elements such as paragraphs, tables, pictures, and attachments. The server defines a preset recursive function for traversing the second data structure and extracting entities and relationships. The main idea of ​​the preset recursive function is to divide the document content into different data blocks according to the style information of the element (such as the title level), and extract entities and relationships from these data blocks.

[0048] The server first obtains all the first-level headings in the second data structure, that is, the paragraph elements with style information "heading 1". For each first-level heading, the server performs text parsing, extracts the keywords and main content, and generates the corresponding first text content. Based on the first text content, the server creates a functional entity object to represent the functional module or functional field corresponding to the first-level heading. One first-level heading corresponds to one functional entity, and multiple functional entities are in a peer relationship, and together they constitute the functional structure of the entire system or product described in the document.

[0049] Next, the server obtains the data block corresponding to each first-level heading. A data block refers to all elements between a first-level heading and the next first-level heading (or at the end of the document), including paragraphs, tables, pictures, etc. The server determines the second-level heading under the first-level heading by analyzing the element style information in the data block, especially the heading level.

[0050] For each secondary title, the server also performs text analysis, extracts keywords and main content, and generates corresponding second text content. Then, the server creates a function system entity object based on the second text content to represent the sub-function or sub-system corresponding to the secondary title.

[0051] There is a hierarchical relationship between functional entities and functional system entities, that is, a functional entity can contain multiple functional system entities, indicating the relationship between the whole and the part. The server also records this relationship for use in subsequent knowledge graph construction.

[0052] The server uses the same method to extract the third-level title based on the functional system entity to obtain the functional component entity. There is also a superior-subordinate relationship between the functional system entity and the functional component entity, that is, a functional system entity can contain multiple functional component entities, indicating the relationship between the whole and the part.

[0053] The server recursively processes each first-level title and its corresponding data block, extracts all functional entities, functional system entities, and functional component entities, and records the relationships between them. For other elements in the data block, such as paragraphs, tables, pictures, etc., the server also performs corresponding text parsing and information extraction, and associates them with the corresponding functional entities or functional system entities as additional attribute information.

[0054] After the preset recursive function processes all the first-level titles and their data blocks, it returns the extracted entity and relationship list. The relationship list contains all the functional entities, functional system entities, functional component entities and the hierarchical relationships between them in the document, forming a tree structure.

[0055] In a possible implementation, after obtaining multiple first-level titles and performing text parsing on each first-level title to obtain the corresponding first text content, the method further includes: traversing the first text content, performing word segmentation processing on the first text content to obtain multiple word segmentation results; performing part-of-speech tagging on the multiple word segmentation results to obtain the part-of-speech corresponding to each word segmentation result; identifying nouns or noun phrases in the word segmentation results according to the part-of-speech corresponding to each word segmentation result, and using the identified nouns or noun phrases as the entity name of the functional entity.

[0056] Specifically, the server will traverse the first text content and perform word segmentation on it. Word segmentation refers to the process of dividing a piece of text into multiple separate words according to certain rules. Next, the server will perform part-of-speech tagging on the obtained word segmentation results. Part-of-speech tagging refers to assigning a part-of-speech label to each word in the word segmentation result, indicating the word's part of speech and grammatical function in the sentence. The server will identify the nouns or noun phrases in the word segmentation results based on the part-of-speech labels, and use them as the entity names of the functional entities. The reason for choosing nouns or noun phrases as entity names is that in the first-level title, nouns or noun phrases usually represent a function or module of the system, and are more suitable as nodes in the knowledge graph.

[0057] Step S105: Use multiple entities as nodes of a preset knowledge graph, and use the relationships between multiple entities as edges of the preset knowledge graph to obtain a target knowledge graph.

[0058] In step S105, a cypher query statement is constructed based on nodes and edges; it is determined whether there are preset characters in the cypher query statement; if it is determined that there are preset characters in the cypher query statement, the preset characters are translated to obtain a target cypher query statement; the target cypher query statement is stored in a preset storage medium, and a target knowledge graph is generated according to the target cypher query statement.

[0059] Specifically, the server obtains the entity and relationship list generated in step S104, and the relationship list contains all functional entities, functional system entities, functional component entities extracted from the document, and the superior-subordinate relationships and attribute information between them. The server converts the entity and relationship list into nodes and edges of a preset knowledge graph. Specifically, the server creates a node for each functional entity, functional system entity, and functional component entity, and the attributes of the node include the name, type, and other additional information of the entity. The server creates an edge for each relationship between entities, and the attributes of the edge include the type of relationship (such as "contains") and other additional information.

[0060] Next, the server constructs a Cypher query statement based on the nodes and edges of the preset knowledge graph. Cypher is a declarative graph query language, which can be understood in the embodiments of the present application as being used to create, query, and modify data in a graph database. The server generates a Cypher statement based on a preset template to create nodes, establish relationships, and set attribute values. In the process of constructing a Cypher query statement, the server determines whether there are preset characters in the statement, such as single quotes, double quotes, backslashes, etc. The preset characters have special meanings in Cypher statements, and if used directly, they may cause syntax errors or injection attacks.

[0061] If there are preset characters in the Cypher query statement, the server will translate these characters. Translation refers to converting special characters into their corresponding escape sequences to ensure that they can be correctly parsed and executed in the Cypher statement. For example, a single quote needs to be translated into two single quotes, and a backslash needs to be translated into two backslashes. After the server translates all preset characters in the Cypher query statement, it obtains the target Cypher query statement. The server stores the target Cypher query statement in a preset storage medium (such as a file or database) for subsequent calls and executions. At the same time, the server sends the target Cypher query statement to the graph database, requests the target Cypher query statement and generates the target knowledge graph.

[0062] After receiving the target Cypher query statement, the graph database creates nodes, establishes relationships, and sets attribute values ​​according to the instructions of the target Cypher query statement. Finally, the graph database completes the execution of the target Cypher query statement and returns the generated target knowledge graph to the server. The target knowledge graph contains all the functional entities, functional system entities, functional component entities in the document and the relationships between them, forming a structured knowledge base.

[0063] In a possible implementation, after storing the target cypher query statement in a preset storage medium, the method further includes: displaying the target knowledge graph to the user, and obtaining the user's modification instructions for the target knowledge graph; adjusting the target knowledge graph according to the modification instructions to obtain a modified knowledge graph, and displaying the modified knowledge graph to the user.

[0064] Specifically, the server presents the target knowledge graph to the user through a graphical user interface. The user interface can be in the form of a web page, desktop application, or mobile application, which can intuitively display the nodes, edges, and their attribute information of the target knowledge graph. The user interface provides a variety of interactive functions, such as zooming, panning, clicking, hovering, etc., to facilitate users to browse and explore the content of the knowledge graph.

[0065] In the process of browsing the knowledge graph, users may find some inaccuracies or incompleteness. For example, the attribute value of a node is wrong, the relationship between two nodes is missing, or the overall structure of the knowledge graph is not clear enough. In order to solve these problems, the server allows users to modify the target knowledge graph through interface interaction. Users can select a node or edge and enter modification instructions through pop-up menus, forms, or dialog boxes. Modification instructions can include the following types: modifying the attribute values ​​of nodes or edges, adding or deleting nodes, adding or deleting edges, and adjusting the layout of the knowledge graph. After receiving the user's modification instructions, the server will make corresponding adjustments and updates to the target knowledge graph. Specifically, the server will generate corresponding Cypher query statements based on the modification instructions, add, delete or modify the nodes, edges and attributes of the knowledge graph, obtain the modified knowledge graph, and modify the knowledge graph.

[0066] Reference Figure 2 The present application also provides a knowledge graph generation device based on word documents, which is a server, and the server includes a document parsing module 201, an element sorting module 202, a data structure segmentation module 203 and a knowledge graph generation module 204, wherein: the document parsing module 201 is used to parse the target document to obtain a corresponding XML file; the document parsing module 201 is also used to parse the XML file to obtain a first data structure, and the first data structure includes multiple elements; the element sorting module 202 is used to sort multiple elements in the first data structure according to a preset sorting rule to obtain a second data structure; the data structure segmentation module 203 is used to segment the second data structure using a preset recursive function to obtain multiple entities and the relationship between multiple entities; the knowledge graph generation module 204 is used to use multiple entities as nodes of a preset knowledge graph, and the relationship between multiple entities as edges of the preset knowledge graph to obtain a target knowledge graph.

[0067] In a possible implementation, the data structure segmentation module 203 uses a preset recursive function to segment the second data structure to obtain multiple entities and the relationship between the multiple entities, specifically including: the data structure segmentation module 203 obtains multiple first-level titles, and performs text analysis on each first-level title to obtain the corresponding first text content; the data structure segmentation module 203 generates corresponding functional entities according to the first text content, one first-level title corresponds to one functional entity, and multiple functional entities are in a peer relationship; the data structure segmentation module 203 obtains the data blocks corresponding to each first-level title, and determines the second-level title corresponding to the first-level title according to the data blocks; the data structure segmentation module 203 performs text analysis on each second-level title to obtain the corresponding second text content; the data structure segmentation module 203 generates corresponding functional system entities according to the second text content, and the functional entities and the functional system entities are in a superior-subordinate relationship; the data structure segmentation module 203 generates functional component entities based on the functional entities and the functional system entities, and the functional system entities and the functional component entities are in a superior-subordinate relationship.

[0068] In a possible implementation, the data structure segmentation module 203 obtains multiple first-level titles, and performs text analysis on each first-level title to obtain the corresponding first text content. The method also includes: the data structure segmentation module 203 traverses the first text content, performs word segmentation processing on the first text content, and obtains multiple word segmentation results; the data structure segmentation module 203 performs part-of-speech tagging on the multiple word segmentation results to obtain the part-of-speech corresponding to each word segmentation result; the data structure segmentation module 203 identifies the nouns or noun phrases in the word segmentation results according to the part-of-speech corresponding to each word segmentation result, and uses the identified nouns or noun phrases as the entity name of the functional entity.

[0069] In a possible implementation, the document parsing module 201 parses the XML file to obtain a first data structure, and after the first data structure includes multiple elements, the method further includes: the document parsing module 201 traverses each element in the XML file and determines the element type corresponding to each element; the document parsing module 201 generates element objects according to each element and the element type corresponding to each element; the element sorting module 202 records the order of appearance of each element object in the XML file during the generation of each element object, and generates a serial number attribute value for each element object according to the order of appearance; the element sorting module 202 sorts each serial number attribute value in ascending order to obtain a preset sorting rule.

[0070] In a possible implementation, the knowledge graph generation module 204 uses multiple entities as nodes of a preset knowledge graph, and uses the relationships between the multiple entities as edges of the preset knowledge graph to obtain a target knowledge graph, specifically including: the knowledge graph generation module 204 constructs a cypher query statement based on the nodes and edges; the knowledge graph generation module 204 determines whether there are preset characters in the cypher query statement; if it is determined that there are preset characters in the cypher query statement, the knowledge graph generation module 204 translates the preset characters to obtain a target cypher query statement; the knowledge graph generation module 204 stores the target cypher query statement in a preset storage medium, and generates a target knowledge graph based on the target cypher query statement.

[0071] In a possible implementation, after the knowledge graph generation module 204 stores the target cypher query statement to a preset storage medium, the method further includes: the knowledge graph generation module 204 displays the target knowledge graph to the user, and obtains the user's modification instructions for the target knowledge graph; the knowledge graph generation module 204 adjusts the target knowledge graph according to the modification instructions, obtains a modified knowledge graph, and displays the modified knowledge graph to the user.

[0072] It should be noted that: when the device provided in the above embodiment realizes its function, only the division of the above functional modules is used as an example. In actual application, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the device and method embodiments provided in the above embodiment belong to the same concept, and the specific implementation process is detailed in the method embodiment, which will not be repeated here.

[0073] The present application also provides an electronic device. Figure 3 , Figure 3 The electronic device 300 may include: at least one processor 301 , at least one network interface 304 , a user interface 303 , a memory 305 , and at least one communication bus 302 .

[0074] The communication bus 302 is used to realize the connection and communication between these components.

[0075] The user interface 303 may include a display screen (Display) and a camera (Camera). Optionally, the user interface 303 may also include a standard wired interface and a wireless interface.

[0076] The network interface 304 may optionally include a standard wired interface or a wireless interface (such as a WI-FI interface).

[0077] Among them, the processor 301 may include one or more processing cores. The processor 301 uses various interfaces and lines to connect various parts in the entire server, and executes various functions of the server and processes data by running or executing instructions, programs, code sets or instruction sets stored in the memory 305, and calling data stored in the memory 305. Optionally, the processor 301 can be implemented in at least one hardware form of digital signal processing (Digital Signal Processing, DSP), field programmable gate array (Field-Programmable Gate Array, FPGA), and programmable logic array (Programmable Logic Array, PLA). The processor 301 can integrate one or a combination of a central processing unit (Central Processing Unit, CPU), a graphics processing unit (Graphics Processing Unit, GPU) and a modem. Among them, the CPU mainly processes the operating system, user interface and application programs; the GPU is responsible for rendering and drawing the content to be displayed on the display screen; the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 301, and it can be implemented separately through a chip.

[0078] Among them, the memory 305 may include a random access memory (Random Access Memory, RAM) and may also include a read-only memory (Read-Only Memory). Optionally, the memory 305 includes a non-transitory computer-readable storage medium. The memory 305 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 305 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store data involved in the above-mentioned various method embodiments, etc. The memory 305 may optionally also be at least one storage device located away from the aforementioned processor 301. Refer to Figure 3 , as a computer storage medium, the memory 305 may include an operating system, a network communication module, a user interface module, and an application program for a knowledge graph generation method based on a word document.

[0079] exist Figure 3In the electronic device 300 shown, the user interface 303 is mainly used to provide an input interface for the user and obtain the data input by the user; and the processor 301 can be used to call the application program storing a knowledge graph generation method based on a word document in the memory 305, and when executed by one or more processors 301, the electronic device 300 executes one or more of the methods described in the above embodiments. It should be noted that for the aforementioned method embodiments, for the sake of simple description, they are all expressed as a series of action combinations, but those skilled in the art should know that the present application is not limited by the described order of actions, because according to the present application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required for the present application.

[0080] The present application also provides a computer-readable storage medium, which stores instructions. When executed by one or more processors 301, the electronic device 300 executes one or more of the methods described in the above embodiments.

[0081] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0082] In the several embodiments provided in this application, it should be understood that the disclosed devices can be implemented in other ways. For example, the device embodiments described above are only schematic, such as the division of units, which is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some service interfaces, and the indirect coupling or communication connection of devices or units can be electrical or other forms.

[0083] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0084] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0085] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a memory and includes several instructions for a computer device (which can be a personal computer, server or network device, etc.) to execute all or part of the steps of the various embodiments of the present application. The aforementioned memory includes: various media that can store program codes, such as USB flash drives, mobile hard drives, magnetic disks or optical disks.

[0086] The above is only an exemplary embodiment of the present disclosure and cannot be used to limit the scope of the present disclosure. That is, any equivalent changes and modifications made according to the teachings of the present disclosure are still within the scope of the present disclosure. After considering the disclosure of the specification and the truth of practice, those skilled in the art will easily think of other embodiments of the present disclosure.

[0087] This application is intended to cover any variation, use or adaptation of the present disclosure, which follows the general principles of the present disclosure and includes common knowledge or customary technical means in the art not described in the present disclosure. The description and examples are to be regarded as exemplary only, and the scope and spirit of the present disclosure are defined by the claims.

Claims

1. A knowledge graph generation method based on word documents, characterized in that: The method comprises: Parse the target document to obtain the corresponding XML file; Parsing the XML file to obtain a first data structure, wherein the first data structure includes a plurality of elements; In the first data structure, a plurality of the elements are sorted according to a preset sorting rule to obtain a second data structure; Using a preset recursive function to segment the second data structure to obtain a plurality of entities and relationships between the plurality of entities; The target knowledge graph is obtained by taking the multiple entities as nodes of a preset knowledge graph and taking the relationships between the multiple entities as edges of the preset knowledge graph.

2. The method according to claim 1, characterized in that The using a preset recursive function to segment the second data structure to obtain a plurality of entities and relationships between the plurality of entities specifically includes: Acquire multiple first-level titles, and perform text parsing on each of the first-level titles to obtain corresponding first text content; Generate a corresponding functional entity according to the first text content, wherein one first-level title corresponds to one functional entity, and multiple functional entities are in a same-level relationship; Acquire the data blocks corresponding to each of the first-level titles, and determine the second-level titles corresponding to the first-level titles according to the data blocks; Performing text analysis on each of the secondary titles to obtain corresponding second text content; Generate a corresponding functional system entity according to the second text content, wherein the functional entity and the functional system entity are in a superior-subordinate relationship; Based on the functional entity and the functional system entity, a functional component entity is generated, and the functional system entity and the functional component entity are in a superior-subordinate relationship.

3. The method according to claim 2, characterized in that After obtaining a plurality of first-level titles and performing text parsing on each of the first-level titles to obtain the corresponding first text content, the method further includes: Traversing the first text content, performing word segmentation processing on the first text content, and obtaining multiple word segmentation results; Performing part-of-speech tagging on the multiple word segmentation results to obtain the part-of-speech corresponding to each of the word segmentation results; According to the parts of speech corresponding to each of the word segmentation results, nouns or noun phrases in the word segmentation results are identified, and the identified nouns or noun phrases are used as entity names of the functional entities.

4. The method according to claim 1, characterized in that: After parsing the XML file to obtain a first data structure, wherein the first data structure includes a plurality of elements, the method further includes: Traverse each element in the xml file and determine the element type corresponding to each element; Generate an element object according to each of the elements and the element type corresponding to each of the elements; In the process of generating each of the element objects, the order in which each of the element objects appears in the XML file is recorded, and a sequence number attribute value is generated for each of the element objects according to the order in which each of the element objects appears; Sort the serial number attribute values ​​in ascending order to obtain the preset sorting rule.

5. The method according to claim 1, characterized in that The method of using the plurality of entities as nodes of a preset knowledge graph and using the relationships between the plurality of entities as edges of the preset knowledge graph to obtain a target knowledge graph specifically includes: Construct a cypher query statement based on the node and the edge; Determine whether there is a preset character in the cypher query statement; If it is determined that the cypher query statement contains a preset character, the preset character is translated to obtain a target cypher query statement; The target cypher query statement is stored in a preset storage medium, and the target knowledge graph is generated according to the target cypher query statement.

6. The method according to claim 5, characterized in that After storing the target cypher query statement in a preset storage medium, the method further includes: Displaying the target knowledge graph to the user, and obtaining the user's modification instructions for the target knowledge graph; The target knowledge graph is adjusted according to the modification instruction to obtain a modified knowledge graph, and the modified knowledge graph is displayed to the user.

7. The method according to claim 1, characterized in that The first data structure includes at least one of a paragraph element, a table element, a picture element, and an attachment element.

8. A knowledge graph generation device based on word documents, characterized in that: The device comprises a document parsing module (201), an element sorting module (202), a data structure segmentation module (203) and a knowledge graph generation module (204), wherein: The document parsing module (201) is used to parse the target document to obtain a corresponding XML file; The document parsing module (201) is further used to parse the XML file to obtain a first data structure, wherein the first data structure includes a plurality of elements; The element sorting module (202) is used to sort the plurality of elements in the first data structure according to a preset sorting rule to obtain a second data structure; The data structure segmentation module (203) is used to segment the second data structure using a preset recursive function to obtain a plurality of entities and relationships between the plurality of entities; The knowledge graph generation module (204) is used to use the multiple entities as nodes of the preset knowledge graph, and use the relationships between the multiple entities as edges of the preset knowledge graph to obtain a target knowledge graph.

9. An electronic device, characterized in that: The electronic device (300) comprises a processor (301), a memory (305), a user interface (303) and a network interface (304), wherein the memory (305) is used to store instructions, the user interface (303) and the network interface (304) are used to communicate with other devices, and the processor (301) is used to execute the instructions stored in the memory (305) so that the electronic device (300) executes the method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores instructions, and when the instructions are executed, the method according to any one of claims 1 to 7 is executed.

Citation Information

Patent Citations

  • Financial document intelligent verification method, device and storage medium

    CN109117479A

  • Knowledge graph construction method and system for multi-source Chinese financial announcement document

    CN113569054A

  • Knowledge graph construction method and device and computer readable storage medium

    CN114238654A

  • Retrieval method based on software test knowledge graph

    CN115422371A

  • Knowledge graph construction method and system based on software testing

    CN115422372A

Cited By

  • Test case generation method and device, equipment and storage medium

    CN119883937A