A knowledge graph generation method and device based on a word document and electronic equipment

By converting Word documents to XML format and using recursive functions to generate knowledge graphs, the problem of inaccurate information extraction in existing technologies is solved, achieving efficient document structure parsing and information extraction, and improving document readability and retrieval efficiency.

CN119597930BActive Publication Date: 2025-11-04BEIJING HUARONG XINNING TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

Existing technologies struggle to effectively extract and parse complex formatting and rich semantic information from Word documents, resulting in low accuracy in information extraction.

Method used

By converting Word documents to XML format, recursive functions are used to identify and parse the document structure, generate a knowledge graph, automatically identify entities and relationships, and avoid character recognition errors in OCR.

Benefits of technology

It improves the accuracy and readability of converting documents into knowledge graphs, reduces the amount of manual construction work, and enhances the descriptive ability and retrieval efficiency of information.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119597930B_ABST
    Figure CN119597930B_ABST
Patent Text Reader

Abstract

A knowledge graph generation method and device based on a word document and electronic equipment, relating to the field of data processing. In the method, the target document is parsed to obtain a corresponding xml file; the xml file is parsed to obtain a first data structure, the first data structure including a plurality of elements; in the first data structure, the plurality of elements are sorted according to a preset sorting rule to obtain a second data structure; the second data structure is split using a preset recursive function to obtain a plurality of entities and relationships between the plurality of entities; the plurality of entities are taken as nodes of a preset knowledge graph, and the relationships between the plurality of entities are taken as edges of the preset knowledge graph to obtain a target knowledge graph. By converting the document content into an XML format for recognition and extraction, the accuracy of the document-to-knowledge graph conversion 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, in particular to a knowledge graph generation method and device based on a word document and electronic equipment. BACKGROUND

[0002] With the rapid development of information technology, especially in the field of data processing and information management, there are more and more data processing challenges. Especially when dealing with a large number of document materials, how to effectively extract valuable information from these documents and organize these information into an easy-to-understand and searchable format has become an important demand. Word documents, as a widely used document format, contain a large amount of structured and unstructured information, but traditional document processing methods are difficult to fully exploit and utilize these information.

[0003] Currently, the related technology uses OCR technology to recognize text content and uses regular expressions to parse titles and levels, etc. This technology often cannot accurately parse the complex format and rich semantic information in the Word document. For example, the OCR technology often has character recognition errors when dealing with documents with complex layout, and the method based on simple rules cannot effectively identify the semantic relationship and hierarchy in the document, which leads to low accuracy of information extraction.

[0004] Therefore, there is an urgent need for a knowledge graph generation method and device based on a word document and electronic equipment. SUMMARY

[0005] The present application provides a knowledge graph generation method and device based on a word document and electronic equipment, which converts the document content into XML format for recognition and extraction, improving the accuracy of converting the document to the knowledge graph.

[0006] In a first aspect of the present application, a knowledge graph generation method 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; sorting the plurality of elements in the first data structure according to a preset sorting rule to obtain a second data structure; using a preset recursive function to split the second data structure to obtain a plurality of entities and relationships between the plurality of entities; taking the plurality of entities as nodes of a preset knowledge graph and taking the relationships between the plurality of entities as edges of the preset knowledge graph to obtain a target knowledge graph.

[0007] By adopting the technical scheme, the target document is parsed to obtain a corresponding xml file, and then the xml file is parsed to obtain a first data structure, so that the unstructured word document can be converted into a structured data form, and subsequent analysis and processing of the document content are facilitated. The recursive function is used to split the second data structure, so that the entities in the target document and the relationships between the entities can be automatically identified. 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-inferior and parallel semantic relationships between the entities. This automatic information extraction method greatly reduces the workload of manually constructing a knowledge graph. Finally, the extracted entities are taken as nodes of a preset knowledge graph, and the entity relationships are taken as edges of the preset knowledge graph, so that a target knowledge graph reflecting the semantic structure of the document is generated. The target knowledge graph presents the core content of the target document in an intuitive graphical form, improving the readability and retrieval efficiency of the target document. The technical scheme converts the document content into an XML format, avoiding the character recognition errors commonly seen in OCR. In addition, the technical scheme utilizes the original XML structure of the target document, which can more accurately identify and utilize the format and structure of the target document than relying only on regular expressions to identify titles and levels, thereby improving the accuracy of the document-to-knowledge graph conversion.

[0008] Optionally, the adopting the preset recursive function to split the second data structure to obtain a plurality of entities and relationships between the plurality of entities specifically includes: obtaining a plurality of first-level titles, and performing text analysis on each first-level title to obtain corresponding first text content; generating corresponding function entities according to the first text content, one first-level title corresponding to one function entity, and a plurality of function entities having a same-level relationship; obtaining a data block corresponding to each first-level title, and determining a second-level title corresponding to the first-level title according to the data block; performing text analysis on each second-level title to obtain corresponding second text content; generating corresponding function system entities according to the second text content, the function entities and the function system entities having a superior-inferior relationship; and generating function component entities based on the function entities and the function system entities, the function system entities and the function component entities having a superior-inferior relationship.

[0009] By adopting the technical solution, the first-level chapter structure of the document can be automatically recognized by acquiring the first-level titles and performing text analysis. The first-level titles are generated into corresponding function entities, and it is determined that the function entities are at the same level, thereby constructing a top-level framework of the document in the knowledge graph. Further, by acquiring the data blocks under the first-level titles, the corresponding second-level titles can be recognized, and the corresponding function system entities can be generated by text analysis. Since it is determined that the function entities and the function system entities are in a superior-inferior relationship, the second-level sub-modules under each first-level chapter are added in the existing top-level framework, so that the knowledge graph can represent a two-level document structure. On this basis, the function component entities at a lower level can also be generated according to the function entities and the function system entities. By determining the superior-inferior relationship of the function system entities and the function component entities, the level 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 all the contents of the document, and greatly improve the description ability and information carrying capacity of the knowledge graph.

[0010] Optionally, after the multiple first-level titles are acquired and text analysis is performed on each first-level title to obtain 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; and according to the part-of-speech corresponding to each word segmentation result, identifying a noun or a noun phrase in the word segmentation result, and taking the identified noun or noun phrase as an entity name of the function entity.

[0011] By adopting the technical solution, after the text content of the first-level title is acquired, the title content can be further granulated by word segmentation processing to divide it into multiple word segmentation results, thereby providing a more basic unit for semantic analysis. The part-of-speech tagging on the word segmentation results can identify the part-of-speech and grammatical function of each word, understand the structure of the title from the grammatical level, and help to more accurately extract semantic information subsequently. According to the part-of-speech tagging result, a noun or a noun phrase in the word segmentation result can be identified, and taken as the name of the function entity. This method automatically extracts a suitable entity name from the title, avoiding the subjectivity and inconsistency of manual definition of entities. At the same time, a noun phrase can express more complete semantics than a single word, and the generated entity name is more readable and easier for users to understand.

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

[0013] By using the above technical solutions, each element in the xml file is traversed and its element type is judged, so that the content form contained in the document, such as a paragraph, a table, a picture and an attachment, can be comprehensively analyzed without missing any information. According to the element type of the element, the corresponding element object is generated, so that the xml file can be converted into a data structure that can be processed by a program, facilitating extraction and analysis of text, attributes and other contents therein. When the element object is generated, the order of appearance of the element objects in the xml file is recorded, and a serial number attribute value is generated. Thus, the elements are numbered according to their positions in the target document, providing a basis for subsequent analysis and reconstruction of the contents according to the order of the elements. The serial number attribute values of the elements are sorted in ascending order to generate the preset sorting rule, ensuring that the elements can be processed in the order of their appearance in the original target document in subsequent processing, avoiding confusion and fragmentation of semantics, and enabling the extracted knowledge graph to accurately reflect the structure and logic of the document.

[0014] Optionally, the plurality of entities are taken as nodes of a preset knowledge graph, and the relationships between the plurality of entities are taken as edges of the preset knowledge graph to obtain a target knowledge graph, specifically comprising: constructing a cypher query statement based on the nodes and the edges; judging whether a preset character exists in the cypher query statement; if it is determined that the preset character exists in the cypher query statement, translating the preset character to obtain a target cypher query statement; storing the target cypher query statement to a preset storage medium, and generating the target knowledge graph according to the target cypher query statement.

[0015] By adopting the technical solution, the cypher query statement is constructed based on the extracted entity nodes and relationship edges, the knowledge graph can be represented in a form that can be recognized and stored by a graph database. The cypher query statement can describe the nodes and edges of the knowledge graph and define the patterns between them. After constructing the cypher query statement, it is judged whether the cypher query statement contains special characters and is 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 saved 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, and the content in the target knowledge graph can be conveniently queried and retrieved through the cypher query statement to quickly locate the relevant part of the original document.

[0016] Optionally, after storing the target cypher query statement in the preset storage medium, the method further comprises: displaying the target knowledge graph to the user and obtaining a modification instruction of the user for the target knowledge graph; adjusting the target knowledge graph according to the modification instruction to obtain a modified knowledge graph, and displaying the modified knowledge graph to the user.

[0017] By adopting the technical solution, the generated target knowledge graph is displayed to the user, 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 attributes of nodes and edges, etc. According to the user's modification instruction, the target knowledge graph is adjusted to generate a modified knowledge graph, which is displayed to the user. In this way, the user can view the modification effect in time and iteratively optimize the knowledge graph. By involving the user in the construction and modification of the target knowledge graph, the fit of the target knowledge graph to the actual needs of the user can be improved. The user can integrate his own understanding and insights into the target knowledge graph, constantly enrich and perfect the content of the target knowledge graph, and make it more comprehensive and accurate.

[0018] In a second aspect of the present application, a word document-based knowledge graph generation device is provided, which comprises a document analysis module, an element sorting module, a data structure cutting module, and a knowledge graph generation module, wherein: the document analysis module is configured to analyze a target document to obtain a corresponding xml file; the document analysis module is further configured to analyze the xml file to obtain a first data structure, the first data structure comprising a plurality of elements; the element sorting module is configured 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 cutting module is configured to cut the second data structure using a preset recursive function to obtain a plurality of entities and relationships between the plurality of entities; and the knowledge graph generation module is configured to take the plurality of entities as nodes of a preset knowledge graph and take the relationships between the plurality of entities as edges of the preset knowledge graph to obtain a target knowledge graph.

[0019] In a third aspect of the present application, an electronic device is provided, which comprises a processor, a memory, a user interface, and a network interface, the memory being configured to store instructions, the user interface and the network interface each being configured to communicate with other devices, and the processor being configured to execute the instructions stored in the memory to enable the electronic device to perform the method according to any one of the above aspects.

[0020] In a fourth aspect of the present application, a computer-readable storage medium is provided, which stores instructions that, when executed, perform the method according to any one of the above aspects.

[0021] In summary, the one or more technical solutions provided in the embodiments of the present application have at least the following technical effects or advantages:

[0022] 1、By parsing the target document, the corresponding xml file is obtained, and then the xml file is parsed 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 recursive function is used to split the second data structure, 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-inferior and parallel semantic relationships between them. This automatic 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 relationship is used as the edge of the preset knowledge graph, so as to generate a target knowledge graph reflecting the semantic structure of the document. The target knowledge graph presents the core content of the target document in an intuitive graphical form, improving the readability and retrieval efficiency of the target document. The technical scheme converts the document content into XML format, avoiding the common character recognition errors in OCR. At the same time, compared with only relying on regular expressions to identify the title and level, the technical scheme can more accurately identify and utilize the format and structure of the target document, improving the accuracy of the document to knowledge graph.

[0023] 2、By obtaining the first-level title and performing text analysis, the first-level chapter structure of the document can be automatically identified. The first-level title is used to generate corresponding functional entities, and the functional entities are determined to be in the same level relationship, so as to construct the top-level framework of the document 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 by text analysis. Since the functional entity and the functional system entity are determined to be in a superior-inferior relationship, the second-level submodules under each first-level chapter are added to the existing top-level framework, so that the knowledge graph can represent a two-level document structure. On this basis, the functional component entity of a lower layer can also be generated according to the functional entity and the functional system entity. By determining the superior-inferior 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 and automatically construct a knowledge graph covering all the content of the document, greatly improving the description ability and information carrying capacity of the knowledge graph.

[0024] 3、After obtaining the text content of the first-level title, the title content can be further granulated by dividing it into multiple segmentation results through segmentation processing, so as to provide more basic units for semantic analysis. The part-of-speech tagging of the segmentation results can identify the part-of-speech and grammatical function of each word, understand the structure of the title from the grammatical level, and help more accurately extract semantic information subsequently. According to the part-of-speech tagging results, the nouns or noun phrases in the 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 defining entities. At the same time, noun phrases can express more complete semantics than single words, and the generated entity names are more readable and easier for users to understand. BRIEF DESCRIPTION OF DRAWINGS

[0025] Figure 1 is a flowchart of a knowledge graph generation method based on a word document disclosed by an embodiment of the present application;

[0026] Figure 2 is a module schematic diagram of a knowledge graph generation device based on a word document disclosed by an embodiment of the present application;

[0027] Figure 3 is a structural schematic diagram of an electronic device disclosed by an embodiment of the present application.

[0028] Legend: 201, document analysis 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

[0029] In order for those skilled in the art to better understand the technical solutions in the specification, the technical solutions in the specification will be clearly and completely described below in conjunction with the drawings in the embodiments of the specification. Obviously, the described embodiments are only some of the embodiments of the present application, not all.

[0030] In the description of the embodiments of the present application, the words such as "for example" or "for instance" are used to represent examples, illustrations or descriptions. Any embodiment or design scheme described as "for example" or "for instance" in the embodiments of the present application should not be interpreted as more preferred or more advantageous than other embodiments or design schemes. Rather, the use of words such as "for example" or "for instance" is intended to present the relevant concept in a specific manner.

[0031] In the description of the embodiments of the present application, the term "a plurality of" means two or more. For example, a plurality of systems means two or more systems, and a plurality of screen terminals means two or more screen terminals. In addition, the terms "first", "second" are only used for the purpose of description, and cannot be understood as indicating or implying relative importance or implicitly indicating the indicated technical features. Therefore, the features defined with "first", "second" can explicitly or implicitly include one or more features. The terms "include", "contain", "have" and their variants mean "include but are not limited to", unless otherwise specifically emphasized.

[0032] The present application provides a knowledge graph generation method based on a word document, referring to Figure 1 , Figure 1 is a flowchart of a knowledge graph generation method based on a word document provided by an embodiment of the present application. The method is applied to a server, and the server is used to execute a knowledge graph generation program based on a word document. The server can be a server, a server cluster composed of multiple servers, or a cloud computing service center. The method includes steps S101 to S105, which are as follows:

[0033] Step S101: Analyzing the target document to obtain the corresponding xml file.

[0034] In step S101, the server receives the target document uploaded by the user, and the target document is a word document in doc format. The server stores the target document in a specified directory and obtains the file path of the target document. Then, the server calls the document parsing module and inputs the file path of the target document to start analyzing the target document. The server first judges whether the format of the target document is Word format. If the format of the target document is not Word format, the server returns an error message to the user, prompting the user to upload a document with the correct format. If the format of the target document is Word format, the server starts to decompress the target document to obtain the XML file of the target document.

[0035] Step S102: Analyzing the xml file to obtain a first data structure, and the first data structure includes a plurality of elements.

[0036] In step S102, the server loads the XML file using the BeautifulSoup library of Python and creates a BeautifulSoup object. This object exists in the form of a parsed XML document tree in memory, facilitating 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 used to store paragraph information; tables is a list used to store table information; images is a list used to store image information; attachments is a list used to store attachment information.

[0037] The server traverses the XML document tree, extracts various types of document content, and converts it into JSON format data, adding it to the first data structure. For the paragraphs in the target document, the server first determines whether the paragraph contains text, tables, or images. If the paragraph contains text, the text content is extracted and saved in the text field; if the paragraph contains tables, the row and column data of the table is extracted and saved in the table field; if the paragraph contains images, the file path of the image is extracted and saved in the image field.

[0038] In addition, the server also extracts style information of the paragraph, such as title level, alignment, etc., and saves it in the style field. The value of the style field includes "heading 1" (first-level heading), "heading 2" (second-level heading), "heading 3" (third-level heading), "table" (table), "image" (image), etc., which records 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 (first data structure).

[0039] In one 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 an element object according to each element and the element type corresponding to each element; recording the appearance order of each element object in the xml file during the generation process of each element object, and generating a serial number attribute value for each element object according to the appearance order; sorting each serial number attribute value in ascending order to obtain a preset sorting rule.

[0040] Specifically, the server traverses each element in the XML file. For each element, the server determines its element type, which includes paragraph, table, image, attachment, etc. The server can determine the element type by analyzing the tag name of the element.

[0041] According to the different element types, the server creates corresponding element objects. For example, for a paragraph element, the server creates a paragraph object containing attributes such as text content, style information, etc.; for a table element, the server creates a table object containing attributes such as row and column data, style information, etc.; for an image element, the server creates an image object containing attributes such as image file path, style information, etc.; for an attachment element, the server creates an attachment object containing attributes such as attachment file path, etc.

[0042] In the process of creating element objects, the server records the order of appearance of each element object in the XML file. Specifically, the server generates a unique order attribute value for each element object, and the order attribute value is incremented according to the order of appearance of the element object in the XML file. For example, the order attribute value of the first appearing element object is 1, the order attribute value of the second appearing element object is 2, and so on.

[0043] After all element objects are created, the server sorts all element objects according to the order attribute value from small to large. The sorted element object list is the preset sorting rule, and the preset sorting rule is the order of appearance of the element object in the original target document.

[0044] Step S103: In the first data structure, sort the plurality of elements according to the preset sorting rule to obtain a second data structure.

[0045] 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, images, and attachments. The server sorts the elements in the first data structure according to the preset sorting rule. The preset sorting rule assigns a unique order attribute value to each element object according to the order of appearance of the element object in the original target document. The smaller the order attribute value, the earlier the element object appears in the document.

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

[0047] During the sorting process, the server maintains a new JSON object to store the sorted elements. This new JSON object, which is the second data structure, has a similar structure to the first data structure, containing lists of paragraphs, tables, images, and attachments. However, the element objects in these lists have been reordered according to the pre-set sorting rules.

[0048] After sorting is complete, 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, preserving the contextual structure and semantic information of the target document.

[0049] Step S104: The second data structure is split using a pre-set recursive function to obtain multiple entities and relationships between multiple entities.

