CN114896946A - Method for converting text and related equipment - Google Patents

Method for converting text and related equipment Download PDF

Info

Publication number
CN114896946A
CN114896946A CN202210233964.5A CN202210233964A CN114896946A CN 114896946 A CN114896946 A CN 114896946A CN 202210233964 A CN202210233964 A CN 202210233964A CN 114896946 A CN114896946 A CN 114896946A
Authority
CN
China
Prior art keywords
scope
tag
character
text
label
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210233964.5A
Other languages
Chinese (zh)
Inventor
林良喜
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Renjing Information Technology Co ltd
Original Assignee
Shanghai Renjing Information Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Renjing Information Technology Co ltd filed Critical Shanghai Renjing Information Technology Co ltd
Priority to CN202210233964.5A priority Critical patent/CN114896946A/en
Publication of CN114896946A publication Critical patent/CN114896946A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/12Use of codes for handling textual entities
    • G06F40/151Transformation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/12Use of codes for handling textual entities
    • G06F40/14Tree-structured documents
    • G06F40/143Markup, e.g. Standard Generalized Markup Language [SGML] or Document Type Definition [DTD]

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Health & Medical Sciences (AREA)
  • Artificial Intelligence (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Document Processing Apparatus (AREA)

Abstract

The present disclosure provides a method of converting text and related devices. The text comprises a first label and a second label, the second label is a sub-label of the first label, and the method comprises the following steps: creating a target object for saving a text conversion result; in response to the first label and the second label being recognized in the text, creating a first scope and a second scope corresponding to the first label and the second label respectively in the target object according to a hierarchical relationship between the first label and the second label, wherein the second scope is a sub-scope of the first scope; and storing the tag names, the attribute names and the attribute values corresponding to the first tags and the second tags in the first scope and the second scope, respectively.

Description

Method for converting text and related equipment
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a method for converting a text and a related device.
Background
With the development of computer technology, source code text written in a variety of programming languages exists in the field. Generally, text written in different programming languages cannot be directly converted into another text, and conversion from one text to another text needs to be completed by means of tools. This conversion process is generally inefficient.
Disclosure of Invention
The present disclosure proposes a method and related device for converting text, so as to solve or partially solve the above problems.
In a first aspect of the present disclosure, a method for converting a text is provided, where the text includes a first tag and a second tag, and the second tag is a sub-tag of the first tag, the method includes:
creating a target object for saving a text conversion result;
in response to the first label and the second label being recognized in the text, creating a first scope and a second scope corresponding to the first label and the second label respectively in the target object according to a hierarchical relationship between the first label and the second label, wherein the second scope is a sub-scope of the first scope; and
and storing the label names, the attribute names and the attribute values corresponding to the first labels and the second labels in the first scope and the second scope respectively.
In a second aspect of the present disclosure, an apparatus for converting text is provided, where the text includes a first tag and a second tag, and the second tag is a sub-tag of the first tag, the apparatus includes:
a creation module configured to: creating a target object for saving the conversion result;
a conversion module configured to:
in response to the first label and the second label being recognized in the text, creating a first scope and a second scope corresponding to the first label and the second label respectively in the target object according to a hierarchical relationship between the first label and the second label, wherein the second scope is a sub-scope of the first scope; and
and storing the label names, the attribute names and the attribute values corresponding to the first labels and the second labels in the first scope and the second scope respectively.
In a third aspect of the disclosure, a computer device is provided, comprising one or more processors, a memory; and one or more programs, wherein the one or more programs are stored in the memory and executed by the one or more processors, the programs comprising instructions for performing the method according to the first aspect.
In a fourth aspect of the disclosure, a non-transitory computer-readable storage medium containing a computer program is provided, which, when executed by one or more processors, causes the processors to perform the method of the first aspect.
In a fifth aspect of the present disclosure, there is provided a computer program product comprising computer program instructions which, when run on a computer, cause the computer to perform the method of the first aspect.
According to the method and the related equipment for converting the text, the text can be quickly converted and less resources are occupied by the label identification and the establishment of the hierarchical relation of the scope.
Drawings
In order to more clearly illustrate the technical solutions in the present disclosure or related technologies, the drawings needed to be used in the description of the embodiments or related technologies are briefly introduced below, and it is obvious that the drawings in the following description are only embodiments of the present disclosure, and for those skilled in the art, other drawings can be obtained according to these drawings without creative efforts.
Fig. 1 shows a hardware structure diagram of an exemplary computer device provided by the embodiment of the present disclosure.
Fig. 2 shows a schematic diagram of exemplary text in accordance with an embodiment of the present disclosure.
FIG. 3A illustrates a schematic diagram of an exemplary target object, according to an embodiment of the present disclosure.
FIG. 3B illustrates a schematic diagram of another exemplary target object, according to an embodiment of the present disclosure.
FIG. 3C illustrates a schematic diagram of yet another exemplary target object, according to an embodiment of the present disclosure.
FIG. 3D illustrates a schematic diagram of yet another exemplary target object, according to an embodiment of the present disclosure.
FIG. 3E illustrates a schematic diagram of another exemplary target object, in accordance with an embodiment of the present disclosure.
FIG. 3F illustrates a schematic diagram of yet another exemplary target object, according to an embodiment of the present disclosure.
FIG. 4A illustrates a schematic diagram of an exemplary scoped stack in accordance with an embodiment of the disclosure.
FIG. 4B illustrates a schematic diagram of another exemplary scoping stack in accordance with embodiments of the present disclosure.
FIG. 4C illustrates a schematic diagram of yet another exemplary scoping stack in accordance with embodiments of the present disclosure.
FIG. 4D illustrates a schematic diagram of yet another exemplary scoping stack in accordance with an embodiment of the present disclosure.
FIG. 4E illustrates a schematic diagram of another exemplary scoping stack in accordance with embodiments of the present disclosure.
FIG. 4F illustrates a schematic diagram of yet another exemplary scoping stack in accordance with an embodiment of the present disclosure.
FIG. 4G illustrates a schematic diagram of yet another exemplary scoping stack in accordance with an embodiment of the present disclosure.
Fig. 5 illustrates a flow diagram of an exemplary method provided by an embodiment of the present disclosure.
Fig. 6 illustrates a schematic diagram of an exemplary apparatus provided by an embodiment of the present disclosure.
Detailed Description
For the purpose of promoting a better understanding of the objects, aspects and advantages of the present disclosure, reference is made to the following detailed description taken in conjunction with the accompanying drawings.
It is to be noted that technical terms or scientific terms used in the embodiments of the present disclosure should have a general meaning as understood by those having ordinary skill in the art to which the present disclosure belongs, unless otherwise defined. The use of "first," "second," and similar terms in the embodiments of the disclosure is not intended to indicate any order, quantity, or importance, but rather is used to distinguish one element from another. The word "comprising" or "comprises", and the like, means that the element or item listed before the word covers the element or item listed after the word and its equivalents, but does not exclude other elements or items. The terms "connected" or "coupled" and the like are not restricted to physical or mechanical connections, but may include electrical connections, whether direct or indirect. "upper", "lower", "left", "right", and the like are used only to indicate relative positional relationships, and when the absolute position of the object being described is changed, the relative positional relationships may also be changed accordingly.
Scalable Vector Graphics (SVG), which is a Vector Graphics format, an open standard Vector Graphics language, can design high-resolution Web Graphics pages, and is generally applied as Document Object Model (DOM) nodes in Web pages.
Webgl (web Graphics library) is a 3D Graphics protocol that eliminates the trouble of developing web page-specific rendering plug-ins, can be used to create web site pages with complex 3D structures, can even be used to design 3D web games, and so on.
In some scenes, pictures in the SVG format may need to be rendered by using WebGL, but because DOM and WebGL rendering principles are different, there is no method for directly converting SVG text into a data format processable by WebGL in a browser, so that a DOM node of SVG cannot be directly rendered in WebGL.
One possible implementation is to parse the SVG text into data that can be processed by WebGL (e.g., data in JSON (JSON Object Notation) format) according to the graphics rules depicted in the SVG text, which in turn renders the image according to the data in JSON format.
For example, SVG text may be converted into a DOM object using DOM Parser (a kind of native API of a browser) provided in a browser, and then the DOM object is converted into a JSON object that WebGL can render by traversing the DOM object and obtaining attributes of the DOM object.
A typical process of converting SVG text into DOM objects by DOM Parser may be to load SVG text (usually in XML format) into memory and parse it into a tree structure, the so-called DOM tree. And, each node of the DOM tree is a DOM object and has data encapsulated therein, providing a corresponding operation method.
Ideally, the DOM should be simple. However, in actual use, a large amount of information irrelevant to the drawing image is generated in the DOM tree. For example, SVG text typically has many line breaks and blanks inserted for the readability of the text, which also appear in the DOM tree in the form of nodes. Meanwhile, nodes of the DOM tree also have data such as attributes, and the data encapsulated in the DOM nodes cannot be directly read but needs to be obtained through parsing. Therefore, it can be understood that, for a complex DOM tree, efficiency of traversing DOM objects and obtaining DOM attributes is low, and the process needs to occupy more resources.
In view of this, the embodiments of the present disclosure provide a method and related device for converting a text, which can implement fast text conversion and occupy less resources.
Fig. 1 shows a hardware structure diagram of an exemplary computer device 100 provided by the embodiment of the present disclosure. The computer device 100 may be used to implement the method of converting text of the embodiments of the present disclosure. As shown in fig. 1, the computer apparatus 100 may include: processor 102, memory 104, network module 106, peripheral interface 108, and bus 110. Wherein the processor 102, memory 104, network module 106, and peripheral interface 108 are communicatively coupled to each other within the computing device 100 via bus 110.
The processor 102 may be a Central Processing Unit (CPU), an image processor, a neural Network Processor (NPU), a Microcontroller (MCU), a programmable logic device, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), or one or more Integrated circuits. Processor 102 may be used to perform functions related to the techniques described in this disclosure. In some embodiments, processor 102 may also include multiple processors integrated into a single logic component. For example, as shown in FIG. 5, the processor 102 may include a plurality of processors 102a, 102b, and 102 c.
The memory 104 may be configured to store data (e.g., instructions, computer code, etc.). As shown in fig. 1, the data stored by the memory 104 may include program instructions (e.g., for implementing the method of converting text of an embodiment of the present disclosure) as well as data to be processed (e.g., the memory may store configuration files for other modules, etc.). The processor 102 may also access program instructions and data stored by the memory 104 and execute the program instructions to operate on the data to be processed. The memory 104 may include volatile memory devices or non-volatile memory devices. In some embodiments, the memory 104 may include Random Access Memory (RAM), Read Only Memory (ROM), optical disks, magnetic disks, hard disks, Solid State Disks (SSDs), flash memory, memory sticks, and the like.
The network interface 106 may be configured to provide communications with other external devices to the computer device 100 via a network. The network may be any wired or wireless network capable of transmitting and receiving data. For example, the network may be a wired network, a local wireless network (e.g., bluetooth, WiFi, Near Field Communication (NFC), etc.), a cellular network, the internet, or a combination of the above. It is to be understood that the type of network is not limited to the specific examples described above.
Peripheral interface 108 may be configured to connect computer device 100 with one or more peripheral devices for the input and output of information. For example, the peripheral devices may include input devices such as keyboards, mice, touch pads, touch screens, microphones, various sensors, and output devices such as displays, speakers, vibrators, indicator lights, and the like.
The bus 110 may be configured to transfer information between various components of the computer device 100 (e.g., the processor 102, the memory 104, the network interface 106, and the peripheral interface 108), such as an internal bus (e.g., a processor-memory bus), an external bus (a USB port, a PCI-E bus), and so forth.
It should be noted that although the architecture of the computer device 100 described above only shows the processor 102, the memory 104, the network interface 106, the peripheral interface 108 and the bus 110, in a specific implementation, the architecture of the computer device 100 may also include other components necessary for normal operation. Furthermore, those skilled in the art will appreciate that the architecture of the computer device 100 described above may also include only the components necessary to implement the embodiments of the present disclosure, and need not include all of the components shown in the figures.
In an initial state, a set of strings that conform to a tag (tag) naming convention may be defined, a scope stack for storing scope information may be defined, and a target object for storing conversion results may be defined. In some embodiments, the target object may be a JSON formatted object.
In some embodiments, for example, in the case of processing SVG text, which constitutes a vector image, the processing may be implemented by writing code (in XML format) in which various shape tags are used, and in order to be able to recognize these tags, tag name strings corresponding to these tags may be defined as a string set conforming to a tag naming specification. For example, a string that conforms to the tag naming specification may be:
SVG, root element in SVG text, refers to root (root) of SVG text; generally, each SVG text contains an outermost < SVG > </SVG > tag for declaring the beginning and end of the SVG text;
g, grouping elements in the SVG text refer to basic repeating units of the SVG text; in SVG text, a label < g > can be nested for further representing primitives and sub-primitives, and any visual basic geometric primitive element can be defined in the label < g >;
path, path elements in the SVG text, for describing paths in the geometric primitives; in the SVG text, an elliptical arc can be redefined using an elliptical arc curve command A of a path element;
circle, ellise, line, polyline, rect, polygon and graphics elements in SVG text are used for describing circles, ellipses, lines, broken lines, rectangles and polygons in geometric primitives; in SVG text, polygons can be redefined using polygon elements.
After the initial preparation is completed, the computer device 100 may first determine the text that needs to be converted. For example, the text that the user needs to convert is provided by the user.
Fig. 2 shows a schematic diagram of exemplary text 200, in accordance with an embodiment of the present disclosure.
As shown in fig. 2, the text 200 may be SVG text in XML format. The grammar and the format definition in the SVG text follow the XML standard, the SVG object is described through various element labels and the attributes corresponding to the labels, and the SVG text is directly analyzed by utilizing the characteristic.
Next, computer device 100 may create a target object, e.g., a JSON formatted object, for text 200 for saving the text conversion results. It is to be appreciated that the created target object can be stored in the memory 104 of FIG. 1.
Fig. 3A illustrates a schematic diagram of an exemplary target object 300, in accordance with an embodiment of the present disclosure.
As shown in FIG. 3A, when creating the target object 300, the target object 300 may be a null object (residual defined) since text parsing has not yet begun. Subsequent computer devices 100 can utilize the empty object to create a scope. The scope is used for storing label information of the text 200, for example, a label name, a label attribute and a corresponding attribute value of a label corresponding to the scope, and sub-label information of a current label (and sub-label information of the sub-label, etc.). Since the target object 300 corresponds to the entire text, all tag information of the entire text can be stored therein.
In some embodiments, the scope created in the target object 300 may include special fields for storing the tag name, tag attribute name and corresponding attribute value, and sub-tag information for the current tag. Fig. 3B illustrates a schematic diagram of an exemplary scope, in accordance with an embodiment of the present disclosure. As shown in FIG. 3B, a scope may include three special fields, label, props, _ children. The label value is a character string and is used for recording the label name of the label corresponding to the scope; the value of the props is a null object and is used for storing the corresponding label attribute name and the corresponding attribute value; the child field is an array for storing the scope of the sub-label of the label corresponding to the scope.
After the target object is created, the computer device 100 may begin parsing and converting the text 200.
Taking SVG text as an example, which is generally described by XML, information of each tag in the text may be obtained before obtaining the graphic information recorded in the SVG text. Thus, the computer device 100 may perform text parsing by tag recognition of the text 200.
Since one tag in XML is typically represented in XML by the start tag < > and the end tag </> and the content between the start tag and the end tag, in some embodiments, the identification tag may first identify its start tag.
Taking the text 200 of fig. 2 as an example, assuming that the first tag svg of the text 200 is the first tag 202, the first tag 202 may include a first tag start character 2022, and the first tag start character 2022 may be, for example, "<". In some embodiments, if the computer device 100 employs character-by-character recognition, after the computer device 100 sequentially recognizes the characters "<" and "s", since the character "s" conforms to the tag name of the tag (e.g., svg) in the tag naming specification, the character "<" opens a new tag, and thus the computer device 100 can determine that the character "<" is the beginning character of a tag, i.e., the first tag beginning character 2022.
When the computer device 100 recognizes the first tag start character 2022 of the first tag 202 in the text 200, a corresponding first scope may be initially created in the target object 300 for the first tag 202. Fig. 3C shows a schematic diagram of another exemplary target object 300, in accordance with an embodiment of the present disclosure. As shown in FIG. 3C, the computer device 100 may create a first scope 304 in the target object 300 for the first tag 202 for storing tag information of the first tag 202. In some embodiments, when creating the first scope 304, fields label, props, and _ child may also be added thereto, which are respectively used to record a character string corresponding to the tag name of the first tag 202, the attribute name and attribute value in the first tag 202, and the sub-tag information of the first tag 202.
It is assumed that the process of parsing is character-by-character parsing, but that the XML nodes (tags) have a hierarchical relationship (or parent-child relationship), and thus, in some embodiments, the computer device 100 may utilize a scope stack to store scope information, such that the stack is used to maintain the hierarchical relationship (or parent-child relationship) for each tag. The stack is initialized with a null array. FIG. 4A illustrates a schematic diagram of an exemplary scope stack 400, according to an embodiment of the present disclosure. As shown in FIG. 4A, in the initial state, the scope stack 400 is empty.
FIG. 4B illustrates a schematic diagram of another exemplary scope stack 400, according to an embodiment of the present disclosure. As shown in FIG. 4B, when the computer device 100 creates the first scope 304 in the target object 300, the information (e.g., 1) of the first scope is stored in the scope stack 400 accordingly. Thus, the computer apparatus 100 can know the information of the current scope by reading the information of the last stack of the scope stack 400 during the subsequent processing, and thus store the corresponding information into the corresponding scope in the target object 300.
Next, after identifying the first tag start character 2022, the computer device 100 may continue to identify characters in the text 200 that follow the first tag start character 2022.
Since the start character "<" is generally followed by a tag name, if the computer device 100 recognizes a first character or a first string 2024 that meets the tag naming specification after the first tag start character 2022, the first character or the first string 2024 may be stored in the first scope 304, which is the current scope, as the tag name of the first tag 202, e.g., the string svg in fig. 3C.
The computer device 100 may then proceed to identify the text 200, and when a character or string is identified in the text 200 that does not meet the tag naming convention, the character or string 2026 that meets the attribute naming convention (e.g., letters, numbers, or combinations thereof) may be stored in the first scope 304 as the attribute name of the first tag 202 as the current scope, and the character or string 2030 following the attribute assigning character 2028 may be stored in the first scope 304 as the attribute value of the first tag 202 as the current scope. As shown in FIG. 3C, the first scope 304 has an attribute name id and a corresponding attribute value 1213 recorded therein. In some embodiments, it is to be appreciated that attribute values are typically written within "" or "", and thus, the attribute assignment character 2028 may be a string, e.g., ", or" ". And, when the computer device 100 recognizes "or", the "or" internal character string may be recorded as an attribute value in the current scope.
Next, the computer device 100 continues to recognize the text 200, and as shown in connection with FIG. 2, before the tag end character is not recognized, a start character "<" (rather than an end character "<") may be further recognized, such that the second tag start character 2042 of the second tag 204 may be considered to be recognized.
At this time, as shown in fig. 4B, the computer apparatus 100 determines that the current scope (i.e., the first scope) already exists by reading the latest one of the information of the scope stack 400, and thus, can create the second scope 306, which is a sub-scope of the first scope 304, in the target object 300 according to the information. As shown in FIG. 3D, for example, a second scope 306 may be added in the field _ child of the first scope 304 to indicate that the second scope 306 is a child of the first scope 304 and that the second label 204 corresponding to the second scope 306 is a child of the first label 202 corresponding to the first scope 304.
The computer device 100 may then store the information (e.g., 2) of the second scope 306 in the scope stack 400 to cause the second scope 306 to replace the first scope 304 as the current scope, as shown in FIG. 4C. Because the information of the second scope 306 is stacked after the information of the first scope 304, the computer device 100 can determine that the second scope 306 is the current scope (and not the first scope 304) by reading the latest piece of information in the scope stack 400 after the information of the second scope 306 is stacked.
After creating second scope 306, computer device 100 may continue to recognize text 200. If a second character or a second string 2024 conforming to the tag naming convention is identified in the text 200, the computer device 100 may store the second character or the second string 2024 in the second scope 306 as the current scope, as the tag name of the second tag 204, for example, the character g in the second scope 306 of fig. 3D.
Then, if a character or character string that does not meet the tag naming convention is identified in the text 200, the computer device 100 may store the character or character string 2046 that meets the attribute naming convention in the second scope 306 as the current scope as the attribute name of the second tag 204, and store the character or character string 2050 after the attribute assignment character 2048 in the second scope 306 as the current scope as the attribute value of the second tag 204. As shown in fig. 3D, the second scope 306 has recorded therein an attribute name prop and a corresponding attribute value 013.
Next, the computer device 100 continues to recognize the text 200, and as illustrated in connection with fig. 2, a further start character "<" (rather than an end character "</") may be recognized before the tag end character is not recognized, and thus the third tag start character 2062 of the third tag 206 may be considered to be recognized.
At this time, as shown in fig. 4C, the computer apparatus 100 determines that the current scope (i.e., the second scope) already exists by reading the latest one of the information of the scope stack 400, and thus, a third scope 308, which is a sub-scope of the second scope 306, can be created in the target object 300 according to the information. As shown in FIG. 3E, for example, a third scope 308 may be added in the field _ child of the second scope 306 to indicate that the third scope 308 is a child of the second scope 306 and that the third label 206 corresponding to the third scope 308 is a child of the second label 204 corresponding to the second scope 306.
The computer device 100 may then store the information (e.g., 3) of the third scope 308 in the scope stack 400 to cause the third scope 308 to replace the second scope 306 as the current scope, as shown in FIG. 4D. Since the information of the third scope 308 is stacked after the information of the second scope 306, the computer device 100 can determine that the third scope 308 is the current scope (and not the first scope 304 or the second scope 306) by reading the latest one of the information in the scope stack 400 after the information of the third scope 308 is stacked.
After creating the third action field 308, the computer device 100 may continue to recognize the text 200, and store the recognized tag name, attribute name, and attribute value in the third action field 308, which is similar to the foregoing embodiment and will not be described herein again.
The computer device 100 may then recognize a tag end character (or string) "</". Since the current scope is the third scope 308, the tag end character is the third tag end character 2064 corresponding to the third tag 206. At this point, the information describing the third label 206 has been collected, and the information for the third scope may be popped (popped) from the scope stack 400, as shown in FIG. 4E. Thus, the current scope is changed from the third scope 308 to the second scope 306.
The computer device 100 may then proceed to recognize a tag end character (or string) "</". Since the current scope is the second scope 306, the tag end character is the second tag end character 2052 corresponding to the second tag 204. At this point, the information describing the second tab 204 has been collected, and the information for the second scope may be popped from the scope stack 400, as shown in FIG. 4F. Thus, the current scope is changed from the second scope 306 to the first scope 304 again.
Next, the computer device 100 may continue to recognize the text 200, and as illustrated in connection with fig. 2, may further recognize a start character "<" (rather than an end character "</") before the tag end character is not recognized again, and thus may consider the fourth tag start character 2082 of the fourth tag 208 to be recognized.
At this time, as shown in fig. 4F, the computer apparatus 100 determines that the current scope (i.e., the first scope) already exists by reading the latest one of the information of the scope stack 400, and thus, can create the fourth scope 310, which is a sub-scope of the first scope 304, in the target object 300 according to the information. As shown in FIG. 3F, for example, the fourth scope 310 may continue to be added in the field _ child of the first scope 304 to indicate that the fourth scope 310 is a child of the first scope 304 and that the fourth label 208 corresponding to the fourth scope 310 is a child of the first label 202 corresponding to the first scope 304.
The computer device 100 may then store the information (e.g., 4) of the fourth scope 310 in the scope stack 400 to cause the fourth scope 310 to replace the first scope 304 as the current scope, as shown in FIG. 4G. Since the information of the fourth scope 310 is stacked after the information of the first scope 304, the computer device 100 can determine that the fourth scope 310 is the current scope (and not the first scope 304) by reading the latest one of the information in the scope stack 400 after the information of the fourth scope 310 is stacked.
After creating the fourth scope 310, the computer device 100 may continue to recognize the text 200, and store the recognized tag name, attribute name, and attribute value in the fourth scope 310, which is similar to the foregoing embodiment and will not be described herein again.
Next, the computer device 100 may sequentially recognize the fourth tag end character 2084 of the fourth tag 208 and the first tag end character 2032 of the first tag 202, and may then sequentially pop the information of the fourth scope and the information of the first scope from the scope stack 400.
The computer device 100 may then determine that the scope stack 400 is empty, and may end the text conversion process. The final converted text is described in the target object 400, as shown in fig. 3F.
At this time, the image information described in the SVG text 200 can be acquired by reading the text recorded in the target object 400.
In some embodiments, the computer device 100 may cause WebGL to render the target object 400 by calling an API of WebGL, thereby obtaining an image corresponding to the SVG text 200.
Compared with the DOMParser that the SVG text is firstly analyzed into the DOM tree and then each child node information of the DOM tree is searched recursively, the SVG text 200 is traversed once in the process of analyzing the text 200 in the embodiment of the disclosure, so that the analysis efficiency is greatly improved, and the resource use is reduced.
In some embodiments, method support is provided in environments where SVG graphics cannot be rendered directly (e.g., WebGL) by converting SVG text to more generalized JSON formatted data. According to actual tests, for the same SVG text 200, it is assumed that the method of resolving the DOM tree by using the DOMParser and then traversing the DOM tree takes 100ms, the method of the embodiment of the present disclosure can complete text conversion only in about 10ms, and the efficiency is greatly improved. In addition, resources are greatly saved because a DOMParser tool is not needed and a DOM tree is not needed to be traversed.
It should be noted that the foregoing embodiment is only described with reference to the exemplary SVG text 200, and it can be understood that an actual SVG text may not only have four tags, but also may be limited to have a hierarchical relationship of three levels, and when the SVG text has more tags and more levels, based on the idea of the foregoing embodiment, corresponding parsing and processing may also be performed, and details are not described herein again.
Fig. 5 illustrates a flow diagram of an exemplary method 500 provided by an embodiment of the present disclosure.
The method 500 may be implemented by the computer device 100 of fig. 1 and may be used to convert text, for example, the SVG text 200 of fig. 2. As shown in fig. 5, the method 500 may specifically include the following steps.
At step 502, the computer device 100 may create a target object (e.g., the target object 300 of FIG. 3A) for saving text conversion results.
At step 504, in response to identifying the first tag (e.g., the first tag 202 of fig. 2) and the second tag (e.g., the second tag 204 of fig. 2) in the text, the computer device 100 may create a first scope (e.g., the first scope 304 of fig. 3C) and a second scope (e.g., the second scope 306 of fig. 3D) in the target object, which correspond to the first tag and the second tag, respectively, according to a hierarchical relationship between the first tag and the second tag. Wherein the second scope is a subdomain of the first scope, as shown in FIG. 3D.
In some embodiments, in response to identifying the first tag and the second tag in the text, creating a first scope and a second scope in the target object corresponding to the first tag and the second tag, respectively, according to a hierarchical relationship between the first tag and the second tag, includes:
storing information of the first scope and the second scope using a scope stack (e.g., scope stack 400 of FIG. 4A); wherein, the information of the first scope is stacked before the information of the second scope, as shown in fig. 4C; and
and determining the hierarchical relationship between the first label and the second label according to the information stored in the scope stack, for example, the information of the first scope corresponding to the first label is firstly stacked, so that the second label can be determined to be a sub-label of the first label according to the stacking sequence.
In some embodiments, in response to identifying the first tag and the second tag in the text, creating a first scope and a second scope in the target object corresponding to the first tag and the second tag, respectively, according to a hierarchical relationship between the first tag and the second tag, includes:
in response to identifying a first tag start character (e.g., character 2022 of FIG. 2) of the first tag in the text, creating the first scope in the target object and storing information of the first scope in the scope stack (e.g., "1" of FIG. 4B); and
in response to identifying a second tag start character (e.g., character 2042 of FIG. 2) of the second tag in the text and not identifying a first tag end character (e.g., character 2032 of FIG. 2) corresponding to the first tag start character, the second scope is created in the target object as a child scope of the first scope and information ("2" of FIG. 4C) of the second scope is stored in the scope stack.
At step 506, computer device 100 may store tag names, attribute names, and attribute values corresponding to the first tag and the second tag in the first scope and the second scope, respectively.
In some embodiments, storing tag names, attribute names, and attribute values corresponding to the first tag and the second tag in the first scope and the second scope, respectively, comprises:
after identifying the first tag start character and before identifying the second tag start character, in response to identifying a first character or a first character string (e.g., character string 2024 of FIG. 2) in the text that conforms to a tag naming specification, storing the first character or the first character string in the first scope as a tag name of the first tag; and
in response to identifying a character or string in the text that does not meet a tag naming specification, storing a character or string that meets a property naming specification (e.g., string 2026 of FIG. 2) in the first scope as the property name of the first tag, and storing a character or string (e.g., string 2030 of FIG. 2) following a property assignment character (e.g., character 2028 of FIG. 2) in the first scope as the property value of the first tag.
In some embodiments, storing tag names, attribute names, and attribute values corresponding to the first tag and the second tag in the first scope and the second scope, respectively, comprises:
after the second tag start character is identified and before other tag start characters and the second tag end character are not identified, in response to identifying a second character or a second string of characters (e.g., character 2044 of FIG. 2) in the text that conforms to a tag naming specification, storing the second character or the second string of characters in the second scope as a tag name for the second tag; and
in response to identifying a character or character string in the text that does not meet the tag naming specification, storing a character or character string that meets the attribute naming specification (e.g., character string 2046 of FIG. 2) in the second scope as the attribute name of the second tag, and storing a character or character string (e.g., character string 2050 of FIG. 2) following the attribute assignment character (e.g., character 2048 of FIG. 2) in the second scope as the attribute value of the second tag.
In some embodiments, the method 500, further comprises:
in response to identifying a second tag end character corresponding to the second tag start character in the text, popping information of the second scope from the scope stack; or
And in response to identifying a first label end character corresponding to the first label start character in the text, popping the information of the first scope from the scope stack.
In some embodiments, the text is SVG text and the target object is a JSON object.
In some embodiments, the method 500, further comprises: and rendering the target object by using WebGL.
It should be noted that the method of the embodiments of the present disclosure may be executed by a single device, such as a computer or a server. The method of the embodiment can also be applied to a distributed scene and completed by the mutual cooperation of a plurality of devices. In such a distributed scenario, one of the devices may only perform one or more steps of the method of the embodiments of the present disclosure, and the devices may interact with each other to complete the method.
It should be noted that the above describes some embodiments of the disclosure. Other embodiments are within the scope of the following claims. In some cases, the actions or steps recited in the claims may be performed in a different order than in the embodiments described above and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. In some embodiments, multitasking and parallel processing may also be possible or may be advantageous.
The embodiment of the disclosure also provides a device for detecting the frame rate. Fig. 6 illustrates a schematic diagram of an exemplary apparatus 600 provided by an embodiment of the present disclosure. The apparatus 600 may include the following structure.
A creation module 602 configured to: a target object for saving the conversion result is created.
A conversion module 604 configured to: in response to the first label and the second label being recognized in the text, creating a first scope and a second scope corresponding to the first label and the second label respectively in the target object according to a hierarchical relationship between the first label and the second label, wherein the second scope is a sub-scope of the first scope; and storing the tag names, the attribute names and the attribute values corresponding to the first tags and the second tags in the first scope and the second scope, respectively.
In some embodiments, the conversion module 604 is configured to: storing information of the first scope and the second scope using a scope stack; wherein the information of the first scope is stacked before the information of the second scope; and determining the hierarchical relationship between the first label and the second label according to the information stored by the scope stack.
In some embodiments, the conversion module 604 is configured to: in response to identifying a first tag start character of the first tag in the text, creating the first scope in the target object and storing information of the first scope in the scope stack; and in response to identifying a second tag start character of the second tag in the text and not identifying a first tag end character corresponding to the first tag start character, creating the second scope in the target object as a sub-scope of the first scope and storing information of the second scope in the scope stack.
In some embodiments, the conversion module 604 is configured to: in response to identifying a second tag end character corresponding to the second tag start character in the text, popping information of the second scope from the scope stack; or in response to identifying a first tag end character corresponding to the first tag start character in the text, popping the information of the first scope from the scope stack.
In some embodiments, the conversion module 604 is configured to: after identifying the first tag start character and before identifying the second tag start character, in response to identifying a first character or a first character string in the text that conforms to a tag naming specification, storing the first character or the first character string in the first scope as a tag name for the first tag; and in response to identifying a character or character string in the text that does not meet the tag naming specification, storing the character or character string that meets the attribute naming specification in the first scope as the attribute name of the first tag, and storing the character or character string after the attribute assignment character in the first scope as the attribute value of the first tag.
In some embodiments, the conversion module 604 is configured to: after the second tag start character is recognized and before other tag start characters and the second tag end character are not recognized, in response to a second character or a second character string conforming to a tag naming specification being recognized in the text, storing the second character or the second character string in the second scope as a tag name of the second tag; and in response to identifying a character or character string in the text that does not meet the tag naming specification, storing the character or character string that meets the attribute naming specification in the second scope as the attribute name of the second tag, and storing the character or character string after the attribute assignment character in the second scope as the attribute value of the second tag.
In some embodiments, the text is SVG text and the target object is a JSON object.
In some embodiments, the apparatus 600 further comprises a rendering module 606 configured to: and rendering the target object by using WebGL.
For convenience of description, the above devices are described as being divided into various modules by functions, and are described separately. Of course, the functionality of the various modules may be implemented in the same one or more software and/or hardware implementations of the present disclosure.
The apparatus of the foregoing embodiment is used to implement the corresponding method 500 in any of the foregoing embodiments, and has the beneficial effects of the corresponding method embodiment, which are not described herein again.
Based on the same inventive concept, the present disclosure also provides a non-transitory computer-readable storage medium storing computer instructions for causing a computer to perform the method 500 according to any of the above embodiments, corresponding to any of the above-described embodiment methods.
Computer-readable media of the present embodiments, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device.
The computer instructions stored in the storage medium of the foregoing embodiment are used to enable the computer to execute the method 500 described in any embodiment, and have the beneficial effects of the corresponding method embodiment, which are not described in detail herein.
The present disclosure also provides a computer program product comprising a computer program, corresponding to any of the embodiment methods 500 described above, based on the same inventive concept. In some embodiments, the computer program is executable by one or more processors to cause the processors to perform the method 500. Corresponding to the execution subject corresponding to each step in the embodiments of the method 500, the processor executing the corresponding step may be the corresponding execution subject.
The computer program product of the foregoing embodiment is used for enabling a processor to execute the method 500 according to any of the foregoing embodiments, and has the advantages of corresponding method embodiments, which are not described herein again.
Those of ordinary skill in the art will understand that: the discussion of any embodiment above is meant to be exemplary only, and is not intended to intimate that the scope of the disclosure, including the claims, is limited to these examples; within the idea of the present disclosure, also technical features in the above embodiments or in different embodiments may be combined, steps may be implemented in any order, and there are many other variations of the different aspects of the embodiments of the present disclosure as described above, which are not provided in detail for the sake of brevity.
In addition, well-known power/ground connections to Integrated Circuit (IC) chips and other components may or may not be shown within the provided figures for simplicity of illustration and discussion, and so as not to obscure the embodiments of the disclosure. Furthermore, devices may be shown in block diagram form in order to avoid obscuring embodiments of the present disclosure, and this also takes into account the fact that specifics with respect to implementation of such block diagram devices are highly dependent upon the platform within which the embodiments of the present disclosure are to be implemented (i.e., specifics should be well within purview of one skilled in the art). Where specific details (e.g., circuits) are set forth in order to describe example embodiments of the disclosure, it should be apparent to one skilled in the art that the embodiments of the disclosure can be practiced without, or with variation of, these specific details. Accordingly, the description is to be regarded as illustrative instead of restrictive.
While the present disclosure has been described in conjunction with specific embodiments thereof, many alternatives, modifications, and variations of these embodiments will be apparent to those of ordinary skill in the art in light of the foregoing description. For example, other memory architectures (e.g., dynamic ram (dram)) may use the discussed embodiments.
The disclosed embodiments are intended to embrace all such alternatives, modifications and variances which fall within the broad scope of the appended claims. Therefore, any omissions, modifications, equivalents, improvements, and the like that may be made within the spirit and principles of the embodiments of the disclosure are intended to be included within the scope of the disclosure.

Claims (12)

1. A method of converting text, wherein the text includes a first tag and a second tag that is a sub-tag of the first tag, the method comprising:
creating a target object for saving a text conversion result;
in response to the first label and the second label being recognized in the text, creating a first scope and a second scope corresponding to the first label and the second label respectively in the target object according to a hierarchical relationship between the first label and the second label, wherein the second scope is a sub-scope of the first scope; and
and storing the label names, the attribute names and the attribute values corresponding to the first labels and the second labels in the first scope and the second scope respectively.
2. The method of claim 1, wherein, in response to identifying the first tag and the second tag in the text, creating a first scope and a second scope in the target object corresponding to the first tag and the second tag, respectively, according to a hierarchical relationship between the first tag and the second tag, comprises:
storing information of the first scope and the second scope using a scope stack; wherein the information of the first scope is stacked before the information of the second scope; and
and determining the hierarchical relationship between the first label and the second label according to the information stored by the scope stack.
3. The method of claim 2, wherein, in response to identifying the first tag and the second tag in the text, creating a first scope and a second scope in the target object corresponding to the first tag and the second tag, respectively, according to a hierarchical relationship between the first tag and the second tag, comprises:
in response to identifying a first tag start character of the first tag in the text, creating the first scope in the target object and storing information of the first scope in the scope stack; and
in response to identifying a second tag start character of the second tag in the text and not identifying a first tag end character corresponding to the first tag start character, creating the second scope in the target object as a sub-scope of the first scope and storing information of the second scope in the scope stack.
4. The method of claim 3, further comprising:
in response to identifying a second tag end character corresponding to the second tag start character in the text, popping information of the second scope from the scope stack; or
And in response to identifying a first label end character corresponding to the first label start character in the text, popping the information of the first scope from the scope stack.
5. The method of claim 3, wherein storing the first and second tags in the first and second scopes, respectively, corresponding tag names, attribute names, and attribute values, comprises:
after identifying the first tag start character and before identifying the second tag start character, in response to identifying a first character or a first character string in the text that conforms to a tag naming specification, storing the first character or the first character string in the first scope as a tag name for the first tag; and
in response to identifying a character or character string in the text that does not meet a tag naming specification, storing the character or character string that meets an attribute naming specification in the first scope as an attribute name of the first tag, and storing a character or character string after an attribute assignment character in the first scope as an attribute value of the first tag.
6. The method of claim 5, wherein storing the first and second tags in the first and second scopes corresponding to tag names, attribute names, and attribute values, respectively, comprises:
after the second tag start character is recognized and before other tag start characters and the second tag end character are not recognized, in response to a second character or a second character string conforming to a tag naming specification being recognized in the text, storing the second character or the second character string in the second scope as a tag name of the second tag; and
and in response to identifying the character or character string which does not meet the label naming specification in the text, storing the character or character string which meets the attribute naming specification in the second action domain as the attribute name of the second label, and storing the character or character string after the attribute assignment character in the second action domain as the attribute value of the second label.
7. The method of any one of claims 1-6, wherein the text is SVG text and the target object is a JSON object.
8. The method of claim 7, further comprising:
and rendering the target object by using WebGL.
9. An apparatus for converting text, wherein the text includes a first tag and a second tag, the second tag being a sub-tag of the first tag, the apparatus comprising:
a creation module configured to: creating a target object for saving the conversion result;
a conversion module configured to:
in response to the first label and the second label being recognized in the text, creating a first scope and a second scope corresponding to the first label and the second label respectively in the target object according to a hierarchical relationship between the first label and the second label, wherein the second scope is a sub-scope of the first scope; and
and storing the label names, the attribute names and the attribute values corresponding to the first labels and the second labels in the first scope and the second scope respectively.
10. A computer device comprising one or more processors, memory; and one or more programs, wherein the one or more programs are stored in the memory and executed by the one or more processors, the programs comprising instructions for performing the method of any of claims 1-8.
11. A non-transitory computer-readable storage medium containing a computer program which, when executed by one or more processors, causes the processors to perform the method of any one of claims 1-8.
12. A computer program product comprising computer program instructions which, when run on a computer, cause the computer to perform the method of any one of claims 1-8.
CN202210233964.5A 2022-03-10 2022-03-10 Method for converting text and related equipment Pending CN114896946A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210233964.5A CN114896946A (en) 2022-03-10 2022-03-10 Method for converting text and related equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210233964.5A CN114896946A (en) 2022-03-10 2022-03-10 Method for converting text and related equipment

