Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create exclamations for a particular sentence

I would like to create exclamations for a particular sentence using the java API?

e.g. It's surprising == Isn't it surprising!
e.g. It's cold == Isn't it cold!

Are there any vendors or tools which help you generate exclamations, provided you give a sentence (i.e. the left hand side in the above example). Note: The sentences will be provided by the user and we should be able to get the correct sentence.

I am not sure, if this needs to be tagged under other categories

EDIT1

Some more examples, I would like this to be as generic as possible

e.g. They're late == Aren't they late!
e.g. He looks tired == Doesn't he look tired!
e.g. That child is dirty == Isn't that child dirty!
e.g. It's hot == Isn't it hot!

like image 271
user339108 Avatar asked Jun 23 '10 11:06

user339108


People also ask

How do you write an exclamation sentence?

The exclamation mark (!), known informally as a bang or a shriek, is used at the end of a sentence or a short phrase which expresses very strong feeling. Here are some examples: What a lovely view you have here! That's fantastic!

What are the 5 examples of exclamation?

Easy Examples of Exclamatory Sentences You scared the life out of me! We won! This puzzle is driving me up the wall! You're adorable!

How do you change a sentence into an exclamation mark?

We change a sentence into an exclamatory sentence simply by using the exclamation mark at the end of the sentence or using WHAT or HOW at the beginning of the sentence when there is a noun, adjective, or adverb of manner after 'what' or 'how'.


2 Answers

Depending on how "smart" and "sophisticated" you want this to be, this can be either very hard or very easy problem. Here's a simple regex solution that is quite dumb:

    String[] sentences = {
        "It's surprising",
        "It's cold",
        "It's $*($&%!",
        "That is a hot coffee indeed..."
    };
    for (String sentence : sentences) {
        System.out.println(
            sentence.replaceAll("It's (.+)", "Isn't it $1!")
        );
    }

This prints (as seen on ideone.com):

Isn't it surprising!
Isn't it cold!
Isn't it $*($&%!!
That is a hot coffee indeed...
like image 143
polygenelubricants Avatar answered Oct 02 '22 07:10

polygenelubricants


I don't think you will get very far with simple regex constructions. The problem is that since you are obviously operating in the natural language domain there are many, many possibilities you have to take into consideration. How general does the solution have to be?

I know you said it something like this is possible with the Java API, but would using Prolog be an option? SWI-Prolog has a Java interface (JPL) and the problem you are describing would be much better solved in Prolog. Infact this is the kind of problem Prolog does best and is used in academia for. SWI-Prolog even includes a package for natural language processing (http://www.swi-prolog.org/pldoc/package/nlp.html). This is the best way I am aware of to handle a problem as yours.

Ofcourse I do not know how important this feature is to your product/project and using Prolog probably isn't an option, so your other option is to write a parser that would extract verb/noun etc and create a corresponding "sentence model" ( aka group of objects). Then you could transform this sentence model into another sentence model based on some rules, designed in an extensible way, so that when new cases pop-up ( and with such a wide domain they will) you can just add a new "rule" to your transformation.

This is indeed a non-trivial solution, but I can't imagine how a trivial solution might look like.

like image 41
BernardMarx Avatar answered Oct 02 '22 07:10

BernardMarx