[0050] In step S104, multiple primary titles are obtained, and text analysis is performed on each primary title to obtain corresponding first text content. Based on the first text content, corresponding functional entities are generated, with one primary title corresponding to one functional entity, and multiple functional entities being in the same level relationship. The data blocks corresponding to each primary title are obtained, and the secondary titles corresponding to the primary titles are determined based on the data blocks. Text analysis is performed on each secondary title to obtain corresponding second text content. Based on the second text content, corresponding functional system entities are generated, with the functional entities and functional system entities being in a superior-inferior relationship. Based on the functional entities and functional system entities, functional component entities are generated, with the functional system entities and functional component entities being in a superior-inferior relationship.

[0051] Specifically, the server obtains the second data structure generated in step S103, which stores structured information and content arranged in the original document order in JSON format, including elements such as paragraphs, tables, images, and attachments. The server defines a pre-set recursive function to traverse the second data structure and extract entities and relationships. The main idea of the pre-set recursive function is to divide the document content into different data blocks based on the style information (such as title level) of the elements, and extract entities and relationships from these data blocks.

[0052] The server first obtains all the first-level headings in the second data structure, i.e. the paragraph elements with style information "heading 1". For each first-level heading, the server performs text parsing to extract the keywords and main content, and generates the corresponding first text content. According to the first text content, the server creates a functional entity object to represent the functional module or functional domain corresponding to the first-level heading. One first-level heading corresponds to one functional entity, and multiple functional entities are in the same level relationship, which together constitute the functional structure of the entire system or product described in the document.

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

[0054] For each second-level heading, the server also performs text parsing to extract the keywords and main content, and generates the corresponding second text content. Then, the server creates a functional system entity object according to the second text content to represent the sub-function or subsystem corresponding to the second-level heading.

[0055] There is a superior-inferior relationship between the functional entity and the functional system entity, i.e. one functional entity can contain multiple functional system entities, representing the relationship between the whole and the part. The server also records this relationship for subsequent construction of the knowledge graph.

[0056] The server uses the same method to extract the third-level headings based on the functional system entity to obtain the functional component entity. There is also a superior-inferior relationship between the functional system entity and the functional component entity, i.e. one functional system entity can contain multiple functional component entities, representing the relationship between the whole and the part.

[0057] The server recursively processes each first-level heading and its corresponding data block to extract all functional entities, functional system entities, and functional component entities, and records their relationships. 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 entity or functional system entity as additional attribute information.

[0058] After the preset recursive function processes all the first-level headings 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 their superior-inferior relationships in the document, forming a tree-like structure.

[0059] In a possible implementation, after obtaining the plurality of first-level titles and performing text analysis on each first-level title to obtain corresponding first text content, the method further includes: traversing the first text content, performing word segmentation processing on the first text content to obtain a plurality of word segmentation results; performing part-of-speech tagging on the plurality of word segmentation results to obtain a part-of-speech corresponding to each word segmentation result; and identifying a noun or a noun phrase in the word segmentation result according to the part-of-speech corresponding to each word segmentation result, and taking the identified noun or noun phrase as an entity name of a function entity.

[0060] Specifically, the server traverses the first text content and performs word segmentation processing thereon. Word segmentation refers to a process of dividing a piece of text into a plurality of individual words according to certain rules. Then, the server performs part-of-speech tagging on the obtained word segmentation results. Part-of-speech tagging refers to assigning a part-of-speech tag to each word in the word segmentation results, indicating the part-of-speech and grammatical function of the word in a sentence. The server identifies a noun or a noun phrase in the word segmentation results according to the part-of-speech tags of the word segmentation results, and takes the identified noun or noun phrase as an entity name of a function entity. The reason for selecting a noun or a noun phrase as an entity name is that, in a first-level title, a noun or a noun phrase usually represents a function or a module of a system, and is more suitable as a node in a knowledge graph.

[0061] Step S105: taking the plurality of entities as nodes of the preset knowledge graph and taking the relationships between the plurality of entities as edges of the preset knowledge graph to obtain a target knowledge graph.

[0062] In step S105, a cypher query statement is constructed based on the nodes and the edges; it is determined whether the preset character exists in the cypher query statement; if it is determined that the preset character exists in the cypher query statement, 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 a target knowledge graph is generated according to the target cypher query statement.

[0063] Specifically, the server obtains the entity and relationship list generated in step S104, and the relationship list contains all function entities, function system entities, function component entities and their hierarchical relationships and attribute information extracted from the document. The server converts the entity and relationship list into nodes and edges of the preset knowledge graph. Specifically, the server creates a node for each function entity, function system entity and function 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 the entities, and the attributes of the edge include the type (such as "contains") of the relationship and other additional information.