Publications (1)

Publication Number Publication Date
CN114896946A true CN114896946A (en) 2022-08-12

Family

ID=82715458

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210233964.5A Pending CN114896946A (en) 2022-03-10 2022-03-10 Method for converting text and related equipment

Country Status (1)

Country Link
CN (1) CN114896946A (en)

Similar Documents

Publication Publication Date Title
CN106919509B (en) Client generation method and device and electronic equipment
JP5671320B2 (en) Information processing apparatus, control method therefor, and program
CN106796525B (en) On-demand loading dynamic script language codes are to reduce memory use
CN106648569B (en) Target serialization realization method and device
CN111079944B (en) Transfer learning model interpretation realization method and device, electronic equipment and storage medium
CN112068911B (en) Electronic form generation method, device, system, equipment and medium
CN112597101A (en) Method and device for converting topological graph file into SVG file based on web front end
CN106776779B (en) Method for generating entity file by JSON data based on Mac platform
CN112667225A (en) Method, system, equipment and readable storage medium for prototype graph code conversion
CN111273903B (en) Webpage making method and device, computer equipment and computer storage medium
JP2005332146A (en) Device, program and method for generating dynamic content creation program
US20230153550A1 (en) Machine Translation Method and Apparatus, Device and Storage Medium
CN114896946A (en) Method for converting text and related equipment
CN112671671B (en) Third party flow identification method, device and equipment based on third party library
CN112651214B (en) Method for converting data table plaintext into binary ciphertext convenient for program to read
CN114722112A (en) Visual list data display method and device
CN111241346B (en) Object serialization method, device, machine-readable medium and system
CN113391806A (en) Method, device, equipment and readable medium for converting color codes
CN114722781A (en) Method and device for converting streaming document into OFD document
CN113176877A (en) Entity class generation method, device and storage medium
CN114707468A (en) Method for converting graphic format and related equipment
CN111880785A (en) Program code conversion method and device and electronic equipment
CN112650479A (en) Webpage CSS structure automatic generation method and storage medium
CN117075912B (en) Method for program language conversion, compiling method and related equipment
CN113296754B (en) Script language conversion method, editor, equipment and storage medium based on xml

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination