I'm creating a power shall scrip to run exe file with arguments. The list of args are constructed in a way that if value of the arg is empty or null, the parameter shall not be passed
Below is my script
$runnerCommand = " "
[string]$splitRun = "20:1"
[string]$maxTestWorkers = "777"
[string]$retryTimes = "9"
[string]$testFilterInXmlFormat = "<filter><cat>XX</cat></filter>"
#$runnerCommand += '--testDllPath ' + $testDllPath + " "
if ($splitRun){
$runnerCommand+= "--splitRun '$splitRun' "
}
if ($maxTestWorkers){
$runnerCommand+= "--maxTestWorkers '$maxTestWorkers' "
}
if ($retryTimes){
$runnerCommand+= "--retryTimes '$retryTimes' "
}
if ($testFilterInXmlFormat){
$runnerCommand+= "--testFilterInXmlFormat '$testFilterInXmlFormat' "
}
$cmdPath = "C:\AutoTests\TestAutomation.Runner\bin\Debug\TestAutomation.Runner.exe"
& $cmdPath --testDllPath C:/AutoTests/Build/TestAutomation.TestsGUI.dll $runnerCommand
It looks like that PowerShell do a 'new line' before $runnerCommand in the last line of code that results in not passing the args from $runnerCommand
Please suggest how to solve the problem.
I tried different approaches
You're currently passing all of the arguments as a single string. You should instead use an array with each argument as a separate element. I can't actually test this, but something like this should work:
[string]$splitRun = "20:1"
[string]$maxTestWorkers = "777"
[string]$retryTimes = "9"
[string]$testFilterInXmlFormat = "<filter><cat>XX</cat></filter>"
$runnerArgs = #(
'--testDllPath', 'C:/AutoTests/Build/TestAutomation.TestsGUI.dll'
if ($splitRun) {
'--splitRun', $splitRun
}
if ($maxTestWorkers) {
'--maxTestWorkers', $maxTestWorkers
}
if ($retryTimes) {
'--retryTimes', $retryTimes
}
if ($testFilterInXmlFormat) {
'--testFilterInXmlFormat', $testFilterInXmlFormat
}
)
$cmdPath = "C:\AutoTests\TestAutomation.Runner\bin\Debug\TestAutomation.Runner.exe"
& $cmdPath $runnerArgs
Note that PowerShell allows expressions, including if-expressions, inside the array sub-expression operator (#()).
Related
how would i implement the following javascript code snippet in powershell?
String.prototype.regexCount = function (pattern) {
if (pattern.flags.indexOf("g") < 0) {
pattern = new RegExp(pattern.source, pattern.flags + "g");
}
return (this.match(pattern) || []).length;
};
I'm thinking its something like this:
$regexCount = {
param(
$pattern
)
# ??????
if ($pattern.flags.indexOf("g") -lt 0) {
# ????
# $pattern = new RegExp(pattern.source, pattern.flags + "g");
$pattern = [regex]::new($pattern)
}
# ????
return ($this.match($pattern) || []).length;
}
I have almost the entire script converted into powershell except for this little nugget of code... Actually, i'm a little bit clueless when javascript starts creating lambda functions with regular expression objects...
for instance what's the significants of string.prototype.somename? wouldn't you just save the lambda to any variable name?
Using Update-TypeData, create a type-level ScriptMethod ETS member for the .NET string type (System.String):
Update-TypeData -TypeName System.String -MemberName RegexCount -MemberType ScriptMethod -Value {
param([regex] $Regex)
$Regex.Matches($this).Count
}
Now you can call the .RegexCount() method on any string instance, analogous to what your JavaScript code does.
Sample call:
'foo'.RegexCount('.') # -> 3
That is, 3 matches for regex . were found in the input string.
I'm trying to convert list result from tJava Component to json object.
Result from tjava component is below.
[{run_id=5d0753d58d93b71a1d12cc22_, parent_run_id=null, pipe_invoker=scheduled, path_id=shared, count=33, plex_path=null, invoker=abc.com, nested_pipeline=true, duration=355, start_time=2020-11-20T11:17:32.298000+00:00, lable=MP_SQS, state=Completed, key=57694b41ee, root_ruuid=2_ba32ea346}, {run_id=5bd4c6ea346, parent_run_id=null, pipe_invoker=scheduled, path_id=shared, count=33, plex_path=null, invoker=wwr.com, nested_pipeline=true, duration=355, start_time=2020-11-20T11:17:32.298000+00:00, lable=Summary_MP_SQS, state=Completed, key=55dfff4f, root_ruuid=1246d2-8bdc-1846}]
i tried using tConvertType, or in tMapper converting into String then replace all function multiple time and then storing result into json file but noting is working as expected.
End Expected result is json file from above result.
I don't think there is an easy way with a Talend component to do that (but I may be wrong :-) ) :
Put quotes on the keys/value
Replace "=" by ":"
But it can be done with regular Java code, here an example :
String input =
"[{run_id=1111, parent_run_id=null1, pipe_invoker=scheduled1, path_id=shared, count=33, plex_path=null}," +
" {run_id=2222, parent_run_id=null2, pipe_invoker=scheduled2, path_id=shared, count=33, plex_path=null}]";
StringBuilder output = new StringBuilder();
input = input.substring(2,input.length() - 2); // remove "[{" .... "}]"
output.append("[{");
String step1 [] = input.split("\\}, \\{"); // each record, split on "}, {"
int j = 1;
for (String record : step1) {
String step2 [] = record.split(","); // each key/value, split on ","
int i = 1;
for (String keyValue : step2) {
// key=value --> "key":"value"
output.append("\"" + keyValue.split("=")[0].trim() + "\":\"" + keyValue.split("=")[1].trim() + "\"");
if (i++ < step2.length ) {
output.append(",");
}
}
if (j++ < step1.length ) {
output.append("} , {");
}
}
output.append("}]");
/*
output :
[{"run_id":"1111","parent_run_id":"null1","pipe_invoker":"scheduled1","path_id":"shared","count":"33","plex_path":"null"} , {"run_id":"2222","parent_run_id":"null2","pipe_invoker":"scheduled2","path_id":"shared","count":"33","plex_path":"null"}]
*/
I am trying to replace the variable "ex" with it's string value(which it gets from subroutine "potatoex()" and put it in the definition of another variable "goodge",
not getting any syntax error but this seems to be not working out.
Please help.
sub potatoex {
my $potato="Junos: 17.4DCB";
if($potato = ~/"Junos: 17.4[a-zA-Z0-9_.]*"/) {
print "/var/home/smoketest/dhcpv6.pl.28709.log";
}
}
main :
{
my $ex= potatoex();
my $goodge= "Apurva $ex Arnav";
print $goodge;
}
CURRENT O/P : /var/home/smoketest/dhcpv6.pl.28709.logApurva 1 Arnav
EXPECTED O/P: Apurva /var/home/smoketest/dhcpv6.pl.28709.log Arnav
Thanks,
Apurva
You are printing from your subroutine instead of returning the value from it. Try using return in potatoex.
sub potatoex {
my $potato = q{Junos: 17.4DCB};
my $returnVal = '';
if( $potato =~ /Junos: 17\.4[a-zA-Z0-9_.]*/ ) {
$returnVal = q{/var/home/smoketest/dhcpv6.pl.28709.log};
}
$returnVal;
}
{
my $ex = potatoex();
my $goodge = qq{Apurva $ex Arnav};
print $goodge;
}
While you could use return in an if block above (instead of print), I instead decided to use a variable, which will always return either the value you are trying to or an empty string. You could explicitly state the return return returnVal;, but it isn't required as perl allows implicit returns (make note of this and figure out if it should fit in your best practices or not).
I am struggling with writing the correct rule which involves macros to identify organizations in a text.
To Identify Matrix Inc. in:
With it's rising share prices Matrix Inc. has come out a winner this quarter.
I am trying to check for words like Inc within the entity and thus defined a macros and rule as below:
$ORGANIZATION_TITLES = "/pharmaceuticals?|group|corp|corporation|international|co.?|inc.?|incorporated|holdings|motors|ventures|parters|llc|limited liability corporation|pvt.? ltd.?/"
ENV.defaults["stage"] = 1
{
ruleType: "tokens",
pattern: ([$ORGANIZATION_TITLES]),
action: ( Annotate($0, ner, "ORGANIZATION") )
}
ENV.defaults["stage"] = 2
{ ( [{tag:NNP}]+? ($ORGANIZATION_TITLES)) => ORGANIZATION }
I tried using bindings also and then applying the rule.
env.bind("$ORGANIZATION_TITLES", TokenSequencePattern.compile(env,"/pharmaceuticals?|group|corp|corporation|international|co.?|inc.?|incorporated|holdings|motors|ventures|parters|llc|limited liability corporation|pvt.? ltd.?/"));
Nothing seems to be working. I need to define more complex pattern rules involving macros like:
pattern: ( [ { ner:PERSON } ]+ /,/*? ($TITLES_CORPORATE_PREFIXES)*? $TITLES_CORPORATE+? /,/*? /of|for/? /,/*? [ { ner:ORGANIZATION } ]+ )
where $TITLES_CORPORATE_PREFIXES and $TITLES_CORPORATE are macros similar to $ORGANIZATION_TITLES.
What am I doing wrong?
EDIT
Here's my code:
public static void main(String[] args)
{
String rulesFile = "D:\\Workspace\\resource\\NERRulesFile.txt";
String dataFile = "D:\\Workspace\\resource\\GoldSetSentences.txt";
Properties props = new Properties();
props.put("annotators", "tokenize, ssplit, pos, lemma");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
// pipeline.addAnnotator(new TokensRegexAnnotator(rulesFile));
String inputText = "Bill Edelman , CEO and Chairman , for Paragonix commented on the Supply Agreement with Essential Pharmaceuticals .";
Annotation document = new Annotation(inputText.toLowerCase());
pipeline.annotate(document);
List<CoreMap> sentences = document.get(SentencesAnnotation.class);
CoreMapExpressionExtractor extractor = CoreMapExpressionExtractor.createExtractorFromFiles(TokenSequencePattern.getNewEnv(), rulesFile);
/* Next we can go over the annotated sentences and extract the annotated words,
Using the CoreLabel Object */
for (CoreMap sentence : sentences)
{
List<MatchedExpression> matched = extractor.extractExpressions(sentence);
for(MatchedExpression phrase : matched){
// Print out matched text and value
System.out.println("matched: " + phrase.getText() + " with value " + phrase.getValue());
// Print out token information
CoreMap cm = phrase.getAnnotation();
for (CoreLabel token : cm.get(TokensAnnotation.class))
{
String word = token.get(TextAnnotation.class);
String lemma = token.get(LemmaAnnotation.class);
String pos = token.get(PartOfSpeechAnnotation.class);
String ne = token.get(NamedEntityTagAnnotation.class);
System.out.println("matched token: " + "word="+word + ", lemma="+lemma + ", pos=" + pos + "ne=" + ne);
}
}
}
}
Here is a rules file that should work:
ner = { type: "CLASS", value: "edu.stanford.nlp.ling.CoreAnnotations$NamedEntityTagAnnotation" }
$ORGANIZATION_TITLES = "/inc\.|corp\./"
{ pattern: ([{pos: NNP}]+ $ORGANIZATION_TITLES), action: ( Annotate($0, ner, "RULE_FOUND_ORG") ) }
I have made some changes to our code base to make the TokensRegexAnnotator more easily accessible. You will need to get the latest version from GitHub: https://github.com/stanfordnlp/CoreNLP
java -Xmx8g edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators tokenize,ssplit,pos,lemma,ner,tokensregex -tokensregex.rules organization.rules -file samples.txt -outputFormat text -tokensregex.caseInsensitive
If you run this command or the equivalent Java API call it should work:
How to create an inline variable in the Play framework 2.x Scala template?
Path from the Play's guide is not clear to me:
#defining(user.firstName + " " + user.lastName) { fullName =>
<div>Hello #fullName</div>
}
First you don't create a variable but a value meaning it's read only.
In your example you have created a value fullName which is accessible inside the curly brackets.
#defining("Farmor") { fullName =>
<div>Hello #fullName</div>
}
Will print Hello Farmor
To define a value which is accessible globally in your template just embrace everything with your curly brackets.
E.g.
#defining("Value") { formId =>
#main("Title") {
#form(routes.Application.addPost, 'id -> formId) {
#inputText(name = "content", required = true)
<input type="submit" value="Create">
}
}
}
In the example you can use the value formId anywere.
If you don't want to use the #defining syntax you can define a reusable block which will be evaluated every time you use it:
#fullName = #{
user.firstName + " " + user.lastName
}
<div>Hello #fullName</div>
With this same syntax you can also pass arguments to the block:
https://github.com/playframework/Play20/blob/master/samples/scala/computer-database/app/views/list.scala.html
It's easy, span your block with code from the sample, then you will can use #fullName variable which has value:
user.firstName + " " + user.lastName