[0064] 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 in the embodiments of the present application can be understood as a language used to create, query and modify data in a graph database. The server generates a Cypher statement according to a preset template, which is used to create nodes, establish relationships and set attribute values. In the process of constructing the Cypher query statement, the server will determine whether there are preset characters in the statement, such as single quotes, double quotes, backslashes, etc. The preset characters have special meanings in the Cypher statement, and if they are used directly, they may cause syntax errors or injection attacks.

[0065] If there are preset characters in the Cypher query statement, the server will perform translation processing on these characters. Translation refers to the conversion of 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 the 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 a database) for subsequent calling and execution. 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.

[0066] After the graph database receives the target Cypher query statement, it 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 and their relationships in the document, forming a structured knowledge base.

[0067] In one possible implementation, after storing the target cypher query statement in the preset storage medium, the method further comprises: displaying the target knowledge graph to the user and obtaining a modification instruction of the user for the target knowledge graph; adjusting the target knowledge graph according to the modification instruction to obtain a modified knowledge graph, and displaying the modified knowledge graph to the user.

[0068] 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, a desktop application or a mobile application, etc., which can intuitively display the nodes, edges and their attribute information of the target knowledge graph. The user interface provides various interactive functions, such as zooming, panning, clicking, hovering, etc., to facilitate the user to browse and explore the content of the knowledge graph.

[0069] In the process of browsing the knowledge graph, the user may find some inaccuracies, incompleteness. For example, the attribute value of a certain node is wrong, the relationship between two nodes is missing, or the overall structure of the knowledge graph is not clear enough, etc. In order to solve these problems, the server allows the user to modify the target knowledge graph through interface interaction. The user can select a certain node or edge and input the modification instruction through a pop-up menu, form or dialog box. The modification instruction can include the following types: modifying the attribute value of a node or edge, adding or deleting a node, adding or deleting an edge, and adjusting the layout of the knowledge graph. After receiving the user's modification instruction, the server will adjust and update the target knowledge graph accordingly. Specifically, the server will generate a corresponding Cypher query statement according to the modification instruction, add, delete or modify the nodes, edges and attributes of the knowledge graph to obtain the modified knowledge graph, and output the modified knowledge graph.

[0070] With reference to Figure 2 The application further provides a knowledge graph generation device based on a word document. The device is a server, and the server comprises a document parsing module 201, an element sorting module 202, a data structure cutting module 203, and a knowledge graph generation module 204. The document parsing module 201 is configured to parse a target document to obtain a corresponding xml file. The document parsing module 201 is further configured to parse the xml file to obtain a first data structure, wherein the first data structure comprises a plurality of elements. The element sorting module 202 is configured 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 cutting module 203 is configured to cut the second data structure by 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 configured to take the plurality of entities as nodes of a preset knowledge graph and take the relationships between the plurality of entities as edges of the preset knowledge graph to obtain a target knowledge graph.

[0071] In a possible implementation, the data structure segmentation module 203 segments the second data structure by using a preset recursive function to obtain a plurality of entities and relationships between the plurality of entities, specifically including: the data structure segmentation module 203 acquires a plurality of first-level titles, and performs text analysis on each first-level title to obtain corresponding first text content; the data structure segmentation module 203 generates corresponding function entities according to the first text content, one first-level title corresponds to one function entity, and the plurality of function entities are in a same-level relationship; the data structure segmentation module 203 acquires a data block corresponding to each first-level title, and determines a second-level title corresponding to the first-level title according to the data block; the data structure segmentation module 203 performs text analysis on each second-level title to obtain corresponding second text content; the data structure segmentation module 203 generates corresponding function system entities according to the second text content, the function entity and the function system entity are in a superior-inferior relationship; and the data structure segmentation module 203 generates function component entities based on the function entity and the function system entity, the function system entity and the function component entity are in a superior-inferior relationship.

[0072] In a possible implementation, after the data structure segmentation module 203 acquires a plurality of first-level titles and performs text analysis on each first-level title to obtain corresponding first text content, the method further includes: the data structure segmentation module 203 traverses the first text content, performs word segmentation processing on the first text content to obtain a plurality of word segmentation results; the data structure segmentation module 203 performs part-of-speech tagging on the plurality of word segmentation results to obtain a part of speech corresponding to each word segmentation result; and the data structure segmentation module 203 identifies a noun or a noun phrase in the word segmentation result according to the part of speech corresponding to each word segmentation result, and takes the identified noun or noun phrase as an entity name of a function entity.

[0073] In a possible implementation, after the document analysis module 201 analyzes an xml file to obtain a first data structure, the first data structure including a plurality of elements, the method further includes: the document analysis module 201 traverses each element in the xml file, and judges an element type corresponding to each element; the document analysis module 201 generates an element object according to each element and the element type corresponding to each element; the element sorting module 202 records an appearance order of each element object in the xml file in the process of generating each element object, and generates a serial number attribute value for each element object according to the appearance order; and the element sorting module 202 sorts each serial number attribute value in ascending order to obtain a preset sorting rule.

[0074] In a possible implementation, the knowledge graph generation module 204 takes the plurality of entities as nodes of a preset knowledge graph and takes the relationships between the plurality of 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 the edges; the knowledge graph generation module 204 determines whether the preset character exists in the cypher query statement; if it is determined that the preset character exists in the cypher query statement, the knowledge graph generation module 204 translates the preset character to obtain a target cypher query statement; and the knowledge graph generation module 204 stores the target cypher query statement in a preset storage medium and generates the target knowledge graph according to the target cypher query statement.

[0075] In a possible implementation, after the knowledge graph generation module 204 stores the target cypher query statement in the preset storage medium, the method further includes: the knowledge graph generation module 204 displays the target knowledge graph to a user and acquires a modification instruction of the user for the target knowledge graph; and the knowledge graph generation module 204 adjusts the target knowledge graph according to the modification instruction to obtain a modified knowledge graph and displays the modified knowledge graph to the user.

[0076] It should be noted that, the apparatus provided in the above embodiments is only taken as an example for the division of the functional modules, and in actual applications, the above functions can be completed by different functional modules according to needs, that is, the internal structure of the apparatus is divided into different functional modules to complete all or part of the above described functions. In addition, the apparatus and method embodiments provided in the above embodiments belong to the same concept, and the specific implementation process is detailed in the method embodiments, which will not be repeated here.

[0077] The present application also provides an electronic device. Referring to Figure 3 , Figure 3 is a structural schematic diagram of an electronic device provided by an embodiment of the present application. The electronic device 300 can 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.

[0078] The communication bus 302 is configured to realize the connection and communication between the components.

[0079] The user interface 303 can include a display screen (Display) and a camera (Camera), and the optional user interface 303 can further include a standard wired interface and a wireless interface.

[0080] The network interface 304 can optionally include a standard wired interface and a wireless interface (such as a WI-FI interface).

[0081] The processor 301 can include one or more processing cores. The processor 301 connects various parts within the server through various interfaces and lines, performs 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. Alternatively, the processor 301 can be implemented in at least one of a hardware form of a digital signal processing (DSP), a field-programmable gate array (FPGA), and a programmable logic array (PLA). The processor 301 can integrate a combination of one or more of a central processing unit (CPU), a graphics processing unit (GPU), and a modem. Among them, the CPU mainly processes operating systems, user interfaces, and application programs; the GPU is responsible for rendering and drawing the content to be displayed on the display screen; and the modem is used for processing wireless communication. It can be understood that the above-mentioned modem can also not be integrated into the processor 301, but can be realized by a separate chip.

[0082] The memory 305 can include a random access memory (RAM) and a read-only memory (ROM). Alternatively, 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 can include a program storage area and a data storage area, wherein the program storage area can store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playing function, an image playing function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area can store data involved in the above-mentioned various method embodiments, etc. The memory 305 can also be at least one storage device located away from the aforementioned processor 301. Referring to Figure 3 The memory 305 as a computer storage medium can include an operating system, a network communication module, a user interface module, and an application program of a knowledge graph generation method based on a word document.

[0083] In Figure 3In the electronic device 300 shown, the user interface 303 is mainly used to provide an interface for the user to input, and obtain data input by the user; and the processor 301 can be used to invoke an application program stored in the memory 305 and storing a knowledge graph generation method based on a word document, which, when executed by one or more processors 301, causes the electronic device 300 to perform the method described in one or more of the above embodiments. It should be noted that, for the foregoing method embodiments, in order to simply describe, they are all expressed as a combination of a series of actions, but those skilled in the art should know that the present application is not limited to the order of the actions described, because according to the present application, certain steps can be performed in other orders or at the same time. Secondly, those skilled in the art should know that the embodiments described in the specification all belong to preferred embodiments, and the actions and modules involved are not necessarily required by the present application.

[0084] The present application also provides a computer-readable storage medium storing instructions. When executed by one or more processors 301, the electronic device 300 performs the method described in one or more of the above embodiments.

[0085] In the above embodiments, the description of each embodiment has its own focus, and the parts not described in detail in a certain embodiment can be referred to the related description of other embodiments.

[0086] In the several embodiments provided by the present application, it should be understood that the disclosed device can be implemented in other ways. For example, the device embodiments described above are only schematic. The division of the units is only a logical function division. There can be another division manner for actual implementation, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the units shown or discussed can be indirect coupling or communication connection through some services interfaces, devices or units, and can be electrical or other forms.

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

[0088] In addition, each functional unit in each embodiment of the present application can be integrated into one processing unit, or each unit can exist physically, or two or more units can be integrated into one unit. The above integrated unit can be realized in the form of hardware, or in the form of a software functional unit.

[0089] If the integrated unit is implemented in the form of a software function unit and sold or used as an independent product, it can be stored in a computer-readable memory. Based on such understanding, the technical solutions of the present application essentially or say the part that contributes to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a memory and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server or a network device, etc.) to execute all or part of the steps of the embodiments of the present application. The aforementioned memory includes: a U disk, a mobile hard disk, a magnetic disk or an optical disk, and various media that can store program codes.

[0090] The above is only exemplary embodiments of the present disclosure, which cannot limit the scope of the present disclosure. That is, any equivalent changes and modifications made in accordance with the teachings of the present disclosure are still within the scope of the present disclosure. Other embodiments of the present disclosure will be readily apparent to those skilled in the art upon considering the specification and practicing the true principles of the present disclosure.

[0091] The present application is intended to cover any variations, uses or adaptive changes of the present disclosure that follow the general principles of the present disclosure and include common knowledge or conventional technical means in the technical field that are not recorded in the present disclosure. The specification and examples are only considered as exemplary, and the scope and spirit of the present disclosure are defined by the claims.

Claims

1. A method for generating a knowledge graph based on a word document, characterized in that, The method comprises: 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; sorting the plurality of elements in the first data structure according to a preset sorting rule to obtain a second data structure; splitting the second data structure using a preset recursive function to obtain a plurality of entities and relationships between the plurality of entities; taking the plurality of entities as nodes of a preset knowledge graph and taking the relationships between the plurality of entities as edges of the preset knowledge graph to obtain a target knowledge graph; the splitting the second data structure using a preset recursive function to obtain a plurality of entities and relationships between the plurality of entities specifically comprises: obtaining a plurality of first-level titles and performing text analysis on each of the first-level titles to obtain corresponding first text content; generating corresponding functional entities according to the first text content, one first-level title corresponding to one functional entity, and the plurality of functional entities being in a same-level relationship; obtaining data blocks corresponding to each of the first-level titles and determining second-level titles corresponding to the first-level titles according to the data blocks; performing text analysis on each of the second-level titles to obtain corresponding second text content; generating corresponding functional system entities according to the second text content, the functional entities and the functional system entities being in a superior-inferior relationship; generating functional component entities based on the functional entities and the functional system entities, the functional system entities and the functional component entities being in a superior-inferior relationship; after the parsing the xml file to obtain a first data structure, the first data structure comprising a plurality of elements, the method further comprises: 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; recording the appearance order of each element object in the xml file during the generation of each element object and generating a serial number attribute value for each element object according to the appearance order; sorting each serial number attribute value in ascending order to obtain the preset sorting rule; the taking the plurality of entities as nodes of a preset knowledge graph and taking the relationships between the plurality of entities as edges of the preset knowledge graph to obtain a target knowledge graph specifically comprises: constructing a cypher query statement based on the nodes and the edges; judging whether there is a preset character in the cypher query statement; if it is determined that there is a preset character in the cypher query statement, translating the preset character to obtain a target cypher query statement; storing the target cypher query statement to a preset storage medium and generating the target knowledge graph according to the target cypher query statement.

2. The method of claim 1, wherein, after the obtaining a plurality of first-level titles and performing text analysis on each of the first-level titles to obtain corresponding first text content, the method further comprises: The first text content is processed by word segmentation to obtain a plurality of word segmentation results; Each word segmentation result is tagged by part of speech to obtain a part of speech corresponding to each word segmentation result; According to the part of speech corresponding to each word segmentation result, a noun or a noun phrase in the word segmentation result is identified, and the identified noun or noun phrase is taken as an entity name of the functional entity.

3. The method of claim 1, wherein, After storing the target cypher query statement in the preset storage medium, the method further comprises: The target knowledge graph is displayed to the user, and a modification instruction of the user for the target knowledge graph is obtained; 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.

4. The method of claim 1, wherein, The first data structure includes at least one of a paragraph element, a table element, a picture element, and an attachment element. 5.A word document based knowledge graph generation apparatus, characterized by, The device is used to execute the method of any one of claims 1-4, and the device includes a document parsing module (201), an element sorting module (202), a data structure cutting module (203), and a knowledge graph generation module (204), wherein: The document parsing module (201) is used to parse a 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, and 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 cutting module (203) is used to cut the second data structure by 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 take the plurality of entities as nodes of a preset knowledge graph and take the relationships between the plurality of entities as edges of the preset knowledge graph to obtain a target knowledge graph.

6. An electronic device, comprising: The electronic device (300) includes a processor (301), a memory (305), a user interface (303), and a network interface (304), 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) to enable the electronic device (300) to execute the method of any one of claims 1-4.

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

Citation Information

Patent Citations

  • Knowledge graph construction method and system in coal mine safety production field

    CN116821376A

  • Service term data processing method, apparatus and device, and storage medium

    WO2022126960A1