ADF Dynamic Expression - concat/if missing period - azure

In what I would have thought was relatively simple code, I can't figure out what the issue is with adding another string to my list of concatenations
Below is the code that I currently have and I get expected output
#concat('start ', if(equals(coalesce(pipeline().parameters.p_source_object.TYPE,''),'x'), 'a', 'b'))
However, I want to add more strings to the concatenation but when I add a comma between the two end brackets like so
#concat('start ', if(equals(coalesce(pipeline().parameters.p_source_object.TYPE,''),'x'), 'a', 'b'), )
I get an "Invalid" error with "Missing period" message. If I put a period before the comma, the error goes away (but obviously invalid syntax)
What is it expecting here?
On a related note, is there a better way to concatenate while also doing some functions that output strings? It's the most unintuitive interface imaginable (Microsoft do seem to pride themselves in the ridiculous!)
Hoping someone can find my sanity for me!

In the end, I completely reworked it avoiding the layers... however, I have discovered a resolution
#{concat('start ', if(equals(coalesce(pipeline().parameters.p_source_object.TYPE,''),'x'), 'a', 'b'), 'dd')}
While it doesn't stand out as to how... there's a space at the start of the line, this stops it being considered "Dynamic content" but instead uses string interpolation

Related

is this code, right? if there is an error, could you guide?

i am a complete noob to programming and i got an assignment from the online course where I am learning, mine also gives the output, but it is not same as the instructor's method. This works for me and this method was easy for me.
but i am not sure is this the right method or had i done something wrong? could someone help?
I was not allowed to use choice()
**
import random
names_string = input("Give me everybody's names, separated by a comma. ")
names = names_string.split(", ")
a=len(names)
random_name=random.randint(0,a)
print(f"{names[random_name]} is going to pay the bill")
**
Welcome!
First of all you need to describe what exactly your problem and what is the problem you are facing.
It looks like you even have not tried to run that code. I will recommend an online interpreter to you to test your code on. You may use that
https://www.online-python.com/
Secondly "import" statement must be in lower case not "Import"
Finally the code works only incase of the string (names) is separated by a comma followed by space ", " same as the split string used. for example "a,b,c" is not going to work, but "a, b, c" does
random.randint(0,a) (a is included; may be returned) so it must be a-1 to avoid IndexError: list index out of range
Fixed code
import random
names_string = input("Give me everybody's names, separated by a comma. ")
names = names_string.split(", ")
a=len(names)
random_name=random.randint(0,a-1)
print(f"{names[random_name]} is going to pay the bill")
no, the code is not right.The error can be solved by replacing "Import" by "import".

Recursively extract contents of (nested) parentheses in string, replace selected content(s) down to a single (char+int), read again and repeat

This is my first post so please comment down if you need further clarification, Say we take in a string such as:
((((a).(5)).((a)*)).((b)*))*
and through the process, we perhaps count++ the amount of '(' read and count-- the amount of ')' read until we come across our first char or variable (we can consider other operators such as '.' or '|' or '*') that is the left and innermost content such that a is replaced so that our string now reads:
(((R1.(5)).((a)*)).((b)*))*
We must consider when a is selected, we also include its parenthesis as well but only consider the string that is read (perhaps store it in or as a vector, pointer, object, etc.), the same applies for when 5 which results in:
(((R1.R2).((a)*)).((b)*))*
at this moment we perhaps find now that the innermost content found is string (R1.R2) and
this results the string to be converted into R3 and having the string as:
((R3.((a)*)).((b)*))*
We continue the iteration for a to be read too.
((R3.(R4*)).((b)*))*
If a star * is read, we can consider extracting that content with R4 to be replaced as R5
((R3.R5).((b)*))*
Our next iteration follows:
((R3.R5).(R6*))*
((R3.R5).R7)*
(R8.R7)*
R9*
and finally as our final result,
R10
And we end.
I've already tried a variety of algorithms from several sources for hours yet I'm still stuck and puzzled at the same spot and I may not be thinking this through very properly as I had hoped.
The only closest that was modified was this:
https://www.geeksforgeeks.org/extract-substrings-between-any-pair-of-delimiters/
but I'm still puzzled about what must be properly implemented.
How would you make this possible? Any solutions or a straight post of your code could surely help me understand this process.

Way to find a number at the end of a string in Smalltalk

I have different commands my program is reading in (i.e., print, count, min, max, etc.). These words can also include a number at the end of them (i.e., print3, count1, min2, max6, etc.). I'm trying to figure out a way to extract the command and the number so that I can use both in my code.
I'm struggling to figure out a way to find the last element in the string in order to extract it, in Smalltalk.
You didn't told which incarnation of Smalltalk you use, so I will explain what I would do in Pharo, that is the one I'm familiar with.
As someone that is playing with Pharo a few months at most, I can tell you the sheer amount of classes and methods available can feel overpowering at first, but the environment actually makes easy to find things. For example, when you know the exact input and output you want, but doesn't know if a method already exists somewhere, or its name, the Finder actually allow you to search by giving a example. You can open it in the world menu, as shown bellow:
By default it seeks selectors (method names) matching your input terms:
But this default is not what we need right now, so you must change the option in the upper right box to "Examples", and type in the search field a example of the input, followed by the output you want, both separated by a ".". The input example I used was the string 'max6', followed by the desired result, the number 6. Pharo then gives me a list of methods that match that:
To get what would return us the text part, you can make a new search, changing the example output from number 6 to the string 'max':
Fortunately there is several built-in methods matching the description of your problem.
There are more elegant ways, I suppose, but you can make use of the fact that String>>#asNumber only parses the part it can recognize. So you can do
'print31' reversed asNumber asString reversed asNumber
to give you 31. That only works if there actually is a number at the end.
This is one of those cases where we can presume the input data has a specific form, ie, the only numbers appear at the end of the string, and you want all those numbers. In that case it's not too hard to do, really, just:
numText := 'Kalahari78' select: [ :each | each isDigit ].
num := numText asInteger. "78"
To get the rest of the string without the digits, you can just use this:
'Kalahari78' withoutTrailingDigits. "Kalahari"6
As some of the Pharo "OGs" pointed out, you can take a look at the String class (just type CMD-Return, type in String, hit Return) and you will find an amazing number of methods for all kinds of things. Usually you can get some ideas from those. But then there are times when you really just need an answer!

Python beginner has some problems with the spotipy search function

i am trying to set up a basic tool which is supposed to do following:
1. Search for Musicans in Spotify
2. Print results in a way i can use them for stuff (e.g. show output in a window or something like that)
Unfortunatly i cant wrap my head around following Problem:
import spotipy
import sys
from spotipy.oauth2 import SpotifyClientCredentials
client_credentials_manager = SpotifyClientCredentials(client_id='',
client_secret='')
spotify = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
result = spotify.search(q='Korn', limit=5)
for i, t in enumerate(result['tracks']['items']): # way i dont understand
print (' ', i, t['name'])
print(result) #way i would like to do it
The code can print a list in this enumerate fashion but isnt capable of printing it normally. The thing is I dont understand the way enumerate does this.
Can someone please give me some insights how the search function and enumerate work and maybe show me an elegant solution so i can print this list?
I don't know about the spotipy module so I'll have to assume a few things, based on what you said works or doesn't work.
So... your variable named 'result' seems to behave like a dictionary. You can index it with keys ('tracks', 'items'), (as shown there: result['tracks']['items']), and this seems to give you back stuff that behaves like a list containing stuff that behaves like a dictionary, that among other things contains the key 'name' (as shown there: t['name']).
To illustrate how enumerate works, here's an example:
>>> hello = ['h', 'e', 'l', 'l', 'o']
>>> print(list(enumerate(hello)))
[(0, 'h'), (1, 'e'), (2, 'l'), (3, 'l'), (4, 'o')]
It essentially gives you back tuples of each index in the list, and what is at that index.
Also note that Python has a principle called 'duck-typing'. It says that “If it looks like a duck and quacks like a duck, it must be a duck.”. That's why I don't worry to much about what type an object is, what I care about is what it behaves like.
Now, when you say something like:
for index, element in enumerate(elements):
You're using what's called unpacking. It lets you separate the tuples that enumerate gives you into two variables.
Then if we wanted to simply do print(result), the class that let you instantiate result would need to implement either the __repr__ or __str__ methods. In it, you would have all the logic that's contained in your for loop, grabbing the data at the appropriate keys in the dictionary-like object and returning a correctly formatted string. But it looks like this class comes from an external library, so I'm not sure it would be a good idea to implement these yourself (I don't have experience doing that yet).
Hope that my explanations were at least a little bit helpful.

How to represent a missing xsd:dateTime in RDF?

I have a dataset with data collected from a form that contains various date and value fields. Not all fields are mandatory so blanks are possible and
in many cases expected, like a DeathDate field for a patient who is still alive.
How do I best represent these blanks in the data?
I represent DeathDate using xsd:dateTime. Blanks or empty spaces are not allowed. All of these are flagged as invalid when validating using Jena RIOT:
foo:DeathDate_1
a foo:Deathdate ;
time:inXSDDatetime " "^^xsd:dateTime .
foo:DeathDate_2
a foo:Deathdate ;
time:inXSDDatetime ""^^xsd:dateTime .
foo:DeathDate_3
a foo:Deathdate ;
time:inXSDDatetime "--"^^xsd:dateTime .
I prefer to not omit the triple because I need to know if it was blank on the source versus a conversion error during construction of my RDF.
What is the best way to code these missing values?
You should represent this by just omitting the triple. That's the meaning of a triple that's "not present": it's information that is (currently) unknown.
Alternatively, you can choose to give it the value "unknown"^^xsd:string when there's no death date. The solution in this case is to not datatype it as an xsd:dateTime, but just as a simple string. It doesn't have to be a string of course, you could use any kind of "special" value for this, e.g. a boolean false - just as long as it's a valid literal value that you can distinguish from actual death dates. This will solve the parsing problem, but IMHO if you do this, you are setting yourself up for headaches in processing the data further down the line (because you will need to ask queries over this data, and they will have to take two different types of values into account, plus the possibility that the field is missing).
I prefer to not omit the triple because I need to know if it was blank
on the source versus a conversion error during construction of my RDF.
This sounds like an XY problem. If there are conversion errors, your application should signal that in another way, e.g. by logging an error. You shouldn't try to solve this by "corrupting" your data.

Resources