Edit: This has been completed. <<Download>>

I'm experimenting with sentence generators. Currently, I only have one definite sentence structure, which is:

article + adjective + noun + verb + preposition + article + adjective + noun

adding different structures would make my program a lot longer. The current program generates some grammatical/syntax errors. Here's the current code:

Code:

DelVar Z"-->Str9
Lbl 1
randInt(1,2->A
2->B
" the a ->Str8
For(C,1,A-1
1+inString(Str8," ",B->B
End
Str9+" "+sub(Str8,B,inString(Str8," ",B)-B->Str9
randInt(1,13->A
2->B
" beautiful new good old young great big tough small large black white little ->Str8
For(C,1,A-1
1+inString(Str8," ",B->B
End
Str9+" "+sub(Str8,B,inString(Str8," ",B)-B->Str9
randInt(1,28->A
2->B
" person man thing woman child guy family student group problem book room case game idea storm mountain cliff bridge valley grass space cave day life place river pond ->Str8   //see what I did there? ;)
For(C,1,A-1
1+inString(Str8," ",B->B
End
Str9+" "+sub(Str8,B,inString(Str8," ",B)-B->Str9
If Z:Stop
randInt(1,9->A
2->B
" went jumped ran walked swam flew moved looked rode ->Str8
For(C,1,A-1
1+inString(Str8," ",B->B
End
Str9+" "+sub(Str8,B,inString(Str8," ",B)-B->Str9
randInt(1,26->A
2->B
" aboard about above across along alongside amid among around atop behind below between by into near off on onto over past through to up under within ->Str8
For(C,1,A-1
1+inString(Str8," ",B->B
End
Str9+" "+sub(Str8,B,inString(Str8," ",B)-B->Str9
1->Z
Goto 1

and the sentence is stored in Str9.
Note: this is not optimized at all, so sorry about the repetition and stuff.

Some examples of what this code will generate:
- the big mountain jumped through the beautiful child
- the new group moved amid a great space
- a little mountain flew between a big man
- a big pond rode behind the beautiful idea
- the old group ran on the large pond

the generator is completely random, so if you happen to get something offensive or something then you can blame randInt(). Razz

Since I can't add every word in the dictionary, one of the things I am still wanting to add is the ability to teach the calculator words. so maybe a menu asking for what part of speech your new word is from, and then inputting your word.
Very cool. I'd like to see more sentence structures. Something that would generate something like: The mountain was cool or The air was dry or The pond was large.
CKH4 wrote:
Very cool. I'd like to see more sentence structures. Something that would generate something like: The mountain was cool or The air was dry or The pond was large.

I'll see what I can do. One of the hard parts is making the sentences make at least some sense (rather than having several completely random words in a string). As you can see, some of the example sentences don't logically make sense.

A good way to add different sentence structures might be asking the user to input a structure (which if they make it something grammatically incorrect, it won't fix that), but what do you guys think? What would be the best way to make this program more customizable?
oooo cool sounding project!
Sounds cool! I did my own dabbling in this when I made Nikky Simulator. In BASIC, you might be able to have lists coding sequences of parts of speech to create a sentence. If you wrote the program to grab words from corresponding word lists based on the numbers in the list, you could add different sentence structures simply by creating new lists. I did something similar in NikkySim, though my implementation (in C) took it a step further and had tables that could direct the program to randomly choose to branch to other tables, giving a wide range of sentence structure variations. The tables made the sentence generator flexible and easy to tweak without altering the code much. The code itself was fairly simple; it just read the instructions in the tables and did what they said, whether that be choosing words from particular lists or jumping to other tables.

Grammatical correctness is tricky, especially for complex sentences. IIRC my 68K BASIC prototype (using logic code instead of tables) was full of headache-inducing hacks for this; the final C version used a zillion different word lists (just look at the file list on the ticalc.org page) to get decent grammar. And this is English; I wouldn't want to try doing something like this in one of those languages with even more complex grammar rules and inflections. Wink

Logic is another matter entirely. I didn't even attempt to make NikkySim "logical"--I just considered incoherent (but gramatically valid) sayings a feature that made it more funny. Razz
Okay, sorry to tell you guys this, but... kind of some bad news. I was trying to fix the new code so that sub() and inString() would work properly and stuff, but I've been messing around with it for a long time and still couldn't get it to work. I had looked over the code several times to see what was going wrong but it was just too time consuming and annoying.

So... in a moment of rage... I deleted everything. yeah... I rage quit.

There are still some other nice ones out there though, so I guess you could try those.

EDIT: I have released the original code (from the 1st post) for this however, so you can find it here.
Really? Sad

Could you get it back with archive undeleter?
Unicorn wrote:
Really? Sad

Could you get it back with archive undeleter?

Yeah... pretty stupid. I just rage deleted it.

No, I don't think I will use archive undeleter. I think I will start fresh again trying to add to it and optimize it, later. It got a bit too confusing having the nests and using sub() and inString() over and over again. I was getting confused by my own code... xD
((sorry for the double post))

Okay, well after some thinking, here's the plan...(some things may change though) (as long as I don't rage quit again)
--User will be allowed to choose between the pre-determined set of vocab (which they can add to) along with the 1 pre-determined sentence structure, or they can choose to make their own set of vocab (which they can add to) and sentence structures.

--User can add to the vocab, by adding to the set of a certain part of speech (so if they wanted to add to the nouns, they would specify using a number or some other special character, then putting their word directly after it - and if they wanted to add multiple words at once, they would separate their words with spaces) edit: it may be better for them to choose a part of speech from a menu. also, the limit on this is that the user can only enter 1 word vocab, so if they want to add a vocab word that has multiple words in it, they can't. that would require some major adjustments... (i think)

--User can add different sentence structures, by putting the part of speech specifier characters in order. (i.e. doing "article + adjective + noun" would be "123") edit: it may be better if they choose them in order from a menu

--Also, the current program will be optimized so there is no repetition of code. Will be optimized so that all of the vocab is in one string, and the different parts of speech are separated by delimiters.
===========================================
Of course, it is mostly up to the user to make it as sensical as possible. So if they enter a sentence structure sequence that wouldn't make sense at all, that's their fault. If they have added a word that doesn't fit inside the part of speech set it's in, that's also their fault. (and so on)


If you have any suggestions on this please feel free to make a post! This is kind of just a rough idea...
Sound good! Maybe you should post your code more often ths time?
Unicorn wrote:
Sound good! Maybe you should post your code more often ths time?

Yep. If I encounter an annoying issue I'll be sure to post here rather than rage deleting the entire thing XD
Here's some of the code for the structure input, can anyone optimize it? It only takes number keys 1-8 (for the 9 parts of speech, excluding interjections).

Code:

" ->Str9
Repeat (K=105 and length(Str9)>1) or K=45
Repeat sum(Ans={72,73,82,83,84,92,93,94,105,45,23
getKey->K:End
If Ans!=105 and Ans!=45:Then
If Ans!=23 and length(Str9)<24:Then
iPart(Ans/10
K-65(Ans=7)-78(Ans=8)-91(Ans=9
Str9+sub("12345678",Ans,1->Str9
End
If K=23 and length(Str9)>1
sub(Str9,1,length(Str9)-1->Str9
Text(54,0,Str9+"   //3 spaces
End:End
Here is what I got:


Code:
" →Str9
Repeat K=10 or (K=11 and 1<length(Str9
Repeat Ans
  sum(cumSum(getKey={105,45,23,73,72,84,83,82,94,93,92
End
Ans→K
If Ans≤8 and 24>length(Str9
  Str9+sub("12345678",K,1→Str9
If K=9 and 1<length(Str9
  sub(Str9,1,length(Str9)-1→Str9
Text(54,0,Str9+"   
End


Keep in mind that the getKey codes for 23, 45, and 105 are returned as 9, 10, and 11, respectively.
v2.0 is here!

It's now customizable, as you can add vocab and sentence structures of your own. Some known bugs are that if you have at least 1 sentence structure but no vocab, or if one of the parts of speech included in your sentence structure does not have vocab in it, then trying to generate a new phrase will cause it to crash. Other than that, it works well! Please leave some feedback Very Happy

<<Download>>

If you would like to try to fix these bugs and/or try to optimize it, then feel free to Smile


Now back to BasicNote... Razz
Cool! I'll be sure to try this out when I find time...
Do you guys like it? Have you found any other bugs? I would love some feedback Very Happy

Travis wrote:
In BASIC, you might be able to have lists coding sequences of parts of speech to create a sentence. If you wrote the program to grab words from corresponding word lists based on the numbers in the list, you could add different sentence structures simply by creating new lists.

Ah, I see what you mean now. However, instead of creating new lists, the way I ended up doing it is having a string that holds all the different sentence structures, by having numbers 1-8 (in whatever order the user inputs them), and having each structure separated by a delimiter. My program selects a random structure out of all the ones you have, and then it adds words to the phrase, based off of what word category (part of speech) is next in the sentence structure it chose Smile Nice idea though!
Michael2_3B wrote:
Ah, I see what you mean now. However, instead of creating new lists, the way I ended up doing it is having a string that holds all the different sentence structures, by having numbers 1-8 (in whatever order the user inputs them), and having each structure separated by a delimiter. My program selects a random structure out of all the ones you have, and then it adds words to the phrase, based off of what word category (part of speech) is next in the sentence structure it chose Smile Nice idea though!


Cool, that's pretty much the same overall concept, just done in a slightly different way. Smile It's a nice way to generalize things and use the same section of code to extract a word from any part of speech, since they're all stored the same way.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement