Splitting a string into substrings so that each string starts with a capital letter? - r

I have the following string:
dt <- "I feel the night explode When we're together Emotion overload In the heat of pleasure Take me I'm yours into your arms Never let me go Tonight I really need to know Tell it to my heart Tell me I'm the only one Is this really love or just a game Tell it to my heart I can feel my body rock Every time you call my name The passion's so complete It's never ending As long as I receive This message you're sending Body to body, soul to soul Always feel you near So say the words I long to hear Tell it to my heart Tell me I'm the only one Is this really love or just a game Tell it to my heart I can feel my body rock Every time you call my name Love...love on the run Breaking us down Though we keep holding on I don't want to lose No...I can't let you go... Tell it to my heart Tell me I'm the only one Is this really love or just a game Tell it to my heart I can feel my body rock Every time you call my name Tell it to my heart Tell me from the stars Tell it to my heart Tell it to my heart Tell me from the stars Tell it to my heart Never make it stop Oh take it to the heart Oh no no ah ah Tell it to my heart Tell me I'm the only one Is this really love or just a game Tell it to my heart I can feel my body rock Every time you call my name"
I tried
unlist(strsplit(dt, split = "[[:upper:]]"))
but it takes out the capital letters.
I want to split it so that each string starts with a capital letter. For example,
"I feel the night explode",
"When we're together",
"Emotion overload", etc.
Is there a way to split it like that? Thanks!

You need to make use of "lookarounds"
x <- "I feel the night explode When we're together Emotion overload In the heat of pleasure Take me I'm yours into your arms Never let me go Tonight I really need to know Tell it to my heart Tell me I'm the only one Is this really love or just a game Tell it to my heart I can feel my body rock Every time you call my name The passion's so complete It's never ending As long as I receive This message you're sending Body to body, soul to soul Always feel you near So say the words I long to hear Tell it to my heart Tell me I'm the only one Is this really love or just a game Tell it to my heart I can feel my body rock Every time you call my name Love...love on the run Breaking us down Though we keep holding on I don't want to lose No...I can't let you go... Tell it to my heart Tell me I'm the only one Is this really love or just a game Tell it to my heart I can feel my body rock Every time you call my name Tell it to my heart Tell me from the stars Tell it to my heart Tell it to my heart Tell me from the stars Tell it to my heart Never make it stop Oh take it to the heart Oh no no ah ah Tell it to my heart Tell me I'm the only one Is this really love or just a game Tell it to my heart I can feel my body rock Every time you call my name"
v <- unlist(strsplit(x, split = "(?=\\s[A-Z])", perl=TRUE))
v <- v[v!=" "]
head(v)
# [1] "I feel the night explode" "When we're together"
# [3] "Emotion overload" "In the heat of pleasure"
# [5] "Take me" "I'm yours into your arms"

ooh_yeah_baby_baby <- "I feel the night explode When we're together Emotion overload In the heat of pleasure Take me I'm yours into your arms Never let me go Tonight I really need to know Tell it to my heart Tell me I'm the only one Is this really love or just a game Tell it to my heart I can feel my body rock Every time you call my name The passion's so complete It's never ending As long as I receive This message you're sending Body to body, soul to soul Always feel you near So say the words I long to hear Tell it to my heart Tell me I'm the only one Is this really love or just a game Tell it to my heart I can feel my body rock Every time you call my name Love...love on the run Breaking us down Though we keep holding on I don't want to lose No...I can't let you go... Tell it to my heart Tell me I'm the only one Is this really love or just a game Tell it to my heart I can feel my body rock Every time you call my name Tell it to my heart Tell me from the stars Tell it to my heart Tell it to my heart Tell me from the stars Tell it to my heart Never make it stop Oh take it to the heart Oh no no ah ah Tell it to my heart Tell me I'm the only one Is this really love or just a game Tell it to my heart I can feel my body rock Every time you call my name"
unlist(stringr::str_split(ooh_yeah_baby_baby, "(?=\\p{Upper})"))[-1]

Related

Getting a simple reply from a character in Inform 7

I have a non-player character in an Inform 7 Interactive Fiction story that I would like to get a simple reply from. The character is a robot doctor. When you get on the exam table the robot doctor holds out a tongue depressor and asks you to say, "Ah." I would like the character to say something when the player types, "say ah" but so far it's not working.
Here is my code thus far:
The exam table is a supporter in the Med Bay. It is fixed in place and enterable.
In the Med Bay is a person called Auto-Doc.
After entering the exam table, say "A number of bright lights embedded in an overhead panel bathe you in a cold, white light. A panel in the wall opens and an auto-doc trundles forth on a three-wheeled base. Clutching a tongue depressor in its mechanical grip, a small speaker hidden within crackles with the words 'Say, ah.'"
After speaking in the presence of the Auto-Doc, say "Mmm. Mm-hmm. Very interesting."
The last line is causing the compiler to throw an error, but I am unable to figure out what to use. I've tried Instead of speaking, After telling the Auto-Doc something, After saying ah in the presence of the Auto-Doc, and so far nothing is working.
Any hints as to how I can get the Auto-Doc to say something after the player types "say ah"? I'd even be happy with the Auto-Doc replying the same way no matter what the player says.
Here's a handy tip: command ACTIONS while playing the game in the IDE to see the action name when you type commands.
>actions
Actions listing on.
>say ah
(to Auto-Doc)
[answering Auto-Doc that "ah"]
There is no reply.
[answering Auto-Doc that "ah" - succeeded]
>
So the rule you're looking for is:
Instead of answering Auto-Doc that "ah":
say "Mmm. Mm-hmm. Very interesting."
After some more research, I have discovered that the responses understood by Inform are yes, no, and sorry. So understand "ah" and "say ah" as saying yes. followed by Instead of saying yes in the presence of the Auto-Doc, say "Mmm. Mm-hmm. Very interesting." is one way to do it.
Here's what the code looks like now:
The exam table is a supporter in the Med Bay. It is fixed in place and enterable.
After entering the exam table, say "A number of LEDs embedded in the ceiling switch on, bathing you in a cold, white light. A panel in the wall opens and an auto-doc trundles forth on a three-wheeled base. Clutching a tongue depressor in its mechanical grip, a small speaker hidden within crackles with the words 'Say, ah.'"
In the Med Bay is a person called Auto-Doc.
Instead of saying yes in the presence of the Auto-Doc, say "Mmm. Mm-hmm. Very interesting."
Understand "ah" and "say ah" as saying yes when location is Med Bay.
Instead of saying no in the presence of the Auto-Doc, say "Hmm..."
This sets up two different non-committal responses for saying yes and no. Saying 'ah' is understood as saying yes, so the player gets a response.

How do I restrict pushing specific items through specific doors in Inform 7

I have a number of things I want to restrict from fitting through specific doors. So the chair is too big/heavy to carry but can be pushed through room to room in most cases. Except if the door is narrow. I can probably write specific code successfully to handle a specific case, but I want to handle this generically so I can have a number of bulky things and narrow doors.
The follow code functionally works, however the second noun ends up "nothing". I would like to use the name of the door in the direction of travel to respond to "push chair s" with the message "The chair is way too bulky to fit through the crack". Any ideas what I am doing wrong or another way of doing this?
A thing can be bulky. A thing is usually not bulky.
A bulky thing is usually pushable between rooms.
A door can be narrow. A door is usually not narrow.
A bulky, enterable supporter called the chair is in room1.
There is a narrow door called the crack. It is south of room1.
Before going with a bulky thing through a narrow door:
say "[The noun] is way too bulky to fit through [the second noun]." instead;
You can name the things in the rule preamble and use those names to print them in the rule.
Before going with a bulky thing (called the cargo) through a narrow door (called the obstacle):
say "[The cargo] is way too bulky to fit through [the obstacle]." instead.

Inform7: Working with properties of rooms

I'm very, very new to this language, and wrapping my head around "how to do things with stuff" is proving to be a very frustrating endeavor.
My goal here is to create a mechanic where certain rooms are dangerous, and become more dangerous the longer the player stays in them. If the player stays in a dangerous room for too long, a death scene is triggered.
I've got code that looks like this:
[The "danger rule"]
A room has a number called danger level. The danger level of a room is usually 0.
Definition: A room is dangerous if its danger level is 1 or more.
Definition: A room is deadly if its danger level is 9 or more.
Every turn (this is the increasing danger rule):
If the player is in a dangerous room:
Increase danger level by 1.
Every turn (this is the death by danger rule):
If the room is deadly:
do nothing.[Later...]
Every turn (this is the danger explanation rule):
say danger level.
[further down]
The Feeding Chamber is south of the dungeon."You enter a large, dimly lit room with straw on the floor, surrounded by various cages embedded in the wall.[line break]Blood spatters are all over the floor, and it looks as if there's been a fight recently". After going to the feeding chamber for the first time:
try looking;
say "It smells like grues around here. I would be careful if I were you..";
The Feeding Chamber has danger level 5.
I can't seem to figure out how to properly work with the "danger level of a room". The explanation rule I defined causes a runtime error when entering a dangerous room:
`*** Run-time problem P31: Attempt to use a property of the 'nothing' non-object: property danger level`
..And attempts to re-word the rule to something like the danger level of the room or the danger level of this room lead to perplexing compilation messages such as:
`In the sentence 'say the danger level of the room' , it looks as if you intend 'danger level of the room' to be a property, but 'a room' is not specific enough about who or what the owner is.`
What is the "right" way to reference properties of objects in this way?
The magic words here were "of the location". If we pretend that that this was another programming language for a moment, the way I was writing this was as if I was referring to a class "the room" rather than an instance of the class currently being referenced "the location".
The working rule is as follows:
Every turn while the player is in a dangerous room:
Increase danger level of the location by 1.
The trick is to give Inform enough information to know which particular thing you're referring to. The problematic sentence in the original question is perfectly valid english that a human could parse, but the computer needs a bit more help in determining what room we mean when we say "the room".

IE + overflow: hidden

I don't know is that an issue or bug, but when I use overflow: hidden, selecting the text and moving the cursor to the page bottom in IE, the page is scrolling (I tried IE9-IE11)! When I use Firefox/Opera/Chrome/Safari the page isn't scrolling... I have to use overflow: hidden, but it has an odd behavior in IE.
So, my question is: how can I avoid page scrolling in IE?
Use -ms-scroll-limit: 0 0 0 0; to prevent any scrolling whatsoever in IE 10+.
For older browsers you can write a workaround using JavaScript.
Example of CSS and JavaScript:
body {
overflow: hidden;
-ms-scroll-limit: 0 0 0 0;
}
window.onscroll = function (event) {
window.scrollTo(0, 0);
}
window.onscroll = function (event) {
window.scrollTo(0, 0);
}
body {
overflow: hidden;
-ms-scroll-limit: 0 0 0 0;
}
We choose to go to the moon in this decade and do the other things, not because they are easy, but because they are hard, because that goal will serve to organize and measure the best of our energies and skills, because that challenge is one that we are willing to accept, one we are unwilling to postpone, and one which we intend to win.
We choose to go to the moon in this decade and do the other things, not because they are easy, but because they are hard, because that goal will serve to organize and measure the best of our energies and skills, because that challenge is one that we are willing to accept, one we are unwilling to postpone, and one which we intend to win.
Never in all their history have men been able truly to conceive of the world as one: a single sphere, a globe, having the qualities of a globe, a round earth in which all the directions eventually meet, in which there is no center because every point, or none, is center — an equal earth which all men occupy as equals. The airman's earth, if free men make it, will be truly round: a globe in practice, not in theory.
What was most significant about the lunar voyage was not that man set foot on the Moon but that they set eye on the earth.
If you could see the earth illuminated when you were in a place as dark as night, it would look to you more splendid than the moon.
When I orbited the Earth in a spaceship, I saw for the first time how beautiful our planet is. Mankind, let us preserve and increase this beauty, and not destroy it!
Buy why, some say, the moon? Why choose this as our goal? And they may as well ask why climb the highest mountain?
Across the sea of space, the stars are other suns.
Many say exploration is part of our destiny, but it’s actually our duty to future generations and their quest to ensure the survival of the human species.
As we got further and further away, it [the Earth] diminished in size. Finally it shrank to the size of a marble, the most beautiful you can imagine. That beautiful, warm, living object looked so fragile, so delicate, that if you touched it with a finger it would crumble and fall apart. Seeing this has to change a man.
If you could see the earth illuminated when you were in a place as dark as night, it would look to you more splendid than the moon.
We have an infinite amount to learn both from nature and from each other
To go places and do things that have never been done before – that’s what living is all about.
Spaceflights cannot be stopped. This is not the work of any one man or even a group of men. It is a historical process which mankind is carrying out in accordance with the natural laws of human development.
Space, the final frontier. These are the voyages of the Starship Enterprise. Its five-year mission: to explore strange new worlds, to seek out new life and new civilizations, to boldly go where no man has gone before.
To be the first to enter the cosmos, to engage, single-handed, in an unprecedented duel with nature—could one dream of anything more?
We have an infinite amount to learn both from nature and from each other
Many say exploration is part of our destiny, but it’s actually our duty to future generations and their quest to ensure the survival of the human species.
NASA is not about the ‘Adventure of Human Space Exploration’…We won’t be doing it just to get out there in space – we’ll be doing it because the things we learn out there will be making life better for a lot of people who won’t be able to go.
Never in all their history have men been able truly to conceive of the world as one: a single sphere, a globe, having the qualities of a globe, a round earth in which all the directions eventually meet, in which there is no center because every point, or none, is center — an equal earth which all men occupy as equals. The airman's earth, if free men make it, will be truly round: a globe in practice, not in theory.
Where ignorance lurks, so too do the frontiers of discovery and imagination.
Astronomy compels the soul to look upward, and leads us from this world to another.
We have an infinite amount to learn both from nature and from each other
Curious that we spend more time congratulating people who have succeeded than encouraging people who have not.
Where ignorance lurks, so too do the frontiers of discovery and imagination.
Curious that we spend more time congratulating people who have succeeded than encouraging people who have not.
Where ignorance lurks, so too do the frontiers of discovery and imagination.
A Chinese tale tells of some men sent to harm a young girl who, upon seeing her beauty, become her protectors rather than her violators. That's how I felt seeing the Earth for the first time. I could not help but love and cherish her.
What was most significant about the lunar voyage was not that man set foot on the Moon but that they set eye on the earth.
That's one small step for [a] man, one giant leap for mankind.
(overflow: hidden is apparently inconsistent across browsers, but I do not know which browser does it right.)
Have you looked at the -ms-overflow-style property?
-ms-overflow-style: none;
More information available here: http://msdn.microsoft.com/en-us/library/ie/hh771902(v=vs.85).aspx
I have a solution for it but not sure that this is the right way or not but you can try it.
http://jsfiddle.net/b5DYf/1/
html{
position:fixed;
}

How do I make both "inside" and "south" go through a door in Inform 7?

Suppose we have:
The storm door is a closed door. It is south of the Garden and north of the Shed.
The following commands all work fine to go through the door from the Garden:
south
s
go through storm door
go through
enter door
However go in doesn't work:
>go in
You can't go that way.
and I can't find a reasonable way to make it work. The best I can do is this, which seems rather absurd:
Inside of the garden is Tumbolia. Outside of the shed is Tumbolia.
Instead of going to Tumbolia from the garden, try entering the storm door.
Instead of going to Tumbolia from the shed, try entering the storm door.
I think you could also do this:
The storm door is a closed door. It is south of the Garden and north of the Shed.
The Shed is inside from the Garden.
Instead of going inside from the Garden, try going south.
Instead of going outside from the Shed, try going north.
The best I was able to come up with was:
Instead of going nowhere in the Garden when the noun is inside, try entering the storm door.
Instead of exiting in the Shed, try entering the storm door.
With this wording, go in / go inside / in / inside all work when in the Garden, and go out / go outside / out / outside / leave / exit all work when in the Shed.
The asymmetry here is because out and go out are interpreted as exiting, a special action. (It is converted to going outside by “the convert exit into go out rule”, but only if there is actually a door or room in the “outside” direction.) Whereas in and go in are interpreted as going inside from the beginning; there is no handy generic entering action for us to use.
To make just plain enter work, add:
Rule for supplying a missing noun when entering in the Garden: now the noun is the storm door.

Resources