The present application is based on, and claims priority from, China Patent Application No. 201710287849.5, filed on Apr. 27, 2017, the disclosure of which is hereby incorporated by reference herein in its entirety.
The invention relates to the field of computers. More specifically, the present invention relates to a method and a device for processing natural language.
Software testing is used to determine whether a particular software application works as expected. Test techniques include, but are not limited to, the process of executing a program or application in a controlled environment. Such testing is conducted with the intent of finding errors, flaws, mistakes, etc. in the software application.
However, in the prior art, it is necessary to write a test case when performing a software test. A general test case consists of a plurality of test steps. Users cannot know whether the test case is written correctly when writing the test case. When the test case needs to be modified, the user has to modify all the steps involved in the test case.
Therefore, the process of generating test cases in the prior art is very tedious, time consuming and inefficient.
The following summary is illustrative only and is not intended to be limiting in any way. That is, the following summary is provided to introduce concepts, highlights, benefits and advantages of the novel and non-obvious techniques described herein. Select, not all, implementations are described further in the detailed description below. Thus, the following summary is not intended to identify essential features of the claimed subject matter, nor is it intended for use in determining the scope of the claimed subject matter.
A method and a device for processing natural language are provided.
In a preferred embodiment, a method for processing natural language is provided in the invention. The method is used in an electronic device, and comprises: receiving a natural language input from a user via a client device; determining whether the natural language input matches a rule in a database; translating the natural language input into an intermediate code corresponding to the natural language input when the natural language input matches the rule; and compiling the intermediate code and generating an operation script code corresponding to the intermediate code.
In a preferred embodiment, a device for processing natural language is provided in the invention. The device comprises a processor and a memory. The memory is coupled to the processor. The processor is configured to execute program codes stored in the memory to: receive a natural language input from a user via a client device; determine whether the natural language input matches a rule in a database; translate the natural language input into an intermediate code corresponding to the natural language input when the natural language input matches the rule; and compile the intermediate code and generate an operation script code corresponding to the intermediate code.
The accompanying drawings are included to provide a further understanding of the invention, and are incorporated in and constitute a part of the present invention. The drawings illustrate implementations of the invention and, together with the description, serve to explain the principles of the invention. It should be appreciated that the drawings are not necessarily to scale as some components may be shown out of proportion to the size in actual implementation in order to clearly illustrate the concept of the present invention.
Several exemplary embodiments of the present disclosure are described with reference to
Certain terms are used throughout the description and following claims to refer to particular components. As one skilled in the art will appreciate, manufacturers may refer to a component by different names. The description does not intend to distinguish between components that differ in name but not function. In the following description and in the claims, the terms “include” and “comprise” are used in an open-ended fashion, and thus should be interpreted to mean “include, but not limited to”. Also, the term “couple” is intended to mean either an indirect or direct electrical connection. Thus, if a first device is coupled to a second device, that connection may be through a direct electrical connection, or through an indirect electrical connection via other devices and connections. The term “application” as used herein is intended to encompass executable and non-executable software files, raw data, aggregated data, patches, and other code segments. The term “exemplary” means that the disclosed element or embodiment is only an example, and does not indicate any preference of user. Further, like numerals refer to like elements throughout the several views, and the articles “a” and “the” includes plural references, unless otherwise specified in the description.
As shown in
The client device 110 can provide client-side functionalities, such as user input and output processing and communications with the NLP server 120. The NLP server 120 can provide server-side functionalities for each client device 110.
The NLP server 120 can include one or more virtual assistant servers 122. As shown in
In some embodiments, the one or more processing modules 1262 can include various programs and instructions for performing various aspects of natural language processing. One or more databases 1264 may include various user data that can be accessed or referenced when performing various aspects of natural language processing, such as natural language inputs (words, sentences, etc.) entered by the user. The database 1264 may also store predefined rules, such as, the grammatical relations between the sentences. For example, the rule is used to define that a verb and a verb cannot be connected together, or whether the sentence conforms to the grammatical relations between the sentences and so on. Therefore, when the natural language input received by the NLP server 120 is “click enter”, the NLP server 120 determines that the natural language input does not conform to the rule since both “click” and “enter” are verbs. In another embodiment, the NLP server 120 may also use a language tool to check whether the syntax of the natural language input conforms to one of the rules.
The NLP server 120 may be implemented on one or more standalone data processing devices or a distributed network of computers. In some embodiments, the NLP server 120 may employ various virtual devices and/or services of third-party service providers (e.g., third-party cloud service providers) to provide the underlying computing resources and/or infrastructure resources of the NLP server 120.
In step S305, the NLP server receives a natural language input from a user via the client device. Next, in step S310, the NLP server determines whether the natural language input matches a rule in the database. When the NLP server determines that the natural language input does not match the rule in the database (“No” in step S310), in step S315, the NLP server displays an error message to notify the user.
When the NLP server determines that the natural language input matches the rule in the database (“Yes” in step S310), in step S320, the NLP server translates the natural language input to an intermediate code corresponding to the natural language input. For example, the NLP server may parse the natural language input (e.g., tagging part of speech, type dependence, coreference analysis, and/or entity recognition) to obtain a syntax tree corresponding to the natural language input. The NLP server translates the natural language input into the intermediate code according to the syntax tree and the data in the database. In step S325, the NLP server compiles the intermediate code and generates an operation script code corresponding to the intermediate code, wherein the operation script code can be executed in an Android operating system. In an embodiment, the operation script code can be an Easy Script. In another embodiment, the operation script code can have a variety of types for applying in the Android operating system.
In addition, when the NLP server receives the natural language input from the user via the client device, the NLP server may further predicts the next input by the user according to the existing natural language inputs stored in the database. In an embodiment, when the natural language input entered by the user via the client device is a single word, the NLP server may query whether at least one sentence including the word is stored in the database according to the word. As shown in
In another embodiment, when the natural language input entered by the user via the client device is a text composed of one or more sentences, the NLP server may query whether at least one sentence included in the text is stored in the database. The NLP server can calculate the probability of occurrence of each sentence when the sentences are stored in the database, and displays a first sentence with the highest probability to prompt the user. As shown in
In step S705, the NLP server receives a high-level instruction from the user via the client device. The NLP server extracts a high-level feature code and a content of the high-level instruction, wherein the high-level feature code includes an entity and an action. Next, in step S710, the NLP server queries whether the high-level feature code matches one of the rules related to the high-level feature code in the database, wherein the rules related to the high-level feature code can be used to extract entities and actions from the sentences. In another embodiment, the rules related to the high-level feature code may conform to the grammatical relations between the sentences. For example, the high-level feature code should include a verb and an object, or should include a subject, a predicate and an object. In addition, in step S710, the NLP server also checks whether the content of the high-level instruction matches a rule in the database. In an embodiment, the rule may be one of the rules of the natural language inputs. When the high-level feature code matches one of the rules related to the high-level feature code in the database and the content of the high-level instruction matches one of the rules in the database, in step S715, the NLP server stores the high-level instruction (such as the high-level feature code and the content of the high-level instruction) into the database.
For example,
In addition, the processor 124 in the NLP server 120 could execute the programs and instructions in the database 1264 to perform all of the above-described actions and steps or others described herein.
Therefore, the method and the device for processing the natural language provided by the present invention can help users to use the natural language which conforms to the grammatical relations, and can predict the next possible input entered by the user according to the existing natural language inputs so that the efficiency of processing the natural language can be further improved.
In addition, the various illustrative logical blocks, modules, and circuits described in connection with the aspects disclosed herein may be implemented within or performed by an integrated circuit (“IC”), an access terminal, or an access point. The IC may comprise a general purpose processor, a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or another programmable logic device, discrete gate or transistor logic, discrete hardware components, electrical components, optical components, mechanical components, or any combination thereof designed to perform the functions described herein, and may execute codes or instructions that reside within the IC, outside of the IC, or both. A general purpose processor may be a microprocessor, but in the alternative, the processor may be any processor, controller, microcontroller, or state machine. A processor may also be implemented as a combination of computing devices, e.g., a combination of a DSP and a microprocessor, a plurality of microprocessors, one or more microprocessors in conjunction with a DSP core, or any other such configuration.
It should be understood that any specific order or hierarchy of steps in any disclosed process is an example of a sample approach. It should be understood that the specific order or hierarchy of steps in the processes may be rearranged while remaining within the scope of the present invention. The accompanying method claims present elements of the various steps in a sample order, and are not meant to be limited to the specific order or hierarchy presented.
While the invention has been described by way of example and in terms of exemplary embodiment, it is to be understood that the invention is not limited thereto. Those who are skilled in this technology can still make various alterations and modifications without departing from the scope and spirit of this invention. Therefore, the scope of the present invention shall be defined and protected by the following claims and their equivalents.
Number | Date | Country | Kind |
---|---|---|---|
201710287849.5 | Apr 2017 | CN | national |