AandP: Utilizing Prolog for converting between active sentence and passive sentence with three-steps conversion

Abstract: I introduce a simple but efficient method to solve one of the critical aspects of English grammar which is the relationship between active sentence and passive sentence. In fact, an active sentence and its corresponding passive sentence express the same meaning, but their structure is different. I utilized Prolog [4] along with Definite Clause Grammars (DCG) [5] for doing the conversion between active sentence and passive sentence. Some advanced techniques were also used such as Extra Arguments, Extra Goals, Lexicon, etc. I tried to solve a variety of cases of active and passive sentences such as 12 English tenses, modal verbs, negative form, etc. More details and my contributions will be presented in the following sections. The source code is available at https://github.com/tqtrunghnvn/ActiveAndPassive.

Language plays a vital role in the human life. A language is a structured system of communication BIBREF2. There are various language systems in the world with the estimated number being between 5,000 and 7,000 BIBREF3. Natural Language Processing (NLP) which we commonly hear is a subfield of linguistics. NLP aims to provide interactions between computers and human languages. The performance of NLP is evaluated by how computers can process and analyze large amounts of natural language data BIBREF4. In terms of language processing, we cannot but mention Computational Linguistics BIBREF5. Computational Linguistics is the scientific study of language from a computational perspective, and thus an interdisciplinary field, involving linguistics, computer science, mathematics, logic, cognitive science, and cognitive psychology.
One of the most useful tools for studying computational linguistics is Prolog programming language BIBREF0. Prolog is a logic programming language associated with artificial intelligence and computational linguistics. Prolog can help deal with issues related to not only logic puzzle (Cryptoarithmetic puzzles, Zebra Puzzle, etc.) but also natural language processing. In this work, I utilized Prolog along with Definite Clause Grammars (DCG) BIBREF1 to solve one of the critical aspects of English grammar, active sentence and passive sentence. DCG proves the efficiency in handling the grammar of the sentence. Basically, a sentence is built out of noun phrase and verb phrase, so the structure of sentence, noun phrase, and verb phrase will be both covered in this work.
In terms of English grammar, we have lots of content to solve as shown in Figure FIGREF1. For example, there are 12 tenses in English such as the simple past tense, the simple present tense, the perfect present tense, etc. We also have more than three types of conditional clause, more than three types of comparative clause, and so on. This work covers the contents of active sentence and passive sentence. For instance, if an active sentence is “a man buys an apple in the supermarket", its corresponding passive sentence will be “an apple is bought by a man in the supermarket". The basic rules for rewriting an active sentence to passive sentence are shown clearly in Figure FIGREF2.
As shown in Figure FIGREF2, basic rules are:
The object of the active sentence becomes the subject of the passive sentence;
The subject of the active sentence becomes the object of the passive sentence;
The finite form of the verb is changed to “to be + past participle".
As my best understanding so far, there are only a few works mentioning the problem of active sentence and passive sentence in terms of language processing and computational linguistics. The conversion between active sentence and passive sentence was early mentioned in BIBREF6 by using a transformation rule to express the relationship between active and passive sentences. According to this rule, a parse tree is produced to represent the deep structure and determine whether the given sentence is active or passive. Similarly, BIBREF7 also used a tree-to-tree mapping to represent the active/passive transformation rule. However, these works just stopped in introducing how to transform an active sentence to passive sentence and did not solve many cases of them. Actually, there are many cases of active and passive sentences, leading to extra rules for converting between them. It is not easy to handle all these cases, and this is the main challenge of this work. My contributions are shown as follows:
As far as I know, this may be the first work utilizing Prolog and DCG to solve a variety of cases of converting between active sentence and passive sentence such as 12 English tenses, modal verbs, negative form, etc.
I proposed a compact version of the representation of the sentence as shown in Figure FIGREF48 and Figure FIGREF50.
In order to deal with 12 tenses in English, I proposed an auxiliary-based solution (is presented in Section SECREF67) for dividing 12 tenses into 4 groups. This is a very nice solution that reduces the workload of defining DCG rules.
I also proposed a three-steps conversion (is presented in Section SECREF73) for doing the conversion between active sentence and passive sentence.
The main challenge of this work is how much it can handle cases. There are a variety of cases in terms of active sentence and passive sentence. The cases that I solved in this work are shown as follows.
The possibility of the conversion: the prerequisite to convert an active sentence to a passive sentence is that the active sentence must have the object. For instance:
The sentence “the man buys an apple" is converted to the passive form being “an apple is bought by the man";
However, the sentence “the man goes to school" cannot be converted to the passive form because of the lack of object.
The tenses of the sentence: there are 12 tenses in English such as simple present tense, continuous past tense, perfect present tense, perfect continuous future tense, etc. With each tense, there is a specific way for converting between active sentence and passive sentence. For example (from active form to passive form):
In the simple present tense: “the man buys an apple" is converted to “an apple is bought by the man";
In the perfect present tense: “the man has bought an apple" is converted to “an apple has been bought by the man".
This work handles all these 12 tenses.
The form of past participle: commonly, a verb is converted to past participle form by adding “ed" at the end (example: “add" becomes “added", “look" becomes “looked"). However, there are some exceptions such as “buy" becomes “bought", “see" becomes “seen", etc.
The case of negative sentence. For example, the negative form of “the man buys an apple" is “the man does not buy an apple", and the corresponding passive sentence is “an apple is not bought by the man".
The case of modal verb: modal verbs (also called modals, modal auxiliary verbs, modal auxiliaries) are special verbs which behave irregularly in English. They are different from normal verbs like “work", “play", “visit", etc. Modal verbs are always followed by an infinitive without “to". For example, the sentence “the boy should bring a pen to the class" is converted to the passive form being “a pen should be brought by the boy to the class" (Figure FIGREF2).
Moreover, this work also handles the cases of singular/plural, subject pronoun/object pronoun, etc. For instance, the pronoun “he" is used for the subject as “he" but is used for the object as “him".
The objective of this work is sentences: active sentence and passive sentence, so I need to determine the representation of both active sentence and passive sentence.
An active sentence is built out of a noun phrase and a verb phrase. Therefore basically, the representation of an active sentence is s(NP,VP). The noun phrase or verb phrase is built out of fundamental elements such as determiner, noun, adjective, verb, etc. Simply, the representation of fundamental elements are shown as follows:
Determiner: det(X). Example: det(a), det(an), det(the), etc.
Noun: n(X). Example: n(man), n(woman), n(apple), etc.
Pronoun: pro(X). Example: pro(he), pro(she), pro(him), etc.
Adjective: adj(X). Example: adj(small), adj(big), adj(beautiful), etc.
Verb: v(X). Example: v(play), v(like), v(love), etc.
Preposition: pre(X). Example: pre(on), pre(in), pre(by), etc.
Auxiliary verb: aux(X). Example: aux(do), aux(does), aux(is), aux(be), etc. Actually, there are three types of auxiliary verbs are used in this work. For example, the sentence “you will have been loving them" (perfect continuous future tense) has three auxiliary verbs are “will", “have", “been" which are determined by three predicates aux/5, aux1/4, aux2/4 as shown in the source code (convertible.pl), respectively.
Auxiliary verb for tense in the passive form: auxTense(X). There are three groups of auxTense:
Group 1: including only simple future tense: auxTense(be). Example: “an apple will be bought buy the man".
Group 2: consisting of continuous past tense, continuous present tense, continuous future tense, perfect continuous past tense, perfect continuous present tense, and perfect continuous future tense: auxTense(being). Example: “an apple was being bought by a man", “an apple will be being bought by him".
Group 3: including perfect past tense, perfect present tense, and perfect future tense: auxTense(been). Example: “an apple has been bought by the man", “an apple will have been bought by the man".
Modal verb: modal(X). Example: modal(should), modal(can), modal(may), etc.
Moreover, this work also uses pol(not) for the negative form and agent(by) for the passive form.
With a noun phrase, there are some ways to build the noun phrase such as:
A noun phrase is built out of a determiner and a noun, so its representation is np(DET,N). Example: noun phrase “the man" has the representation is np(det(the),n(man)).
A noun phrase is built out of pronoun such as “he", “she", “we", etc. In this case, the representation of the noun phrase is simply np(PRO). For example: np(pro(he)).
A noun phrase is built out of a determiner, adjectives, and a noun. In this case, the representation of the noun phrase is np(DET,ADJ,N). For example, the noun phrase “a small beautiful girl" has the representation is np(det(a),adi([small, beautiful]), n(girl)).
A noun phrase is built out of a noun phrase and a prepositional phrase. The representation of the noun phrase in this case is np(DET,N,PP), np(PRO,PP), or np(DET,ADJ,N,PP). For example, the noun phrase “a cat on the big table" has the representation is
np(det(a),n(cat),pp(pre(on),det(the),adj([big]),n(table))).
With a verb phrase, there are two ways to build the verb phrase:
A verb phrase is built out of a verb and a noun phrase. In this case, the presentation of the verb phrase is vp(V,NP). For example, the verb phrase “love a beautiful woman" has the representation is vp(v(love), np(det(a), adj([beautiful]), n(woman))).
A verb phrase is built out of only a verb, so its representation is simply vp(V). Example: vp(v(love)) or vp(v(eat)). In fact, as presented above, in order to be able to convert from an active sentence to a passive sentence, the active sentence has to have the object. Therefore, the case of verb phrase vp(V) will not be considered in this work.
After having the representation of noun phrase and verb phrase, the representation of the sentence could be obtained.
Originally, the active sentence “he buys an apple" has the representation is
s(np(pro(he)),vp(v(buys),np(det(an),n(apple)))).
However, as presented above, this work only considers the case of verb phrase vp(V,NP), so I proposed a compact version of the representation of the sentence as shown in Figure FIGREF48.
Therefore, the active sentence “he buys an apple" has the representation is
s(np(pro(he)), v(buys), np(det(an), n(apple))).
The passive sentence “an apple is bought by him" has the representation is
s(np(det(an), n(apple)), aux(is), v(bought), agent(by), np(pro(
him))).
As introduced in the DCG BIBREF1, the representation of the sentence is represented by “parse tree" as illustrated in Figure FIGREF48 (active sentence) and Figure FIGREF50 (passive sentence). Parse tree could be found with the help of advanced techniques like extra arguments and extra goals.
“Inference" is the conversion between a sentence and its representation, or even the conversion between an active sentence and a passive sentence:
Given a sentence, “inference" is the process of getting the representation of that sentence;
Given a representation of a sentence, “inference" is the process of getting that sentence.
The final purpose of this work is that:
Given an active sentence, we will get the respective passive sentence; and vice versa,
Given a passive sentence, we will get the respective active sentence.
User interacts with the program by posing the query with the form (Figure FIGREF56):
convert(ActiveS, ActiveRe, PassiveS, PassiveRe).
Where:
ActiveS: the active sentence represented by a list where each element of the list corresponds to each word of the sentence. Example: [he,buys,an,apple].
ActiveRe: the representation of the active sentence ActiveS.
Example: s(np(pro(he)),v(buys),np(det(an),n(apple))).
PassiveS: the passive sentence represented by a list where each element of the list corresponds to each word of the sentence. Example: [an,apple,is,bought,by,him].
PassiveRe: the representation of the passive sentence PassiveS. Example:
s(np(det(an),n(apple)),aux(is),v(bought),agent(by),np(pro(him))).
Input will be either ActiveS or PassiveS for the case of converting from an active sentence to a passive sentence and the case of converting from a passive sentence to an active sentence, respectively.
There are several cases of output:
If the input is ActiveS and it is able to convert to the passive sentence, the outputs will be ActiveRe, PassiveS, and PassiveRe.
If the input is PassiveS and it is able to convert to the active sentence, the outputs will be ActiveS, ActiveRe, and PassiveRe.
If the input is either ActiveS or PassiveS but it is not able to convert to passive/active sentence, the output will be ‘false’. There are some cases which cannot be converted:
ActiveS is the active sentence but is typed as a passive sentence;
PassiveS is the passive sentence but is typed as an active sentence;
ActiveS is an active sentence having no object. Example: the sentence “he goes" cannot be converted to the passive sentence.
Especially, we can pose the query with no input, and the program will generate all possible cases of the active sentence and passive sentence. Some examples to make user interaction more clear will be presented in Section SECREF4.
There are 12 tenses in English. Each tense has a specific structure for the sentence. If each tense is handled individually, it will be quite long and be not an optimal solution. Therefore, as my best observation, I found a solution which divides 12 English tenses into 4 groups (same color means same group) based on the number of auxiliary verbs in the active sentence. This solution is summarized in Figure FIGREF72, consisting of:
Group 1: the number of auxiliary verbs in the active sentence is equal to 0. This group consists of the simple past tense and the simple present tense;
Group 2: the number of auxiliary verbs in the active sentence is equal to 1. We have 5 tenses in this group, those are the simple future tense, the continuous past tense, the continuous present tense, the perfect past tense, and the perfect present tense;
Group 3: the number of auxiliary verbs in the active sentence is equal to 2. This group consists of the continuous future tense, the perfect future tense, the perfect continuous past tense, and the perfect continuous present tense;
Group 4: the number of auxiliary verbs in the active sentence is equal to 3. This group has only one tense which is the perfect continuous future tense.
As we can easily see in Figure FIGREF72, tenses in the same group has the same structure of representation. For example, DCG rules for active sentence and passive sentence of group 3 are implemented as follows.
The three-steps conversion consists of three steps:
From the input sentence fed as a list, the program first finds the representation of the sentence.
From the representation of active or passive sentence, the program then finds the representation of passive or active sentence, respectively.
From the representation achieved in the 2nd step, the program returns the converted sentence as a list.
The implementation of the three-steps conversion (written in convert.pl) is shown as follows.
The 1st and 3rd steps are done by using DCG rules (implemented in convertible.pl). The 2nd step is easily done by the rule like:
As you can see above, the 2nd step is easily done by doing the conversion between corresponding elements. More details for other groups are shown in convert.pl.
All implementations above are for the positive form of the sentence. The negative form of the sentence can be easily done by inheriting the rules that are defined for the positive form. DCG rule for the negative form is implemented as follows.
DCG rules for the negative form is almost similar to those of the positive form, except from pol/1 predicate. However, in the 2nd step for the negative form, it completely utilizes the rule for the positive form as follows.
However, there is an exception of the 2nd step for group 1, it needs an extra rule like:
As we can see above, the negative form of group 1 needs the extra rule lex(AUX_POL,pol,Tense
,Qs) because, in this negative form, an extra auxiliary verb is needed. For example, the positive sentence is “he buys an apple", but the corresponding negative sentence is “he does not buy an apple". Other implementations such as lexicon, modal verbs, etc. are carefully written in the source code.
This work has been already done with three files:
convertible.pl: implementing DCG rules for 1st and 3rd steps in the three-steps conversion, as well as other rules including lexicon.
convert.pl: implementing the three-steps conversion and its 2nd step.
testSuite.pl: providing commands for user interaction. Users do not need to type the input sentence as a list (like [the, man, buys, an, apple]) but can type the sentence in the common way (directly type: the man buys an apple) by using two commands: active and passive. Moreover, users can easily check the correctness of the program by using two test suite commands: activeTestSuite and passiveTestSuite.
Some execution examples are shown as follows.
It should be noted that if users use active or passive commands, everything they type has to be defined in the lexicon or users have to define them in the lexicon (implemented in convertible.pl).
I introduced an effort to solve the problem of active and passive sentences using Prolog in terms of computation linguistics. By observing the possibility of converting an active sentence to passive sentence, I proposed a compact version of the representation of the sentence (Figure FIGREF48 and Figure FIGREF50). I also introduced a solution called auxiliary-based solution (Section SECREF67) to deal with 12 tenses in English. The auxiliary-based solution helps to reduce the workload of defining DCG rules. Finally, I proposed the three-steps conversion (Section SECREF73) for converting between active sentence and passive sentence. In the future, this work should consider solving other cases of active and passive sentences as much as possible.

Figure and table captions:
Figure 1: A variety of stuff in English grammar
Figure 2: Basic rules for converting an active sentence to passive sentence
Figure 3: The compact version of the representation of the active sentence
Figure 4: The representation of the passive sentence
Figure 5: The scenario for user interaction
Figure 6: Auxiliary-based solution: the division of 12 tenses into 4 groups

Questions about this paper:
What DCGs are used?

Answers:
Author's own DCG rules are defined from scratch.