I am working on a modified version of the example trivia game skill with Alexa. Certain words in the questions can't be pronounced properly so I would like to implement an SSML phoneme spelling for those words. However adding in the full pecan style command breaks the message as the code sees it as unbalancing brackets, but not enclosing it in quotations creates an unresolved regular expression. Does anyone have any recommendations how I can include it as x-sampa SSML while still keeping it as the currently implemented var? Here is an example of how it is currently breaking.
{
"Test question 1?": [
"Answer 1",
"<phoneme alphabet="x-sampa" ph="EksIlUs">Exilus</phoneme> Adapter",
"Answer 3",
"Answer 4"
]
},
Your problem is likely the fact that you're wrapping your SSML string in double quotes, but then also including non-escaped double quotes in the SSML itself. To solve this, try either replacing the quotes in the SSML with single quotes, or escaping them with the backslash character like this:
{
"Test question 1?": [
"Answer 1",
"<phoneme alphabet=\"x-sampa\" ph=\"EksIlUs\">Exilus</phoneme> Adapter",
"Answer 3",
"Answer 4"
]
},
If you look at the example Alexa skills which use SSML, you'll see that that's how they're handling quotes:
speechText = "That's not how knock knock jokes work! <break time=\"0.3s\" /> "
+ "Knock knock!";
Related
If I use a linebreak "\n" in flextable I get a soft return in word. This is intended and also stated in the documentation. But what if I really want a hard return? It would be no problem for me if the code for that was hacky. Couldn't find anything in the documentation.
Example:
flextable(data.frame(a = "Line one\nLine two"))
I want to extract all text in a string before a "\n" appears.
Test string:
string <- "Stack Overflow\nIs a great website for asking programming questions\nOther Info"
Solution extracts "Stack Overflow"
Bonus point if it grabs the first word of the string and the last word before the "\n"
Example:
string2 <- "Stack Overflow Dot Com\nIS a great website for asking programming questions\nOther Info"
Solution extracts "Stack Com"
Seems you want to have a solution with regexp, to answer your first question
/(.*)/
will match the whole string before your first end of line (\n)
regexp101 Test
To have the first and the last word matched on a one liner you can try
/([^ ]+).* (.*)$/
Probably someone can improve my answer to filter out this solution to match the first and last word before the first occurrence of newline.
regexp101 Test
Here is trick of using double gsub
> s
[1] "Stack Overflow\nIs a great website for asking programming questions\nOther Info"
[2] "Stack Overflow Dot Com\nIS a great website for asking programming questions\nOther Info"
> gsub("\\s.*\\s", " ", gsub("\n.*", "", s))
[1] "Stack Overflow" "Stack Com"
Regexp for first example click
^(?:([\w\s]+)\\n)
Regexp for second example click
^(?:(\w*\w\b)[\w\s]+\s(\w*\w\b)\\n)
I want to create a simple program that simply prints the phrase "Sample set [number]" repeatedly in a loop, but increasing by 1 each time. For example, the first print will return "Sample set 1" while the next should print "Sample set 2", then "Sample set 3" and so on, all the way until "Sample set 50". I'm new to R and am not sure how to go about doing this, can someone help me out here? This is for a personal project.
You'll want to use R's for-each construct
for (num in c(1:50)) {
paste("sample set", num, sep=" ")
}
You'll certainly need to get a handle on loops, but don't neglect learning to reason about your programs using functional techniques. R has a wide range of functionals that with a little effort outperform most loops and are much more elegant
This SonarQube rule checks that Quoted identifiers are not used.
But SQL syntax requires quotes when column alias is composed with a space.
Agree with the rule when developers create such variable:
"hello" VARCHAR2(42) := 'world';
but disagree for that:
Select myColA as "Column A",
myColB as "column B",
...
Sonar should not hit for alias in Select statement.
Correct ?
It seems reasonable. This improvement should be included in the next version of SonarPLSQL.
I have scraped some data and stored it in a data frame. Some rows contain unwanted information within square brackets. Example "[N] Team Name".
I want to keep just the part containing the team name, so first I use the code below to remove the brackets and any text contained within them
gsub( " *\\(.*?\\) *", "", x)
This leaves me with " Team Name" (notice the space before the T).
Now I am trying to remove the white space before the T using trimws or the method shown here, but it is not working
could someone please help me with removing the extra white space.
Note: if I write the string containing the space manually and apply trimws on it, it works. However when obtaining the string directly from the data frame it doesnt. Also when running the code snippet below (where df[1,1] is the same string retreived from the data frame), I get FALSE. This gives me reason to believe that the string in the data frame is not the same as the manually typed string.
" team name" == df[1,1]
You could try
gsub( "\\[[^]]*\\]\\W*", "", "[N] Team Name")
We can use
sub(".*\\]\\s+", "", x)
#[1] "Team Name"
Or just
sub("\\S+\\s+", "", x)
#[1] "Team Name"
data
x <- '[N] Team Name';
You should be able to remove the bracketed piece as well as any following whitespace with a single regex substitution. Your regex is correct as-is, and should successfully accomplish this. (Note: I've ignored the unexplained discrepancy between your use of parentheses vs. square brackets in your question. I've assumed square brackets for my answer.)
Strangely, this seems to be a case where the default regex engine is failing, but adding perl=T gets it working:
x <- '[N] Team Name';
gsub(' *\\[.*?\\] *','',x);
## [1] " Team Name"
gsub(perl=T,' *\\[.*?\\] *','',x);
## [1] "Team Name"
In the past I have run across cases where the default regex engine flakes out, but I have never encountered this with perl=T, so I suggest you use that. I really think there is something broken in the default regex implementation.