1

An ideal scenario would be something like this:

var sentence = SentenceFactory.Sentence("fox", "fence");
// sentence could be "The quick brown fox jumped over the fence."

Does anyone know if something similar exists?

If not, could you point me in a direction to write something similar myself? My knowledge of linguistics isn't very good.

The requirements are pretty low, it doesn't have to be clean english as long as it is a somewhat grammatically correct sentence.

Obviously the sentence should not be the same with just one word replaced everytime. Anyone can do string concatenation...

  • You say "a keyword" and then provide 2 of them. How many does it need to support? – Thomas Weller Nov 18 '15 at 15:36
  • string result = "Hey James, can you look up " + keyword + " in the dictionary for me?"; – Thomas Weller Nov 18 '15 at 15:37
  • This question is on-topic. Actually, I was a mentor for a Google Summer of Code project whose goal was to create a software similar to this. The user would give a few words, and it would retrieve sentences from an existing corpus. Peter, are you OK with sentences from a corpus, or do you need all sentences to be generated from scratch? – Nicolas Raoul Nov 19 '15 at 4:43
  • Peter, is Thomas' solution OK? It actually answers your question, handling several keywords separated with + " and " +. If it is not a valid answer, you must detail why. – Nicolas Raoul Nov 19 '15 at 5:03
  • @NicolasRaoul I'm definitely ok with retrieving sentences from an existing corpus! Do you know some software that can already do this? – Peter Nov 19 '15 at 8:22
1

There is a template language called Spintax. If you operate a website or handle email spam, you may have seen it in action.

The idea is: you provide a sentence template providing several options to choose from. The generator has a built-in randomizer and generates different sentences each time.

A short example that is used for spam:

I {couldn’t|could not} {resist|refrain from} commenting. 
{Very well|Perfectly|Well|Exceptionally well} written!

One of the possible outputs:

I could not refrain from commenting. Very well written!

Applied to the comment I gave earlier, you can write the template like

{Hi | Hey | Hello} {James|Andrew|Lisa}, {can|could} you {find|look up} $KEYWORD in the dictionary {|for me}?

Of course this approach will still take some time of manual work. You'll also want to first choose from different sentences first and then spin them. And you'd also need to replace the keyword later.

Another sentence:

I {know|am aware of} many English {words|terms} but {can't|cannot} get the meaning of $KEYWORD.

To me it seems the code you have already written before can be converted into Spintax.

I could not find a spintax library for C#, but there is a code example on Stack Overflow.

-1

Simple beginnings....

/// <summary>
/// Generates a random sentence. You can optionally provide a subject or verb
/// </summary>
/// <param name="subject">Use a specific verb in the sentence</param>
/// <param name="verb">Use a specific verb in the sentence</param>
/// <returns></returns>
public static string Sentence(string subject = null, string verb = null)
{
    var subjects = new string[] {"I", "You", "Bob", "John", "Sue", "Kate", "The lizard people"};
    var verbs = new string[]
    {
        "will search for", "will get", "will find", "attained", "found", "will start interacting with",
        "will accept", "accepted"
    };
    var objects = new string[] {"Billy", "an apple", "a Triforce", "the treasure", "a sheet of paper"};
    var endings = new string[] {".", ", right?", ".", ", like I said.", ".", ", just like your momma!"};

    var randomSubject = subject ?? subjects.Random();
    var randomVerb = verb ?? verbs.Random();

    return $"{randomSubject} {randomVerb} {objects.Random()} {endings.Random()}";
}
  • 1
    @downvoter: care to comment? – Peter Nov 19 '15 at 8:20
  • Possibly this was downvoted, because it's not a recommendation for a library (or some other software)? – svick Nov 21 '15 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.